scripts/evaluate_gate0v_composite_release.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/evaluate_gate0v_composite_release.py · SHA-256: 2be0252340222fe4…
name: str,
doc: Dict[str, Any],
expected_verdict: str,
*,
l_fn=leg_fn,
g_fn=g0v_fn,
store_path: Path | str | None = None,
expected_legacy_pass: bool | None = None,
expected_gate0v_pass: bool | None = None,
expected_token: str | None = None,
) -> Dict[str, Any]:
res = evaluate_composite_clinical_release(
doc,
legacy_evaluator=l_fn,
gate0v_evaluator=g_fn,
trusted_qualification_store=store_path,
openislet_root=openislet_root,
)
ok = res["composite_verdict"] == expected_verdict
if expected_legacy_pass is not None:
ok = ok and bool((res["legacy_result_summary"] or {}).get("legacy_evaluator_passed") is expected_legacy_pass)
if expected_gate0v_pass is not None:
ok = ok and bool((res["gate0v_result_summary"] or {}).get("gate0v_evaluator_passed") is expected_gate0v_pass)
if expected_token is not None:
all_msgs = res["hard_stops"] + res["holds"]
ok = ok and any(expected_token in m for m in all_msgs)
cases.append({
"case": name,
"expected_verdict": expected_verdict,
"actual_verdict": res["composite_verdict"],
"operational_tier": res.get("operational_tier"),
"legacy_passed": (res["legacy_result_summary"] or {}).get("legacy_evaluator_passed"),
"legacy_tier": (res["legacy_result_summary"] or {}).get("lot_release_readiness_tier"),
"legacy_resolved_pvid": (res["legacy_result_summary"] or {}).get("resolved_product_variant_id"),
"gate0v_passed": (res["gate0v_result_summary"] or {}).get("gate0v_evaluator_passed"),
"gate0v_verdict": (res["gate0v_result_summary"] or {}).get("verdict"),
"expected_token": expected_token,
"hard_stops": res["hard_stops"][:3],
"holds": res["holds"][:3],
"passed": ok,
})
return res
with tempfile.TemporaryDirectory() as td:
trusted_store = Path(td) / "independent_qa_store.json"
# 1. BANK_QUALIFICATION on canonical ISLET1_A4_ARM1B -> PASS_COMPOSITE_BANK_QUALIFICATION
leg_bank = build_legacy_complete_stage0_observations(
lot_id=bank_lot_id, mcb_id=mcb_id, product_variant_id=pv_lead, beta_only_cells_scored=5990.0
)
g0v_bank = v38.build_passing_reference_payload(
lot_id=bank_lot_id,
mcb_id=mcb_id,
product_variant_id=pv_lead,
qualification_tier="BANK_QUALIFICATION",
openislet_root=openislet_root,
)
bank_bundle = _make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_bank)
bank_res = _run_case(
"bank_qualification_canonical_arm1b_emits_pass_bank",
bank_bundle,
"PASS_COMPOSITE_BANK_QUALIFICATION",
expected_legacy_pass=True,
expected_gate0v_pass=True,
)
auth_bank_rec = bank_res["authenticated_bank_qualification_record"]
v38.write_record_to_trusted_qualification_store(
trusted_store,
auth_bank_rec,
category="bank_qualifications",
archived_payload=bank_bundle,
)
# 2. B1 LOT_RELEASE_SURROGATE clinical lot WITH independent external trusted store -> PASS_COMPOSITE_CLINICAL_RELEASE!
leg_clin = build_legacy_complete_stage0_observations(
lot_id=clin_lot_id, mcb_id=mcb_id, product_variant_id=pv_lead, beta_only_cells_scored=5990.0
)
g0v_clin = 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=auth_bank_rec["sha256"],
openislet_root=openislet_root,
)
clin_bundle = _make_composite_bundle(clin_lot_id, mcb_id, pv_lead, leg_clin, g0v_clin)
_run_case(
"b1_clinical_lot_with_external_trusted_store_emits_pass_clinical_release",
clin_bundle,
"PASS_COMPOSITE_CLINICAL_RELEASE",
store_path=trusted_store,
expected_legacy_pass=True,
expected_gate0v_pass=True,
)
# 3. B1 Self-attested inline bank-qual record WITHOUT --trusted-qualification-store -> HOLD_UNVERIFIED_EXTERNAL_APPROVAL_STORE!
g0v_self_att = 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_record=auth_bank_rec,
openislet_root=openislet_root,
)
_run_case(
"b1_self_attested_inline_bank_qual_without_external_store_held",
_make_composite_bundle(clin_lot_id, mcb_id, pv_lead, leg_clin, g0v_self_att, prior_bank_qual_record=auth_bank_rec),
"HOLD_COMPOSITE_RELEASE",
store_path=None,
expected_legacy_pass=True,
expected_token="HOLD_UNVERIFIED_EXTERNAL_APPROVAL_STORE",
)
# 4. B1 Reference SHA-256 NOT present in external trusted store -> HOLD_UNVERIFIED_EXTERNAL_APPROVAL_STORE!
g0v_absent = 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=hashlib.sha256(b"UNREGISTERED_BANK_APPROVAL").hexdigest(),
openislet_root=openislet_root,
)
_run_case(
"b1_unknown_digest_absent_from_external_store_held",
_make_composite_bundle(clin_lot_id, mcb_id, pv_lead, leg_clin, g0v_absent),
"HOLD_COMPOSITE_RELEASE",
store_path=trusted_store,
expected_token="HOLD_UNVERIFIED_EXTERNAL_APPROVAL_STORE",
)
# 5. B1 Mismatched MCB ID in external trusted store -> HOLD!
wrong_mcb_bank = copy.deepcopy(auth_bank_rec)
wrong_mcb_bank["mcb_id"] = "MCB-DIFFERENT-999"
wrong_mcb_bank["sha256"] = compute_qualification_record_sha256(wrong_mcb_bank)
v38.write_record_to_trusted_qualification_store(trusted_store, wrong_mcb_bank, category="bank_qualifications")
g0v_wrong_mcb = 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=wrong_mcb_bank["sha256"],
openislet_root=openislet_root,
)
_run_case(
"b1_mismatched_mcb_id_in_trusted_store_held",
_make_composite_bundle(clin_lot_id, mcb_id, pv_lead, leg_clin, g0v_wrong_mcb),
"HOLD_COMPOSITE_RELEASE",
store_path=trusted_store,
expected_token="PRIOR_BANK_QUAL_MCB_ID_MISMATCH",
)
# 6. B1 Mismatched product_variant_id in external trusted store -> HOLD!
wrong_pv_bank = copy.deepcopy(auth_bank_rec)
wrong_pv_bank["product_variant_id"] = "ISLET1_A4_ARM1A"
wrong_pv_bank["product_variant"] = "ISLET1_A4_ARM1A"
wrong_pv_bank["sha256"] = compute_qualification_record_sha256(wrong_pv_bank)
v38.write_record_to_trusted_qualification_store(trusted_store, wrong_pv_bank, category="bank_qualifications")
g0v_wrong_pv = 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=wrong_pv_bank["sha256"],
openislet_root=openislet_root,
)
_run_case(
"b1_mismatched_product_variant_id_in_trusted_store_held",
_make_composite_bundle(clin_lot_id, mcb_id, pv_lead, leg_clin, g0v_wrong_pv),
"HOLD_COMPOSITE_RELEASE",
store_path=trusted_store,
expected_token="PRIOR_BANK_QUAL_PRODUCT_VARIANT_ID_MISMATCH",
)
# 7. B1 Failing underlying Gate 0V verdict in trusted store -> HOLD!
fail_bank = copy.deepcopy(auth_bank_rec)
fail_bank["verdict"] = "HOLD_COMPOSITE_RELEASE"
fail_bank["sha256"] = compute_qualification_record_sha256(fail_bank)
v38.write_record_to_trusted_qualification_store(trusted_store, fail_bank, category="bank_qualifications")
g0v_fail_bank = 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=fail_bank["sha256"],
openislet_root=openislet_root,
)
_run_case(
"b1_failing_prior_bank_verdict_in_trusted_store_held",
_make_composite_bundle(clin_lot_id, mcb_id, pv_lead, leg_clin, g0v_fail_bank),
"HOLD_COMPOSITE_RELEASE",
store_path=trusted_store,
expected_token="VERDICT_NOT_PASS_COMPOSITE_BANK_QUALIFICATION",
)
# 8. B1 Tampered record inside external trusted store -> HOLD!
tampered_store = Path(td) / "tampered_store.json"
tampered_rec = copy.deepcopy(auth_bank_rec)
tampered_rec["bank_lot_id"] = "BANK-TAMPERED"
tampered_store.write_text(
json.dumps({"bank_qualifications": {auth_bank_rec["sha256"]: tampered_rec}}),
encoding="utf-8",
)
_run_case(
"b1_tampered_bank_record_inside_external_store_held",
clin_bundle,
"HOLD_COMPOSITE_RELEASE",
store_path=tampered_store,
expected_token="RECORD_INTERNAL_SHA256_MISMATCH",
)
# 9. B2 Unregistered product_variant_id ("ISLET1_DESIGN_A_LEAD") rejected fail-closed!
leg_unreg = build_legacy_complete_stage0_observations(lot_id=bank_lot_id, mcb_id=mcb_id, product_variant_id="ISLET1_DESIGN_A_LEAD")
g0v_unreg = v38.build_passing_reference_payload(lot_id=bank_lot_id, mcb_id=mcb_id, product_variant_id="ISLET1_DESIGN_A_LEAD", openislet_root=openislet_root)
_run_case(
"b2_unregistered_product_variant_id_held",
_make_composite_bundle(bank_lot_id, mcb_id, "ISLET1_DESIGN_A_LEAD", leg_unreg, g0v_unreg),
"HOLD_COMPOSITE_RELEASE",
expected_token="UNREGISTERED_PRODUCT_VARIANT_ID",
)
# 10. B2 Registered alias ("ARM_1B") reconciles canonically to ISLET1_A4_ARM1B across wrapper, wetlab_contract, and Gate 0V!
leg_alias = build_legacy_complete_stage0_observations(lot_id=bank_lot_id, mcb_id=mcb_id, product_variant_id="ARM_1B")
_run_case(
"b2_registered_alias_arm1b_reconciles_canonically",
_make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_alias, g0v_bank),
"PASS_COMPOSITE_BANK_QUALIFICATION",
expected_legacy_pass=True,
expected_gate0v_pass=True,
)
# 11. B2 Legacy vs Gate 0V product_variant_id mismatch (ISLET1_A4_ARM1A vs ISLET1_A4_ARM1B) -> HOLD!
leg_other_pv = build_legacy_complete_stage0_observations(lot_id=bank_lot_id, mcb_id=mcb_id, product_variant_id="ISLET1_A4_ARM1A")
_run_case(
"b2_legacy_vs_gate0v_product_variant_id_mismatch_held",
_make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_other_pv, g0v_bank),
"HOLD_COMPOSITE_RELEASE",
expected_token="LEGACY_PRODUCT_VARIANT_ID_MISMATCH",
)
# 12. B2 Staged execution_supported=False CD55/CFH comparator is HONESTLY HELD by live wetlab_contract.py even when Gate 0V passes!
pv_cfh = "ISLET1_Y_FULLSTACK_V2_CD55_CFH_COMPARATOR"
leg_cfh = build_legacy_complete_stage0_observations(lot_id=bank_lot_id, mcb_id=mcb_id, product_variant_id=pv_cfh)
g0v_cfh = v38.build_passing_reference_payload(
lot_id=bank_lot_id,
mcb_id=mcb_id,
product_variant_id=pv_cfh,
ectopic_receptors=["CD55_FULL_LENGTH"],
include_cd46_addendum=False,
include_cd55_addendum=True,
openislet_root=openislet_root,