# Given a verified WCB cohort attested with `wcb_id="W0"`, (a) replacing `wcb_id` with # `working_cell_bank_id="W0"` AND (b) adding matching `working_cell_bank_id="W0"` alongside `wcb_id="W0"` # BOTH yield the IDENTICAL `cohort_canonical_sha256`, verify unchanged stored attestations, and PROMOTE, # while (c) adding conflicting `working_cell_bank_id="W_OTHER"` or invalid whitespace changes the digest # and fails closed! r12_wcb_base = copy.deepcopy(r12_120) for rec_w12 in r12_wcb_base: if rec_w12["lot_id"] == "L12-00": rec_w12["wcb_id"] = "W0" p_b2_base, _ = build_valid_gate28a_reference_bundle( r12_store, r12_wcb_base, cohort_id="COHORT-R12-B2-WCB-NORM", ) r_b2_base = evaluate_gate28a_h1_promotion(p_b2_base, trusted_clinical_store=r12_store) p_b2_swap = copy.deepcopy(p_b2_base) for rec_sw in p_b2_swap["recipients"]: if "wcb_id" in rec_sw: rec_sw["working_cell_bank_id"] = rec_sw.pop("wcb_id") r_b2_swap = evaluate_gate28a_h1_promotion(p_b2_swap, trusted_clinical_store=r12_store) p_b2_both_match = copy.deepcopy(p_b2_base) for rec_bm in p_b2_both_match["recipients"]: if "wcb_id" in rec_bm: rec_bm["working_cell_bank_id"] = rec_bm["wcb_id"] r_b2_both_match = evaluate_gate28a_h1_promotion(p_b2_both_match, trusted_clinical_store=r12_store) p_b2_conflict = copy.deepcopy(p_b2_base) p_b2_conflict["recipients"][0]["working_cell_bank_id"] = "W_OTHER" r_b2_conflict = evaluate_gate28a_h1_promotion(p_b2_conflict, trusted_clinical_store=r12_store) p_b2_bad_ws = copy.deepcopy(p_b2_base) p_b2_bad_ws["recipients"][0]["working_cell_bank_id"] = " W0" r_b2_bad_ws = evaluate_gate28a_h1_promotion(p_b2_bad_ws, trusted_clinical_store=r12_store) if not ( r_b2_base["promotion_authorized"] is True and r_b2_swap["cohort_canonical_sha256"] == r_b2_base["cohort_canonical_sha256"] and r_b2_swap["promotion_authorized"] is True and r_b2_swap["prespecification_attestation_verified"] is True and r_b2_swap["source_verification_attestation_verified"] is True and r_b2_swap["lot_to_wcb_manifest_verified"] is True and r_b2_both_match["cohort_canonical_sha256"] == r_b2_base["cohort_canonical_sha256"] and r_b2_both_match["promotion_authorized"] is True and r_b2_both_match["prespecification_attestation_verified"] is True and r_b2_both_match["source_verification_attestation_verified"] is True and r_b2_conflict["cohort_canonical_sha256"] != r_b2_base["cohort_canonical_sha256"] and r_b2_conflict["promotion_authorized"] is False and r_b2_conflict["lot_bank_hierarchy_valid"] is False and r_b2_conflict["lot_to_wcb_manifest_verified"] is False and r_b2_conflict["deff"] is None and any("CONFLICTING_WCB_ALIAS" in fr for fr in r_b2_conflict["failure_reasons"]) and r_b2_bad_ws["cohort_canonical_sha256"] != r_b2_base["cohort_canonical_sha256"] and r_b2_bad_ws["promotion_authorized"] is False and r_b2_bad_ws["lot_bank_hierarchy_valid"] is False ): raise ValueError( f"R12 B2 recipient WCB alias normalization check failed: base={r_b2_base}, swap={r_b2_swap}, " f"match={r_b2_both_match}, conflict={r_b2_conflict}, ws={r_b2_bad_ws}" ) cases.append({"case": "b2_r12_gate28a_recipient_wcb_alias_semantic_canonicalization_and_conflict_preservation", "passed": True}) # 64. R12 B3: Contradictory duplicate clinical rescue identities linked to incompatible lineages # (RA -> M12-0/WR-A vs RB -> M12-1/WR-B, CMC records RA) route through the full fail-closed ancestry # nullification path in BOTH row orders (RA, RB) and (RB, RA) with 100% identical outputs! r12_mcb_map = {f"L12-{lot:02d}": f"M12-{lot // 3}" for lot in range(30)} r12_resc_ra = copy.deepcopy(r12_120) r12_resc_ra[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_lot_id="RA") r12_resc_mcb_full = {**r12_mcb_map, "RA": "M12-0", "RB": "M12-1"} r12_resc_wcb_full = {"RA": "WR-A", "RB": "WR-B"} r12_cmc_ra = _derive_reconciling_cmc_lot_ledger_from_recipients( r12_resc_ra, r12_resc_mcb_full, lot_to_wcb_manifest=r12_resc_wcb_full ) r12_dup_ab = copy.deepcopy(r12_120) r12_dup_ab[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_lot_id="RA") r12_dup_ab.append({**r12_120[0], "intercurrent_event": "RESCUE_REPEAT_INFUSION", "rescue_lot_id": "RB"}) r12_dup_ba = copy.deepcopy(r12_120) r12_dup_ba[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_lot_id="RB") r12_dup_ba.append({**r12_120[0], "intercurrent_event": "RESCUE_REPEAT_INFUSION", "rescue_lot_id": "RA"}) p_b3_ab, _ = build_valid_gate28a_reference_bundle( r12_store, r12_dup_ab, cohort_id="COHORT-R12-B3-DUP-LINEAGE", lot_to_mcb_manifest=r12_resc_mcb_full, lot_to_wcb_manifest=r12_resc_wcb_full, parallel_cmc_lot_ledger=r12_cmc_ra, ) p_b3_ba, _ = build_valid_gate28a_reference_bundle( r12_store, r12_dup_ba, cohort_id="COHORT-R12-B3-DUP-LINEAGE", lot_to_mcb_manifest=r12_resc_mcb_full, lot_to_wcb_manifest=r12_resc_wcb_full, parallel_cmc_lot_ledger=r12_cmc_ra, ) r_b3_ab = evaluate_gate28a_h1_promotion(p_b3_ab, trusted_clinical_store=r12_store) r_b3_ba = evaluate_gate28a_h1_promotion(p_b3_ba, trusted_clinical_store=r12_store) if not ( r_b3_ab == r_b3_ba and r_b3_ab["status"] == "HOLD_H1_AT_88PCT" and r_b3_ab["promotion_authorized"] is False and r_b3_ab["external_clinical_store_verified"] is False and r_b3_ab["parallel_cmc_ledger_verified"] is False and r_b3_ab["lot_bank_hierarchy_valid"] is False and r_b3_ab["lot_to_mcb_manifest_verified"] is False and r_b3_ab["lot_to_wcb_manifest_verified"] is False and r_b3_ab["deff"] is None and r_b3_ab["n_eff"] is None and r_b3_ab["k_eff"] is None and r_b3_ab["icc_sensitivity_report_attached"] is False and r_b3_ab["icc_sensitivity_report"] is None and any("CONFLICTING_DUPLICATE_RECIPIENT_RESCUE" in fr for fr in r_b3_ab["failure_reasons"]) and any("CONFLICTING_DUPLICATE_RECIPIENT_RESCUE_ANCESTRY" in fr for fr in r_b3_ab["failure_reasons"]) ): raise ValueError( f"R12 B3 contradictory duplicate rescue lineage nullification failed: ab={r_b3_ab}, ba={r_b3_ba}" ) cases.append({"case": "b3_r12_gate28a_contradictory_duplicate_rescue_ancestry_nullification_both_orders", "passed": True}) # 65. R12 M1: Explicit clinical rescue fields strictly narrowed to canonical `rescue_lot_id` / `rescue_lot_ids`; # undocumented `rescue_repeat_lot_id` and `rescue_repeat_lot_ids` fail closed! r12_m1_scalar = copy.deepcopy(r12_120) r12_m1_scalar[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_repeat_lot_id="RA") r12_m1_list = copy.deepcopy(r12_120) r12_m1_list[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_repeat_lot_ids=["RA"]) r12_m1_canon = copy.deepcopy(r12_120) r12_m1_canon[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_lot_id="RA") cmc_m1 = _derive_reconciling_cmc_lot_ledger_from_recipients(r12_m1_canon, {**r12_mcb_map, "RA": "M12-0"}) p_m1_sc, _ = build_valid_gate28a_reference_bundle( r12_store, r12_m1_scalar, cohort_id="COHORT-R12-M1-REPEAT-SCALAR", lot_to_mcb_manifest={**r12_mcb_map, "RA": "M12-0"}, parallel_cmc_lot_ledger=cmc_m1, ) p_m1_ls, _ = build_valid_gate28a_reference_bundle( r12_store, r12_m1_list, cohort_id="COHORT-R12-M1-REPEAT-LIST", lot_to_mcb_manifest={**r12_mcb_map, "RA": "M12-0"}, parallel_cmc_lot_ledger=cmc_m1, ) p_m1_ok, _ = build_valid_gate28a_reference_bundle( r12_store, r12_m1_canon, cohort_id="COHORT-R12-M1-CANON-OK", lot_to_mcb_manifest={**r12_mcb_map, "RA": "M12-0"}, parallel_cmc_lot_ledger=cmc_m1, ) r_m1_sc = evaluate_gate28a_h1_promotion(p_m1_sc, trusted_clinical_store=r12_store) r_m1_ls = evaluate_gate28a_h1_promotion(p_m1_ls, trusted_clinical_store=r12_store) r_m1_ok = evaluate_gate28a_h1_promotion(p_m1_ok, trusted_clinical_store=r12_store) if not ( r_m1_ok["status"] == "PROMOTE_H1_88_TO_90" and r_m1_ok["promotion_authorized"] is True and r_m1_ok["parallel_cmc_ledger_verified"] is True and r_m1_sc["status"] == "HOLD_H1_AT_88PCT" and r_m1_sc["promotion_authorized"] is False and r_m1_sc["parallel_cmc_ledger_verified"] is False and any("CLINICAL_RESCUE_MISSING_EXPLICIT_LOT_ID" in fr for fr in r_m1_sc["failure_reasons"]) and any("UNRECOGNIZED_CLINICAL_RESCUE_LOT_ALIAS" in fr for fr in r_m1_sc["failure_reasons"]) and r_m1_ls["status"] == "HOLD_H1_AT_88PCT" and r_m1_ls["promotion_authorized"] is False and r_m1_ls["parallel_cmc_ledger_verified"] is False and any("CLINICAL_RESCUE_MISSING_EXPLICIT_LOT_ID" in fr for fr in r_m1_ls["failure_reasons"]) and any("UNRECOGNIZED_CLINICAL_RESCUE_LOT_ALIAS" in fr for fr in r_m1_ls["failure_reasons"]) ): raise ValueError( f"R12 M1 narrowed rescue fields check failed: ok={r_m1_ok}, sc={r_m1_sc}, ls={r_m1_ls}" ) cases.append({"case": "m1_r12_gate28a_narrowed_explicit_rescue_fields_reject_undocumented_aliases", "passed": True}) # --- R13 B1 & M1: Final-Closure Self-Tests (Cases 66-68) --- r13_store = tmp_dir_p / "r13_gate28a_store.json" # 66. R13 B1a: Single-row clinical-vs-CMC rescue identity/lineage contradiction (RA -> M12-0/WR-A vs # CMC RB -> M12-1/WR-B) AND omitted CMC rescue row BOTH route unconditionally through full fail-closed # ancestry nullification identically in forward & reversed recipient order, while matching RA promotes! r13_mcb_full = {**r12_mcb_map, "RA": "M12-0", "RB": "M12-1"} r13_wcb_full = {"RA": "WR-A", "RB": "WR-B"} r13_clin_ra = copy.deepcopy(r12_120) r13_clin_ra[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_lot_id="RA") r13_clin_ra_rev = list(reversed(copy.deepcopy(r13_clin_ra))) r13_cmc_ra = _derive_reconciling_cmc_lot_ledger_from_recipients( r13_clin_ra, r13_mcb_full, lot_to_wcb_manifest=r13_wcb_full ) r13_cmc_rb = copy.deepcopy(r13_cmc_ra) for row_rb in r13_cmc_rb: if row_rb.get("lot_type") == "RESCUE_REPEAT_LOT": row_rb["lot_id"] = "RB" row_rb["mcb_id"] = "M12-1" row_rb["wcb_id"] = "WR-B" r13_cmc_omit = [row_o for row_o in r13_cmc_ra if row_o.get("lot_type") != "RESCUE_REPEAT_LOT"] p_r13_match, _ = build_valid_gate28a_reference_bundle( r13_store, r13_clin_ra, cohort_id="COHORT-R13-B1-MATCH-RA", lot_to_mcb_manifest=r13_mcb_full, lot_to_wcb_manifest=r13_wcb_full, parallel_cmc_lot_ledger=r13_cmc_ra, ) p_r13_sub_fwd, _ = build_valid_gate28a_reference_bundle( r13_store, r13_clin_ra, cohort_id="COHORT-R13-B1-SUB-RA-VS-RB", lot_to_mcb_manifest=r13_mcb_full, lot_to_wcb_manifest=r13_wcb_full, parallel_cmc_lot_ledger=r13_cmc_rb, ) p_r13_sub_rev, _ = build_valid_gate28a_reference_bundle( r13_store, r13_clin_ra_rev, cohort_id="COHORT-R13-B1-SUB-RA-VS-RB", lot_to_mcb_manifest=r13_mcb_full, lot_to_wcb_manifest=r13_wcb_full, parallel_cmc_lot_ledger=r13_cmc_rb, ) p_r13_omit, _ = build_valid_gate28a_reference_bundle( r13_store, r13_clin_ra, cohort_id="COHORT-R13-B1-OMIT-CMC-RESC", lot_to_mcb_manifest=r13_mcb_full, lot_to_wcb_manifest=r13_wcb_full, parallel_cmc_lot_ledger=r13_cmc_omit, ) r_r13_match = evaluate_gate28a_h1_promotion(p_r13_match, trusted_clinical_store=r13_store) r_r13_sub_fwd = evaluate_gate28a_h1_promotion(p_r13_sub_fwd, trusted_clinical_store=r13_store) r_r13_sub_rev = evaluate_gate28a_h1_promotion(p_r13_sub_rev, trusted_clinical_store=r13_store) r_r13_omit = evaluate_gate28a_h1_promotion(p_r13_omit, trusted_clinical_store=r13_store) if not ( r_r13_match["status"] == "PROMOTE_H1_88_TO_90" and r_r13_match["promotion_authorized"] is True and r_r13_match["parallel_cmc_ledger_verified"] is True and r_r13_match["lot_bank_hierarchy_valid"] is True and r_r13_match["lot_to_mcb_manifest_verified"] is True and r_r13_match["lot_to_wcb_manifest_verified"] is True and r_r13_match["icc_sensitivity_report_attached"] is True and r_r13_match["deff"] is not None and r_r13_sub_fwd == r_r13_sub_rev and r_r13_sub_fwd["status"] == "HOLD_H1_AT_88PCT" and r_r13_sub_fwd["promotion_authorized"] is False and r_r13_sub_fwd["parallel_cmc_ledger_verified"] is False and r_r13_sub_fwd["lot_bank_hierarchy_valid"] is False and r_r13_sub_fwd["lot_to_mcb_manifest_verified"] is False and r_r13_sub_fwd["lot_to_wcb_manifest_verified"] is False and r_r13_sub_fwd["deff"] is None and r_r13_sub_fwd["n_eff"] is None and r_r13_sub_fwd["k_eff"] is None and r_r13_sub_fwd["icc_sensitivity_report_attached"] is False and r_r13_sub_fwd["icc_sensitivity_report"] is None and any("CLINICAL_RESCUE_LOT_ID_MISMATCH_IN_CMC_LEDGER" in fr for fr in r_r13_sub_fwd["failure_reasons"]) and any("CMC_EXTRA_RESCUE_LOT_OMITTED_FROM_CLINICAL_COHORT" in fr for fr in r_r13_sub_fwd["failure_reasons"]) and any("CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT" in fr for fr in r_r13_sub_fwd["failure_reasons"]) and r_r13_omit["status"] == "HOLD_H1_AT_88PCT" and r_r13_omit["promotion_authorized"] is False and r_r13_omit["parallel_cmc_ledger_verified"] is False and r_r13_omit["lot_bank_hierarchy_valid"] is False and r_r13_omit["lot_to_mcb_manifest_verified"] is False and r_r13_omit["lot_to_wcb_manifest_verified"] is False and r_r13_omit["deff"] is None and r_r13_omit["n_eff"] is None and r_r13_omit["k_eff"] is None and r_r13_omit["icc_sensitivity_report_attached"] is False and r_r13_omit["icc_sensitivity_report"] is None and any("CLINICAL_RESCUE_OMITTED_FROM_CMC_LEDGER" in fr for fr in r_r13_omit["failure_reasons"]) and any("CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT" in fr for fr in r_r13_omit["failure_reasons"]) ): raise ValueError( f"R13 B1a single-row rescue substitution/omission nullification failed: " f"match={r_r13_match}, sub_fwd={r_r13_sub_fwd}, sub_rev={r_r13_sub_rev}, omit={r_r13_omit}" ) # R17 M1: Same rescue ID ('RA') with mutated bank (MCB), WCB, or linked primary lot MUST retain