OpenIslet

scripts/verify_iip0051_htmpk_azt_switch_gate.py

Standalone Zero-LIMS-Touch Verifier & Executable Stage-0 Switch Evaluator for

script Release v0.8.0 gen-eb955f8266035aba 30 KB · 3 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0051_htmpk_azt_switch_gate.py · SHA-256: a2060242361d1b3d…

    gy2_synced = all(
        tok in gy2_blob
        for tok in ("IIP-0051", "GATE-33", "hTMPK-F105Y", "never a post-mitotic whole-graft erasability substitute", "23186165", "10390227", "15371631")
    )
    bp_synced = all(
        tok in bp
        for tok in ("IIP-0051", "GATE-33", "hTMPK-F105Y", "Design Y-FullStack v2", "D1b-Auto-C v2", "23186165")
    )
    dt_blk = dt.get(DECISION_TREE_KEY)
    dt_synced = isinstance(dt_blk, dict) and dt_blk.get("gate_id") == GATE_ID and dt_blk.get("contribution_id") == CONTRIBUTION_ID

    return {
        "playbook_has_tyms_postmitotic_caveat": "never a post-mitotic whole-graft erasability substitute" in pb,
        "gate0v_is_ap1903_panlineage_only_confirmed": ("AZT" not in g0v and "hTMPK" not in g0v),
        "gy002_severity_preserved": gy2.get("severity_level") == "BLOCK",
        "gy002_grid_entry_count": len(gy.get("graveyard_entries", [])),
        "offgrid_guardrail_count": len(gy.get("off_grid_molecular_dead_end_guardrails", {}).get("guardrails", [])),
        "gy002_iip0051_addendum_synced": gy2_synced,
        "blueprint_design_y_d_and_htmpk_synced": bp_synced,
        "decision_tree_gate33_block_synced": dt_synced,
    }


def build_verification_report(repo_root: Path) -> Dict[str, Any]:
    pin_checks: Dict[str, Dict[str, Any]] = {}
    for rel, expected in FROZEN_SHA256_PINS.items():
        actual = sha256_file(repo_root / rel)
        pin_checks[rel] = {
            "expected_sha256": expected,
            "actual_sha256": actual,
            "matched": actual == expected,
        }
        if actual != expected:
            raise RuntimeError(f"Frozen SHA-256 pin mismatch for {rel}: {actual} != {expected}")

    pb_sha = _extract_playbook_sec4120_sha256(repo_root / PLAYBOOK_REL)
    if pb_sha != EXPECTED_PLAYBOOK_SEC4120_SHA256:
        raise RuntimeError(f"Playbook sec 4.1.20 SHA-256 mismatch: {pb_sha} != {EXPECTED_PLAYBOOK_SEC4120_SHA256}")

    sc = load_strict_json_file(repo_root / SIDE_CONTRACT_REL)
    if sc.get("gate_id") != GATE_ID or sc.get("contribution_id") != CONTRIBUTION_ID:
        raise RuntimeError("Side contract gate_id/contribution_id mismatch")

    pk_anchors = compute_azt_pk_and_clonogenic_anchors()
    self_tests = run_gate33_decision_table_self_tests()
    audit = audit_playbook_gy002_and_blueprint_sync(repo_root)

    if not (
        audit["playbook_has_tyms_postmitotic_caveat"]
        and audit["gate0v_is_ap1903_panlineage_only_confirmed"]
        and audit["gy002_severity_preserved"]
        and audit["gy002_iip0051_addendum_synced"]
        and audit["blueprint_design_y_d_and_htmpk_synced"]
        and audit["decision_tree_gate33_block_synced"]
    ):
        raise RuntimeError(f"Audit check failed: {audit}")

    return {
        "schema_version": "iip0051_htmpk_azt_switch_verification_v0.8.0",
        "contribution_id": CONTRIBUTION_ID,
        "decision_id": DECISION_ID,
        "gate_id": GATE_ID,
        "gate_alias": GATE_ALIAS,
        "generated_date": GENERATED_DATE,
        "live_headline_delta_pp_today": 0.0,
        "zero_lims_touch_and_frozen_pins": {
            "all_pins_matched": True,
            "playbook_sec4120_sha256_matched": True,
            "pins": pin_checks,
        },
        "clinical_azt_pk_and_clonogenic_anchors": pk_anchors,
        "gate33_decision_table_self_tests": self_tests,
        "cross_document_and_graveyard_audit": audit,
        "all_checks_passed": True,
    }


def main(argv: Optional[List[str]] = None) -> int:
    parser = argparse.ArgumentParser(description="IIP-0051 / Gate 33 hTMPK-F105Y/AZT switch verifier and evaluator")
    parser.add_argument("--repo-root", type=Path, default=REPO_ROOT)
    parser.add_argument("--output", type=Path, default=None, help="Write deterministic verification JSON receipt")
    parser.add_argument("--check", action="store_true", help="Verify on-disk receipt matches recomputed output")
    parser.add_argument("--evaluate-azt-switch", type=Path, default=None, help="Evaluate a Stage-0 Gate 33 JSON payload")
    args = parser.parse_args(argv)

    if args.evaluate_azt_switch is not None:
        try:
            obs = load_strict_json_file(args.evaluate_azt_switch)
        except Exception as exc:
            err_out = {
                "gate_id": GATE_ID,
                "gate_alias": GATE_ALIAS,
                "verdict": "HOLD_INVALID_OR_MISSING_INPUT",
                "exit_code": 2,
                "chr13_backup_switch_qualified": False,
                "postmitotic_whole_graft_substitute_authorized": False,
                "primary_aavs1_icasp9_gate_unaffected": True,
                "reasons": [f"Strict JSON parse failure: {exc}"],
                "derived_summary": {},
            }
            print(json.dumps(err_out, indent=2, ensure_ascii=False))
            return 2
        res = evaluate_gate33_htmpk_azt_switch(obs)
        print(json.dumps(res, indent=2, ensure_ascii=False))
        return int(res["exit_code"])

    report = build_verification_report(args.repo_root)
    rendered = json.dumps(report, indent=2, ensure_ascii=False) + "\n"

    if args.output is not None:
        args.output.parent.mkdir(parents=True, exist_ok=True)
        args.output.write_text(rendered, encoding="utf-8")
        print(f"Wrote {args.output} (all_checks_passed={report['all_checks_passed']})")
        return 0

    if args.check:
        target = args.repo_root / VERIFICATION_REL
        if not target.is_file():
            print(f"ERROR: Missing receipt {target}", file=sys.stderr)
            return 1
        actual = target.read_text(encoding="utf-8")
        if actual != rendered:
            print(f"ERROR: On-disk receipt {target} drifts from recomputed output", file=sys.stderr)
            return 1
        print(
            f"PASS: {target.name} byte-exact | cmax={report['clinical_azt_pk_and_clonogenic_anchors']['human_300mg_cmax_alone_uM']} uM "
            f"| self_tests={report['gate33_decision_table_self_tests']['total_cases']}/{report['gate33_decision_table_self_tests']['total_cases']}"
        )
        return 0

    print(rendered)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())