from __future__ import annotations import argparse import hashlib import json import shutil from datetime import datetime, timezone from pathlib import Path from typing import Any SOURCE_REMOTE = "https://github.com/aws-samples/aws-mainframe-modernization-carddemo.git" SOURCE_HEAD = "59cc6c2fd7ebd7ef7925cad552a01a4b8b6e4d5e" BUNDLE_VERSION = "carddemo_hf_public_bundle_v0" DEFAULT_REPO_ID = "cjc0013/aws-carddemo-no-cost-modernization-proof" EXCLUDE_DIRS = {"__pycache__", ".dettools_backups", ".dettools_checkpoints", ".git", "final_proof", "reports"} EXCLUDE_SUFFIXES = {".pyc", ".sqlite", ".db", ".log"} FINAL_PROOF_FILES = [ "FINAL_PROOF_README.md", "FINAL_RECEIPT_SUMMARY.json", "REPRO_COMMANDS.txt", "STATIC_ORACLE_REPLAY_REPORT.json", "KNOWN_LIMITS.md", "ARTIFACT_MANIFEST.json", "A_GRADE_PROMOTION_REPORT.json", "A_GRADE_PROMOTION_README.md", "NO_COST_CONFIDENCE_REPORT.json", "NO_COST_CONFIDENCE_README.md", "CLEAN_REPRO_VERIFICATION.json", ] def read_json(path: Path) -> Any: return json.loads(path.read_text(encoding="utf-8")) def write_json(path: Path, payload: Any) -> None: path.parent.mkdir(parents=True, exist_ok=True) path.write_text(json.dumps(payload, indent=2, sort_keys=True, default=str) + "\n", encoding="utf-8") def write_text(path: Path, text: str) -> None: path.parent.mkdir(parents=True, exist_ok=True) path.write_text(text.strip() + "\n", encoding="utf-8") def sha256_path(path: Path) -> str: digest = hashlib.sha256() with path.open("rb") as handle: for chunk in iter(lambda: handle.read(1024 * 1024), b""): digest.update(chunk) return digest.hexdigest() def stable_hash(payload: Any) -> str: return hashlib.sha256(json.dumps(payload, sort_keys=True, default=str).encode("utf-8")).hexdigest() def clean_dir(path: Path) -> None: resolved = path.resolve() if resolved.anchor == str(resolved): raise ValueError(f"Refusing to clear drive root: {resolved}") if resolved.exists(): shutil.rmtree(resolved) resolved.mkdir(parents=True, exist_ok=True) def should_copy_modern_file(path: Path, modern_root: Path) -> bool: rel = path.resolve().relative_to(modern_root.resolve()) if any(part in EXCLUDE_DIRS for part in rel.parts): return False if path.suffix.lower() in EXCLUDE_SUFFIXES: return False if rel.parts and rel.parts[0].startswith(".dettools"): return False return path.is_file() def copy_tree_filtered(src_root: Path, dst_root: Path) -> list[dict[str, Any]]: copied = [] for path in sorted(src_root.rglob("*")): if not should_copy_modern_file(path, src_root): continue rel = path.resolve().relative_to(src_root.resolve()) target = dst_root / rel target.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(path, target) copied.append(file_record(target, dst_root)) return copied def file_record(path: Path, base: Path) -> dict[str, Any]: return { "path": str(path.resolve().relative_to(base.resolve())).replace("\\", "/"), "size_bytes": path.stat().st_size, "sha256": sha256_path(path), } def collect_files(root: Path) -> list[dict[str, Any]]: return [file_record(path, root) for path in sorted(root.rglob("*")) if path.is_file()] def copy_final_proof(modern_root: Path, bundle_root: Path) -> list[dict[str, Any]]: src = modern_root / "final_proof" dst = bundle_root / "final_proof" copied = [] for name in FINAL_PROOF_FILES: source = src / name if not source.exists(): continue target = dst / name target.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(source, target) copied.append(file_record(target, bundle_root)) return copied def build_readme(summary: dict[str, Any], no_cost: dict[str, Any], repo_id: str) -> str: no_cost_summary = no_cost["no_cost_confidence_summary"] coverage = no_cost["capability_coverage"] a_gate = summary["a_grade_promotion"] return f"""--- license: other language: - en tags: - mainframe-modernization - cobol - cics - static-analysis - verification - reproducibility - legacy-modernization pretty_name: AWS CardDemo No-Cost Modernization Proof --- # AWS CardDemo No-Cost Modernization Proof This repository publishes a reproducible proof bundle for a local modernization run against AWS CardDemo. It is intentionally **not** a claim of live COBOL/CICS all-path runtime equivalence. Plainly: this is not a claim of live COBOL/CICS all-path runtime equivalence. The practical claim is narrower and receipt-backed: we pushed the free/no-cost verification path as far as we reasonably could. The remaining validation requires a real or licensed-compatible legacy runtime for COBOL/CICS/VSAM/JCL execution. In short: without paid/licensed legacy runtime access, this is as far as this proof can honestly go. ## Headline Result - Reviewer posture: `{no_cost_summary['reviewer_posture']}` - Ready for pre-runtime review: `{no_cost_summary['ready_for_pre_runtime_review']}` - Current static/source-oracle parity: `B={summary['parity']['B']} / F={summary['parity']['F']} / gaps={summary['parity']['gap_count']}` - A-grade live runtime parity: `A={summary['parity']['grade_counts'].get('A', 0)}` - A-grade promotion gate: `{a_gate['decision_action']}` - A-grade live matches accepted: `{a_gate['accepted_live_matches']}` - A-grade live matches missing: `{a_gate['missing_live_matches']}` - Paid runtime used: `{no_cost['no_cost_scope']['paid_runtime_used']}` - Legacy runtime equivalence claimed: `{no_cost['no_cost_scope']['legacy_runtime_claim_made']}` ## Source Identity - Upstream source repo: `{SOURCE_REMOTE}` - Upstream source commit: `{SOURCE_HEAD}` - Source files hashed in receipt: `{summary['source']['source_hash_count']}` - Source hash digest: `{summary['source']['source_hashes_digest']}` The upstream AWS CardDemo source tree is **not copied into this repository**. Clone it from the upstream project at the exact commit above when reproducing. ## Evidence Included - `final_proof/FINAL_PROOF_README.md`: technical reviewer entry point. - `final_proof/FINAL_RECEIPT_SUMMARY.json`: machine-readable receipt summary. - `final_proof/NO_COST_CONFIDENCE_REPORT.json`: no-cost confidence evidence and methodology. - `final_proof/A_GRADE_PROMOTION_REPORT.json`: strict A-grade gate and why it does not promote without live traces. - `final_proof/STATIC_ORACLE_REPLAY_REPORT.json`: executable modern replay over static/source-derived oracles. - `METHODOLOGY.md`: evidence method and proof boundaries. - `REPRODUCIBILITY.md`: one-command local checks. - `DUE_DILIGENCE.md`: quick reviewer checklist. - `modern_code/`: modern Python/SQLite implementation snapshot and proof tooling. ## No-Cost Evidence Summary - Capability count: `{coverage['capability_count']}` - Static/source-oracle-ready capabilities: `{coverage['static_oracle_ready_count']}` - Capability source references: `{coverage['source_ref_total']}` - Golden traces: `{no_cost['fixture_corpus']['golden_trace_count']}` - Edge cases: `{no_cost['fixture_corpus']['edge_case_count']}` - COBOL programs scanned: `{no_cost['legacy_source_semantics_scan']['cobol_program_count']}` - CICS programs identified: `{no_cost['legacy_source_semantics_scan']['cics_program_count']}` - Free GnuCOBOL probe candidates: `{no_cost['legacy_source_semantics_scan']['free_gnucobol_probe_candidate_count']}` ## The Unpaid Boundary We cannot honestly push this to live runtime parity without access to a real or licensed-compatible legacy execution environment. That means one of: - AWS Mainframe Modernization runtime access, - Micro Focus / Enterprise Server-style runtime access, - UniKix or equivalent runtime access, - a real z/OS/CICS/VSAM/JCL endpoint, - or another compatible environment capable of executing the original legacy paths. Without that, the correct remaining statement is: the modernization is strongly supported by source-derived static oracles and executable modern replay, but final production-equivalence validation must happen on the legacy runtime owner’s environment. ## Repository Type This is published as a Hugging Face dataset-style proof artifact, not a trained model and not a hosted runtime. HF repo target used for staging: `{repo_id}` """ def build_methodology(summary: dict[str, Any], no_cost: dict[str, Any]) -> str: return f""" # Methodology ## Goal Produce the strongest practical modernization proof possible without paid or licensed legacy runtime infrastructure. ## Method 1. Pin the upstream AWS CardDemo source repository and commit. 2. Hash the source files and generated modern files. 3. Extract capabilities from legacy source, copybooks, BMS maps, JCL, seed data, and static contracts. 4. Build a one-for-one capability ledger. 5. Implement the modern Python/SQLite target against those source-derived contracts. 6. Generate receipts, golden traces, edge cases, and parity reports. 7. Execute the modern service against static/source-oracle replay checks. 8. Run clean-copy reproduction and API smoke checks. 9. Run a strict A-grade gate that refuses promotion without live legacy runtime traces. 10. Publish the evidence with explicit boundaries. ## Current Proof State - B-grade static/source-oracle capabilities: `{summary['parity']['B']}` - F-grade gaps: `{summary['parity']['F']}` - Gap count: `{summary['parity']['gap_count']}` - Static replay passed: `{summary['static_oracle_replay']['passed']}` - No-cost confidence posture: `{no_cost['no_cost_confidence_summary']['reviewer_posture']}` - A-grade promotable: `{summary['a_grade_promotion']['promotable_to_A']}` ## What Would Upgrade This To A The A-grade gate requires accepted live legacy runtime trace records for every capability. Each record must bind a capability ID to the pinned source head, a live runtime trace kind, a raw legacy trace hash, a modern observation hash, a comparator version, and `matched=true`. The current bundle has zero accepted live runtime matches because no paid/licensed legacy runtime was executed. """ def build_due_diligence(summary: dict[str, Any], repo_id: str) -> str: return f""" # Basic Due Diligence Clone this HF repository and inspect: 1. `README.md` 2. `final_proof/FINAL_PROOF_README.md` 3. `final_proof/NO_COST_CONFIDENCE_README.md` 4. `final_proof/A_GRADE_PROMOTION_README.md` Then clone the upstream AWS source next to `modern_code`: ```powershell git clone {SOURCE_REMOTE} source git -C source checkout {SOURCE_HEAD} ``` From `modern_code`, run: ```powershell python -m unittest discover -s tests python tools\\replay_static_oracles.py --source-root ..\\source --out-dir .\\reports --source-head {SOURCE_HEAD} python tools\\build_no_cost_confidence.py --source-root ..\\source --out-dir .\\final_proof python tools\\evaluate_a_grade_promotion.py --source-root ..\\source --out-dir .\\final_proof ``` Expected high-level result: - tests pass, - static replay returns `"passed": true`, - no-cost confidence returns `"reviewer_posture": "strong_pre_runtime_confidence"`, - A-grade gate returns `"promotable_to_A": false`. That last result is intentional: `{repo_id}` does not claim live COBOL/CICS runtime parity. """ def build_reproducibility(summary: dict[str, Any]) -> str: source_head = summary["source"]["head"] return f""" # Reproducibility This bundle is reproducible with no paid legacy runtime, but it still requires cloning the upstream AWS source at the pinned commit. ```powershell git clone {SOURCE_REMOTE} source git -C source checkout {source_head} cd modern_code powershell -NoProfile -Command "python -m carddemo.cli init-db --source-root ..\\source --db-path .\\carddemo.sqlite; python -m unittest discover -s tests; python tools\\generate_receipts.py --source-root ..\\source --db-path .\\carddemo.sqlite --out-dir .\\reports; python tools\\replay_static_oracles.py --source-root ..\\source --out-dir .\\reports --source-head {source_head}; python tools\\evaluate_a_grade_promotion.py --source-root ..\\source --out-dir .\\final_proof; python tools\\build_no_cost_confidence.py --source-root ..\\source --out-dir .\\final_proof; python tools\\package_final_proof.py --source-root ..\\source" ``` For clean-copy reproduction, run: ```powershell python tools\\verify_clean_repro.py --modern-root . --source-root ..\\source ``` """ def build_publication_notes() -> str: return """ # Publication Notes - This is a proof artifact, not a production migration recommendation. - The original AWS CardDemo source tree is not redistributed here. - The modern code snapshot is provided for review of the local modernization artifact. - The proof explicitly avoids claiming live COBOL/CICS equivalence. - The phrase "strong pre-runtime confidence" means the no-cost checks passed; it does not mean production acceptance. - Further proof requires paid/licensed or customer-owned legacy runtime access. """ def build_bundle(modern_root: Path, out_dir: Path, repo_id: str) -> dict[str, Any]: modern_root = modern_root.resolve() out_dir = out_dir.resolve() final_proof = modern_root / "final_proof" summary = read_json(final_proof / "FINAL_RECEIPT_SUMMARY.json") no_cost = read_json(final_proof / "NO_COST_CONFIDENCE_REPORT.json") clean_dir(out_dir) write_text(out_dir / "README.md", build_readme(summary, no_cost, repo_id)) write_text(out_dir / "METHODOLOGY.md", build_methodology(summary, no_cost)) write_text(out_dir / "DUE_DILIGENCE.md", build_due_diligence(summary, repo_id)) write_text(out_dir / "REPRODUCIBILITY.md", build_reproducibility(summary)) write_text(out_dir / "PUBLICATION_NOTES.md", build_publication_notes()) proof_files = copy_final_proof(modern_root, out_dir) modern_files = copy_tree_filtered(modern_root, out_dir / "modern_code") manifest = { "bundle_version": BUNDLE_VERSION, "generated_utc": datetime.now(timezone.utc).replace(microsecond=0).isoformat(), "hf_repo_id": repo_id, "source_repo": SOURCE_REMOTE, "source_head": SOURCE_HEAD, "claim_boundary": "No live COBOL/CICS all-path runtime equivalence is claimed.", "proof_summary": { "B": summary["parity"]["B"], "F": summary["parity"]["F"], "gaps": summary["parity"]["gap_count"], "no_cost_reviewer_posture": summary["no_cost_confidence"]["reviewer_posture"], "a_promotable": summary["a_grade_promotion"]["promotable_to_A"], }, "proof_file_count": len(proof_files), "modern_snapshot_file_count": len(modern_files), "files": collect_files(out_dir), "public_safe_checks": { "original_source_tree_copied": False, "paid_runtime_claim_made": False, "live_runtime_equivalence_claim_made": False, }, } manifest["manifest_hash"] = stable_hash(manifest) write_json(out_dir / "HF_PUBLICATION_MANIFEST.json", manifest) manifest["files"] = collect_files(out_dir) manifest["manifest_hash"] = stable_hash(manifest) write_json(out_dir / "HF_PUBLICATION_MANIFEST.json", manifest) return manifest def main() -> None: parser = argparse.ArgumentParser(description="Build HF-ready public proof bundle") parser.add_argument("--modern-root", type=Path, default=Path(__file__).resolve().parents[1]) parser.add_argument("--out-dir", type=Path, required=True) parser.add_argument("--repo-id", default=DEFAULT_REPO_ID) args = parser.parse_args() manifest = build_bundle(args.modern_root, args.out_dir, args.repo_id) print( json.dumps( { "out_dir": str(args.out_dir.resolve()), "hf_repo_id": args.repo_id, "file_count": len(manifest["files"]), "manifest_hash": manifest["manifest_hash"], "proof_summary": manifest["proof_summary"], }, indent=2, sort_keys=True, ) ) if __name__ == "__main__": main()