and abs(cmc_split["p_infuse_given_released"] - 0.75) < 1e-9 and abs(cmc_split["projected_cmc_attempted_lot_readiness"] - 0.66) < 1e-9 and abs(cmc_split["measured_weighted_cmc_readiness"] - 0.75) < 1e-9 and abs(cmc_split["empirical_product_readiness"] - 0.75) < 1e-9 and cmc_split["unique_clinical_recipients_n"] == 3 ): raise ValueError(f"B1 split-lot check failed: {cmc_split}") cases.append({"case": "b1_cmc_split_lot_recipient_weighted_accounting", "passed": True, "projected": cmc_split["projected_cmc_attempted_lot_readiness"], "measured": cmc_split["measured_weighted_cmc_readiness"]}) # 3. B1 valid 2-lot pooled course: matching conditioning (1.0 infused course-equiv / 2 lots = 0.50) AND outcome (1.0 / 2 = 0.50)! cmc_multi = evaluate_cmc_attempted_lot_readiness([ { "lot_id": "LOT-ML-1", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_PRIMARY", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "c2b_responder_doses_n": 1, "recipient_ids": ["REC-ML1"], "recipient_outcomes": {"REC-ML1": 1}, "pooled_course_id": "COURSE-001", "pooled_lot_count": 2, "primary_lot_id": "LOT-ML-1", "pooled_course_lot_ids": ["LOT-ML-1", "LOT-ML-2"], }, { "lot_id": "LOT-ML-2", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_CONSTITUENT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "c2b_responder_doses_n": 1, "recipient_ids": ["REC-ML1"], "recipient_outcomes": {"REC-ML1": 1}, "pooled_course_id": "COURSE-001", "pooled_lot_count": 2, "primary_lot_id": "LOT-ML-1", "pooled_course_lot_ids": ["LOT-ML-1", "LOT-ML-2"], }, ]) if not ( cmc_multi["attempted_lots_n"] == 2 and cmc_multi["released_lots_n"] == 2 and abs(cmc_multi["infused_lot_equivalents"] - 1.0) < 1e-9 and abs(cmc_multi["p_infuse_given_released"] - 0.50) < 1e-9 and cmc_multi["unique_clinical_recipients_n"] == 1 and cmc_multi["clinical_primary_responders_n"] == 1 and abs(cmc_multi["lot_weighted_primary_successes"] - 1.0) < 1e-9 and abs(cmc_multi["measured_weighted_cmc_readiness"] - 0.50) < 1e-9 and abs(cmc_multi["empirical_product_readiness"] - 0.50) < 1e-9 and abs(cmc_multi["projected_cmc_attempted_lot_readiness"] - 0.44) < 1e-9 ): raise ValueError(f"B1 multi-lot course check failed: {cmc_multi}") cases.append({"case": "b1_cmc_multilot_course_matching_conditioning_and_outcome_weights", "passed": True, "infused_equiv": cmc_multi["infused_lot_equivalents"], "measured": cmc_multi["measured_weighted_cmc_readiness"], "projected": cmc_multi["projected_cmc_attempted_lot_readiness"]}) # 4. B1 unplanned rescue repeat-lot infusion forces primary single-infusion outcome to 0 and w_infuse=0 on rescue lot! cmc_resc = evaluate_cmc_attempted_lot_readiness([ { "lot_id": "LOT-INIT-1", "mcb_id": "MCB-1", "lot_type": "SINGLE_RECIPIENT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "c2b_responder_doses_n": 0, "recipient_ids": ["REC-R1"], "recipient_outcomes": {"REC-R1": 0}, }, { "lot_id": "LOT-RESC-1", "mcb_id": "MCB-1", "lot_type": "RESCUE_REPEAT_LOT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "c2b_responder_doses_n": 1, "recipient_ids": ["REC-R1"], "recipient_outcomes": {"REC-R1": 1}, "rescued_recipient_id": "REC-R1", "rescued_primary_lot_id": "LOT-INIT-1", }, ]) if not ( cmc_resc["attempted_lots_n"] == 2 and cmc_resc["rescue_lots_n"] == 1 and abs(cmc_resc["infused_lot_equivalents"] - 1.0) < 1e-9 and abs(cmc_resc["p_infuse_given_released"] - 0.50) < 1e-9 and cmc_resc["unique_clinical_recipients_n"] == 1 and cmc_resc["clinical_primary_responders_n"] == 0 and abs(cmc_resc["lot_weighted_primary_successes"] - 0.0) < 1e-9 and abs(cmc_resc["measured_weighted_cmc_readiness"] - 0.0) < 1e-9 and abs(cmc_resc["projected_cmc_attempted_lot_readiness"] - 0.44) < 1e-9 ): raise ValueError(f"B1 rescue repeat-lot check failed: {cmc_resc}") cases.append({"case": "b1_cmc_rescue_repeat_lot_forces_primary_nonresponder", "passed": True, "measured": cmc_resc["measured_weighted_cmc_readiness"]}) # 5. B1 adversarial: incomplete 2-lot pooled course (missing constituent row) MUST raise ValueError! _expect_cmc_value_error( "b1_cmc_reject_incomplete_pooled_course_missing_constituent", [ { "lot_id": "LOT-INC-1", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_PRIMARY", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "recipient_outcomes": {"REC-INC": 1}, "pooled_course_id": "C-INC", "pooled_lot_count": 2, "primary_lot_id": "LOT-INC-1", "pooled_course_lot_ids": ["LOT-INC-1", "LOT-INC-2"], } ], ) # 6. B1 adversarial: 2-lot pooled course with conflicting primary_lot_id MUST raise ValueError! _expect_cmc_value_error( "b1_cmc_reject_pooled_course_conflicting_primary_lot_id", [ { "lot_id": "LOT-CONF-1", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_PRIMARY", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "recipient_outcomes": {"REC-CONF": 1}, "course_id": "C-CONF", "primary_lot_id": "LOT-CONF-1", "course_lot_ids": ["LOT-CONF-1", "LOT-CONF-2"], }, { "lot_id": "LOT-CONF-2", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_CONSTITUENT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "recipient_outcomes": {"REC-CONF": 1}, "course_id": "C-CONF", "primary_lot_id": "LOT-CONF-2", "course_lot_ids": ["LOT-CONF-1", "LOT-CONF-2"], }, ], ) # 7. B1 adversarial: split-lot omitting explicit recipient_outcomes (positional-only) MUST raise ValueError! _expect_cmc_value_error( "b1_cmc_reject_split_lot_without_explicit_recipient_outcomes", [ { "lot_id": "LOT-POS-1", "mcb_id": "MCB-1", "lot_type": "SPLIT_LOT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 2, "infused_doses_n": 2, "c2b_responder_doses_n": 1, "recipient_ids": ["REC-A", "REC-B"], } ], ) # 8. B1 adversarial: split-lot + rescue MUST be 100% invariant to recipient_ids order AND lot_ledger order! split_fwd = { "lot_id": "LOT-SP-INV", "mcb_id": "MCB-1", "lot_type": "SPLIT_LOT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 2, "infused_doses_n": 2, "c2b_responder_doses_n": 1, "recipient_ids": ["REC-A", "REC-B"], "recipient_outcomes": {"REC-A": 1, "REC-B": 0}, } split_rev = { "lot_id": "LOT-SP-INV", "mcb_id": "MCB-1", "lot_type": "SPLIT_LOT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 2, "infused_doses_n": 2, "c2b_responder_doses_n": 1, "recipient_ids": ["REC-B", "REC-A"], "recipient_records": [{"recipient_id": "REC-B", "c2b_responder": False}, {"recipient_id": "REC-A", "c2b_responder": True}], } resc_b = { "lot_id": "LOT-RESC-B", "mcb_id": "MCB-1", "lot_type": "RESCUE_REPEAT_LOT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "c2b_responder_doses_n": 1, "recipient_ids": ["REC-B"], "recipient_outcomes": {"REC-B": 1}, "rescued_recipient_id": "REC-B", "rescued_primary_lot_id": "LOT-SP-INV", } r_p1 = evaluate_cmc_attempted_lot_readiness([split_fwd, resc_b]) r_p2 = evaluate_cmc_attempted_lot_readiness([split_rev, resc_b]) r_p3 = evaluate_cmc_attempted_lot_readiness([resc_b, split_fwd]) r_p4 = evaluate_cmc_attempted_lot_readiness([resc_b, split_rev]) if not ( r_p1 == r_p2 == r_p3 == r_p4 and r_p1["clinical_primary_responders_n"] == 1 and abs(r_p1["measured_weighted_cmc_readiness"] - 0.25) < 1e-9 and abs(r_p1["empirical_product_readiness"] - 0.25) < 1e-9 and abs(r_p1["projected_cmc_attempted_lot_readiness"] - 0.44) < 1e-9 ): raise ValueError(f"B1 split+rescue order invariance failed: p1={r_p1}, p2={r_p2}, p3={r_p3}, p4={r_p4}") cases.append({"case": "b1_cmc_split_lot_plus_rescue_100pct_order_invariant", "passed": True, "measured": r_p1["measured_weighted_cmc_readiness"]}) # 9. B1 adversarial: orphan rescue-only row MUST raise ValueError (NEVER fabricate a recipient)! _expect_cmc_value_error( "b1_cmc_reject_orphan_rescue_only_row", [ { "lot_id": "LOT-ORPHAN-RESC", "mcb_id": "MCB-1", "lot_type": "RESCUE_REPEAT_LOT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "recipient_outcomes": {"REC-GHOST": 1}, "rescued_recipient_id": "REC-GHOST", "rescued_primary_lot_id": "LOT-MISSING-INIT", } ], ) # 10. R06 Blocking 1a: lot_id == course_id == "COLLIDE-1" for same recipient MUST raise ValueError in ALL orders! collide_single = { "lot_id": "COLLIDE-1", "mcb_id": "MCB-1", "lot_type": "SINGLE_RECIPIENT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "c2b_responder_doses_n": 0, "recipient_ids": ["REC-COL"], "recipient_outcomes": {"REC-COL": 0}, } collide_ml1 = { "lot_id": "ML-COL-1", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_PRIMARY", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "c2b_responder_doses_n": 1, "recipient_ids": ["REC-COL"], "recipient_outcomes": {"REC-COL": 1}, "course_id": "COLLIDE-1", "primary_lot_id": "ML-COL-1", "course_lot_ids": ["ML-COL-1", "ML-COL-2"], } collide_ml2 = { "lot_id": "ML-COL-2", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_CONSTITUENT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "c2b_responder_doses_n": 1, "recipient_ids": ["REC-COL"], "recipient_outcomes": {"REC-COL": 1}, "course_id": "COLLIDE-1", "primary_lot_id": "ML-COL-1", "course_lot_ids": ["ML-COL-1", "ML-COL-2"], } _expect_cmc_value_error("b1_r06_cmc_reject_single_and_pooled_id_collision_fwd", [collide_single, collide_ml1, collide_ml2]) # Also test reverse lexical sort order where pooled lot_id sorts BEFORE single lot_id ("A-ML-1" < "Z-COLLIDE") collide_single_z = dict(collide_single, lot_id="Z-COLLIDE") collide_ml1_a = dict(collide_ml1, lot_id="A-ML-1", course_id="Z-COLLIDE", primary_lot_id="A-ML-1", course_lot_ids=["A-ML-1", "A-ML-2"]) collide_ml2_a = dict(collide_ml2, lot_id="A-ML-2", course_id="Z-COLLIDE", primary_lot_id="A-ML-1", course_lot_ids=["A-ML-1", "A-ML-2"]) _expect_cmc_value_error("b1_r06_cmc_reject_single_and_pooled_id_collision_rev", [collide_ml1_a, collide_ml2_a, collide_single_z]) # 11. R06 Blocking 1b: Reordered equivalent pooled_course_lot_ids vs course_lot_ids SUCCEEDS cleanly (and duplicates/mismatches reject)! cmc_reord = evaluate_cmc_attempted_lot_readiness([ { "lot_id": "LOT-ORD-1", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_PRIMARY", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "recipient_outcomes": {"REC-ORD": 1}, "pooled_course_id": "C-ORD", "course_id": "C-ORD", "primary_lot_id": "LOT-ORD-1", "pooled_course_lot_ids": ["LOT-ORD-1", "LOT-ORD-2"], "course_lot_ids": ["LOT-ORD-2", "LOT-ORD-1"], }, { "lot_id": "LOT-ORD-2", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_CONSTITUENT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "recipient_outcomes": {"REC-ORD": 1}, "pooled_course_id": "C-ORD", "course_id": "C-ORD", "primary_lot_id": "LOT-ORD-1", "pooled_course_lot_ids": ["LOT-ORD-2", "LOT-ORD-1"], "course_lot_ids": ["LOT-ORD-1", "LOT-ORD-2"], }, ]) if not ( cmc_reord["unique_clinical_recipients_n"] == 1 and abs(cmc_reord["infused_lot_equivalents"] - 1.0) < 1e-9 and abs(cmc_reord["measured_weighted_cmc_readiness"] - 0.5) < 1e-9 ): raise ValueError(f"R06 B1 reordered equivalent course_lot_ids aliases failed: {cmc_reord}") cases.append({"case": "b1_r06_cmc_accept_reordered_equivalent_course_lot_ids_aliases", "passed": True}) _expect_cmc_value_error( "b1_r06_cmc_reject_duplicate_inside_course_lot_ids_alias", [ { "lot_id": "LOT-DUP-1", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_PRIMARY", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "recipient_outcomes": {"REC-DUP": 1}, "course_id": "C-DUP", "primary_lot_id": "LOT-DUP-1", "pooled_course_lot_ids": ["LOT-DUP-1", "LOT-DUP-2"], "course_lot_ids": ["LOT-DUP-1", "LOT-DUP-1", "LOT-DUP-2"], }, { "lot_id": "LOT-DUP-2", "mcb_id": "MCB-1", "lot_type": "MULTI_LOT_COURSE_CONSTITUENT", "disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1, "recipient_outcomes": {"REC-DUP": 1}, "course_id": "C-DUP", "primary_lot_id": "LOT-DUP-1", "pooled_course_lot_ids": ["LOT-DUP-1", "LOT-DUP-2"], }, ], ) with tempfile.TemporaryDirectory() as tmp_g28a_dir: tmp_dir_p = pathlib.Path(tmp_g28a_dir) clin_store_json = tmp_dir_p / "gate28a_trusted_clinical_store.json" clin_store_dir = tmp_dir_p / "gate28a_trusted_clinical_store_dir" # 12. B2 skewed 21/21 (20 from Lot 1 + 1 from Lot 2, single bank) FAILS to promote even with trusted store! skewed_21 = [ { "recipient_id": f"P-{i:02d}", "lot_id": "LOT-01" if i <= 20 else "LOT-02", "mcb_id": "MCB-A", "followup_months": 12.0, "met_c2b_criteria": True, "intercurrent_event": "NONE", } for i in range(1, 22) ] p_skew, _ = build_valid_gate28a_reference_bundle(clin_store_json, skewed_21, cohort_id="COHORT-SKEW-21") g28a_skew = evaluate_gate28a_h1_promotion(p_skew, trusted_clinical_store=clin_store_json) if g28a_skew["promotion_authorized"] is not False or g28a_skew["status"] != "HOLD_H1_AT_88PCT": raise ValueError(f"B2 skewed 20+1 21/21 MUST fail closed: {g28a_skew}")