OpenIslet

scripts/verify_iip0057_foundry_v2_shield_invvax_insl82i_cuffv2.py

W6-C3 (Provisional Next-Free IIP-0057 / DEC-138 / GATE-36 / GY-035; staging slot iip0057,

script Release v0.8.0 gen-eb955f8266035aba 412 KB · 32 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_iip0057_foundry_v2_shield_invvax_insl82i_cuffv2.py · SHA-256: 1c63dcf649c42be4…

    _rec("r14_shield_live_gate32_partial_coverage_graded_cap_hold", r_r14_part)
    _rec("r14_shield_live_gate32_l95_below_0p70_fail", r_r14_l95_fail)
    _rec("r14_shield_live_gate32_residual_gt_0p30_fail", r_r14_res_fail)
    _rec("r14_shield_live_gate32_unrelated_recall_false_fail", r_r14_unrel_fail)
    _rec("r14_upstream_live_gate32_role_collision_rejected_fail", r_r14_coll)

    expected = {
        "shield_synthetic_15uM_self_test_no_promo": {"decision": "SYNTHETIC_SELF_TEST_PASS", "promotion_authorized": False},
        "shield_missing_manifest_fail": {"decision": "FAIL", "promotion_authorized": False},
        "shield_l95_7p5uM_u95_15uM_review_probe_fail": {"decision": "FAIL", "promotion_authorized": False},
        "shield_1nM_peak_2000nM_trough_fail": {"decision": "FAIL", "promotion_authorized": False},
        "shield_plasma_trough_lt_dln_trough_fail": {"decision": "FAIL", "promotion_authorized": False},
        "shield_kd_on_1e_320_underflow_fail": {"decision": "FAIL", "promotion_authorized": False},
        "shield_5000x_selectivity_fail": {"decision": "FAIL", "promotion_authorized": False},
        "shield_q84d_relabeled_q28d_dataset_fail": {"decision": "FAIL", "promotion_authorized": False},
        "shield_q84d_2nM_fail": {"decision": "FAIL", "promotion_authorized": False},
        "shield_q84d_unmeasured_human_pk_fail": {"decision": "FAIL", "promotion_authorized": False},
        "shield_design_a_arm_fail": {"decision": "FAIL", "promotion_authorized": False},
        "ins_synthetic_self_test_no_promo": {"decision": "SYNTHETIC_SELF_TEST_PASS", "promotion_authorized": False},
        "ins_4_duplicated_donors_across_3_alleles_fail": {"decision": "FAIL", "promotion_authorized": False},
        "ins_hla_binding_false_fail": {"decision": "FAIL", "promotion_authorized": False},
        "ins_design_a_exposed_fail": {"decision": "FAIL", "promotion_authorized": False},
        "ins_pe4max_mlh1dn_fail": {"decision": "FAIL", "promotion_authorized": False},
        "cuff_synthetic_3protein_self_test_no_promo": {"decision": "SYNTHETIC_SELF_TEST_PASS", "promotion_authorized": False},
        "cuff_1protein_manifest_fail": {"decision": "FAIL", "promotion_authorized": False},
        "cuff_zero_efferocytosis_fail": {"decision": "FAIL", "promotion_authorized": False},
        "cuff_zero_pericyte_fail": {"decision": "FAIL", "promotion_authorized": False},
        "cuff_cd200r_accessibility_false_fail": {"decision": "FAIL", "promotion_authorized": False},
        "cuff_design_a_exposed_fail": {"decision": "FAIL", "promotion_authorized": False},
        "invvax_synthetic_self_test_no_promo": {"decision": "SYNTHETIC_SELF_TEST_PASS", "promotion_authorized": False},
        "invvax_single_dose_minus7_fail": {"decision": "FAIL", "promotion_authorized": False},
        "invvax_duplicate_matrix_assay_id_fail": {"decision": "FAIL", "promotion_authorized": False},
        "invvax_post_tx_day_plus1_fail": {"decision": "FAIL", "promotion_authorized": False},
        "invvax_llod_1e6_fail": {"decision": "FAIL", "promotion_authorized": False},
        "invvax_design_a_exposed_fail": {"decision": "FAIL", "promotion_authorized": False},
        "auth_without_store_holds_no_promo": {"decision": "HOLD_UNRESOLVED_TRUSTED_EVIDENCE_STORE", "promotion_authorized": False},
        "auth_with_upstream_only_store_holds_no_promo": {"decision": "HOLD_UNRESOLVED_TRUSTED_EVIDENCE_STORE", "promotion_authorized": False},
        "auth_store_promotion_false_tamper_fail": {"decision": "FAIL_EVIDENCE_STORE_MISMATCH", "promotion_authorized": False},
        "auth_with_verified_dual_store_authorizes": {"decision": "PASS", "promotion_authorized": True},
        "r5_shield_archive_apc_100pct_vs_parent_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r5_shield_archive_14p9999999995uM_zero_tol_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r5_ins_archive_bystander_100pct_vs_parent_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r5_ins_archive_gsis_1p0_vs_parent_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r5_ins_archive_4donors_vs_12_claimed_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r5_cuff_archive_serum_killing_100pct_vs_parent_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r5_cuff_archive_c4b2a_14pct_vs_parent_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r5_cuff_archive_eff_79p9999995_zero_tol_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r5_invvax_archive_ae_grade5_vs_parent_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r5_invvax_archive_conc_at_llod_zero_tol_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r5_store_conflicting_index_aliases_fail": {"decision": "FAIL_EVIDENCE_STORE_MISMATCH", "promotion_authorized": False},
        "r5_contradictory_physical_qual_false_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r8_ins_12_distinct_canonical_donors_pass": {"decision": "PASS", "promotion_authorized": True},
        "r8_ins_4donors_whitespace_padded_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r8_ins_4donors_case_variants_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r8_ins_4donors_unicode_nfkc_invisibles_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r8_ins_4donors_separator_variants_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r8_ins_reactive_noncanonical_donor_id_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r9_ins_4donors_digit_separator_0_1_both_rosters_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r9_ins_4donors_digit_separator_d101_both_rosters_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r9_ins_roster_issuer_identity_mismatch_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r9_ins_12_distinct_donors_both_rosters_same_issuer_pass": {"decision": "PASS", "promotion_authorized": True},
        "r10_ins_both_rosters_omitted_issuer_hold": {"decision": "HOLD", "promotion_authorized": False},
        "r10_ins_single_form_archived_omitted_issuer_hold": {"decision": "HOLD", "promotion_authorized": False},
        "r10_ins_archive_one_form_omitted_issuer_hold": {"decision": "HOLD", "promotion_authorized": False},
        "r10_ins_current_omitted_issuer_vs_archived_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r10_ins_both_rosters_positive_hla_registry_issuer_pass": {"decision": "PASS", "promotion_authorized": True},
        "r11_ins_caller_only_reactive_preserves_archive_u95_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r11_ins_missing_archive_null_verified_stats_hold": {"decision": "HOLD", "promotion_authorized": False},
        "r11_ins_missing_trusted_store_null_verified_stats_hold": {"decision": "HOLD_UNRESOLVED_TRUSTED_EVIDENCE_STORE", "promotion_authorized": False},
        "r11_ins_internal_archive_conflict_null_verified_stats_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r11_ins_archive_1of12_reactive_matched_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r11_shield_caller_only_adverse_preserves_archive_ro_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r11_shield_missing_store_null_verified_stats_hold": {"decision": "HOLD_UNRESOLVED_TRUSTED_EVIDENCE_STORE", "promotion_authorized": False},
        "r12_shield_omitted_archived_study_id_null_stats_hold": {"decision": "HOLD", "promotion_authorized": False},
        "r12_shield_omitted_archived_study_id_independent_fail_withheld": {"decision": "FAIL", "promotion_authorized": False},
        "r12_shield_archived_trough_gt_peak_null_stats_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r12_shield_archived_regimen_interval_conflict_null_stats_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r12_shield_archived_7p5uM_metric_conflict_null_stats_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r12_ins_omitted_archived_study_id_null_stats_hold": {"decision": "HOLD", "promotion_authorized": False},
        "r13_shield_omitted_archived_peak_null_stats_hold": {"decision": "HOLD", "promotion_authorized": False},
        "r13_ins_missing_archive_independent_fail_withheld": {"decision": "FAIL", "promotion_authorized": False},
        "r13_ins_missing_store_independent_fail_withheld": {"decision": "FAIL", "promotion_authorized": False},
        "r13_ins_tampered_store_fail_withheld": {"decision": "FAIL_EVIDENCE_STORE_MISMATCH", "promotion_authorized": False},
        "r13_ins_missing_archived_issuer_independent_fail_withheld": {"decision": "FAIL", "promotion_authorized": False},
        "r14_shield_live_gate32_debris_recall_full_credit_pass": {"decision": "PASS", "promotion_authorized": True},
        "r14_shield_missing_live_gate32_debris_recall_hold": {"decision": "HOLD", "promotion_authorized": False},
        "r14_shield_missing_live_gate32_plus_independent_fail_withheld": {"decision": "FAIL", "promotion_authorized": False},
        "r14_shield_live_gate32_partial_coverage_graded_cap_hold": {"decision": "HOLD", "promotion_authorized": False},
        "r14_shield_live_gate32_l95_below_0p70_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r14_shield_live_gate32_residual_gt_0p30_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r14_shield_live_gate32_unrelated_recall_false_fail": {"decision": "FAIL", "promotion_authorized": False},
        "r14_upstream_live_gate32_role_collision_rejected_fail": {"decision": "FAIL", "promotion_authorized": False},
    }
    require_cond(cases == expected, f"Gate 36 self-test mismatch: {cases}")
    return {
        "synthetic_fixture_self_test_only": True,
        "certifies_wetlab_lot": False,
        "synthetic_fixtures_never_authorize_promotion": True,
        "all_passed": True,
        "total_cases": len(cases),
        "cases": cases,
    }


# ---------------------------------------------------------------------------
# Portable Payload SHA-256 & Cross-Surface Receipt Builder
# ---------------------------------------------------------------------------
def portable_projection(receipt: dict[str, Any]) -> dict[str, Any]:
    proj = copy.deepcopy(receipt)
    proj.pop("portable_payload_sha256", None)
    rt = proj.get("runtime_environment")
    if isinstance(rt, dict):
        rt.pop("python_version", None)
    return proj


def compute_portable_payload_sha256(receipt: dict[str, Any]) -> str:
    canonical = json.dumps(portable_projection(receipt), sort_keys=True, separators=(",", ":"), ensure_ascii=False)
    return sha256_str(canonical)


def build_verification_receipt(
    repo_root: Path,
    *,
    standalone: bool,
    shared_dir: Path | None = None,
    master_contract_path: Path | None = None,
    arm_manifest_path: Path | None = None,
    openislet_root: Path | None = None,
) -> dict[str, Any]:
    fasta_path = repo_root / "data" / "constructs" / "openislet_foundry_v2_cuff_v2_and_shield_fc_v0.9.0.fasta"
    coords_path = repo_root / "data" / "structures" / "rcsb_shield_interface_coords_v0.9.0.json"
    sc_path = repo_root / "data" / "protocols" / "iip0057_foundry_v2_h3_side_contract_v0.9.0.json"
    proto_path = repo_root / "docs" / "GATE-36-FOUNDRY-V2-SHIELD-INVVAX-INSL82I-CUFFV2-PROTOCOL.md"
    gy_path = repo_root / "data" / "protocols" / "iip0057_gy035_entry.json"

    contract_p, manifest_p = resolve_release_shared_paths(
        repo_root,
        shared_dir=shared_dir,
        master_contract_path=master_contract_path,
        arm_manifest_path=arm_manifest_path,
    )

    require_cond(fasta_path.is_file(), f"Missing required FASTA: {fasta_path}")
    require_cond(coords_path.is_file(), f"Missing required RCSB coords JSON: {coords_path}")
    require_cond(sc_path.is_file(), f"Missing required side contract: {sc_path}")
    require_cond(proto_path.is_file(), f"Missing required GATE-34 protocol doc: {proto_path}")
    require_cond(gy_path.is_file(), f"Missing required GY-034 entry JSON: {gy_path}")

    lims_live_checked = False
    if not standalone:
        lims_root = openislet_root.resolve() if openislet_root is not None else repo_root
        for rel_lims, exp_sha in FROZEN_LIMS_SHA256.items():
            p_lims = lims_root / rel_lims
            if not p_lims.is_file():
                raise FileNotFoundError(
                    f"REPO_CROSSCHECK mode requires frozen LIMS file {p_lims} "
                    f"(pass --standalone for isolated staging verification or --openislet-root <repo>)."
                )
            got_sha = sha256_file(p_lims)
            require_cond(got_sha == exp_sha, f"Frozen LIMS SHA-256 mismatch on {rel_lims}: {got_sha} != {exp_sha}")
        lims_live_checked = True

    arm_manifest, manifest_sha = load_and_verify_arm_manifest(manifest_p)
    master_contract, contract_sha, contract_file_sha = load_and_verify_master_contract(contract_p, manifest_sha)

    fasta_records = parse_fasta_text(fasta_path.read_text(encoding="utf-8"))
    sc_obj = load_strict_json(sc_path)
    proto_text = proto_path.read_text(encoding="utf-8")
    gy_obj = load_strict_json(gy_path)

    # Cross-check companion artifacts (side contract, protocol doc, GY-035 [staged gy035_entry.json])
    require_cond(
        sc_obj.get("proposal_id") == "IIP-0057"
        and sc_obj.get("decision_id") == "DEC-138"
        and sc_obj.get("gate_id") == "GATE-36"
        and sc_obj.get("graveyard_card_id") == "GY-035",
        "Side contract provisional Round-14 ID mismatch (expected IIP-0057 / DEC-138 / GATE-36 / GY-035)",
    )
    require_cond(sc_obj["zero_lims_touch_compliance"]["deposited_fasta_sha256"] == EXPECTED_FASTA_SHA256, "Side contract FASTA SHA-256 mismatch")
    require_cond(sc_obj["zero_lims_touch_compliance"]["rcsb_coords_sha256"] == EXPECTED_RCSB_COORDS_SHA256, "Side contract RCSB coords SHA-256 mismatch")
    require_cond(sc_obj["zero_lims_touch_compliance"]["canonical_arm_manifest_sha256"] == EXPECTED_ARM_MANIFEST_SHA256, "Side contract manifest SHA-256 mismatch")
    require_cond(sc_obj["zero_lims_touch_compliance"]["canonical_arm_manifest_canonical_json_sha256"] == EXPECTED_ARM_MANIFEST_CANONICAL_JSON_SHA256, "Side contract manifest canonical SHA-256 mismatch")
    require_cond(sc_obj["zero_lims_touch_compliance"]["wave6_master_contract_sha256"] == EXPECTED_MASTER_CONTRACT_SHA256, "Side contract master contract SHA-256 mismatch")
    require_cond(sc_obj["zero_lims_touch_compliance"]["wave6_master_contract_file_sha256"] == EXPECTED_MASTER_CONTRACT_FILE_SHA256, "Side contract master contract file SHA-256 mismatch")
    require_cond(sc_obj["governance_and_invariants"]["design_a_zero_additional_biologics_beyond_v080_catalase_hydrogel"] is True, "Design A zero-additional-biologics invariant missing")
    require_cond(sc_obj["governance_and_invariants"]["design_a_contains_preexisting_p04040_catalase_hydrogel"] is True, "Design A catalase disclosure missing")
    require_cond(sc_obj["governance_and_invariants"]["design_a_strictly_zero_protein_biologics"] is False, "Design A strict protein biologic flag mismatch")
    require_cond(sc_obj["governance_and_invariants"]["gy_021_enforced_pe2max_only_no_pe4max_mlh1dn"] is True, "GY-021 PE2max invariant missing")
    common_inv = sc_obj["executable_gate_34_subgates"]["common_promotion_and_manifest_invariants"]
    require_cond(
        common_inv["unified_evidence_schema_revision"] == UPSTREAM_EVIDENCE_SCHEMA_REVISION
        and common_inv["zero_threshold_crossing_tolerance_enforced"] is True
        and common_inv["alias_consistent_trusted_store_lookup_enforced"] is True
        and common_inv["contradictory_producer_flags_rejected"] is True
        and common_inv["all_governing_measurements_derived_from_verified_current_assay_archive"] is True
        and common_inv.get("upstream_lot_release_gate_source") == CANONICAL_UPSTREAM_GATE34_SOURCE
        and common_inv.get("rejected_upstream_role_collision_source") == CANONICAL_LIVE_GATE32_DEBRIS_RECALL_SOURCE
        and common_inv.get("module_current_assay_gate_sources") == CANONICAL_GATE36_MODULE_SOURCES,
        "Side contract Round-14 common invariants / gate source de-collision mismatch",
    )
    sh_gate = sc_obj["executable_gate_34_subgates"]["Gate_34_SHIELD_SEL"]
    require_cond(
        sh_gate["off_target_kd_l95_um_min"] == 15.0
        and sh_gate["selectivity_ratio_l95_min"] == 15000.0
        and sh_gate["on_target_kd_u95_nm_calibrated_floor"] == MIN_CALIBRATED_KD_ON_NM
        and sh_gate.get("official_statistics_strictly_authenticated_archive_only") is True
        and sh_gate.get("null_official_statistics_on_unverified_or_conflict") is True
        and sh_gate.get("archive_completeness_required_before_official_statistics") is True
        and sh_gate.get("all_internal_archive_consistency_checks_required_before_official_statistics") is True
        and sh_gate.get("caller_reconciliation_separated_from_archive_gating") is True
        and sh_gate.get("omitted_peak_never_substitutes_trough_for_ro_agreement") is True
        and sh_gate.get("fail_verdict_never_emits_hold_derivation_source") is True
        and sh_gate.get("live_gate32_debris_recall_required") is True
        and sh_gate.get("live_gate32_gate_source") == CANONICAL_LIVE_GATE32_DEBRIS_RECALL_SOURCE
        and sh_gate.get("live_gate32_required_verdict") == "PASS_DEBRIS_RECALL_FULL_CREDIT"
        and sh_gate.get("live_gate32_min_l95_suppressed_frac") == LIVE_GATE32_MIN_L95_SUPPRESSED_FRAC
        and sh_gate.get("live_gate32_max_residual_class2_u95_frac") == LIVE_GATE32_MAX_RESIDUAL_CLASS2_U95_FRAC
        and sh_gate.get("live_gate32_unrelated_recall_preserved_required") is True
        and sh_gate.get("live_gate32_missing_hold_code") == "HOLD_MISSING_LIVE_GATE32_WHOLE_DEBRIS_RECALL"
        and set(sh_gate.get("shield_statistics_derivation_sources", [])) == set(SHIELD_STATISTICS_DERIVATION_SOURCES),
        "Side contract Round-14 SHIELD L95/15,000x/1fM floor, live GATE-32 debris-recall co-prerequisite, & complete/consistent archive-only stats mismatch",
    )
    ins_gate = sc_obj["executable_gate_34_subgates"]["Gate_34_INS_L82I_ELISA_PE2MAX"]
    require_cond(
        ins_gate["min_unique_hla_donors"] == 12