live_gate32_debris_recall_record: dict[str, Any] | None = None, store_key_mode: str = "record_id", ) -> tuple[dict[str, Any], dict[str, dict[str, Any]]]: """Build an in-memory mock AUTHENTICATED_ARCHIVED_WETLAB Gate 36 observation + trusted_evidence_store. Populates ALL governing module fields in current_assay_evidence_record (GATE-36-) identically to parent obs, supports direct relay of an unmodified W6-C1 GATE-34 upstream_lot_evidence_record_v1, and for SHIELD automatically builds & stores a matching sealed live GATE-32 whole-islet-debris recall co-prerequisite record (PASS_DEBRIS_RECALL_FULL_CREDIT) in record_id, archive_sha256, or both mode. """ fx_all = _canonical_synthetic_gate34_fixtures() require_cond(module_name in fx_all, f"Unknown Gate 36 module: {module_name}") obs = copy.deepcopy(fx_all[module_name]) if upstream_record is not None: up = copy.deepcopy(upstream_record) if arm_id is not None: obs["target_arm_id"] = arm_id elif arm_manifest is not None and isinstance(arm_manifest.get("arms"), dict): for ak, aentry in arm_manifest["arms"].items(): if aentry.get("product_id") == up.get("product_id"): obs["target_arm_id"] = ak break obs["product_id"] = up["product_id"] obs["lot_id"] = up["lot_id"] obs["bank_id"] = up["bank_id"] obs["bank_origin"] = up["bank_origin"] obs["construct_manifest_sha256"] = up["construct_manifest_sha256"] obs["evidence_tier"] = up["evidence_tier"] obs["upstream_lot_evidence_record"] = up else: if arm_id is not None and arm_manifest is not None: aentry = arm_manifest["arms"][arm_id] obs["target_arm_id"] = arm_id obs["product_id"] = aentry["product_id"] obs["bank_origin"] = aentry["cell_origin"] obs["lot_id"] = f"AUTH_{module_name.upper()}_{arm_id}_LOT_001" obs["bank_id"] = f"MCB_{arm_id}_AUTH_01" obs["construct_manifest_sha256"] = sha256_str(f"lot_construct_manifest|{obs['product_id']}|{obs['lot_id']}|v0.9.0") obs["evidence_tier"] = "AUTHENTICATED_ARCHIVED_WETLAB" up = _make_evidence_record_v2( record_id=f"REC_G34_AUTH_{module_name.upper()}_{obs['target_arm_id']}_001", gate_source=CANONICAL_UPSTREAM_GATE34_SOURCE, product_id=obs["product_id"], lot_id=obs["lot_id"], bank_id=obs["bank_id"], bank_origin=obs["bank_origin"], construct_manifest_sha256=obs["construct_manifest_sha256"], evidence_tier="AUTHENTICATED_ARCHIVED_WETLAB", decision="PASS", authority_scope="CLINICAL_LOT_RELEASE", bank_qualified=True, promotion_authorized=True, ) obs["upstream_lot_evidence_record"] = up cur_extra = { k: v for k, v in obs["current_assay_evidence_record"].items() if k not in UPSTREAM_EVIDENCE_REQUIRED_FIELDS } is_auth = obs["evidence_tier"] == "AUTHENTICATED_ARCHIVED_WETLAB" cur = _make_evidence_record_v2( record_id=f"REC_G36_{module_name.upper()}_{'AUTH' if is_auth else 'SYNTH'}_{obs['target_arm_id']}_001", gate_source=CANONICAL_GATE36_MODULE_SOURCES[module_name], product_id=obs["product_id"], lot_id=obs["lot_id"], bank_id=obs["bank_id"], bank_origin=obs["bank_origin"], construct_manifest_sha256=obs["construct_manifest_sha256"], evidence_tier=obs["evidence_tier"], decision="PASS" if is_auth else "SYNTHETIC_SELF_TEST_PASS", authority_scope="CLINICAL_LOT_RELEASE" if is_auth else "SYNTHETIC_SELF_TEST", bank_qualified=True if is_auth else False, promotion_authorized=True if is_auth else False, extra_fields=cur_extra, ) obs["current_assay_evidence_record"] = cur if module_name == "shield": if live_gate32_debris_recall_record is not None: g32_debris = copy.deepcopy(live_gate32_debris_recall_record) else: g32_debris = _make_evidence_record_v2( record_id=f"REC_LIVE_G32_DEBRIS_{'AUTH' if is_auth else 'SYNTH'}_{obs['target_arm_id']}_001", gate_source=CANONICAL_LIVE_GATE32_DEBRIS_RECALL_SOURCE, product_id=obs["product_id"], lot_id=obs["lot_id"], bank_id=obs["bank_id"], bank_origin=obs["bank_origin"], construct_manifest_sha256=obs["construct_manifest_sha256"], evidence_tier=obs["evidence_tier"], decision="PASS_DEBRIS_RECALL_FULL_CREDIT" if is_auth else "SYNTHETIC_SELF_TEST_PASS", authority_scope="CLINICAL_LOT_RELEASE" if is_auth else "SYNTHETIC_SELF_TEST", bank_qualified=True if is_auth else False, promotion_authorized=True if is_auth else False, extra_fields={ "debris_recall_verdict": "PASS_DEBRIS_RECALL_FULL_CREDIT", "debris_recall_l95_suppressed_frac": 0.78, "residual_class2_recall_u95_frac": 0.22, "unrelated_recall_preserved": True, }, ) obs["live_gate32_debris_recall_record"] = g32_debris store = build_trusted_store_for_obs(obs, store_key_mode=store_key_mode) return obs, store def run_gate34_self_tests(arm_manifest: dict[str, Any]) -> dict[str, Any]: fx = _canonical_synthetic_gate34_fixtures() ok_sh, ok_ins, ok_cuff, ok_iv = fx["shield"], fx["ins"], fx["cuff"], fx["invvax"] cases: dict[str, dict[str, Any]] = {} def _rec(name: str, res: dict[str, Any]) -> None: cases[name] = { "decision": res["decision"], "promotion_authorized": res["promotion_authorized"], } def _reseal_cur(base_obs: dict[str, Any], cur_updates: dict[str, Any]) -> tuple[dict[str, Any], dict[str, dict[str, Any]]]: o = copy.deepcopy(base_obs) c = copy.deepcopy(o["current_assay_evidence_record"]) c.update(cur_updates) o["current_assay_evidence_record"] = seal_evidence_record(c) st = build_trusted_store_for_obs(o, store_key_mode="record_id") return o, st # 1. SHIELD-SEL synthetic & adversarial checks (Round-5 archive-derived, zero threshold tolerance) _rec("shield_synthetic_15uM_self_test_no_promo", evaluate_gate34_shield_sel(ok_sh, arm_manifest)) _rec("shield_missing_manifest_fail", evaluate_gate34_shield_sel(ok_sh, None)) _rec( "shield_l95_7p5uM_u95_15uM_review_probe_fail", evaluate_gate34_shield_sel( {**ok_sh, "on_target_kd_u95_nm": 0.5, "off_target_kd_l95_um": 7.5, "off_target_kd_u95_um": 15.0, "selectivity_ratio_l95": 15000.0}, arm_manifest, ), ) _rec("shield_1nM_peak_2000nM_trough_fail", evaluate_gate34_shield_sel({**ok_sh, "peak_free_nm": 1.0, "plasma_trough_free_nm": 2000.0}, arm_manifest)) _rec("shield_plasma_trough_lt_dln_trough_fail", evaluate_gate34_shield_sel({**ok_sh, "plasma_trough_free_nm": 80.0, "dln_trough_free_nm": 150.0}, arm_manifest)) _rec("shield_kd_on_1e_320_underflow_fail", evaluate_gate34_shield_sel({**ok_sh, "on_target_kd_u95_nm": 1e-320}, arm_manifest)) _rec("shield_5000x_selectivity_fail", evaluate_gate34_shield_sel({**ok_sh, "on_target_kd_u95_nm": 2.0, "selectivity_ratio_l95": 5000.0}, arm_manifest)) _rec("shield_q84d_relabeled_q28d_dataset_fail", evaluate_gate34_shield_sel({**ok_sh, "regimen_id": "Q84D"}, arm_manifest)) _rec("shield_q84d_2nM_fail", evaluate_gate34_shield_sel({**ok_sh, "regimen_id": "Q84D", "timed_pk_day": 84, "on_target_kd_u95_nm": 2.0, "off_target_kd_l95_um": 30.0}, arm_manifest)) _rec("shield_q84d_unmeasured_human_pk_fail", evaluate_gate34_shield_sel({**ok_sh, "regimen_id": "Q84D", "timed_pk_day": 84, "measured_human_pk_verified": False}, arm_manifest)) _rec("shield_design_a_arm_fail", evaluate_gate34_shield_sel({**ok_sh, "target_arm_id": "A"}, arm_manifest)) # 2. INS L82I synthetic & adversarial checks (governed kit/analyte + 4-donor deduplication probe) _rec("ins_synthetic_self_test_no_promo", evaluate_gate34_ins_l82i_elisa_pe2max(ok_ins, arm_manifest)) dup4_ins = copy.deepcopy(ok_ins) for al in MANDATORY_INS_HLA_ALLELES: dup4_ins["hla_allele_panel_records"][al]["donor_ids"] = ["D1", "D2", "D3", "D4"] dup4_ins["hla_allele_panel_records"][al]["donor_count"] = 4 _rec("ins_4_duplicated_donors_across_3_alleles_fail", evaluate_gate34_ins_l82i_elisa_pe2max(dup4_ins, arm_manifest)) _rec("ins_hla_binding_false_fail", evaluate_gate34_ins_l82i_elisa_pe2max({**ok_ins, "hla_binding_verified": False}, arm_manifest)) _rec("ins_design_a_exposed_fail", evaluate_gate34_ins_l82i_elisa_pe2max({**ok_ins, "design_a_exposed": True}, arm_manifest)) _rec("ins_pe4max_mlh1dn_fail", evaluate_gate34_ins_l82i_elisa_pe2max({**ok_ins, "mlh1dn_used": True}, arm_manifest)) # 3. Cuff v2.0 synthetic & adversarial checks (exact 3-protein + GY-025 efferocytosis/pericyte) _rec("cuff_synthetic_3protein_self_test_no_promo", evaluate_gate34_cuff_v2(ok_cuff, arm_manifest)) _rec("cuff_1protein_manifest_fail", evaluate_gate34_cuff_v2({**ok_cuff, "core_cuff_proteins": ["sCR1_v2"]}, arm_manifest)) _rec("cuff_zero_efferocytosis_fail", evaluate_gate34_cuff_v2({**ok_cuff, "exact_stack_efferocytosis_abs_pct": 0.0}, arm_manifest)) _rec("cuff_zero_pericyte_fail", evaluate_gate34_cuff_v2({**ok_cuff, "exact_stack_pericyte_recruitment_pct_of_wt": 0.0}, arm_manifest)) _rec("cuff_cd200r_accessibility_false_fail", evaluate_gate34_cuff_v2({**ok_cuff, "coimmobilized_cd200r_accessibility_verified": False}, arm_manifest)) _rec("cuff_design_a_exposed_fail", evaluate_gate34_cuff_v2({**ok_cuff, "design_a_exposed": True}, arm_manifest)) # 4. InvVax synthetic & adversarial checks (3-dose schedule + distinct governed matrix assay IDs) _rec("invvax_synthetic_self_test_no_promo", evaluate_gate34_invvax_recall(ok_iv, arm_manifest)) _rec("invvax_single_dose_minus7_fail", evaluate_gate34_invvax_recall({**ok_iv, "administration_days": [-7], "last_dose_day": -7}, arm_manifest)) _rec("invvax_duplicate_matrix_assay_id_fail", evaluate_gate34_invvax_recall({**ok_iv, "lymph_node_assay_id": "LCMS_INVVAX_PLASMA_V1"}, arm_manifest)) _rec("invvax_post_tx_day_plus1_fail", evaluate_gate34_invvax_recall({**ok_iv, "administration_days": [-28, -21, 1], "last_dose_day": 1}, arm_manifest)) _rec("invvax_llod_1e6_fail", evaluate_gate34_invvax_recall({**ok_iv, "plasma_llod_ng_ml": 1e6}, arm_manifest)) _rec("invvax_design_a_exposed_fail", evaluate_gate34_invvax_recall({**ok_iv, "design_a_exposed": True}, arm_manifest)) # 5. Authenticated archived wet-lab dual-record isolation, store-tamper, alias-conflict, producer-flag, & Round-5 archive-vs-parent probes auth_sh, auth_store = make_authenticated_gate34_fixture_and_store("shield", arm_manifest=arm_manifest) _rec("auth_without_store_holds_no_promo", evaluate_gate34_shield_sel(auth_sh, arm_manifest, trusted_evidence_store=None)) _rec( "auth_with_upstream_only_store_holds_no_promo", evaluate_gate34_shield_sel( auth_sh, arm_manifest, trusted_evidence_store={auth_sh["upstream_lot_evidence_record"]["record_id"]: copy.deepcopy(auth_sh["upstream_lot_evidence_record"])}, ), ) tampered_store = copy.deepcopy(auth_store) tampered_store[auth_sh["upstream_lot_evidence_record"]["record_id"]]["promotion_authorized"] = False _rec("auth_store_promotion_false_tamper_fail", evaluate_gate34_shield_sel(auth_sh, arm_manifest, trusted_evidence_store=tampered_store)) _rec("auth_with_verified_dual_store_authorizes", evaluate_gate34_shield_sel(auth_sh, arm_manifest, trusted_evidence_store=auth_store)) # Round-5 Review #4 / Audit R4-05 archive-vs-parent contradiction & zero-threshold-tolerance probes sh_adv, sh_adv_st = _reseal_cur(auth_sh, {"apc_cytotoxicity_u95_pct": 100.0}) _rec("r5_shield_archive_apc_100pct_vs_parent_fail", evaluate_gate34_shield_sel(sh_adv, arm_manifest, trusted_evidence_store=sh_adv_st)) sh_eps, sh_eps_st = _reseal_cur(auth_sh, {"off_target_kd_l95_um": 14.9999999995}) _rec("r5_shield_archive_14p9999999995uM_zero_tol_fail", evaluate_gate34_shield_sel(sh_eps, arm_manifest, trusted_evidence_store=sh_eps_st)) auth_ins, _ = make_authenticated_gate34_fixture_and_store("ins", arm_manifest=arm_manifest) ins_bys, ins_bys_st = _reseal_cur(auth_ins, {"per_lot_bystander_edit_pct": 100.0}) _rec("r5_ins_archive_bystander_100pct_vs_parent_fail", evaluate_gate34_ins_l82i_elisa_pe2max(ins_bys, arm_manifest, trusted_evidence_store=ins_bys_st)) ins_gsis, ins_gsis_st = _reseal_cur(auth_ins, {"gsis_si": 1.0}) _rec("r5_ins_archive_gsis_1p0_vs_parent_fail", evaluate_gate34_ins_l82i_elisa_pe2max(ins_gsis, arm_manifest, trusted_evidence_store=ins_gsis_st)) ins_4don_panels = copy.deepcopy(auth_ins["current_assay_evidence_record"]["hla_allele_panel_records"]) for al in MANDATORY_INS_HLA_ALLELES: ins_4don_panels[al]["donor_ids"] = ["ARCH_D1", "ARCH_D2", "ARCH_D3", "ARCH_D4"] ins_4don_panels[al]["donor_count"] = 4 ins_4don, ins_4don_st = _reseal_cur(auth_ins, {"hla_allele_panel_records": ins_4don_panels}) r_ins_4don = evaluate_gate34_ins_l82i_elisa_pe2max(ins_4don, arm_manifest, trusted_evidence_store=ins_4don_st) require_cond( r_ins_4don["unique_hla_donors_verified"] == 4 and abs(r_ins_4don["exact_one_sided_95pct_u95_pct"] - 52.7129) < 1e-3, f"INS archived 4-donor U95 must equal 52.7129%, got {r_ins_4don}", ) _rec("r5_ins_archive_4donors_vs_12_claimed_fail", r_ins_4don) auth_cuff, _ = make_authenticated_gate34_fixture_and_store("cuff", arm_manifest=arm_manifest) cuff_sk, cuff_sk_st = _reseal_cur(auth_cuff, {"intact_serum_total_killing_u95_pct": 100.0}) _rec("r5_cuff_archive_serum_killing_100pct_vs_parent_fail", evaluate_gate34_cuff_v2(cuff_sk, arm_manifest, trusted_evidence_store=cuff_sk_st)) cuff_c4, cuff_c4_st = _reseal_cur(auth_cuff, {"classical_c4b2a_residual_l95_pct": 14.0}) _rec("r5_cuff_archive_c4b2a_14pct_vs_parent_fail", evaluate_gate34_cuff_v2(cuff_c4, arm_manifest, trusted_evidence_store=cuff_c4_st)) cuff_eps_base = copy.deepcopy(auth_cuff) cuff_eps_base["exact_stack_efferocytosis_abs_pct"] = 80.0 cuff_eps, cuff_eps_st = _reseal_cur(cuff_eps_base, {"exact_stack_efferocytosis_abs_pct": 79.9999995}) _rec("r5_cuff_archive_eff_79p9999995_zero_tol_fail", evaluate_gate34_cuff_v2(cuff_eps, arm_manifest, trusted_evidence_store=cuff_eps_st)) auth_iv, _ = make_authenticated_gate34_fixture_and_store("invvax", arm_manifest=arm_manifest) iv_ae, iv_ae_st = _reseal_cur(auth_iv, {"max_ae_grade": 5}) _rec("r5_invvax_archive_ae_grade5_vs_parent_fail", evaluate_gate34_invvax_recall(iv_ae, arm_manifest, trusted_evidence_store=iv_ae_st)) iv_llod_base = copy.deepcopy(auth_iv) iv_llod_base["measured_plasma_conc_ng_ml"] = 0.0499999995 iv_llod, iv_llod_st = _reseal_cur(iv_llod_base, {"measured_plasma_conc_ng_ml": 0.05}) _rec("r5_invvax_archive_conc_at_llod_zero_tol_fail", evaluate_gate34_invvax_recall(iv_llod, arm_manifest, trusted_evidence_store=iv_llod_st)) # Round-5 Review #5 alias conflict & Audit R4-01 contradictory producer flags auth_sh_both, alias_store = make_authenticated_gate34_fixture_and_store("shield", arm_manifest=arm_manifest, store_key_mode="both") alias_store[auth_sh_both["upstream_lot_evidence_record"]["archive_sha256"]]["bank_qualified"] = False _rec("r5_store_conflicting_index_aliases_fail", evaluate_gate34_shield_sel(auth_sh_both, arm_manifest, trusted_evidence_store=alias_store)) pqc_sh, pqc_st = _reseal_cur(auth_sh, {"physical_qualification_complete": False}) _rec("r5_contradictory_physical_qual_false_fail", evaluate_gate34_shield_sel(pqc_sh, arm_manifest, trusted_evidence_store=pqc_st)) # Round-8 Audit R7-05: Strict canonical ASCII INS donor ID grammar, formatting normalization, & deduplication auth_ins_ok, auth_ins_st = make_authenticated_gate34_fixture_and_store("ins", arm_manifest=arm_manifest) r_ins_12_ok = evaluate_gate34_ins_l82i_elisa_pe2max(auth_ins_ok, arm_manifest, trusted_evidence_store=auth_ins_st) require_cond( r_ins_12_ok["decision"] == "PASS" and r_ins_12_ok["promotion_authorized"] is True and r_ins_12_ok["unique_hla_donors_verified"] == 12 and abs(r_ins_12_ok["exact_one_sided_95pct_u95_pct"] - 22.0922) < 1e-3, f"INS 12 distinct canonical donors must PASS with U95=22.0922%, got {r_ins_12_ok}", ) _rec("r8_ins_12_distinct_canonical_donors_pass", r_ins_12_ok)