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…

            "legacy_resolved_pvid": (res_dir_abs["legacy_result_summary"] or {}).get("resolved_product_variant_id"),
            "gate0v_passed": (res_dir_abs["gate0v_result_summary"] or {}).get("gate0v_evaluator_passed"),
            "gate0v_verdict": (res_dir_abs["gate0v_result_summary"] or {}).get("verdict"),
            "expected_token": "HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD",
            "exit_code": rc_dir_abs,
            "archived_bank_payload_verified": res_dir_abs["prior_qualification_authentication"]["archived_bank_payload_verified"],
            "hard_stops": res_dir_abs["hard_stops"][:3],
            "holds": res_dir_abs["holds"][:4],
            "passed": ok_36,
        })

        # 37. R05-B1e: File-backed directory store with NON-OBJECT archived bank payloads (None/list/str/int) -> HOLD (exit 2)!
        dir_nonobj_all_ok = True
        for tag, bad_val in (("none", None), ("list", ["not", "an", "object"]), ("str", "invalid"), ("int", 7)):
            dir_bad = Path(td) / f"r05_dir_nonobj_{tag}"
            v38.write_record_to_trusted_qualification_store(
                dir_bad,
                auth_bank_rec,
                category="bank_qualifications",
                archived_payload=None,
            )
            arch_dir_b = dir_bad / "archived_payloads"
            arch_dir_b.mkdir(parents=True, exist_ok=True)
            (arch_dir_b / f"{auth_bank_rec['bank_payload_sha256']}.json").write_text(
                json.dumps(bad_val), encoding="utf-8"
            )
            r_d, rc_d = evaluate_composite_lot_file(
                clin_bundle_file,
                legacy_evaluator=leg_fn,
                gate0v_evaluator=g0v_fn,
                trusted_qualification_store=dir_bad,
                openislet_root=openislet_root,
            )
            if not (
                rc_d == 2
                and r_d["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
                and (r_d["gate0v_result_summary"] or {}).get("verdict") == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
                and "HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD" in r_d["holds"]
                and r_d["prior_qualification_authentication"]["archived_bank_payload_verified"] is False
            ):
                dir_nonobj_all_ok = False
        cases.append({
            "case": "r05_b1_dir_store_nonobject_archived_bank_payloads_held_exit_2",
            "expected_verdict": "HOLD_COMPOSITE_RELEASE",
            "actual_verdict": "HOLD_COMPOSITE_RELEASE" if dir_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 dir_nonobj_all_ok else -1,
            "archived_bank_payload_verified": False if dir_nonobj_all_ok else None,
            "hard_stops": [],
            "holds": ["HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD"],
            "passed": dir_nonobj_all_ok,
        })

        # 38. R06-B1a: Indirect-only conditional escape on BANK_QUALIFICATION -> HOLD_COMPOSITE_RELEASE (exit 2), NEVER PASS!
        g0v_ind_only = v38.build_passing_reference_payload(
            lot_id=bank_lot_id,
            mcb_id=mcb_id,
            product_variant_id=pv_lead,
            qualification_tier="BANK_QUALIFICATION",
            use_direct_infected_veh_survivor_mode=False,
            openislet_root=openislet_root,
        )
        ind_bundle = _make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_ind_only)
        ind_bundle_file = Path(td) / "r06_ind_only_bundle.json"
        ind_bundle_file.write_text(json.dumps(ind_bundle), encoding="utf-8")
        res_ind_c, rc_ind_c = evaluate_composite_lot_file(
            ind_bundle_file,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            openislet_root=openislet_root,
        )
        ok_38 = bool(
            rc_ind_c == 2
            and res_ind_c["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
            and (res_ind_c["legacy_result_summary"] or {}).get("legacy_evaluator_passed") is True
            and (res_ind_c["gate0v_result_summary"] or {}).get("verdict") == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
            and "HOLD_INDIRECT_CONDITIONAL_ESCAPE_UNSUPPORTED_FOR_RELEASE" in res_ind_c["holds"]
        )
        cases.append({
            "case": "r06_b1_indirect_only_conditional_escape_composite_hold_exit_2",
            "expected_verdict": "HOLD_COMPOSITE_RELEASE",
            "actual_verdict": res_ind_c["composite_verdict"],
            "operational_tier": res_ind_c.get("operational_tier"),
            "legacy_passed": (res_ind_c["legacy_result_summary"] or {}).get("legacy_evaluator_passed"),
            "legacy_tier": (res_ind_c["legacy_result_summary"] or {}).get("lot_release_readiness_tier"),
            "legacy_resolved_pvid": (res_ind_c["legacy_result_summary"] or {}).get("resolved_product_variant_id"),
            "gate0v_passed": (res_ind_c["gate0v_result_summary"] or {}).get("gate0v_evaluator_passed"),
            "gate0v_verdict": (res_ind_c["gate0v_result_summary"] or {}).get("verdict"),
            "expected_token": "HOLD_INDIRECT_CONDITIONAL_ESCAPE_UNSUPPORTED_FOR_RELEASE",
            "exit_code": rc_ind_c,
            "hard_stops": res_ind_c["hard_stops"][:3],
            "holds": res_ind_c["holds"][:4],
            "passed": ok_38,
        })

        # 39. R06-B1b: Indirect-only bundle WITH conclusive adverse viral caspase blockade -> FAIL_HARD_STOP (exit 3)!
        g0v_ind_adv = copy.deepcopy(g0v_ind_only)
        g0v_ind_adv["gate0v_kill_stress_ap1903"]["active_or_persistent_hcmv_infection"]["plvap_iec"]["caspase9_3_activity_fold_over_vehicle"] = "1.2"
        g0v_ind_adv["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_ind_adv)
        _run_case(
            "r06_b1_indirect_only_with_adverse_caspase_composite_hard_stop",
            _make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_ind_adv),
            "FAIL_HARD_STOP_COMPOSITE_RELEASE",
            expected_legacy_pass=True,
            expected_gate0v_pass=False,
            expected_token="VIRAL_CASPASE_BLOCKADE",
        )

        # 40. R06-B2: Exact component-probability ratio boundary (veh 51/100, treated 0/90402 -> HOLD exit 2; 0/90404 -> PASS exit 0)!
        g0v_b2_h = copy.deepcopy(g0v_bank)
        arm_b2 = g0v_b2_h["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["alpha"]
        arm_b2["veh_72h_viable_n"] = 51
        arm_b2["veh_72h_input_n"] = 100
        arm_b2["ap1903_72h_input_n"] = 90402
        arm_b2["ap1903_72h_viable_survivors_k"] = 0
        v38.reconcile_fixture_per_unit_counts(g0v_b2_h)
        g0v_b2_h["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_b2_h)
        _run_case(
            "r06_b2_exact_component_ratio_veh51of100_0of90402_composite_hold",
            _make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_b2_h),
            "HOLD_COMPOSITE_RELEASE",
            expected_legacy_pass=True,
            expected_gate0v_pass=False,
            expected_token="72H_UNDERPOWERED_N_EFF",
        )

        g0v_b2_p = copy.deepcopy(g0v_b2_h)
        g0v_b2_p["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["alpha"]["ap1903_72h_input_n"] = 90404
        v38.reconcile_fixture_per_unit_counts(g0v_b2_p)
        g0v_b2_p["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_b2_p)
        _run_case(
            "r06_b2_exact_component_ratio_veh51of100_0of90404_composite_pass",
            _make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_b2_p),
            "PASS_COMPOSITE_BANK_QUALIFICATION",
            expected_legacy_pass=True,
            expected_gate0v_pass=True,
        )

        # 41. R06-B3a: Indeterminate straddling interval (1/5,000) under low vehicle survival -> HOLD (exit 2), NEVER FAIL_HARD_STOP!
        g0v_strad = copy.deepcopy(g0v_bank)
        arm_st = g0v_strad["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["alpha"]
        arm_st["veh_24h_viable_n"] = 50
        arm_st["veh_24h_input_n"] = 1000
        arm_st["ap1903_24h_input_n"] = 5000
        arm_st["ap1903_24h_viable_survivors_k"] = 1
        v38.reconcile_fixture_per_unit_counts(g0v_strad)
        g0v_strad["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_strad)
        _run_case(
            "r06_b3_1of5000_straddling_under_low_veh_composite_hold_not_hard_stop",
            _make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_strad),
            "HOLD_COMPOSITE_RELEASE",
            expected_legacy_pass=True,
            expected_gate0v_pass=False,
            expected_token="HOLD_INDETERMINATE_INTERVAL_STRADDLING_CAP_UNDER_CONTROL_HOLD",
        )

        # 42. R06-B3b: Conclusively adverse 30/5,000 under low vehicle survival -> FAIL_HARD_STOP_COMPOSITE_RELEASE!
        g0v_conc = copy.deepcopy(g0v_strad)
        g0v_conc["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["alpha"]["ap1903_24h_viable_survivors_k"] = 30
        v38.reconcile_fixture_per_unit_counts(g0v_conc)
        g0v_conc["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_conc)
        _run_case(
            "r06_b3_30of5000_conclusive_l_gt_cap_under_low_veh_composite_hard_stop",
            _make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_conc),
            "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",
        )

        # 43-46. R06-B4: Archived bank payload full structure, self-digest, nested identity, and live revalidation
        #        negative tests across BOTH store layouts (registry JSON AND file-backed directory store, CLI exit 2)!
        def _run_r06_b4_both_layouts(case_name: str, bad_arch_obj: Dict[str, Any], arch_key_sha: str) -> None:
            bad_rec_b4 = copy.deepcopy(auth_bank_rec)
            bad_rec_b4["bank_payload_sha256"] = arch_key_sha
            bad_rec_b4["sha256"] = compute_qualification_record_sha256(bad_rec_b4)
            g0v_surr_b4 = 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=bad_rec_b4["sha256"],
                openislet_root=openislet_root,
            )
            b4_bundle = _make_composite_bundle(clin_lot_id, mcb_id, pv_lead, leg_clin, g0v_surr_b4)
            b4_file = Path(td) / f"r06_b4_bundle_{case_name}.json"
            b4_file.write_text(json.dumps(b4_bundle), encoding="utf-8")

            reg_st = Path(td) / f"r06_b4_reg_{case_name}.json"
            reg_st.write_text(
                json.dumps({
                    "schema_version": v38.TRUSTED_STORE_SCHEMA_VERSION,
                    "store_authority_id": "OPENISLET_QA_RELEASE_BOARD_V1",
                    "bank_qualifications": {bad_rec_b4["sha256"]: bad_rec_b4},
                    "process_qualifications": {},
                    "archived_payloads": {arch_key_sha: bad_arch_obj},
                }),
                encoding="utf-8",
            )
            dir_st = Path(td) / f"r06_b4_dir_{case_name}"
            v38.write_record_to_trusted_qualification_store(dir_st, bad_rec_b4, category="bank_qualifications", archived_payload=None)
            (dir_st / "archived_payloads").mkdir(parents=True, exist_ok=True)
            (dir_st / "archived_payloads" / f"{arch_key_sha}.json").write_text(json.dumps(bad_arch_obj), encoding="utf-8")

            all_ok_both = True
            last_holds_b4: List[str] = []
            for st_l in (reg_st, dir_st):
                r_l, rc_l = evaluate_composite_lot_file(
                    b4_file,
                    legacy_evaluator=leg_fn,
                    gate0v_evaluator=g0v_fn,
                    trusted_qualification_store=st_l,
                    openislet_root=openislet_root,
                )
                last_holds_b4 = r_l["holds"]
                if not (
                    rc_l == 2
                    and r_l["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
                    and (r_l["gate0v_result_summary"] or {}).get("verdict") == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
                    and "HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD" in r_l["holds"]
                    and r_l["prior_qualification_authentication"]["archived_bank_payload_verified"] is False
                ):
                    all_ok_both = False
            cases.append({
                "case": case_name,
                "expected_verdict": "HOLD_COMPOSITE_RELEASE",
                "actual_verdict": "HOLD_COMPOSITE_RELEASE" if all_ok_both 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 all_ok_both else -1,
                "archived_bank_payload_verified": False if all_ok_both else None,
                "hard_stops": [],
                "holds": last_holds_b4[:4],
                "passed": all_ok_both,
            })

        # 43. (i) Metadata-only stub archive
        stub_b4 = {
            "lot_id": bank_lot_id,