scripts/verify_iip0043_wholegraft_gate0v_and_calibration.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0043_wholegraft_gate0v_and_calibration.py · SHA-256: 20706180ed1ed6a2…
bad_call()
except ValueError:
raised_ve = True
except Exception:
raised_ve = False
if not raised_ve:
r10_api_ok = False
tests.append({
"test": "r10_b2_nw08_ocr_file_and_api_reject_10pow400_1e500_overflow_and_list_route_exit_2",
"file_cases_all_structured_hold_exit_2": r10_f_ok,
"api_cases_all_raise_value_error": r10_api_ok,
"passed": bool(r10_f_ok and r10_api_ok),
})
# 20. R10-B1: Coupled lot + planned-route + lot_payload_sha256 + evidence digest + external store binding
# on `evaluate_nw08_measured_ocr_file`: matched R2_DZ40 passes (exit 0), matched failing R1_350_stress
# fails (exit 3), while route swap, stale lot hash, tampered ocr_record_sha256, and missing lot route HOLD (exit 2)!
with tempfile.TemporaryDirectory() as td_r10_bind:
td_rb = Path(td_r10_bind)
ev_sha = _valid_digest("r10_b1_nw08_raw_respirometry_v1")
lot_sha_r2 = _valid_digest("r10_b1_lot_bundle_r2")
lot_sha_r1 = _valid_digest("r10_b1_lot_bundle_r1")
bind_ctx_r2 = {
"lot_id": "LOT-R10-BIND-001",
"mcb_id": "MCB-R10-BIND-001",
"canonical_product_variant_id": "ISLET1_A4_ARM1B",
"computed_payload_sha256": lot_sha_r2,
"payload_sha256_verified": True,
"planned_nw08_route_id": "R2_DZ40",
"planned_nw08_route_errors": [],
"planned_nw08_measurement_evidence_sha256": ev_sha,
"planned_nw08_measurement_not_before_utc": "2026-11-28T00:00:00Z",
"require_trusted_nw08_ocr_record": True,
}
bind_ctx_r1 = {
**bind_ctx_r2,
"computed_payload_sha256": lot_sha_r1,
"planned_nw08_route_id": "R1_350_stress",
"require_trusted_nw08_ocr_record": False,
}
bind_ctx_no_route = {**bind_ctx_r1, "planned_nw08_route_id": None}
rec_r2_ok = build_bound_nw08_ocr_record(
lot_id="LOT-R10-BIND-001",
mcb_id="MCB-R10-BIND-001",
product_variant_id="ISLET1_A4_ARM1B",
route_id="R2_DZ40",
lot_payload_sha256=lot_sha_r2,
measured_ocr=1.097,
uncertainty_se=0.0,
measurement_record_id="OCR-REC-R10-001",
measurement_evidence_sha256=ev_sha,
measurement_timestamp_utc="2026-11-29T00:00:00Z",
)
rec_r1_fail = build_bound_nw08_ocr_record(
lot_id="LOT-R10-BIND-001",
mcb_id="MCB-R10-BIND-001",
product_variant_id="ISLET1_A4_ARM1B",
route_id="R1_350_stress",
lot_payload_sha256=lot_sha_r1,
measured_ocr=1.3164,
uncertainty_se=0.0,
measurement_record_id="OCR-REC-R10-002",
measurement_evidence_sha256=ev_sha,
measurement_timestamp_utc="2026-11-29T00:00:00Z",
)
rec_r1_swapped_r2 = build_bound_nw08_ocr_record(
lot_id="LOT-R10-BIND-001",
mcb_id="MCB-R10-BIND-001",
product_variant_id="ISLET1_A4_ARM1B",
route_id="R2_DZ40",
lot_payload_sha256=lot_sha_r1,
measured_ocr=1.3164,
uncertainty_se=0.0,
measurement_record_id="OCR-REC-R10-SWAP",
measurement_evidence_sha256=ev_sha,
measurement_timestamp_utc="2026-11-29T00:00:00Z",
)
rec_stale_hash = build_bound_nw08_ocr_record(
lot_id="LOT-R10-BIND-001",
mcb_id="MCB-R10-BIND-001",
product_variant_id="ISLET1_A4_ARM1B",
route_id="R1_350_stress",
lot_payload_sha256=_valid_digest("r10_b1_older_lot_hash"),
measured_ocr=1.097,
uncertainty_se=0.0,
measurement_record_id="OCR-REC-R10-STALE",
measurement_evidence_sha256=ev_sha,
measurement_timestamp_utc="2026-11-29T00:00:00Z",
)
ocr_store_f = td_rb / "qa_ocr_store.json"
write_record_to_trusted_qualification_store(ocr_store_f, rec_r2_ok, category="nw08_ocr_records")
f_r2 = td_rb / "r2_ok.json"
f_r2.write_text(json.dumps(rec_r2_ok), encoding="utf-8")
f_r1_f = td_rb / "r1_fail.json"
f_r1_f.write_text(json.dumps(rec_r1_fail), encoding="utf-8")
f_swap = td_rb / "r1_swap_r2.json"
f_swap.write_text(json.dumps(rec_r1_swapped_r2), encoding="utf-8")
f_stale = td_rb / "r1_stale.json"
f_stale.write_text(json.dumps(rec_stale_hash), encoding="utf-8")
rp_ok, rcp_ok = evaluate_nw08_measured_ocr_file(
f_r2, openislet_root=openislet_root, coupled_lot_binding=bind_ctx_r2, trusted_qualification_store=ocr_store_f
)
rp_nostore, rcp_nostore = evaluate_nw08_measured_ocr_file(
f_r2, openislet_root=openislet_root, coupled_lot_binding=bind_ctx_r2, trusted_qualification_store=None
)
rf_r1, rcf_r1 = evaluate_nw08_measured_ocr_file(
f_r1_f, openislet_root=openislet_root, coupled_lot_binding=bind_ctx_r1
)
rs_sw, rcs_sw = evaluate_nw08_measured_ocr_file(
f_swap, openislet_root=openislet_root, coupled_lot_binding=bind_ctx_r1
)
rs_st, rcs_st = evaluate_nw08_measured_ocr_file(
f_stale, openislet_root=openislet_root, coupled_lot_binding=bind_ctx_r1
)
rs_nr, rcs_nr = evaluate_nw08_measured_ocr_file(
f_r1_f, openislet_root=openislet_root, coupled_lot_binding=bind_ctx_no_route
)
ok_20 = bool(
rcp_ok == 0
and rp_ok.get("adjudicated_verdict") == "PASS"
and rp_ok.get("lot_binding_verified") is True
and rcp_nostore == 2
and "HOLD_NW08_COUPLED_EXTERNAL_OCR_STORE_REQUIRED_BUT_NOT_PROVIDED" in (rp_nostore.get("holds") or [])
and rcf_r1 == 3
and rf_r1.get("adjudicated_verdict") == "FAIL"
and rcs_sw == 2
and "HOLD_NW08_COUPLED_ROUTE_ID_MISMATCH" in (rs_sw.get("holds") or [])
and rcs_st == 2
and "HOLD_NW08_COUPLED_STALE_OR_MISMATCHED_LOT_PAYLOAD_SHA256" in (rs_st.get("holds") or [])
and rcs_nr == 2
and "HOLD_NW08_COUPLED_LOT_MISSING_PLANNED_ROUTE" in (rs_nr.get("holds") or [])
)
tests.append({
"test": "r10_b1_nw08_ocr_file_coupled_binding_matched_swapped_stale_missing_route_and_store",
"matched_pass_rc": rcp_ok,
"missing_required_store_rc": rcp_nostore,
"matched_fail_rc": rcf_r1,
"route_swap_rc": rcs_sw,
"stale_hash_rc": rcs_st,
"missing_lot_route_rc": rcs_nr,
"passed": ok_20,
})
# 21. R11-B2: Standalone unbound `--dispatch-nw08-ocr` (`evaluate_nw08_measured_ocr_file` with
# coupled_lot_binding=None) MUST emit `release_authorizing = False` at top-level AND across
# every nested sub-dict on BOTH monotone fast-path PASS, 3D-FVM solve PASS, and 3D-FVM FAIL!
def _has_any_release_authorizing_true(obj: Any) -> bool:
stack: List[Any] = [obj]
while stack:
cur = stack.pop()
if isinstance(cur, dict):
if cur.get("release_authorizing") is True:
return True
for v in cur.values():
if isinstance(v, (dict, list, tuple)):
stack.append(v)
elif isinstance(cur, (list, tuple)):
for item in cur:
if isinstance(item, (dict, list, tuple)):
stack.append(item)
return False
with tempfile.TemporaryDirectory() as td_r11_b2:
td_b2 = Path(td_r11_b2)
f_sa_fast = td_b2 / "sa_fast_pass.json"
f_sa_fast.write_text('{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": 0.0}', encoding="utf-8")
f_sa_3d_pass = td_b2 / "sa_3d_pass.json"
f_sa_3d_pass.write_text('{"route_id": "R2_DZ40", "measured_ocr": 1.3164, "uncertainty_se": 0.0}', encoding="utf-8")
f_sa_3d_fail = td_b2 / "sa_3d_fail.json"
f_sa_3d_fail.write_text('{"route_id": "R1_350_stress", "measured_ocr": 1.3164, "uncertainty_se": 0.0}', encoding="utf-8")
r_sa_fast, rc_sa_fast = evaluate_nw08_measured_ocr_file(f_sa_fast, openislet_root=openislet_root)
r_sa_3dp, rc_sa_3dp = evaluate_nw08_measured_ocr_file(f_sa_3d_pass, openislet_root=openislet_root)
r_sa_3df, rc_sa_3df = evaluate_nw08_measured_ocr_file(f_sa_3d_fail, openislet_root=openislet_root)
ok_21 = bool(
rc_sa_fast == 0
and r_sa_fast.get("adjudicated_verdict") == "PASS"
and r_sa_fast.get("binding_mode") == "STANDALONE_UNBOUND_DIAGNOSTIC_ONLY"
and r_sa_fast.get("lot_binding_verified") is False
and r_sa_fast.get("release_authorizing") is False
and r_sa_fast.get("solver_cleared_oxygen_floor_diagnostic") is True
and not _has_any_release_authorizing_true(r_sa_fast)
and rc_sa_3dp == 0
and r_sa_3dp.get("adjudicated_verdict") == "PASS"
and r_sa_3dp.get("solver_executed") is True
and r_sa_3dp.get("release_authorizing") is False
and r_sa_3dp.get("solver_cleared_oxygen_floor_diagnostic") is True
and not _has_any_release_authorizing_true(r_sa_3dp)
and rc_sa_3df == 3
and r_sa_3df.get("adjudicated_verdict") == "FAIL"
and r_sa_3df.get("release_authorizing") is False
and r_sa_3df.get("solver_cleared_oxygen_floor_diagnostic") is False
and not _has_any_release_authorizing_true(r_sa_3df)
)
tests.append({
"test": "r11_b2_standalone_unbound_nw08_ocr_release_authorizing_false_recursively",
"fast_pass_release_authorizing": r_sa_fast.get("release_authorizing"),
"solve_pass_release_authorizing": r_sa_3dp.get("release_authorizing"),
"solve_fail_release_authorizing": r_sa_3df.get("release_authorizing"),
"passed": ok_21,
})
# 22. R11-B4: JSON nesting depth > 64 AND injected parser RecursionError on `--dispatch-nw08-ocr`
# intake BOTH map cleanly to structured HOLD exit 2 (`release_authorizing = False`), zero traceback!
with tempfile.TemporaryDirectory() as td_r11_b4:
td_b4 = Path(td_r11_b4)
f_deep_ocr = td_b4 / "deep_70_ocr.json"
f_deep_ocr.write_text('{"a":' * 70 + "1" + "}" * 70, encoding="utf-8")
r_deep_ocr, rc_deep_ocr = evaluate_nw08_measured_ocr_file(f_deep_ocr, openislet_root=openislet_root)
f_empty_ocr = td_b4 / "empty_ocr.json"
f_empty_ocr.write_text("{}", encoding="utf-8")
orig_json_loads = json.loads
def _raise_rec_err(*_a: Any, **_kw: Any) -> Any:
raise RecursionError("simulated parser recursion limit")
json.loads = _raise_rec_err # type: ignore[assignment]
try:
r_rec_ocr, rc_rec_ocr = evaluate_nw08_measured_ocr_file(f_empty_ocr, openislet_root=openislet_root)
finally:
json.loads = orig_json_loads # type: ignore[assignment]
ok_22 = bool(
rc_deep_ocr == 2
and r_deep_ocr.get("adjudicated_verdict") == "HOLD"
and r_deep_ocr.get("release_authorizing") is False
and "HOLD_NW08_AMBIGUOUS_OR_NONCANONICAL_OCR_JSON:JSON_DEPTH_OR_RECURSION_LIMIT_EXCEEDED" in (r_deep_ocr.get("holds") or [])
and rc_rec_ocr == 2
and r_rec_ocr.get("adjudicated_verdict") == "HOLD"
and r_rec_ocr.get("release_authorizing") is False
and "HOLD_NW08_AMBIGUOUS_OR_NONCANONICAL_OCR_JSON:JSON_DEPTH_OR_RECURSION_LIMIT_EXCEEDED" in (r_rec_ocr.get("holds") or [])
)
tests.append({
"test": "r11_b4_nw08_ocr_depth_gt_64_and_injected_recursion_error_structured_hold_exit_2",
"deep_70_rc": rc_deep_ocr,
"injected_recursion_error_rc": rc_rec_ocr,
"passed": ok_22,
})
# 23. R12-B2: Nonzero float underflow (-1e-400, 1e-400) AND signed negative zero (-0.0, "-0.0")
# on NW-08 OCR boundary keys MUST fail closed (exit 2 HOLD, release_authorizing=False,
# solver_executed=False on file entry; ValueError on Python API) — NEVER silent PASS!
with tempfile.TemporaryDirectory() as td_r12_b2:
td_12b2 = Path(td_r12_b2)
f_uf_se = td_12b2 / "underflow_neg_se.json"
f_uf_se.write_text('{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": -1e-400}', encoding="utf-8")
f_uf_pos = td_12b2 / "underflow_pos_ocr.json"
f_uf_pos.write_text('{"route_id": "R2_DZ40", "measured_ocr": 1e-400, "uncertainty_se": 0.0}', encoding="utf-8")
f_sz_num = td_12b2 / "signed_zero_num.json"
f_sz_num.write_text('{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": -0.0}', encoding="utf-8")