"primary_peer_reviewed_full_text_verified": True, "parallel_cmc_readiness_ledger_disclosed": True, "lot_to_mcb_manifest": {f"LOT-{j}": f"MCB-{(j - 1) // 2 + 1}" for j in range(1, 7)}, "recipients": good_30, } g28a_bare = evaluate_gate28a_h1_promotion(p_bare_bools, trusted_clinical_store=clin_store_json) p_stale = copy.deepcopy(p_good_json) p_stale["recipients"][0]["followup_months"] = 18.0 g28a_stale = evaluate_gate28a_h1_promotion(p_stale, trusted_clinical_store=clin_store_json) if g28a_bare["promotion_authorized"] is not False or g28a_stale["promotion_authorized"] is not False: raise ValueError(f"B2 bare booleans or stale cohort digest MUST fail closed: {g28a_bare} / {g28a_stale}") cases.append({"case": "b2_gate28a_reject_bare_booleans_and_wrong_cohort_or_digest_attestation", "passed": True}) # 25. B2 prohibited peri-infusion systemic glucocorticoid recipient in same 30-cohort FAILS to promote! steroid_30 = copy.deepcopy(good_30) steroid_30[0]["intercurrent_event"] = "PROHIBITED_PERI_INFUSION_GLUCOCORTICOIDS" p_ster, _ = build_valid_gate28a_reference_bundle(clin_store_json, steroid_30, cohort_id="COHORT-STER-30") g28a_ster = evaluate_gate28a_h1_promotion(p_ster, trusted_clinical_store=clin_store_json) if ( g28a_ster["promotion_authorized"] is not False or g28a_ster["k"] != 29 or g28a_ster["secondary_steroid_exposed_c2b_count_excluded_from_primary"] != 1 ): raise ValueError(f"B2 prohibited glucocorticoid recipient MUST count as 0 and fail promotion: {g28a_ster}") cases.append({"case": "b2_gate28a_prohibited_glucocorticoid_counts_as_zero_and_fails", "passed": True, "k": g28a_ster["k"]}) # 26. B2 rescue repeat infusion, missing endpoint, and pre-landmark death all adjudicate deterministically to 0! ie_30 = copy.deepcopy(good_30) ie_30[0]["intercurrent_event"] = "RESCUE_REPEAT_INFUSION" ie_30[1]["intercurrent_event"] = "MISSING_PRIMARY_ENDPOINT_OR_LTFU" ie_30[2]["intercurrent_event"] = "PRE_LANDMARK_DEATH" p_ie, _ = build_valid_gate28a_reference_bundle(clin_store_json, ie_30, cohort_id="COHORT-IE-30") g28a_ie = evaluate_gate28a_h1_promotion(p_ie, trusted_clinical_store=clin_store_json) if g28a_ie["promotion_authorized"] is not False or g28a_ie["k"] != 27: raise ValueError(f"B2 intercurrent-event adjudication check failed: {g28a_ie}") cases.append({"case": "b2_gate28a_rescue_missing_death_all_adjudicate_zero", "passed": True, "k": g28a_ie["k"]}) # 27. B2 incompatible cohort (autologous product or rectus-sheath site) fails closed! p_inc, _ = build_valid_gate28a_reference_bundle( clin_store_json, good_30, cohort_id="COHORT-INC-SITE", transplant_site="ABDOMINAL_ANTERIOR_RECTUS_SHEATH" ) g28a_inc = evaluate_gate28a_h1_promotion(p_inc, trusted_clinical_store=clin_store_json) if g28a_inc["promotion_authorized"] is not False: raise ValueError(f"B2 incompatible site cohort MUST fail closed: {g28a_inc}") cases.append({"case": "b2_gate28a_incompatible_site_fails_closed", "passed": True}) # 28. B2/B5 context-independence: max_single_lot_share = 13/32 (0.40625 > 0.40) FAILS identically under prec=2 and prec=28! share_32 = [ { "recipient_id": f"SH-{i:02d}", "lot_id": "LOT-BIG" if i <= 13 else f"LOT-{(i - 14) // 5 + 2}", "mcb_id": "MCB-1" if i <= 13 else f"MCB-{(i - 14) // 10 + 2}", "followup_months": 12.0, "met_c2b_criteria": True, "intercurrent_event": "NONE", } for i in range(1, 33) ] share_payload, _ = build_valid_gate28a_reference_bundle(clin_store_json, share_32, cohort_id="COHORT-SHARE-32") with localcontext() as ctx_low: ctx_low.prec = 2 r_sh_low = evaluate_gate28a_h1_promotion(share_payload, trusted_clinical_store=clin_store_json) with localcontext() as ctx_hi: ctx_hi.prec = 28 r_sh_hi = evaluate_gate28a_h1_promotion(share_payload, trusted_clinical_store=clin_store_json) if r_sh_low["promotion_authorized"] is not False or r_sh_hi["promotion_authorized"] is not False: raise ValueError(f"B2/B5 max_single_lot_share 13/32 MUST fail identically under prec=2 and prec=28: {r_sh_low} / {r_sh_hi}") cases.append({"case": "b2_b5_gate28a_max_single_lot_share_context_independent_prec2_vs_prec28", "passed": True}) # 29. R06 Blocking 4 file-wide: Gate 28-A & CMC evaluators immune to ALL caller Decimal traps! with localcontext() as trap_ctx: trap_ctx.prec = 4 for sig in (decimal.Inexact, decimal.Rounded, decimal.Subnormal, decimal.Clamped, decimal.Underflow): trap_ctx.traps[sig] = True r_trap_g28a = evaluate_gate28a_h1_promotion(p_good_json, trusted_clinical_store=clin_store_json) r_trap_cmc = evaluate_cmc_attempted_lot_readiness(ledger_ex, h1_blueprint_override=Decimal("0.888888888")) if not (r_trap_g28a["promotion_authorized"] is True and r_trap_cmc["attempted_lots_n"] == 10): raise ValueError(f"R06 B4 Gate 28-A / CMC trap immunity check failed: {r_trap_g28a} / {r_trap_cmc}") cases.append({"case": "b4_r06_gate28a_and_cmc_immune_to_all_caller_decimal_traps", "passed": True}) # 30. R07 M2: Unequal split-lot example explicitly labels empirical_product_readiness as diagnostic-only vs authoritative measured_weighted_cmc_readiness! cmc_unequal = evaluate_cmc_attempted_lot_readiness([ { "lot_id": "LOT-UEQ-1", "mcb_id": "MCB-1", "lot_type": "SPLIT_LOT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 2, "infused_doses_n": 2, "c2b_responder_doses_n": 2, "recipient_ids": ["UEQ-1", "UEQ-2"], "recipient_outcomes": {"UEQ-1": 1, "UEQ-2": 1}, }, { "lot_id": "LOT-UEQ-2", "mcb_id": "MCB-2", "lot_type": "SPLIT_LOT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 10, "infused_doses_n": 1, "c2b_responder_doses_n": 0, "recipient_ids": ["UEQ-3"], "recipient_outcomes": {"UEQ-3": 0}, }, ]) if not ( abs(cmc_unequal["measured_weighted_cmc_readiness"] - 0.50) < 1e-9 and abs(cmc_unequal["empirical_product_readiness"] - (11.0 / 30.0)) < 1e-6 and cmc_unequal["empirical_product_readiness_scope"] == "DIAGNOSTIC_UNWEIGHTED_RECIPIENT_RATE_PRODUCT_ONLY" and cmc_unequal["authoritative_attempted_lot_metric"] == "measured_weighted_cmc_readiness" ): raise ValueError(f"R07 M2 unequal split-lot diagnostic vs measured check failed: {cmc_unequal}") cases.append({ "case": "m2_r07_cmc_empirical_product_diagnostic_vs_authoritative_measured_weighted", "passed": True, "measured_weighted": cmc_unequal["measured_weighted_cmc_readiness"], "diagnostic_empirical_product": cmc_unequal["empirical_product_readiness"], }) # 31. R07 B1: Balanced 60-recipient fixture (15 split lots x 4 across 3 MCBs) with trusted_clinical_store=None # MUST return lot_bank_hierarchy_valid=False, lot_to_mcb_manifest_verified=False, lot_to_wcb_manifest_verified=False, # deff=None, n_eff=None, k_eff=None, promotion_authorized=False! bal_60 = [ { "recipient_id": f"B60-{i:02d}", "lot_id": f"LOT60-{(i - 1) // 4 + 1:02d}", "mcb_id": f"MCB60-{(i - 1) // 20 + 1}", "followup_months": 12.0, "met_c2b_criteria": True, "intercurrent_event": "NONE", } for i in range(1, 61) ] p_bal60, _ = build_valid_gate28a_reference_bundle(clin_store_json, bal_60, cohort_id="COHORT-R07-BAL60") g28a_bal60_nostore = evaluate_gate28a_h1_promotion(p_bal60, trusted_clinical_store=None) g28a_bal60_store = evaluate_gate28a_h1_promotion(p_bal60, trusted_clinical_store=clin_store_json) if not ( g28a_bal60_nostore["lot_bank_hierarchy_valid"] is False and g28a_bal60_nostore["lot_to_mcb_manifest_verified"] is False and g28a_bal60_nostore["lot_to_wcb_manifest_verified"] is False and g28a_bal60_nostore["deff"] is None and g28a_bal60_nostore["n_eff"] is None and g28a_bal60_nostore["k_eff"] is None and g28a_bal60_nostore["promotion_authorized"] is False and g28a_bal60_store["lot_bank_hierarchy_valid"] is True and g28a_bal60_store["promotion_authorized"] is True and abs(g28a_bal60_store["deff"] - 1.53) < 1e-6 and abs(g28a_bal60_store["n_eff"] - 39.215686) < 1e-5 ): raise ValueError(f"R07 B1 absent-store 60-recipient hierarchy nullification failed: nostore={g28a_bal60_nostore} store={g28a_bal60_store}") cases.append({"case": "b1_r07_gate28a_absent_store_60_recipient_nullifies_hierarchy_and_cluster_outputs", "passed": True}) # 32 & 33. R07 B2: Bidirectional rescue-infusion reconciliation on fixed 59/60 clinical cohort with 1 rescue # (15 split lots x 4 across 5 MCBs so primary & moderate ICC both clear while keeping exact 16-lot CMC 92.1875%): # (a) Matching 16-lot CMC ledger (15 split lots + 1 infused rescue lot, 92.1875% measured readiness) -> VERIFIES & PROMOTES! # (b) Otherwise identical 15-lot CMC ledger omitting that rescue lot (98.3333% measured readiness) -> FAILS CLOSED! resc_59of60 = [ { "recipient_id": f"B60-{i:02d}", "lot_id": f"LOT60-{(i - 1) // 4 + 1:02d}", "mcb_id": f"MCB60-{(i - 1) // 12 + 1}", "followup_months": 12.0, "met_c2b_criteria": True, "intercurrent_event": "NONE", } for i in range(1, 61) ] resc_59of60[0]["intercurrent_event"] = "RESCUE_REPEAT_INFUSION" resc_59of60[0]["rescue_infusion_occurred"] = True resc_59of60[0]["rescue_lot_id"] = "RESCUE-LOT60-01-001" mcb60_map = {f"LOT60-{j:02d}": f"MCB60-{(j - 1) // 3 + 1}" for j in range(1, 16)} cmc_16_with_rescue = _derive_reconciling_cmc_lot_ledger_from_recipients(resc_59of60, mcb60_map) cmc_15_omit_rescue = [row for row in cmc_16_with_rescue if row["lot_type"] != "RESCUE_REPEAT_LOT"] p_resc_16, _ = build_valid_gate28a_reference_bundle( clin_store_json, resc_59of60, cohort_id="COHORT-R07-RESC-16LOT", parallel_cmc_lot_ledger=cmc_16_with_rescue ) r_resc_16 = evaluate_gate28a_h1_promotion(p_resc_16, trusted_clinical_store=clin_store_json) if not ( r_resc_16["parallel_cmc_ledger_verified"] is True and r_resc_16["promotion_authorized"] is True and r_resc_16["status"] == "PROMOTE_H1_88_TO_90" and r_resc_16["k"] == 59 and r_resc_16["n"] == 60 and r_resc_16["parallel_cmc_readiness_summary"]["attempted_lots_n"] == 16 and abs(r_resc_16["parallel_cmc_readiness_summary"]["measured_weighted_cmc_readiness_pct"] - 92.1875) < 1e-4 ): raise ValueError(f"R07 B2 matching 16-lot rescue CMC ledger should verify and promote: {r_resc_16}") cases.append({ "case": "b2_r07_gate28a_59of60_with_rescue_matching_16lot_cmc_92p1875pct_promotes", "passed": True, "measured_weighted_pct": r_resc_16["parallel_cmc_readiness_summary"]["measured_weighted_cmc_readiness_pct"], }) p_resc_15, _ = build_valid_gate28a_reference_bundle( clin_store_json, resc_59of60, cohort_id="COHORT-R07-RESC-15LOT-OMIT", parallel_cmc_lot_ledger=cmc_15_omit_rescue ) r_resc_15 = evaluate_gate28a_h1_promotion(p_resc_15, trusted_clinical_store=clin_store_json) cmc_16_wrong_rlid = copy.deepcopy(cmc_16_with_rescue) for row in cmc_16_wrong_rlid: if row["lot_type"] == "RESCUE_REPEAT_LOT": row["lot_id"] = "RESCUE-WRONG-ID" p_resc_wrong_rlid, _ = build_valid_gate28a_reference_bundle( clin_store_json, resc_59of60, cohort_id="COHORT-R07-RESC-WRONG-ID", parallel_cmc_lot_ledger=cmc_16_wrong_rlid ) r_resc_wrong_rlid = evaluate_gate28a_h1_promotion(p_resc_wrong_rlid, trusted_clinical_store=clin_store_json) if not ( r_resc_15["parallel_cmc_ledger_verified"] is False and r_resc_15["promotion_authorized"] is False and r_resc_15["status"] == "HOLD_H1_AT_88PCT" and r_resc_15["parallel_cmc_readiness_summary"]["attempted_lots_n"] == 15 and abs(r_resc_15["parallel_cmc_readiness_summary"]["measured_weighted_cmc_readiness_pct"] - 98.3333) < 1e-4 and any("CLINICAL_RESCUE_OMITTED_FROM_CMC_LEDGER" in fr for fr in r_resc_15["failure_reasons"]) and r_resc_wrong_rlid["parallel_cmc_ledger_verified"] is False and r_resc_wrong_rlid["promotion_authorized"] is False and any("CLINICAL_RESCUE_LOT_ID_MISMATCH_IN_CMC_LEDGER" in fr for fr in r_resc_wrong_rlid["failure_reasons"]) ): raise ValueError(f"R07 B2 omitted/mismatched rescue lot in CMC ledger MUST fail closed: omit={r_resc_15} wrong={r_resc_wrong_rlid}") cases.append({ "case": "b2_r07_gate28a_59of60_with_rescue_omitted_in_15lot_cmc_98p3333pct_fails_closed", "passed": True, "omitted_measured_weighted_pct": r_resc_15["parallel_cmc_readiness_summary"]["measured_weighted_cmc_readiness_pct"], }) # 34. R07 B3a: Contradictory embedded vs top-level WCB manifest aliases MUST fail closed BEFORE merging (in BOTH external store & payload)! bad_alias_store = tmp_dir_p / "r07_b3_bad_wcb_alias_store.json" wcb_ok_copy = copy.deepcopy(wcb_good_30) p_alias_base, recs_alias = build_valid_gate28a_reference_bundle( bad_alias_store, wcb_ok_copy, cohort_id="COHORT-R07-WCB-ALIAS-CONFLICT" ) # Tamper signed external VERIFIED_LOT_TO_BANK_MANIFEST so embedded WCB contradicts top-level WCB for LOT-1! bad_mrec = { "record_type": "VERIFIED_LOT_TO_BANK_MANIFEST", "cohort_id": "COHORT-R07-WCB-ALIAS-CONFLICT", "manifest_source_id": "QA-BANK-MANIFEST-CONFLICT-TEST", "issuer_authority_id": "OPENISLET_CLINICAL_ADJUDICATION_BOARD_V1", "lot_to_mcb_manifest": { f"LOT-{j}": { "mcb_id": f"MCB-{(j - 1) // 2 + 1}", "wcb_id": "WCB-EMBEDDED-CONFLICT" if j == 1 else f"WCB-FOR-LOT-{j}", } for j in range(1, 7) }, "lot_to_wcb_manifest": {f"LOT-{j}": f"WCB-FOR-LOT-{j}" for j in range(1, 7)}, } bad_mrec["record_sha256"] = compute_gate28a_record_sha256(bad_mrec) write_gate28a_trusted_clinical_store( bad_alias_store, verified_lot_to_bank_manifests=[bad_mrec], store_authority_id="OPENISLET_CLINICAL_ADJUDICATION_BOARD_V1", ) p_alias_store_test = copy.deepcopy(p_alias_base) p_alias_store_test["clinical_store_refs"]["verified_lot_to_bank_manifest_sha256"] = bad_mrec["record_sha256"] r_alias_store = evaluate_gate28a_h1_promotion(p_alias_store_test, trusted_clinical_store=bad_alias_store) p_alias_payload = copy.deepcopy(p_alias_base) p_alias_payload["lot_to_mcb_manifest"] = copy.deepcopy(bad_mrec["lot_to_mcb_manifest"]) r_alias_payload = evaluate_gate28a_h1_promotion(p_alias_payload, trusted_clinical_store=bad_alias_store) for lbl_al, res_al in (("store_manifest", r_alias_store), ("payload_manifest", r_alias_payload)):