lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=cmc_r08_resc_match, ) r_r08_resc_ok = evaluate_gate28a_h1_promotion(p_r08_resc_ok, trusted_clinical_store=r08_store) p_r08_resc_conf, _ = build_valid_gate28a_reference_bundle( r08_store, r08_resc_60, cohort_id="COHORT-R08-B2-RESC-CONF", lot_to_mcb_manifest=r08_mcb_with_resc, lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=cmc_r08_resc_conflict, ) r_r08_resc_conf = evaluate_gate28a_h1_promotion(p_r08_resc_conf, trusted_clinical_store=r08_store) p_r08_resc_omit, _ = build_valid_gate28a_reference_bundle( r08_store, r08_resc_60, cohort_id="COHORT-R08-B2-RESC-OMIT-MAN", lot_to_mcb_manifest=r08_resc_mcb_map, lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=cmc_r08_resc_match, ) r_r08_resc_omit = evaluate_gate28a_h1_promotion(p_r08_resc_omit, trusted_clinical_store=r08_store) if not ( r_r08_resc_ok["status"] == "PROMOTE_H1_88_TO_90" and r_r08_resc_ok["promotion_authorized"] is True and r_r08_resc_ok["parallel_cmc_ledger_verified"] is True and r_r08_resc_conf["status"] == "HOLD_H1_AT_88PCT" and r_r08_resc_conf["promotion_authorized"] is False and r_r08_resc_conf["parallel_cmc_ledger_verified"] is False and r_r08_resc_conf["lot_bank_hierarchy_valid"] is False and r_r08_resc_conf["deff"] is None and r_r08_resc_conf["n_eff"] is None and any("CMC_ROW_ANCESTRY_CONFLICTS_WITH_VERIFIED_MANIFEST" in fr for fr in r_r08_resc_conf["failure_reasons"]) and r_r08_resc_omit["status"] == "HOLD_H1_AT_88PCT" and r_r08_resc_omit["promotion_authorized"] is False and r_r08_resc_omit["parallel_cmc_ledger_verified"] is False and r_r08_resc_omit["lot_bank_hierarchy_valid"] is False and r_r08_resc_omit["deff"] is None and any("CMC_INFUSED_LOT_MISSING_FROM_VERIFIED_MANIFEST" in fr for fr in r_r08_resc_omit["failure_reasons"]) ): raise ValueError( f"R08 B2a rescue ancestry reconciliation failed: ok={r_r08_resc_ok}, conf={r_r08_resc_conf}, omit={r_r08_resc_omit}" ) cases.append({"case": "b2a_r08_gate28a_rescue_lot_verified_ancestry_required_and_mcb_conflict_rejected", "passed": True}) # 42. R08 B2b: Non-infused CMC rows (RELEASED_UNINFUSED & FAILED_RELEASE): consistent non-infused rows # absent from manifest promote cleanly; contradictory MCB vs verified manifest fails closed! cmc_r08_noninf_clean = _derive_reconciling_cmc_lot_ledger_from_recipients(r08_bal60, r08_mcb_map) + [ { "lot_id": "L_UNINF_CLEAN", "mcb_id": "M0", "lot_type": "SINGLE_RECIPIENT", "disposition": "RELEASED_UNINFUSED", "planned_doses_n": 1, "infused_doses_n": 0, "c2b_responder_doses_n": 0, "recipient_ids": [], "recipient_outcomes": {}, }, { "lot_id": "L_FAIL_CLEAN", "mcb_id": "M1", "lot_type": "SINGLE_RECIPIENT", "disposition": "FAILED_RELEASE", "planned_doses_n": 1, "infused_doses_n": 0, "c2b_responder_doses_n": 0, "recipient_ids": [], "recipient_outcomes": {}, }, ] p_r08_noninf_ok, _ = build_valid_gate28a_reference_bundle( r08_store, r08_bal60, cohort_id="COHORT-R08-B2-NONINF-OK", lot_to_mcb_manifest=r08_mcb_map, lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=cmc_r08_noninf_clean, ) r_r08_noninf_ok = evaluate_gate28a_h1_promotion(p_r08_noninf_ok, trusted_clinical_store=r08_store) r08_mcb_with_uninf = dict(r08_mcb_map, L_UNINF_01="M0") cmc_r08_uninf_conf = _derive_reconciling_cmc_lot_ledger_from_recipients(r08_bal60, r08_mcb_with_uninf) + [ { "lot_id": "L_UNINF_01", "mcb_id": "M1", "lot_type": "SINGLE_RECIPIENT", "disposition": "RELEASED_UNINFUSED", "planned_doses_n": 1, "infused_doses_n": 0, "c2b_responder_doses_n": 0, "recipient_ids": [], "recipient_outcomes": {}, }, ] p_r08_uninf_conf, _ = build_valid_gate28a_reference_bundle( r08_store, r08_bal60, cohort_id="COHORT-R08-B2-UNINF-CONF", lot_to_mcb_manifest=r08_mcb_with_uninf, lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=cmc_r08_uninf_conf, ) r_r08_uninf_conf = evaluate_gate28a_h1_promotion(p_r08_uninf_conf, trusted_clinical_store=r08_store) r08_mcb_with_fail = dict(r08_mcb_map, L_FAIL_01="M0") cmc_r08_fail_conf = _derive_reconciling_cmc_lot_ledger_from_recipients(r08_bal60, r08_mcb_with_fail) + [ { "lot_id": "L_FAIL_01", "mcb_id": "M2", "lot_type": "SINGLE_RECIPIENT", "disposition": "FAILED_RELEASE", "planned_doses_n": 1, "infused_doses_n": 0, "c2b_responder_doses_n": 0, "recipient_ids": [], "recipient_outcomes": {}, }, ] p_r08_fail_conf, _ = build_valid_gate28a_reference_bundle( r08_store, r08_bal60, cohort_id="COHORT-R08-B2-FAIL-CONF", lot_to_mcb_manifest=r08_mcb_with_fail, lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=cmc_r08_fail_conf, ) r_r08_fail_conf = evaluate_gate28a_h1_promotion(p_r08_fail_conf, trusted_clinical_store=r08_store) if not ( r_r08_noninf_ok["status"] == "PROMOTE_H1_88_TO_90" and r_r08_noninf_ok["promotion_authorized"] is True and r_r08_noninf_ok["parallel_cmc_ledger_verified"] is True and r_r08_uninf_conf["status"] == "HOLD_H1_AT_88PCT" and r_r08_uninf_conf["promotion_authorized"] is False and r_r08_uninf_conf["parallel_cmc_ledger_verified"] is False and r_r08_uninf_conf["lot_bank_hierarchy_valid"] is False and r_r08_uninf_conf["deff"] is None and any("CMC_ROW_ANCESTRY_CONFLICTS_WITH_VERIFIED_MANIFEST" in fr for fr in r_r08_uninf_conf["failure_reasons"]) and r_r08_fail_conf["status"] == "HOLD_H1_AT_88PCT" and r_r08_fail_conf["promotion_authorized"] is False and r_r08_fail_conf["parallel_cmc_ledger_verified"] is False and r_r08_fail_conf["lot_bank_hierarchy_valid"] is False and r_r08_fail_conf["deff"] is None and any("CMC_ROW_ANCESTRY_CONFLICTS_WITH_VERIFIED_MANIFEST" in fr for fr in r_r08_fail_conf["failure_reasons"]) ): raise ValueError( f"R08 B2b non-infused CMC row ancestry check failed: ok={r_r08_noninf_ok}, uninf={r_r08_uninf_conf}, fail={r_r08_fail_conf}" ) cases.append({"case": "b2b_r08_gate28a_noninfused_released_and_failed_cmc_rows_mcb_conflict_rejected", "passed": True}) # 43. R08 B2c: Non-infused CMC row (absent from manifest) declaring W0 -> M1 contradicts manifest W0 -> M0! cmc_r08_wcb_tree_conf = _derive_reconciling_cmc_lot_ledger_from_recipients(r08_bal60, r08_mcb_map) + [ { "lot_id": "L_UNINF_WCB_BAD", "mcb_id": "M1", "wcb_id": "W0", "lot_type": "SINGLE_RECIPIENT", "disposition": "RELEASED_UNINFUSED", "planned_doses_n": 1, "infused_doses_n": 0, "c2b_responder_doses_n": 0, "recipient_ids": [], "recipient_outcomes": {}, }, ] p_r08_wcb_tree_conf, _ = build_valid_gate28a_reference_bundle( r08_store, r08_bal60, cohort_id="COHORT-R08-B2-WCB-TREE-CONF", lot_to_mcb_manifest=r08_mcb_map, lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=cmc_r08_wcb_tree_conf, ) r_r08_wcb_tree_conf = evaluate_gate28a_h1_promotion(p_r08_wcb_tree_conf, trusted_clinical_store=r08_store) if not ( r_r08_wcb_tree_conf["status"] == "HOLD_H1_AT_88PCT" and r_r08_wcb_tree_conf["promotion_authorized"] is False and r_r08_wcb_tree_conf["parallel_cmc_ledger_verified"] is False and r_r08_wcb_tree_conf["lot_bank_hierarchy_valid"] is False and r_r08_wcb_tree_conf["deff"] is None and any("CMC_ROW_ANCESTRY_CONFLICTS_WITH_VERIFIED_MANIFEST" in fr for fr in r_r08_wcb_tree_conf["failure_reasons"]) and any("NON_UNIQUE_WCB_PARENTAGE" in fr for fr in r_r08_wcb_tree_conf["failure_reasons"]) ): raise ValueError(f"R08 B2c non-infused CMC row WCB-to-MCB parentage conflict MUST fail closed: {r_r08_wcb_tree_conf}") cases.append({"case": "b2c_r08_gate28a_noninfused_cmc_row_wcb_parentage_conflict_rejected", "passed": True}) # 44. R08 M2: Explicit course-equivalent weighted unit surfaced on p_infuse_given_released if not ( cmc_multi.get("p_infuse_given_released_unit") == "infused_primary_course_equivalents_per_released_lot" and abs(cmc_multi["p_infuse_given_released"] - 0.50) < 1e-9 ): raise ValueError(f"R08 M2 p_infuse_given_released_unit missing or invalid: {cmc_multi}") cases.append({"case": "m2_r08_cmc_p_infuse_given_released_course_equivalent_unit_surfaced", "passed": True}) # --- R09 B1 & M3: Typed raw-CMC ancestry error propagation, strict JSON duplicate-key intake, # ordinary clinical HOLD preservation, and separate variance-component ICC sum <= 1.0 bounds --- r09_store = tmp_dir_p / "r09_gate28a_store.json" r09_base_cmc = _derive_reconciling_cmc_lot_ledger_from_recipients(r08_bal60, r08_mcb_map) for row_b in r09_base_cmc: if row_b["lot_id"] == "L00": row_b["wcb_id"] = "W0" # 45. R09 B1a: Positive 60-recipient control with raw CMC W0 on L00 promotes, while adding failed-release # lot F01 reusing W0 under M1 MUST fail closed with null deff/n_eff/k_eff and all ancestry flags False! p_r09_ctrl, _ = build_valid_gate28a_reference_bundle( r09_store, r08_bal60, cohort_id="COHORT-R09-B1-CTRL", lot_to_mcb_manifest=r08_mcb_map, lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=r09_base_cmc, ) r_r09_ctrl = evaluate_gate28a_h1_promotion(p_r09_ctrl, trusted_clinical_store=r09_store) cmc_r09_wcb_reuse = copy.deepcopy(r09_base_cmc) + [ { "lot_id": "F01", "mcb_id": "M1", "wcb_id": "W0", "lot_type": "SINGLE_RECIPIENT", "disposition": "FAILED_RELEASE", "planned_doses_n": 1, "infused_doses_n": 0, } ] p_r09_wcb_reuse, _ = build_valid_gate28a_reference_bundle( r09_store, r08_bal60, cohort_id="COHORT-R09-B1-WCB-REUSE", lot_to_mcb_manifest=r08_mcb_map, lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=cmc_r09_wcb_reuse, ) r_r09_wcb_reuse = evaluate_gate28a_h1_promotion(p_r09_wcb_reuse, trusted_clinical_store=r09_store) if not ( r_r09_ctrl["status"] == "PROMOTE_H1_88_TO_90" and r_r09_ctrl["promotion_authorized"] is True and r_r09_ctrl["lot_bank_hierarchy_valid"] is True and r_r09_ctrl["lot_to_mcb_manifest_verified"] is True and r_r09_ctrl["lot_to_wcb_manifest_verified"] is True and r_r09_ctrl["parallel_cmc_ledger_verified"] is True and abs(r_r09_ctrl["deff"] - 1.53) < 1e-6 and abs(r_r09_ctrl["n_eff"] - 39.215686) < 1e-5 and abs(r_r09_ctrl["k_eff"] - 39.215686) < 1e-5 and r_r09_wcb_reuse["status"] == "HOLD_H1_AT_88PCT" and r_r09_wcb_reuse["promotion_authorized"] is False and r_r09_wcb_reuse["parallel_cmc_ledger_verified"] is False and r_r09_wcb_reuse["lot_bank_hierarchy_valid"] is False and r_r09_wcb_reuse["lot_to_mcb_manifest_verified"] is False and r_r09_wcb_reuse["lot_to_wcb_manifest_verified"] is False and r_r09_wcb_reuse["deff"] is None and r_r09_wcb_reuse["n_eff"] is None and r_r09_wcb_reuse["k_eff"] is None and any("NON_UNIQUE_WCB_PARENTAGE" in fr for fr in r_r09_wcb_reuse["failure_reasons"]) ): raise ValueError(f"R09 B1a raw CMC WCB reuse across infused+failed lots check failed: ctrl={r_r09_ctrl}, wcb={r_r09_wcb_reuse}") cases.append({"case": "b1a_r09_gate28a_raw_cmc_wcb_reuse_infused_and_failed_lot_invalidates_hierarchy", "passed": True}) # 46. R09 B1b: Released-uninfused raw CMC row with canonical MCB vs recognized MCB alias (and WCB alias) # contradicting verified manifest MUST fail closed with null deff/n_eff/k_eff and all ancestry flags False! r09_mcb_u01 = dict(r08_mcb_map, U01="M0") for lbl_al9, extra_row_al9, exp_tok_al9 in ( ( "master_cell_bank_id", { "lot_id": "U01", "mcb_id": "M1", "master_cell_bank_id": "M0", "lot_type": "SINGLE_RECIPIENT", "disposition": "RELEASED_UNINFUSED", "planned_doses_n": 1, "infused_doses_n": 0, }, "CONFLICTING_MCB_ALIAS", ), ( "bank_id", { "lot_id": "U01", "mcb_id": "M1", "bank_id": "M0", "lot_type": "SINGLE_RECIPIENT", "disposition": "RELEASED_UNINFUSED", "planned_doses_n": 1, "infused_doses_n": 0, }, "CONFLICTING_MCB_ALIAS", ), ( "working_cell_bank_id",