and r_r10_wcb_omitted["deff"] is None and r_r10_wcb_omitted["n_eff"] is None and r_r10_wcb_omitted["k_eff"] is None and any("CMC_INFUSED_LOT_MISSING_DECLARED_WCB_ID" in fr for fr in r_r10_wcb_omitted["failure_reasons"]) ): raise ValueError( f"R10 M1 explicit infused CMC WCB attestation failed: match={r_r10_wcb_match}, omitted={r_r10_wcb_omitted}" ) cases.append({"case": "m1_r10_gate28a_infused_cmc_row_missing_manifest_declared_wcb_fails_closed", "passed": True}) # 55. R10 M2: Reichman cryptococcal meningitis death entry preserves full NEJM clinical context part_a_r10 = analyze_clinical_h1_reanchor() reich_r10 = next( e for e in part_a_r10["per_study_endpoint_adjudication_ledger"] if e["study_id"] == "Reichman_2025_NEJM_PMID_40544428" ) d1_txt = reich_r10["published_counts"]["trial_deaths_product_vs_regimen_attribution"]["death_1_cryptococcal_meningitis"] if not ( "skull-base injury" in d1_txt and "prolonged protocol-prohibited systemic glucocorticoids" in d1_txt and "concurrent chronic immunosuppression" in d1_txt and "UNRELATED to zimislecel" in d1_txt and "RELATED to the chronic immunosuppressive" in d1_txt ): raise ValueError(f"R10 M2 Reichman cryptococcal death context incomplete: {d1_txt}") cases.append({"case": "m2_r10_reichman_cryptococcal_death_clinical_context_preserved", "passed": True}) # --- R11 B1, B2, B3, M1, M2, M3: Final-Closure Self-Tests (Cases 56-61) --- r11_store = tmp_dir_p / "r11_gate28a_store.json" # 56. R11 B1: Deterministic ITT non-response events (MISSING_PRIMARY_ENDPOINT_OR_LTFU, PRE_LANDMARK_DEATH, # PRIMARY_GRAFT_NON_FUNCTION) with endpoint & follow-up omitted/None adjudicate to 0 BEFORE endpoint checks # and MUST reject CMC=1 (parallel_cmc_ledger_verified=False + CMC_OUTCOME_MISMATCH) while matching CMC=0! # Also: non-response-exempt IE="NONE" with missing follow-up MUST NOT skip CMC reconciliation (missing adjudication fails closed!). for ie_nr_lbl in ("MISSING_PRIMARY_ENDPOINT_OR_LTFU", "PRE_LANDMARK_DEATH", "PRIMARY_GRAFT_NON_FUNCTION"): for omit_mode in ("omitted", "explicit_none"): r11_nr_recs = copy.deepcopy(r10_plain60) r11_nr_recs[0]["intercurrent_event"] = ie_nr_lbl if omit_mode == "omitted": r11_nr_recs[0].pop("met_c2b_criteria", None) r11_nr_recs[0].pop("followup_months", None) else: r11_nr_recs[0]["met_c2b_criteria"] = None r11_nr_recs[0]["followup_months"] = None cmc_nr_contra = copy.deepcopy(r10_plain_rows) # R00-0 == 1 contradicting clinical 0 p_nr_contra, _ = build_valid_gate28a_reference_bundle( r11_store, r11_nr_recs, cohort_id=f"COHORT-R11-B1-{ie_nr_lbl}-{omit_mode}-CONTRA", lot_to_mcb_manifest=r10_bank_map, parallel_cmc_lot_ledger=cmc_nr_contra, ) r_nr_contra = evaluate_gate28a_h1_promotion(p_nr_contra, trusted_clinical_store=r11_store) cmc_nr_match = copy.deepcopy(r10_plain_rows) cmc_nr_match[0]["recipient_outcomes"]["R00-0"] = 0 cmc_nr_match[0]["c2b_responder_doses_n"] = 3 p_nr_match, _ = build_valid_gate28a_reference_bundle( r11_store, r11_nr_recs, cohort_id=f"COHORT-R11-B1-{ie_nr_lbl}-{omit_mode}-MATCH", lot_to_mcb_manifest=r10_bank_map, parallel_cmc_lot_ledger=cmc_nr_match, ) r_nr_match = evaluate_gate28a_h1_promotion(p_nr_match, trusted_clinical_store=r11_store) if not ( r_nr_contra["parallel_cmc_ledger_verified"] is False and r_nr_contra["promotion_authorized"] is False and r_nr_contra["k"] == 59 and any("CMC_OUTCOME_MISMATCH" in fr for fr in r_nr_contra["failure_reasons"]) and r_nr_match["parallel_cmc_ledger_verified"] is True and r_nr_match["k"] == 59 and not any("CMC_OUTCOME_MISMATCH" in fr for fr in r_nr_match["failure_reasons"]) ): raise ValueError( f"R11 B1 deterministic non-response CMC reconciliation failed ({ie_nr_lbl}/{omit_mode}): " f"contra={r_nr_contra}, match={r_nr_match}" ) r11_unadj = copy.deepcopy(r10_plain60) r11_unadj[0]["followup_months"] = None # IE='NONE' -> cannot adjudicate clinical outcome p_unadj, _ = build_valid_gate28a_reference_bundle( r11_store, r11_unadj, cohort_id="COHORT-R11-B1-UNRECONCILED-NONE", lot_to_mcb_manifest=r10_bank_map, parallel_cmc_lot_ledger=r10_plain_rows, ) r_unadj = evaluate_gate28a_h1_promotion(p_unadj, trusted_clinical_store=r11_store) if not ( r_unadj["parallel_cmc_ledger_verified"] is False and r_unadj["promotion_authorized"] is False and any("CMC_OUTCOME_UNRECONCILED_MISSING_CLINICAL_ADJUDICATION" in fr for fr in r_unadj["failure_reasons"]) ): raise ValueError(f"R11 B1 unreconciled clinical outcome MUST fail CMC verification: {r_unadj}") cases.append({"case": "b1_r11_gate28a_deterministic_nonresponse_omitted_fields_reconciled_against_cmc", "passed": True}) # 57. R11 B2: Duplicate clinical rescue rows (RA, RB) vs (RB, RA) produce 100% IDENTICAL order-independent # results with parallel_cmc_ledger_verified=False in BOTH orders; identical duplicates also fail CMC # reconciliation; unindexed single rescue without explicit rescue_lot_id fails closed! r11_dup_ab = copy.deepcopy(r10_resc_base60) r11_dup_ab[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_lot_id="RA") r11_dup_ab.append({**r10_resc_base60[0], "intercurrent_event": "RESCUE_REPEAT_INFUSION", "rescue_lot_id": "RB"}) r11_dup_ba = copy.deepcopy(r10_resc_base60) r11_dup_ba[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_lot_id="RB") r11_dup_ba.append({**r10_resc_base60[0], "intercurrent_event": "RESCUE_REPEAT_INFUSION", "rescue_lot_id": "RA"}) p_dup_ab, _ = build_valid_gate28a_reference_bundle( r11_store, r11_dup_ab, cohort_id="COHORT-R11-B2-DUP-RESC", lot_to_mcb_manifest={**r10_resc_bank_map, "RA": "M0", "RB": "M0"}, parallel_cmc_lot_ledger=r10_resc1_rows, ) p_dup_ba, _ = build_valid_gate28a_reference_bundle( r11_store, r11_dup_ba, cohort_id="COHORT-R11-B2-DUP-RESC", lot_to_mcb_manifest={**r10_resc_bank_map, "RA": "M0", "RB": "M0"}, parallel_cmc_lot_ledger=r10_resc1_rows, ) r_dup_ab = evaluate_gate28a_h1_promotion(p_dup_ab, trusted_clinical_store=r11_store) r_dup_ba = evaluate_gate28a_h1_promotion(p_dup_ba, trusted_clinical_store=r11_store) # Identical non-conflicting duplicate (RA, RA) still invalidates 1:1 CMC reconciliation r11_dup_aa = copy.deepcopy(r10_resc_base60) r11_dup_aa[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_lot_id="RA") r11_dup_aa.append({**r10_resc_base60[0], "intercurrent_event": "RESCUE_REPEAT_INFUSION", "rescue_lot_id": "RA"}) p_dup_aa, _ = build_valid_gate28a_reference_bundle( r11_store, r11_dup_aa, cohort_id="COHORT-R11-B2-DUP-AA", lot_to_mcb_manifest={**r10_resc_bank_map, "RA": "M0"}, parallel_cmc_lot_ledger=r10_resc1_rows, ) r_dup_aa = evaluate_gate28a_h1_promotion(p_dup_aa, trusted_clinical_store=r11_store) # Unindexed single clinical rescue (omitting rescue_lot_id) vs single CMC rescue RA MUST fail closed! r11_unindexed_1 = copy.deepcopy(r10_resc_base60) r11_unindexed_1[0]["intercurrent_event"] = "RESCUE_REPEAT_INFUSION" p_unidx_1, _ = build_valid_gate28a_reference_bundle( r11_store, r11_unindexed_1, cohort_id="COHORT-R11-B2-UNINDEXED-1", lot_to_mcb_manifest={**r10_resc_bank_map, "RA": "M0"}, parallel_cmc_lot_ledger=r10_resc1_rows, ) r_unidx_1 = evaluate_gate28a_h1_promotion(p_unidx_1, trusted_clinical_store=r11_store) if not ( r_dup_ab["cohort_canonical_sha256"] == r_dup_ba["cohort_canonical_sha256"] and r_dup_ab == r_dup_ba and r_dup_ab["parallel_cmc_ledger_verified"] is False and r_dup_ba["parallel_cmc_ledger_verified"] is False and r_dup_ab["lot_bank_hierarchy_valid"] is False and r_dup_ab["lot_to_mcb_manifest_verified"] is False and r_dup_ab["lot_to_wcb_manifest_verified"] is False and r_dup_ab["deff"] is None and r_dup_ab["n_eff"] is None and r_dup_ab["k_eff"] is None and r_dup_ab["icc_sensitivity_report_attached"] is False and r_dup_ab["icc_sensitivity_report"] is None and r_dup_ab["promotion_authorized"] is False and any("CONFLICTING_DUPLICATE_RECIPIENT_RESCUE" in fr for fr in r_dup_ab["failure_reasons"]) and any("DUPLICATE_CLINICAL_RECIPIENT_INVALIDATES_CMC_RECONCILIATION" in fr for fr in r_dup_ab["failure_reasons"]) and any("CLINICAL_RESCUE_LOT_ID_MISMATCH_IN_CMC_LEDGER" in fr for fr in r_dup_ab["failure_reasons"]) and r_dup_aa["parallel_cmc_ledger_verified"] is False and any("DUPLICATE_CLINICAL_RECIPIENT_INVALIDATES_CMC_RECONCILIATION" in fr for fr in r_dup_aa["failure_reasons"]) and r_unidx_1["parallel_cmc_ledger_verified"] is False and r_unidx_1["promotion_authorized"] is False and any("CLINICAL_RESCUE_MISSING_EXPLICIT_LOT_ID" in fr for fr in r_unidx_1["failure_reasons"]) ): raise ValueError( f"R11 B2 duplicate rescue order-independence / explicit lot ID check failed: " f"ab={r_dup_ab}, ba={r_dup_ba}, aa={r_dup_aa}, unidx1={r_unidx_1}" ) cases.append({"case": "b2_r11_gate28a_duplicate_clinical_rescue_order_independent_and_explicit_lot_id_required", "passed": True}) # 58. R11 B3: Prespecified 3-scenario same-cohort icc_sensitivity_report and 4-state icc_sensitivity_review_status # (ROBUST 3/3 promote; BOUNDARY_SENSITIVE primary+moderate promote with disclosure; MODERATE FAIL HARD HOLD; # PRIMARY FAIL HARD HOLD; below-floor supplied ICC rejected with icc_sensitivity_report_attached=False!) p_good30_hold, _ = build_valid_gate28a_reference_bundle(r11_store, good_30, cohort_id="COHORT-R11-B3-GOOD30-MODHOLD") r_good30_hold = evaluate_gate28a_h1_promotion(p_good30_hold, trusted_clinical_store=r11_store) r11_59of60_3mcb = copy.deepcopy(r10_plain60) r11_59of60_3mcb[0]["met_c2b_criteria"] = False p_59_3mcb, _ = build_valid_gate28a_reference_bundle( r11_store, r11_59of60_3mcb, cohort_id="COHORT-R11-B3-59OF60-3MCB-MODHOLD", lot_to_mcb_manifest=r10_bank_map, ) r_59_3mcb = evaluate_gate28a_h1_promotion(p_59_3mcb, trusted_clinical_store=r11_store) p_below_floor, _ = build_valid_gate28a_reference_bundle( r11_store, robust_45, cohort_id="COHORT-R11-B3-BELOW-FLOOR", rho_lot=0.04, rho_bank=0.02 ) r_below_floor = evaluate_gate28a_h1_promotion(p_below_floor, trusted_clinical_store=r11_store) for scen_k in ("primary_floor", "moderate_sensitivity", "high_clustering_sensitivity"): if scen_k not in g28a_bal60_store["icc_sensitivity_report"]: raise ValueError(f"R11 B3 missing scenario {scen_k} in icc_sensitivity_report") for req_field in ("rho_lot", "rho_mcb", "deff_cluster", "n_eff", "posterior_mean", "posterior_p_ge_090", "meets_reanchor_bar"): if req_field not in g28a_bal60_store["icc_sensitivity_report"][scen_k]: raise ValueError(f"R11 B3 missing field {req_field} in scenario {scen_k}") if not ( g28a_ok["icc_sensitivity_report_attached"] is True and g28a_ok["boundary_sensitive_under_high_icc"] is False and g28a_ok["icc_sensitivity_review_status"] == "ROBUST_ACROSS_ALL_THREE_PRESPECIFIED_ICC_SCENARIOS" and g28a_ok["icc_sensitivity_report"]["high_clustering_sensitivity"]["meets_reanchor_bar"] is True and g28a_bal60_store["icc_sensitivity_report_attached"] is True and g28a_bal60_store["boundary_sensitive_under_high_icc"] is True and g28a_bal60_store["icc_sensitivity_review_status"] == "BOUNDARY_SENSITIVE_DISCLOSED_CLEARS_PRIMARY_AND_MODERATE" and g28a_bal60_store["promotion_authorized"] is True and g28a_bal60_store["icc_sensitivity_report"]["primary_floor"]["meets_reanchor_bar"] is True and g28a_bal60_store["icc_sensitivity_report"]["moderate_sensitivity"]["meets_reanchor_bar"] is True and g28a_bal60_store["icc_sensitivity_report"]["high_clustering_sensitivity"]["meets_reanchor_bar"] is False and abs(g28a_bal60_store["icc_sensitivity_report"]["high_clustering_sensitivity"]["n_eff"] - 17.910448) < 1e-5 and r_good30_hold["icc_sensitivity_report_attached"] is True and r_good30_hold["boundary_sensitive_under_high_icc"] is False and r_good30_hold["icc_sensitivity_review_status"] == "HOLD_FAILS_MODERATE_ICC_SENSITIVITY" and r_good30_hold["promotion_authorized"] is False and r_good30_hold["status"] == "HOLD_H1_AT_88PCT" and any("HOLD_FAILS_MODERATE_ICC_SENSITIVITY" in fr for fr in r_good30_hold["failure_reasons"]) and r_59_3mcb["icc_sensitivity_report_attached"] is True and r_59_3mcb["icc_sensitivity_review_status"] == "HOLD_FAILS_MODERATE_ICC_SENSITIVITY" and r_59_3mcb["promotion_authorized"] is False and r_r09_hold["icc_sensitivity_report_attached"] is True and r_r09_hold["icc_sensitivity_review_status"] == "HOLD_FAILS_PRIMARY_ICC_FLOOR" and r_r09_hold["promotion_authorized"] is False and r_below_floor["icc_sensitivity_report_attached"] is False and r_below_floor["icc_sensitivity_report"] is None and r_below_floor["promotion_authorized"] is False and any("INVALID_ICC_DOMAIN" in fr for fr in r_below_floor["failure_reasons"]) ): raise ValueError( f"R11 B3 3-scenario ICC sensitivity report check failed: ok={g28a_ok}, bal60={g28a_bal60_store}, " f"good30={r_good30_hold}, c59={r_59_3mcb}, r09hold={r_r09_hold}, below={r_below_floor}" ) cases.append({"case": "b3_r11_gate28a_three_scenario_icc_sensitivity_report_and_four_state_rule", "passed": True}) # 59. R11 M1: Structural mmCIF helper prefers wwPDB label_asym_id over auth_asym_id, preserving 4X4M Assembly 2 # glycan label chains L (14 heavy atoms) and M (10 heavy atoms, total 24 heavy atoms sharing auth_asym_id='D'), # exact protein (>=7.709 A) and glycan (>=21.821 A) distances, AND catching a positive-control 3.5 A contact on L! def _build_synthetic_4x4m_asm2_cif(glyc_l_x: float) -> str: cif_lines = [ "data_SYNTH_4X4M_ASM2", "#", "loop_", "_struct_conn.id", "_struct_conn.conn_type_id", "_struct_conn.ptnr1_label_asym_id", "_struct_conn.ptnr1_auth_asym_id", "_struct_conn.ptnr1_auth_comp_id", "_struct_conn.ptnr1_auth_seq_id", "_struct_conn.ptnr2_label_asym_id", "_struct_conn.ptnr2_auth_asym_id", "_struct_conn.ptnr2_auth_comp_id", "_struct_conn.ptnr2_auth_seq_id", "covale4 covale D D ASN 297 L D NAG 1001", "#", "loop_", "_struct_ref_seq_dif.pdbx_pdb_strand_id", "_struct_ref_seq_dif.pdbx_seq_db_seq_num", "_struct_ref_seq_dif.db_mon_id", "_struct_ref_seq_dif.mon_id",