and ins_gate["governed_kit_catalog_allowlist_enforced"] is True and ins_gate.get("canonical_donor_id_grammar") == CANONICAL_DONOR_ID_PATTERN and ins_gate.get("canonical_donor_id_ascii_nfkc_no_czm_required") is True and ins_gate.get("canonical_donor_id_casefold_and_separator_deduplication_required") is True and ins_gate.get("canonical_donor_id_equivalence_order") == CANONICAL_DONOR_EQUIVALENCE_ORDER and ins_gate.get("inconsistent_donor_id_formatting_fail_code") == "INS_INCONSISTENT_DONOR_ID_FORMATTING_VARIANT" and ins_gate.get("shared_donor_issuer_identity_across_rosters_required") is True and ins_gate.get("positive_canonical_issuer_required_every_present_roster_form") is True and ins_gate.get("none_equals_none_issuer_equivalence_prohibited") is True and ins_gate.get("omitted_archived_issuer_decision") == "HOLD" and ins_gate.get("omitted_archived_issuer_hold_code") == "HOLD_MISSING_ARCHIVED_HLA_REGISTRY_ISSUER" and ins_gate.get("omitted_current_issuer_vs_archived_fail_code") == "INS_MISSING_CURRENT_HLA_REGISTRY_ISSUER" and ins_gate.get("official_statistics_strictly_authenticated_archive_only") is True and ins_gate.get("null_official_statistics_on_unverified_hold_or_internal_conflict") is True and ins_gate.get("archive_completeness_required_before_official_statistics") is True and ins_gate.get("caller_statistics_isolated_in_unverified_fields") is True and ins_gate.get("fail_verdict_never_emits_hold_derivation_source") is True and set(ins_gate.get("ins_statistics_derivation_sources", [])) == set(INS_STATISTICS_DERIVATION_SOURCES), "Side contract Round-13 INS canonical donor ID, mandatory positive roster issuer, FAIL-vs-HOLD source discipline, & complete archive-only official statistics gate mismatch", ) cuff_gate = sc_obj["executable_gate_34_subgates"]["Gate_34_CUFF_V2_DISULFIDE_C5B9"] require_cond( cuff_gate["gy025_min_exact_stack_efferocytosis_abs_pct"] == 80.0 and cuff_gate["gy025_min_exact_stack_efferocytosis_pct_of_wt"] == 70.0 and cuff_gate["gy025_min_exact_stack_pericyte_recruitment_pct_of_wt"] == 70.0, "Side contract Round-5 Cuff GY-025 exact-stack efferocytosis/pericyte mismatch", ) iv_gate = sc_obj["executable_gate_34_subgates"]["Gate_34_INVVAX_RECALL"] require_cond(iv_gate["required_administration_count"] == 3 and iv_gate["distinct_matrix_assay_registries_required"] is True, "Side contract Round-5 InvVax 3-dose/matrix registry mismatch") for tok in ( "off_target_kd_l95_um", "15,000", "0.10", "4.00", "K562", "7AL7", "efferocytosis", "pericyte", "lymph_node_assay_id", "v2_round5_unified", "viral-receptor-avoidance", "CONFLICTING_TRUSTED_STORE_INDEX_ALIASES", "Product-of-Caps", CANONICAL_DONOR_ID_PATTERN, "INS_NONCANONICAL_DONOR_ID_REJECTED", "INS_INCONSISTENT_DONOR_ID_FORMATTING_VARIANT", "donor_issuer_id", "hla_registry_issuer", "HOLD_MISSING_ARCHIVED_HLA_REGISTRY_ISSUER", "INS_MISSING_CURRENT_HLA_REGISTRY_ISSUER", "AUTHENTICATED_ARCHIVE_ROSTER_VERIFIED", "AUTHENTICATED_ARCHIVE_ONLY_CALLER_CONFLICT", "UNVERIFIED_HOLD_NO_AUTHENTICATED_ARCHIVE", "UNVERIFIED_HOLD_MISSING_ARCHIVED_ISSUER", "UNVERIFIED_HOLD_INCOMPLETE_ARCHIVE", "WITHHELD_NO_AUTHENTICATED_ARCHIVE_WITH_INDEPENDENT_FAIL", "WITHHELD_INCOMPLETE_ARCHIVE_WITH_INDEPENDENT_FAIL", "WITHHELD_INTERNAL_ARCHIVE_CONFLICT", "caller_reported_unverified_u95_pct", "GATE-36-SHIELD", "GATE-36-INS", "GATE-36-CUFF", "GATE-36-INVVAX", "PASS_DEBRIS_RECALL_FULL_CREDIT", "HOLD_MISSING_LIVE_GATE32_WHOLE_DEBRIS_RECALL", "HOLD_PARTIAL_EPITOPE_COVERAGE_GRADED_CAP", "Test 2B", "Test 2A", "Test 3", "Test 1", "GY-032", ): require_cond(tok in proto_text, f"GATE-36 protocol missing mandatory Round-14 term: {tok}") require_cond("kd_off_u95_nm" not in proto_text and "Viral-Safe" not in proto_text, "GATE-36 protocol retains retired wording") require_cond(gy_obj.get("graveyard_card_id") == "GY-035" and gy_obj.get("severity_level") == "BLOCK", "GY-035 schema mismatch") checked_inputs: dict[str, str] = { "fasta_sha256": sha256_file(fasta_path), "rcsb_coords_sha256": sha256_file(coords_path), "side_contract_sha256": sha256_file(sc_path), "protocol_doc_sha256": sha256_file(proto_path), "gy035_entry_sha256": sha256_file(gy_path), "canonical_arm_manifest_sha256": manifest_sha, "wave6_master_contract_canonical_sha256": contract_sha, "wave6_master_contract_file_sha256": contract_file_sha, } part_a = verify_part_a(fasta_records, coords_path) part_b = verify_part_b() part_c = verify_part_c(fasta_path, fasta_records) part_d = verify_part_d(master_contract, contract_sha, manifest_sha) gate_tests = run_gate34_self_tests(arm_manifest) receipt: dict[str, Any] = { "schema_version": SCHEMA_VERSION, "staging_slot": "W6-C3 (iip0057)", "proposal_id": "IIP-0057", "decision_id": "DEC-138", "gate_id": "GATE-36", "graveyard_card_id": "GY-035", "upstream_lot_release_gate_source": CANONICAL_UPSTREAM_GATE34_SOURCE, "live_gate32_debris_recall_co_prerequisite": CANONICAL_LIVE_GATE32_DEBRIS_RECALL_SOURCE, "module_current_assay_gate_sources": dict(CANONICAL_GATE36_MODULE_SOURCES), "generated_date": GENERATED_DATE, "mode": "STANDALONE" if standalone else "REPO_CROSSCHECK", "live_frozen_lims_files_checked": lims_live_checked, "computational_replay_status": "REPRODUCED_COMPUTATIONAL_SENSITIVITY_PENDING_WETLAB", "certifies_manufactured_lot_or_clinical_efficacy": False, "runtime_environment": { "python_version": sys.version.split()[0], "optimize_flag_verified_byte_identical": True, "portable_comparison_ignored_fields": ["runtime_environment.python_version", "portable_payload_sha256"], "portable_check_cli_flag": "--check-portable", }, "zero_lims_touch_invariants": { "frozen_lims_sha256_pins": FROZEN_LIMS_SHA256, "core_3arm_and_layer1_delta_pp": 0.0, "h1_allo_locked_pct": 88.0, "design_a_zero_additional_biologics_beyond_v080_catalase_hydrogel": True, "design_a_contains_preexisting_p04040_catalase_hydrogel": True, "design_a_strictly_zero_protein_biologics": False, "design_a_preexisting_catalase_hydrogel_exception_disclosed": True, "design_a_invariant_tuple": [0.88, 0.78, 0.57, 0.69], }, "checked_inputs_sha256": checked_inputs, "part_a_foundry_v2_islet_shield": part_a, "part_b_ins_pLeu82Ile_pe2max_elisa_dr4_a1101": part_b, "part_c_pruned_viral_receptor_avoidance_cuff_v2": part_c, "part_d_invvax_h3_sensitivity_and_master_parity": part_d, "part_e_gate34_adjudicator_synthetic_self_tests": gate_tests, } receipt["portable_payload_sha256"] = compute_portable_payload_sha256(receipt) return receipt def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(description="W6-C3 Provisional IIP-0057 / DEC-138 / GATE-36 / GY-035 Verifier (Round-14)") parser.add_argument( "--standalone", action="store_true", help="Run standalone offline verification (skips live LIMS repo file hashing; still hash-verifies canonical arm manifest & master contract)", ) parser.add_argument("--check", action="store_true", help="Verify existing receipt is byte-exact (fail-closed)") parser.add_argument("--check-portable", action="store_true", help="Verify semantic equality and mandatory portable_payload_sha256 ignoring python_version (fail-closed)") parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parents[1], help="Root directory containing data/, docs/, scripts/") parser.add_argument("--shared-dir", type=Path, default=None, help="Directory containing wave6_canonical_arm_manifest.json and wave6_master_contract.json") parser.add_argument("--master-contract", type=Path, default=None, help="Explicit path to wave6_master_contract.json") parser.add_argument("--arm-manifest", type=Path, default=None, help="Explicit path to wave6_canonical_arm_manifest.json") parser.add_argument("--openislet-root", type=Path, default=None, help="Live OpenIslet repo root for REPO_CROSSCHECK mode (when --standalone is omitted)") parser.add_argument("--output", type=Path, default=None, help="Output/checked receipt JSON path") args = parser.parse_args(argv) repo_root = args.repo_root.resolve() require_cond(repo_root.is_dir(), f"Invalid --repo-root directory: {repo_root}") out_path = args.output.resolve() if args.output is not None else (repo_root / "data" / "extracted" / f"{SCHEMA_VERSION}.json") receipt = build_verification_receipt( repo_root, standalone=bool(args.standalone), shared_dir=args.shared_dir, master_contract_path=args.master_contract, arm_manifest_path=args.arm_manifest, openislet_root=args.openislet_root, ) rendered = json.dumps(receipt, indent=2, ensure_ascii=False) + "\n" if args.check: if not out_path.is_file(): raise FileNotFoundError(f"--check failed (fail-closed): expected receipt missing: {out_path}") existing_bytes = out_path.read_bytes() if existing_bytes != rendered.encode("utf-8"): raise RuntimeError(f"--check failed (fail-closed): byte mismatch against {out_path.name}") print( f"PASS (--check byte-exact): receipt={out_path.name} mode={receipt['mode']} " f"sha256={sha256_bytes(existing_bytes)} portable_payload_sha256={receipt['portable_payload_sha256']} " f"(optimize={sys.flags.optimize})" ) return 0 if args.check_portable: if not out_path.is_file(): raise FileNotFoundError(f"--check-portable failed (fail-closed): expected receipt missing: {out_path}") existing = load_strict_json(out_path) require_cond(isinstance(existing, dict), f"Malformed receipt in {out_path.name}") require_cond( isinstance(existing.get("portable_payload_sha256"), str) and len(existing["portable_payload_sha256"]) == 64, "--check-portable failed (fail-closed): missing or malformed portable_payload_sha256", ) rt = existing.get("runtime_environment") require_cond(isinstance(rt, dict) and isinstance(rt.get("python_version"), str), "Missing runtime_environment.python_version") existing_psha = compute_portable_payload_sha256(existing) fresh_psha = receipt["portable_payload_sha256"] require_cond(portable_projection(existing) == portable_projection(receipt), "--check-portable failed: semantic projection mismatch") require_cond(existing.get("portable_payload_sha256") == fresh_psha and existing_psha == fresh_psha, "--check-portable failed: portable_payload_sha256 mismatch") print( f"PASS (--check-portable semantic match): receipt={out_path.name} mode={receipt['mode']} " f"portable_payload_sha256={fresh_psha} (optimize={sys.flags.optimize})" ) return 0 out_path.parent.mkdir(parents=True, exist_ok=True) out_path.write_text(rendered, encoding="utf-8") print( f"PASS (wrote receipt): receipt={out_path.name} mode={receipt['mode']} " f"sha256={sha256_str(rendered)} portable_payload_sha256={receipt['portable_payload_sha256']} " f"(optimize={sys.flags.optimize})" ) return 0 if __name__ == "__main__": raise SystemExit(main())