OpenIslet

scripts/evaluate_gate0v_composite_release.py

IIP-0043 / DEC-122 (CAND-034 / EXP-031) Executable Dual-Evaluator Composite Release Wrapper

script Release v0.8.0 gen-eb955f8266035aba 357 KB · 28 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/evaluate_gate0v_composite_release.py · SHA-256: 2be0252340222fe4…

            "HOLD_COMPOSITE_RELEASE",
            store_path=trusted_store,
            expected_gate0v_pass=False,
            expected_token="HOLD_INAPPLICABLE_QUALIFICATION_TIER_FOR_PRODUCT_FAMILY",
        )

        # 28. R04-B2a: Exact Round-03 counterexample — external QA bank record omitting antiviral_genotype_stratum
        # + archived WT bank bundle used for protective-LOF current lot -> HOLD_COMPOSITE_RELEASE!
        nogeno_bank = copy.deepcopy(auth_bank_rec)
        nogeno_bank.pop("antiviral_genotype_stratum", None)
        nogeno_bank["sha256"] = compute_qualification_record_sha256(nogeno_bank)
        v38.write_record_to_trusted_qualification_store(
            trusted_store, nogeno_bank, category="bank_qualifications", archived_payload=bank_bundle
        )
        g0v_lof_nogeno = v38.build_passing_reference_payload(
            lot_id=clin_lot_id,
            mcb_id=mcb_id,
            product_variant_id=pv_lead,
            qualification_tier="LOT_RELEASE_SURROGATE",
            bridged_mcb_qualification_sha256=nogeno_bank["sha256"],
            antiviral_genotype_stratum="TYK2_WT__IFIH1_PROTECTIVE_LOF",
            openislet_root=openislet_root,
        )
        _run_case(
            "r04_b2_missing_bank_stratum_with_archived_wt_for_lof_lot_held",
            _make_composite_bundle(clin_lot_id, mcb_id, pv_lead, leg_clin, g0v_lof_nogeno),
            "HOLD_COMPOSITE_RELEASE",
            store_path=trusted_store,
            expected_legacy_pass=True,
            expected_gate0v_pass=False,
            expected_token="HOLD_UNVERIFIED_OR_MISMATCHED_BANK_GENOTYPE_STRATUM",
        )

        # 29. R04-B2b: Bank record declaring LOF contradicting archived WT bank payload -> HOLD_COMPOSITE_RELEASE!
        contradict_bank = copy.deepcopy(auth_bank_rec)
        contradict_bank["antiviral_genotype_stratum"] = "TYK2_WT__IFIH1_PROTECTIVE_LOF"
        contradict_bank["sha256"] = compute_qualification_record_sha256(contradict_bank)
        v38.write_record_to_trusted_qualification_store(
            trusted_store, contradict_bank, category="bank_qualifications", archived_payload=bank_bundle
        )
        g0v_lof_contra = v38.build_passing_reference_payload(
            lot_id=clin_lot_id,
            mcb_id=mcb_id,
            product_variant_id=pv_lead,
            qualification_tier="LOT_RELEASE_SURROGATE",
            bridged_mcb_qualification_sha256=contradict_bank["sha256"],
            antiviral_genotype_stratum="TYK2_WT__IFIH1_PROTECTIVE_LOF",
            openislet_root=openislet_root,
        )
        _run_case(
            "r04_b2_bank_record_stratum_contradicts_archived_wt_payload_held",
            _make_composite_bundle(clin_lot_id, mcb_id, pv_lead, leg_clin, g0v_lof_contra),
            "HOLD_COMPOSITE_RELEASE",
            store_path=trusted_store,
            expected_legacy_pass=True,
            expected_gate0v_pass=False,
            expected_token="HOLD_UNVERIFIED_OR_MISMATCHED_BANK_GENOTYPE_STRATUM",
        )

        # 30. R04-B3a: Extra non-canonical lineage key inside required stress regime with adverse raw counts -> FAIL_HARD_STOP!
        g0v_extra_lin_adv = copy.deepcopy(g0v_bank)
        extra_arm = copy.deepcopy(g0v_extra_lin_adv["gate0v_kill_stress_ap1903"]["hypoxia_1pct_plus_cytokines"]["beta"])
        extra_arm["ap1903_24h_viable_survivors_k"] = 7000
        g0v_extra_lin_adv["gate0v_kill_stress_ap1903"]["hypoxia_1pct_plus_cytokines"]["ductal_noncanonical"] = extra_arm
        v38.reconcile_fixture_per_unit_counts(g0v_extra_lin_adv)
        g0v_extra_lin_adv["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_extra_lin_adv)
        _run_case(
            "r04_b3_extra_noncanonical_lineage_key_adverse_counts_hard_stop",
            _make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_extra_lin_adv),
            "FAIL_HARD_STOP_COMPOSITE_RELEASE",
            expected_legacy_pass=True,
            expected_gate0v_pass=False,
            expected_token="AP1903_24H_KILL_BELOW_99P9PCT_HYPOXIA_1PCT_PLUS_CYTOKINES_DUCTAL_NONCANONICAL",
        )

        # 31. R04-B3b: Zero-killing arm paired with poorly surviving vehicle control -> FAIL_HARD_STOP!
        g0v_zero_kill_low_veh = copy.deepcopy(g0v_bank)
        g0v_zero_kill_low_veh["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["alpha"]["veh_24h_viable_n"] = 50
        g0v_zero_kill_low_veh["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["alpha"]["ap1903_24h_viable_survivors_k"] = 10000
        v38.reconcile_fixture_per_unit_counts(g0v_zero_kill_low_veh)
        g0v_zero_kill_low_veh["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_zero_kill_low_veh)
        _run_case(
            "r04_b3_zero_killing_with_low_vehicle_survival_preserves_hard_stop",
            _make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_zero_kill_low_veh),
            "FAIL_HARD_STOP_COMPOSITE_RELEASE",
            expected_legacy_pass=True,
            expected_gate0v_pass=False,
            expected_token="AP1903_24H_KILL_BELOW_99P9PCT_ER_STRESS_TG_OR_TM_ALPHA",
        )

        # 32. R04-B4: CD55 comparator with legacy aggregate-only block (no per-strain strain_results) -> HOLD!
        g0v_cfh_agg = copy.deepcopy(g0v_cfh)
        g0v_cfh_agg["cd55_tropic_echovirus_addendum"] = {
            "echovirus_strain_panel": ["echovirus_7", "echovirus_11"],
            "echovirus_titer_72h_log10_pfu_u95": "1.35",
            "echovirus_day14_log10_reduction_l95": "3.80",
            "echovirus_day28_supernatant_pfu_ml": "0",
            "echovirus_day28_assay_volume_ml": "2.0",
            "echovirus_day28_lod_pfu_ml": "0.5",
            "echovirus_persistence_confirmed_k": 0,
            "echovirus_cells_screened_per_lineage_min_n": 16000,
            "protocol_evidence_sha256": v38._valid_digest("cd55_legacy_agg_comp"),
        }
        g0v_cfh_agg["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_cfh_agg)
        _run_case(
            "r04_b4_cd55_legacy_aggregate_only_block_held",
            _make_composite_bundle(bank_lot_id, mcb_id, pv_cfh, leg_cfh, g0v_cfh_agg),
            "HOLD_COMPOSITE_RELEASE",
            expected_legacy_pass=False,
            expected_gate0v_pass=False,
            expected_token="CD55_MISSING_PER_STRAIN_RESULTS_AGGREGATE_ONLY_REJECTED",
        )

        # 33. R05-B1a: File-backed directory store WITH valid archived bank payload -> PASS_COMPOSITE_CLINICAL_RELEASE!
        trusted_dir = Path(td) / "independent_qa_store_dir"
        v38.write_record_to_trusted_qualification_store(
            trusted_dir,
            auth_bank_rec,
            category="bank_qualifications",
            archived_payload=bank_bundle,
        )
        res_dir_pass = _run_case(
            "r05_b1_file_backed_dir_store_with_valid_archived_bank_payload_passes",
            clin_bundle,
            "PASS_COMPOSITE_CLINICAL_RELEASE",
            store_path=trusted_dir,
            expected_legacy_pass=True,
            expected_gate0v_pass=True,
        )
        if res_dir_pass["prior_qualification_authentication"].get("archived_bank_payload_verified") is not True:
            cases[-1]["passed"] = False

        # 34. R05-B1b: Embedded-dict registry JSON store with ABSENT archived bank payload -> HOLD (exit 2)!
        reg_absent_arch = Path(td) / "r05_reg_absent_archive.json"
        v38.write_record_to_trusted_qualification_store(
            reg_absent_arch,
            auth_bank_rec,
            category="bank_qualifications",
            archived_payload=None,
        )
        clin_bundle_file = Path(td) / "r05_clin_bundle.json"
        clin_bundle_file.write_text(json.dumps(clin_bundle), encoding="utf-8")
        res_reg_abs, rc_reg_abs = evaluate_composite_lot_file(
            clin_bundle_file,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=reg_absent_arch,
            openislet_root=openislet_root,
        )
        ok_34 = bool(
            rc_reg_abs == 2
            and res_reg_abs["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
            and (res_reg_abs["gate0v_result_summary"] or {}).get("verdict") == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
            and "HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD" in res_reg_abs["holds"]
            and res_reg_abs["prior_qualification_authentication"]["archived_bank_payload_verified"] is False
        )
        cases.append({
            "case": "r05_b1_registry_store_absent_archived_bank_payload_held_exit_2",
            "expected_verdict": "HOLD_COMPOSITE_RELEASE",
            "actual_verdict": res_reg_abs["composite_verdict"],
            "operational_tier": res_reg_abs.get("operational_tier"),
            "legacy_passed": (res_reg_abs["legacy_result_summary"] or {}).get("legacy_evaluator_passed"),
            "legacy_tier": (res_reg_abs["legacy_result_summary"] or {}).get("lot_release_readiness_tier"),
            "legacy_resolved_pvid": (res_reg_abs["legacy_result_summary"] or {}).get("resolved_product_variant_id"),
            "gate0v_passed": (res_reg_abs["gate0v_result_summary"] or {}).get("gate0v_evaluator_passed"),
            "gate0v_verdict": (res_reg_abs["gate0v_result_summary"] or {}).get("verdict"),
            "expected_token": "HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD",
            "exit_code": rc_reg_abs,
            "archived_bank_payload_verified": res_reg_abs["prior_qualification_authentication"]["archived_bank_payload_verified"],
            "hard_stops": res_reg_abs["hard_stops"][:3],
            "holds": res_reg_abs["holds"][:4],
            "passed": ok_34,
        })

        # 35. R05-B1c: Embedded-dict registry JSON store with NON-OBJECT archived bank payloads (None/list/str/int) -> HOLD (exit 2)!
        reg_nonobj_all_ok = True
        for tag, bad_val in (("none", None), ("list", ["not", "an", "object"]), ("str", "invalid"), ("int", 7)):
            reg_bad = Path(td) / f"r05_reg_nonobj_{tag}.json"
            reg_bad.write_text(
                json.dumps({
                    "schema_version": v38.TRUSTED_STORE_SCHEMA_VERSION,
                    "store_authority_id": "OPENISLET_QA_RELEASE_BOARD_V1",
                    "bank_qualifications": {auth_bank_rec["sha256"]: auth_bank_rec},
                    "process_qualifications": {},
                    "archived_payloads": {auth_bank_rec["bank_payload_sha256"]: bad_val},
                }),
                encoding="utf-8",
            )
            r_b, rc_b = evaluate_composite_lot_file(
                clin_bundle_file,
                legacy_evaluator=leg_fn,
                gate0v_evaluator=g0v_fn,
                trusted_qualification_store=reg_bad,
                openislet_root=openislet_root,
            )
            if not (
                rc_b == 2
                and r_b["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
                and (r_b["gate0v_result_summary"] or {}).get("verdict") == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
                and "HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD" in r_b["holds"]
                and r_b["prior_qualification_authentication"]["archived_bank_payload_verified"] is False
            ):
                reg_nonobj_all_ok = False
        cases.append({
            "case": "r05_b1_registry_store_nonobject_archived_bank_payloads_held_exit_2",
            "expected_verdict": "HOLD_COMPOSITE_RELEASE",
            "actual_verdict": "HOLD_COMPOSITE_RELEASE" if reg_nonobj_all_ok else "UNEXPECTED_PASS_OR_EXIT",
            "operational_tier": "LOT_RELEASE_SURROGATE",
            "legacy_passed": True,
            "legacy_tier": LEGACY_PASS_TIER,
            "legacy_resolved_pvid": pv_lead,
            "gate0v_passed": False,
            "gate0v_verdict": "HOLD_INCOMPLETE_OR_UNDERPOWERED",
            "expected_token": "HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD",
            "exit_code": 2 if reg_nonobj_all_ok else -1,
            "archived_bank_payload_verified": False if reg_nonobj_all_ok else None,
            "hard_stops": [],
            "holds": ["HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD"],
            "passed": reg_nonobj_all_ok,
        })

        # 36. R05-B1d: File-backed directory store with ABSENT archived bank payload -> HOLD (exit 2)!
        dir_absent_arch = Path(td) / "r05_dir_absent_archive"
        v38.write_record_to_trusted_qualification_store(
            dir_absent_arch,
            auth_bank_rec,
            category="bank_qualifications",
            archived_payload=None,
        )
        res_dir_abs, rc_dir_abs = evaluate_composite_lot_file(
            clin_bundle_file,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=dir_absent_arch,
            openislet_root=openislet_root,
        )
        ok_36 = bool(
            rc_dir_abs == 2
            and res_dir_abs["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
            and (res_dir_abs["gate0v_result_summary"] or {}).get("verdict") == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
            and "HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD" in res_dir_abs["holds"]
            and res_dir_abs["prior_qualification_authentication"]["archived_bank_payload_verified"] is False
        )
        cases.append({
            "case": "r05_b1_dir_store_absent_archived_bank_payload_held_exit_2",
            "expected_verdict": "HOLD_COMPOSITE_RELEASE",
            "actual_verdict": res_dir_abs["composite_verdict"],
            "operational_tier": res_dir_abs.get("operational_tier"),
            "legacy_passed": (res_dir_abs["legacy_result_summary"] or {}).get("legacy_evaluator_passed"),
            "legacy_tier": (res_dir_abs["legacy_result_summary"] or {}).get("lot_release_readiness_tier"),