if not ( res_al["lot_to_wcb_manifest_verified"] is False and res_al["lot_bank_hierarchy_valid"] is False and res_al["lot_to_mcb_manifest_verified"] is False and res_al["deff"] is None and res_al["n_eff"] is None and res_al["k_eff"] is None and res_al["promotion_authorized"] is False and any("CONFLICTING_WCB_MANIFEST_ALIAS" in fr for fr in res_al["failure_reasons"]) ): raise ValueError(f"R07 B3a contradictory WCB alias ({lbl_al}) MUST fail closed: {res_al}") cases.append({"case": "b3_r07_gate28a_reject_contradictory_wcb_manifest_aliases_before_merge", "passed": True}) # 35. R07 B3b: One literal wcb_id assigned to 3 distinct MCBs MUST fail closed (unique WCB-to-MCB parentage)! shared_wcb_store = tmp_dir_p / "r07_b3_shared_wcb_3mcbs_store.json" shared_wcb_30 = copy.deepcopy(good_30) for rec in shared_wcb_30: rec["wcb_id"] = "WCB-SHARED-ACROSS-3MCBS" mcb30_map = {f"LOT-{j}": f"MCB-{(j - 1) // 2 + 1}" for j in range(1, 7)} shared_wcb_map = {f"LOT-{j}": "WCB-SHARED-ACROSS-3MCBS" for j in range(1, 7)} cmc_sh_bytes, cmc_sh_sha = build_gate28a_parallel_cmc_ledger_bytes( cohort_id="COHORT-R07-WCB-3MCBS", lot_ledger=_derive_reconciling_cmc_lot_ledger_from_recipients(shared_wcb_30, mcb30_map), issuer_authority_id="OPENISLET_CLINICAL_ADJUDICATION_BOARD_V1", ) p_shared_wcb = { "cohort_id": "COHORT-R07-WCB-3MCBS", **GATE_28A_COMPATIBILITY_TARGET, "includes_reichman": False, "rho_lot": GATE_28A_RHO_LOT_MIN, "rho_bank": GATE_28A_RHO_BANK_MIN, "primary_peer_reviewed_full_text_verified": True, "parallel_cmc_readiness_ledger_disclosed": True, "parallel_cmc_readiness_ledger_sha256": cmc_sh_sha, "lot_to_mcb_manifest": mcb30_map, "lot_to_wcb_manifest": shared_wcb_map, "recipients": shared_wcb_30, } sh_canon = compute_gate28a_cohort_canonical_sha256(p_shared_wcb) sh_prespec = build_gate28a_prespecification_attestation(cohort_id="COHORT-R07-WCB-3MCBS", cohort_canonical_sha256=sh_canon) sh_source = build_gate28a_source_verification_attestation( cohort_id="COHORT-R07-WCB-3MCBS", cohort_canonical_sha256=sh_canon, parallel_cmc_readiness_ledger_sha256=cmc_sh_sha ) sh_mrec = { "record_type": "VERIFIED_LOT_TO_BANK_MANIFEST", "cohort_id": "COHORT-R07-WCB-3MCBS", "manifest_source_id": "QA-BANK-MANIFEST-3MCBS-TEST", "issuer_authority_id": "OPENISLET_CLINICAL_ADJUDICATION_BOARD_V1", "lot_to_mcb_manifest": mcb30_map, "lot_to_wcb_manifest": shared_wcb_map, } sh_mrec["record_sha256"] = compute_gate28a_record_sha256(sh_mrec) write_gate28a_trusted_clinical_store( shared_wcb_store, prespecification_attestations=[sh_prespec], source_verification_attestations=[sh_source], verified_lot_to_bank_manifests=[sh_mrec], parallel_cmc_readiness_ledgers=[cmc_sh_bytes], store_authority_id="OPENISLET_CLINICAL_ADJUDICATION_BOARD_V1", ) p_shared_wcb["clinical_store_refs"] = { "prespecification_attestation_sha256": sh_prespec["record_sha256"], "source_verification_attestation_sha256": sh_source["record_sha256"], "verified_lot_to_bank_manifest_sha256": sh_mrec["record_sha256"], "parallel_cmc_readiness_ledger_sha256": cmc_sh_sha, } r_shared_wcb = evaluate_gate28a_h1_promotion(p_shared_wcb, trusted_clinical_store=shared_wcb_store) # Also test when cohort omits WCB entirely while the external VERIFIED_LOT_TO_BANK_MANIFEST assigns 1 literal WCB to 3 MCBs! p_no_wcb_payload, _ = build_valid_gate28a_reference_bundle( shared_wcb_store, good_30, cohort_id="COHORT-R07-STORE-WCB-3MCBS" ) sh_mrec_store_only = copy.deepcopy(sh_mrec) sh_mrec_store_only["cohort_id"] = "COHORT-R07-STORE-WCB-3MCBS" sh_mrec_store_only["record_sha256"] = compute_gate28a_record_sha256(sh_mrec_store_only) write_gate28a_trusted_clinical_store( shared_wcb_store, verified_lot_to_bank_manifests=[sh_mrec_store_only], store_authority_id="OPENISLET_CLINICAL_ADJUDICATION_BOARD_V1", ) p_no_wcb_payload["clinical_store_refs"]["verified_lot_to_bank_manifest_sha256"] = sh_mrec_store_only["record_sha256"] r_shared_wcb_store_only = evaluate_gate28a_h1_promotion(p_no_wcb_payload, trusted_clinical_store=shared_wcb_store) for lbl_sw, res_sw in (("payload_and_store", r_shared_wcb), ("store_manifest_only", r_shared_wcb_store_only)): if not ( res_sw["lot_to_wcb_manifest_verified"] is False and res_sw["lot_bank_hierarchy_valid"] is False and res_sw["lot_to_mcb_manifest_verified"] is False and res_sw["deff"] is None and res_sw["n_eff"] is None and res_sw["k_eff"] is None and res_sw["promotion_authorized"] is False and any("NON_UNIQUE_WCB_PARENTAGE" in fr for fr in res_sw["failure_reasons"]) ): raise ValueError(f"R07 B3b single literal WCB assigned to 3 MCBs ({lbl_sw}) MUST fail closed: {res_sw}") cases.append({"case": "b3_r07_gate28a_reject_single_literal_wcb_assigned_to_three_mcbs", "passed": True}) # --- R08 B1, B2, M2: Unified manifest-alias digest & parentage, all-disposition CMC ancestry reconciliation, course-equiv unit --- r08_store = tmp_dir_p / "r08_gate28a_store.json" r08_bal60: list[dict[str, Any]] = [] r08_mcb_map: dict[str, str] = {} r08_wcb_map: dict[str, str] = {"L00": "W0"} for g_idx in range(15): lid_g = f"L{g_idx:02d}" mid_g = f"M{g_idx // 5}" r08_mcb_map[lid_g] = mid_g for r_idx in range(4): row_r: dict[str, Any] = { "recipient_id": f"R08-{g_idx:02d}-{r_idx}", "lot_id": lid_g, "mcb_id": mid_g, "followup_months": 12.0, "met_c2b_criteria": True, "intercurrent_event": "NONE", } if g_idx == 0: row_r["wcb_id"] = "W0" r08_bal60.append(row_r) p_r08_base, r08_base_recs = build_valid_gate28a_reference_bundle( r08_store, r08_bal60, cohort_id="COHORT-R08-B1-BASE", lot_to_mcb_manifest=r08_mcb_map, lot_to_wcb_manifest=r08_wcb_map, ) r_r08_base = evaluate_gate28a_h1_promotion(p_r08_base, trusted_clinical_store=r08_store) if not ( r_r08_base["status"] == "PROMOTE_H1_88_TO_90" and r_r08_base["promotion_authorized"] is True and r_r08_base["lot_bank_hierarchy_valid"] is True and r_r08_base["lot_to_wcb_manifest_verified"] is True and abs(r_r08_base["n_eff"] - 39.215686) < 1e-5 ): raise ValueError(f"R08 B1 baseline positive control failed: {r_r08_base}") # 38. R08 B1a: Adding L05 -> W0 -> M1 solely in lot_to_bank_manifest on submitted cohort MUST alter # cohort_canonical_sha256 AND fail closed with null DEFF/n_eff/k_eff! p_r08_alias_payload = copy.deepcopy(p_r08_base) p_r08_alias_payload["lot_to_bank_manifest"] = { lid: ({"mcb_id": mid, "wcb_id": "W0"} if lid == "L05" else mid) for lid, mid in r08_mcb_map.items() } r_r08_alias_payload = evaluate_gate28a_h1_promotion(p_r08_alias_payload, trusted_clinical_store=r08_store) if not ( r_r08_alias_payload["cohort_canonical_sha256"] != r_r08_base["cohort_canonical_sha256"] and r_r08_alias_payload["status"] == "HOLD_H1_AT_88PCT" and r_r08_alias_payload["promotion_authorized"] is False and r_r08_alias_payload["lot_bank_hierarchy_valid"] is False and r_r08_alias_payload["lot_to_wcb_manifest_verified"] is False and r_r08_alias_payload["deff"] is None and r_r08_alias_payload["n_eff"] is None and r_r08_alias_payload["k_eff"] is None and any("CONFLICTING_BANK_MANIFEST_ALIASES" in fr for fr in r_r08_alias_payload["failure_reasons"]) and any("NON_UNIQUE_WCB_PARENTAGE" in fr for fr in r_r08_alias_payload["failure_reasons"]) ): raise ValueError(f"R08 B1a conflicting WCB parent hidden in cohort lot_to_bank_manifest MUST fail closed: {r_r08_alias_payload}") cases.append({"case": "b1a_r08_gate28a_reject_wcb_parent_conflict_in_cohort_lot_to_bank_manifest_and_change_digest", "passed": True}) # 39. R08 B1b: Adding L05 -> W0 -> M1 solely in lot_to_bank_manifest inside externally signed # VERIFIED_LOT_TO_BANK_MANIFEST (clean cohort payload) MUST fail closed with null DEFF/n_eff/k_eff! bad_store_mrec_r08 = copy.deepcopy(r08_base_recs["verified_lot_to_bank_manifest"]) bad_store_mrec_r08["lot_to_bank_manifest"] = { lid: ({"mcb_id": mid, "wcb_id": "W0"} if lid == "L05" else mid) for lid, mid in r08_mcb_map.items() } bad_store_mrec_r08["record_sha256"] = compute_gate28a_record_sha256(bad_store_mrec_r08) write_gate28a_trusted_clinical_store( r08_store, verified_lot_to_bank_manifests=[bad_store_mrec_r08], store_authority_id="OPENISLET_CLINICAL_ADJUDICATION_BOARD_V1", ) p_r08_alias_store = copy.deepcopy(p_r08_base) p_r08_alias_store["clinical_store_refs"]["verified_lot_to_bank_manifest_sha256"] = bad_store_mrec_r08["record_sha256"] r_r08_alias_store = evaluate_gate28a_h1_promotion(p_r08_alias_store, trusted_clinical_store=r08_store) if not ( r_r08_alias_store["status"] == "HOLD_H1_AT_88PCT" and r_r08_alias_store["promotion_authorized"] is False and r_r08_alias_store["lot_bank_hierarchy_valid"] is False and r_r08_alias_store["lot_to_wcb_manifest_verified"] is False and r_r08_alias_store["deff"] is None and r_r08_alias_store["n_eff"] is None and r_r08_alias_store["k_eff"] is None and any("CONFLICTING_BANK_MANIFEST_ALIASES" in fr for fr in r_r08_alias_store["failure_reasons"]) and any("NON_UNIQUE_WCB_PARENTAGE" in fr for fr in r_r08_alias_store["failure_reasons"]) ): raise ValueError(f"R08 B1b conflicting WCB parent hidden in store VERIFIED_LOT_TO_BANK_MANIFEST alias MUST fail closed: {r_r08_alias_store}") cases.append({"case": "b1b_r08_gate28a_reject_wcb_parent_conflict_in_store_lot_to_bank_manifest", "passed": True}) # 40. R08 B1c: Widening extra WCB entry (L05 -> W5 -> M1) solely in lot_to_bank_manifest AND unrecognized # manifest alias key (bank_manifest) MUST both alter digest and fail closed! p_r08_widen = copy.deepcopy(p_r08_base) p_r08_widen["lot_to_bank_manifest"] = { lid: ({"mcb_id": mid, "wcb_id": "W5"} if lid == "L05" else mid) for lid, mid in r08_mcb_map.items() } r_r08_widen = evaluate_gate28a_h1_promotion(p_r08_widen, trusted_clinical_store=r08_store) p_r08_unrec_alias = copy.deepcopy(p_r08_base) p_r08_unrec_alias["bank_manifest"] = copy.deepcopy(r08_mcb_map) r_r08_unrec_alias = evaluate_gate28a_h1_promotion(p_r08_unrec_alias, trusted_clinical_store=r08_store) if not ( r_r08_widen["cohort_canonical_sha256"] != r_r08_base["cohort_canonical_sha256"] and r_r08_widen["lot_bank_hierarchy_valid"] is False and r_r08_widen["deff"] is None and r_r08_widen["promotion_authorized"] is False and any("CONFLICTING_BANK_MANIFEST_ALIASES" in fr for fr in r_r08_widen["failure_reasons"]) and r_r08_unrec_alias["cohort_canonical_sha256"] != r_r08_base["cohort_canonical_sha256"] and r_r08_unrec_alias["lot_bank_hierarchy_valid"] is False and r_r08_unrec_alias["deff"] is None and r_r08_unrec_alias["promotion_authorized"] is False and any("UNRECOGNIZED_BANK_MANIFEST_ALIAS" in fr for fr in r_r08_unrec_alias["failure_reasons"]) ): raise ValueError(f"R08 B1c widening/unrecognized manifest alias checks failed: widen={r_r08_widen}, unrec={r_r08_unrec_alias}") cases.append({"case": "b1c_r08_gate28a_reject_widening_and_unrecognized_bank_manifest_aliases", "passed": True}) # 41. R08 B2a: Rescue lot ancestry reconciliation on 59/60 cohort (15 lots x 4 across 5 MCBs so moderate ICC clears; # matched positive control promotes; conflicting rescue MCB M0 vs M1 fails closed; rescue lot omitted from manifest fails closed!) r08_resc_60: list[dict[str, Any]] = [] r08_resc_mcb_map: dict[str, str] = {} for g_idx in range(15): lid_g = f"L{g_idx:02d}" mid_g = f"M{g_idx // 3}" r08_resc_mcb_map[lid_g] = mid_g for r_idx in range(4): row_r = { "recipient_id": f"R08-{g_idx:02d}-{r_idx}", "lot_id": lid_g, "mcb_id": mid_g, "followup_months": 12.0, "met_c2b_criteria": True, "intercurrent_event": "NONE", } if g_idx == 0: row_r["wcb_id"] = "W0" r08_resc_60.append(row_r) r08_resc_60[0]["intercurrent_event"] = "RESCUE_REPEAT_INFUSION" r08_resc_60[0]["rescue_infusion_occurred"] = True r08_resc_60[0]["rescue_lot_id"] = "L_RESC_01" r08_mcb_with_resc = dict(r08_resc_mcb_map, L_RESC_01="M0") cmc_r08_resc_match = _derive_reconciling_cmc_lot_ledger_from_recipients(r08_resc_60, r08_mcb_with_resc) cmc_r08_resc_conflict = copy.deepcopy(cmc_r08_resc_match) for row_c in cmc_r08_resc_conflict: if row_c["lot_id"] == "L_RESC_01": row_c["mcb_id"] = "M1" p_r08_resc_ok, _ = build_valid_gate28a_reference_bundle( r08_store, r08_resc_60, cohort_id="COHORT-R08-B2-RESC-OK", lot_to_mcb_manifest=r08_mcb_with_resc,