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…
"HOLD_NW08_COUPLED_MEASUREMENT_EVIDENCE_SHA256_MISMATCH",
),
(
"stale_timestamp",
clin_r2_f,
v38.build_bound_nw08_ocr_record(
lot_id=clin_lot_id, mcb_id=mcb_id, product_variant_id=pv_lead, route_id="R2_DZ40",
lot_payload_sha256=clin_r2_bundle["payload_sha256"], measured_ocr=1.097, uncertainty_se=0.0,
measurement_record_id="OCR-OLDTS-1", measurement_evidence_sha256=clin_ev_sha,
measurement_timestamp_utc="2026-11-27T23:59:59Z",
),
"HOLD_NW08_COUPLED_STALE_MEASUREMENT_TIMESTAMP_UTC",
),
(
"unbound_legacy_3field",
clin_r2_f,
{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": 0.0},
"HOLD_NW08_COUPLED_MISSING_REQUIRED_BINDING_KEY:lot_id",
),
(
"lot_missing_planned_route",
clin_noroute_f,
v38.build_bound_nw08_ocr_record(
lot_id=clin_lot_id, mcb_id=mcb_id, product_variant_id=pv_lead, route_id="R2_DZ40",
lot_payload_sha256=clin_bundle["payload_sha256"], measured_ocr=1.097, uncertainty_se=0.0,
measurement_record_id="OCR-NOROUTE-1", measurement_evidence_sha256=clin_ev_sha,
measurement_timestamp_utc="2026-11-29T01:00:00Z",
),
"HOLD_NW08_COUPLED_LOT_MISSING_PLANNED_ROUTE",
),
]
ok_67 = True
last_67_holds: List[str] = []
for tag_67, lot_f_67, ocr_obj_67, exp_tok_67 in bad_coupled_matrix:
of_67 = Path(td) / f"r10_b1d_{tag_67}.json"
of_67.write_text(json.dumps(ocr_obj_67, sort_keys=True), encoding="utf-8")
r_67, rc_67 = evaluate_composite_lot_file(
lot_f_67,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=trusted_store,
openislet_root=openislet_root,
nw08_ocr_json_path=of_67,
)
last_67_holds = r_67["holds"]
if not (
rc_67 == 2
and r_67["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
and exp_tok_67 in r_67["holds"]
and (r_67.get("nw08_measured_ocr_dispatch_result") or {}).get("solver_executed") is False
):
ok_67 = False
cases.append({
"case": "r10_b1d_coupled_stale_hash_mismatched_ids_tampered_digest_unbound_and_missing_route_held_exit_2",
"expected_verdict": "HOLD_COMPOSITE_RELEASE",
"actual_verdict": "HOLD_COMPOSITE_RELEASE" if ok_67 else "UNEXPECTED_PASS_OR_TOKEN",
"operational_tier": "LOT_RELEASE_SURROGATE",
"legacy_passed": True,
"legacy_tier": LEGACY_PASS_TIER,
"legacy_resolved_pvid": pv_lead,
"gate0v_passed": True,
"gate0v_verdict": "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE",
"expected_token": "HOLD_NW08_COUPLED_LOT_MISSING_PLANNED_ROUTE",
"exit_code": 2 if ok_67 else -1,
"hard_stops": [],
"holds": last_67_holds[:3],
"passed": ok_67,
})
# 68. R10-B1e: External `--trusted-qualification-store` `nw08_ocr_records` verification across BOTH
# registry JSON and directory store layouts (registered -> exit 0; unregistered/tampered -> exit 2)!
clin_r2_req_store = _make_composite_bundle(
clin_lot_id,
mcb_id,
pv_lead,
leg_clin,
g0v_clin,
nw08_route_id="R2_DZ40",
nw08_measurement_evidence_sha256=clin_ev_sha,
require_trusted_nw08_ocr_record=True,
)
clin_r2_req_f = Path(td) / "r10_b1e_clin_req_store.json"
clin_r2_req_f.write_text(json.dumps(clin_r2_req_store, sort_keys=True), encoding="utf-8")
ocr_r2_req_rec = v38.build_bound_nw08_ocr_record(
lot_id=clin_lot_id,
mcb_id=mcb_id,
product_variant_id=pv_lead,
route_id="R2_DZ40",
lot_payload_sha256=clin_r2_req_store["payload_sha256"],
measured_ocr=1.097,
uncertainty_se=0.0,
measurement_record_id="OCR-CLIN-STORE-001",
measurement_evidence_sha256=clin_ev_sha,
measurement_timestamp_utc="2026-11-29T02:00:00Z",
)
ocr_r2_req_f = Path(td) / "r10_b1e_ocr_req.json"
ocr_r2_req_f.write_text(json.dumps(ocr_r2_req_rec, sort_keys=True), encoding="utf-8")
reg_with_ocr = Path(td) / "r10_b1e_reg_ocr.json"
dir_with_ocr = Path(td) / "r10_b1e_dir_ocr"
for st_ocr in (reg_with_ocr, dir_with_ocr):
v38.write_record_to_trusted_qualification_store(
st_ocr, auth_bank_rec, category="bank_qualifications", archived_payload=bank_bundle
)
v38.write_record_to_trusted_qualification_store(st_ocr, ocr_r2_req_rec, category="nw08_ocr_records")
ok_68 = True
for st_ocr in (reg_with_ocr, dir_with_ocr):
rp_68, rcp_68 = evaluate_composite_lot_file(
clin_r2_req_f,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=st_ocr,
openislet_root=openislet_root,
nw08_ocr_json_path=ocr_r2_req_f,
)
if not (
rcp_68 == 0
and rp_68["composite_verdict"] == "PASS_COMPOSITE_CLINICAL_RELEASE"
and (((rp_68.get("nw08_measured_ocr_dispatch_result") or {}).get("nw08_lot_binding") or {}).get("external_ocr_store_verification") or {}).get("verified") is True
):
ok_68 = False
# Unregistered OCR record against store missing nw08_ocr_records when require_trusted_nw08_ocr_record=True -> HOLD exit 2!
rm_68, rcm_68 = evaluate_composite_lot_file(
clin_r2_req_f,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=trusted_store,
openislet_root=openislet_root,
nw08_ocr_json_path=ocr_r2_req_f,
)
if not (
rcm_68 == 2
and rm_68["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
and "HOLD_NW08_COUPLED_UNVERIFIED_EXTERNAL_OCR_STORE_RECORD" in rm_68["holds"]
):
ok_68 = False
cases.append({
"case": "r10_b1e_coupled_external_trusted_store_nw08_ocr_records_both_layouts_pass_and_unregistered_hold",
"expected_verdict": "PASS_0_AND_UNREGISTERED_HOLD_2",
"actual_verdict": "PASS_0_AND_UNREGISTERED_HOLD_2" if ok_68 else "STORE_VERIFICATION_FAILED",
"operational_tier": "LOT_RELEASE_SURROGATE",
"legacy_passed": True,
"legacy_tier": LEGACY_PASS_TIER,
"legacy_resolved_pvid": pv_lead,
"gate0v_passed": True,
"gate0v_verdict": "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE",
"expected_token": "HOLD_NW08_COUPLED_UNVERIFIED_EXTERNAL_OCR_STORE_RECORD",
"exit_code": 0 if ok_68 else -1,
"hard_stops": [],
"holds": rm_68["holds"][:3],
"passed": ok_68,
})
# 69. R10-B2: Composite CLI boundary rejects schema-invalid unhashable list qualification_tier AND
# out-of-float64-range finite integers (10**400) / overflowing floats (1e500) on --nw08-ocr-json
# with structured JSON HOLD_COMPOSITE_RELEASE (exit 2), ZERO uncaught tracebacks!
list_tier_lot_f = Path(td) / "r10_b2_list_tier_lot.json"
list_tier_lot_f.write_text(
json.dumps({"lot_id": "L1", "mcb_id": "M1", "product_variant_id": pv_lead, "qualification_tier": ["BANK_QUALIFICATION"]}),
encoding="utf-8",
)
r_lt_69, rc_lt_69 = evaluate_composite_lot_file(
list_tier_lot_f, legacy_evaluator=leg_fn, gate0v_evaluator=g0v_fn, openislet_root=openislet_root
)
ok_69 = bool(rc_lt_69 == 2 and r_lt_69["composite_verdict"] == "HOLD_COMPOSITE_RELEASE")
last_69_holds = r_lt_69["holds"]
for tag_69, raw_69 in (
("meas_1e400", f'{{"route_id": "R2_DZ40", "measured_ocr": {10**400}, "uncertainty_se": 0}}'),
("se_1e400", f'{{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": {10**400}}}'),
("pbed_1e400", f'{{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": 0, "p_bed_mmhg": {10**400}}}'),
("flt_1e500", '{"route_id": "R2_DZ40", "measured_ocr": 1e500, "uncertainty_se": 0}'),
):
hf_69 = Path(td) / f"r10_b2_ocr_{tag_69}.json"
hf_69.write_text(raw_69, encoding="utf-8")
rh_69, rch_69 = evaluate_composite_lot_file(
clin_r2_f,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=trusted_store,
openislet_root=openislet_root,
nw08_ocr_json_path=hf_69,
)
last_69_holds = rh_69["holds"]
if not (rch_69 == 2 and rh_69["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"):
ok_69 = False
cases.append({
"case": "r10_b2_composite_cli_boundary_unhashable_list_tier_and_10pow400_ocr_structured_hold_exit_2",
"expected_verdict": "HOLD_COMPOSITE_RELEASE",
"actual_verdict": "HOLD_COMPOSITE_RELEASE" if ok_69 else "UNHANDLED_ERROR_OR_WRONG_RC",
"operational_tier": "LOT_RELEASE_SURROGATE",
"legacy_passed": True,
"legacy_tier": LEGACY_PASS_TIER,
"legacy_resolved_pvid": pv_lead,
"gate0v_passed": True,
"gate0v_verdict": "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE",
"expected_token": "HOLD_NW08_AMBIGUOUS_OR_NONCANONICAL_OCR_JSON",
"exit_code": 2 if ok_69 else -1,
"hard_stops": [],
"holds": last_69_holds[:3],
"passed": ok_69,
})
# ------------------------------------------------------------------
# Round-11 Final-Closure Regressions (R11-B1, R11-B3, R11-B4)
# ------------------------------------------------------------------
# 70. R11-B1: Complete 4-state release acceptance matrix for `require_trusted_nw08_ocr_record = True`
# across BOTH Python API (`evaluate_composite_clinical_release`) AND CLI file entry point
# (`evaluate_composite_lot_file`), plus independent biological FAIL preservation & strict bool check!
clin_r1_req_store = _make_composite_bundle(
clin_lot_id,
mcb_id,
pv_lead,
leg_clin,
g0v_clin,
nw08_route_id="R1_350_stress",
nw08_measurement_evidence_sha256=clin_ev_sha,
require_trusted_nw08_ocr_record=True,
)
clin_r1_req_f = Path(td) / "r11_b1_clin_r1_req.json"
clin_r1_req_f.write_text(json.dumps(clin_r1_req_store, sort_keys=True), encoding="utf-8")
ocr_r1_req_fail = v38.build_bound_nw08_ocr_record(
lot_id=clin_lot_id,
mcb_id=mcb_id,
product_variant_id=pv_lead,
route_id="R1_350_stress",
lot_payload_sha256=clin_r1_req_store["payload_sha256"],
measured_ocr=1.3164,
uncertainty_se=0.0,
measurement_record_id="OCR-CLIN-R1-REQ-FAIL",
measurement_evidence_sha256=clin_ev_sha,
measurement_timestamp_utc="2026-11-29T02:00:00Z",
)
ocr_r1_req_fail_f = Path(td) / "r11_b1_ocr_r1_req_fail.json"
ocr_r1_req_fail_f.write_text(json.dumps(ocr_r1_req_fail, sort_keys=True), encoding="utf-8")
reg_with_both_ocr = Path(td) / "r11_b1_reg_both_ocr.json"
v38.write_record_to_trusted_qualification_store(
reg_with_both_ocr, auth_bank_rec, category="bank_qualifications", archived_payload=bank_bundle
)
v38.write_record_to_trusted_qualification_store(reg_with_both_ocr, ocr_r2_req_rec, category="nw08_ocr_records")
v38.write_record_to_trusted_qualification_store(reg_with_both_ocr, ocr_r1_req_fail, category="nw08_ocr_records")
# State 1: Required OCR omitted -> HOLD_NW08_REQUIRED_OCR_RECORD_MISSING (exit 2, release_authorizing=False)
api_s1 = evaluate_composite_clinical_release(
clin_r2_req_store,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=reg_with_both_ocr,
openislet_root=openislet_root,
)
cli_s1, rc_s1 = evaluate_composite_lot_file(
clin_r2_req_f,