scripts/verify_iip0044_foundry_v1_3_biologics.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0044_foundry_v1_3_biologics.py · SHA-256: 1d6c53a0817f6254…
f"{cond_lbl}.expression_batch_ids={sorted(out_batches)} not covered by "
f"register_qc_records Comp2 batches={sorted(rqc_comp2_batches)}",
)
if not out_batches.issubset(sec_comp2_qualified_batches):
comp_row_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"{cond_lbl}.expression_batch_ids={sorted(out_batches)} lack passing Comp2 "
f"SEC-MALS/DLS qualification ({sorted(sec_comp2_qualified_batches)})",
)
if "crystal_ref_1jk8_14aa" in reg_screens and reg_screens["crystal_ref_1jk8_14aa"] is not None:
c1jk8_obj = reg_screens["crystal_ref_1jk8_14aa"]
c1jk8_lbl = f"comparator[{cid_c}].register_control_screens.crystal_ref_1jk8_14aa"
if not isinstance(c1jk8_obj, dict):
comp_row_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", f"{c1jk8_lbl} must be an object or null")
else:
extra_1k = sorted(set(c1jk8_obj.keys()) - _allowed_comp_1jk8_keys)
missing_1k = sorted(_required_comp_1jk8_keys - set(c1jk8_obj.keys()))
if extra_1k or missing_1k:
comp_row_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"{c1jk8_lbl} closed-schema key violation (missing={missing_1k}, extra={extra_1k})",
)
if c1jk8_obj.get("screened") is not True:
comp_row_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", f"{c1jk8_lbl}.screened must be literal boolean True")
if c1jk8_obj.get("peptide_sequence") != "LVEALYLVCGERGG":
comp_row_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"{c1jk8_lbl}.peptide_sequence={c1jk8_obj.get('peptide_sequence')!r} != expected 'LVEALYLVCGERGG'",
)
if not r1jk8_qc_valid:
comp_row_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"{c1jk8_lbl} supplied without passing register_qc_records.crystal_ref_1jk8_14aa QC",
)
if "peptide_reagent_lot_id" in c1jk8_obj:
raw_1k_lot = c1jk8_obj["peptide_reagent_lot_id"]
if (
type(raw_1k_lot) is not str
or not raw_1k_lot
or raw_1k_lot != raw_1k_lot.strip()
or not _SHIELD_STRICT_ID_RE.match(raw_1k_lot)
):
comp_row_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"{c1jk8_lbl}.peptide_reagent_lot_id invalid ({raw_1k_lot!r})",
)
elif raw_1k_lot in {x for x in (rqc_hip11_lot, rqc_wt_lot, rqc_6dfx_lot) if x is not None}:
comp_row_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"{c1jk8_lbl}.peptide_reagent_lot_id={raw_1k_lot!r} reuses HIP11, WT15, or 6DFX lot ID",
)
elif rqc_1jk8_lot is not None and raw_1k_lot != rqc_1jk8_lot:
comp_row_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"{c1jk8_lbl}.peptide_reagent_lot_id={raw_1k_lot!r} != register_qc_records lot {rqc_1jk8_lot!r}",
)
_, c1rep_err = _shield_check_strict_int(
c1jk8_obj.get("replicates_n"), f"{c1jk8_lbl}.replicates_n", min_val=_SHIELD_MIN_SPR_REPLICATES_N
)
if c1rep_err is not None:
comp_row_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", c1rep_err)
raw_1ev = c1jk8_obj.get("evidence_record_id")
if (
type(raw_1ev) is not str
or not raw_1ev
or raw_1ev != raw_1ev.strip()
or not _SHIELD_EVIDENCE_REF_RE.match(raw_1ev)
):
comp_row_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", f"{c1jk8_lbl}.evidence_record_id invalid ({raw_1ev!r})")
elif raw_1ev in conflicted_comp_ev_ids:
comp_row_valid = False
tmp_1k_b: set[str] = set()
c1b_err = _shield_validate_batch_ids(
c1jk8_obj.get("expression_batch_ids"),
c1jk8_lbl,
passing_batch_constructs,
tmp_1k_b,
required_construct_all=cid_c,
)
if c1b_err is not None:
comp_row_valid = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", c1b_err)
elif b_err is None and not tmp_1k_b.issubset(tmp_ref_c):
comp_row_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"{c1jk8_lbl}.expression_batch_ids={sorted(tmp_1k_b)} must be a subset of "
f"comparator[{cid_c}].expression_batch_ids={sorted(tmp_ref_c)}",
)
# R16 Shared Blocker #2: Require non-empty shared comparator expression batch intersection
# evaluated across BOTH native WT15 AND engineered 6DFX before granting complete-comparator
# credit, batch-linkage credit, or Track-B candidacy!
dual_reg_batches = cond_wt_batches & cond_6dfx_batches
if cond_wt_batches and cond_6dfx_batches and len(dual_reg_batches) == 0:
comp_row_valid = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"comparator[{cid_c}]: native_wt_insb9_23_15aa expression_batch_ids={sorted(cond_wt_batches)} "
f"and engineered_6dfx_p8e9e_12aa expression_batch_ids={sorted(cond_6dfx_batches)} have empty "
f"shared-batch intersection (matched comparator material evaluated across BOTH WT15 and 6DFX "
f"is required to identify the register contrast; disjoint batches earn zero comparator credit "
f"and suppress Track-B candidacy)",
)
if comp_row_valid and len(dual_reg_batches) > 0:
referenced_batches.update(dual_reg_batches)
if cid_c == _SHIELD_COMP2_LEAD:
comp2_assay_batches.update(dual_reg_batches & tmp_c2_c)
verified_comparators_both_registers.add(cid_c)
comparator_shared_batches_by_id[cid_c] = sorted(dual_reg_batches)
missing_comps = [c for c in _SHIELD_MANDATORY_COMP2_COMPARATORS if c not in seen_comps]
if missing_comps:
_escalate("HOLD_INVALID_OR_MISSING_INPUT", f"Missing mandatory Comp2 parallel comparators: {missing_comps}")
derived_summary["comparator_mandatory_register_controls"] = [
"native_wt_insb9_23_15aa",
"engineered_6dfx_p8e9e_12aa",
]
derived_summary["comparator_shared_batch_required_across_wt15_and_6dfx"] = True
derived_summary["comparator_shared_wt15_6dfx_batches"] = comparator_shared_batches_by_id
derived_summary["comparator_wt15_and_6dfx_verified_count"] = len(verified_comparators_both_registers)
derived_summary["comparator_mandatory_register_coverage_verified"] = bool(
len(conflicted_comps) == 0
and len(conflicted_comp_ev_ids) == 0
and verified_comparators_both_registers == set(_SHIELD_MANDATORY_COMP2_COMPARATORS)
)
# (Step 6 SEC-MALS/DLS physicochemical qualification was evaluated strictly BEFORE Steps 3 & 4 in Step 2b above.)
# 7. Primary human T-cell blockade & off-target APC cytotoxicity donors
# (R09 B2: MANDATORY cryptographically hash-pinned outcome-blind preregistered_donor_family_roster
# reconciled 100% against submitted donors + optional pre-assay excluded_donor_records;
# NEVER optional, NEVER defaults to submitted row count; missing/tampered/incomplete
# roster fails closed to non-authorizing HOLD_INVALID_OR_MISSING_INPUT!
# R09 B3: Distribution-free exact one-sided Clopper-Pearson responder-proportion suppression test
# over fixed N_roster (estimand P(suppression_pct >= 70.0%), PASS requires L95_CP >= 70.0%
# [min N_roster=9] + min >= 0.0% anti-enhancement guard + mean >= 70.0%; FAIL requires
# L95_CP(k_lt_40, N_roster) > 60.0%; Student-t is strictly non-authorizing diagnostic!).
# R09 M1: Mandatory structured gy018_independence_justification per donor.
# R08 B3/B4/B5: Two-pass order-independent donor_id uniqueness; fixed pre-exclusion N_roster
# Bonferroni FWER <= 0.05 under H0_all: max_i p_i <= 5.0%; mandatory typed T1D eligibility;
# exact GY-018 deff == 1.0 preserved as Decimal through JSON decoding.)
roster_obj = observation.get("preregistered_donor_family_roster")
roster_verified = False
roster_id_val: str | None = None
roster_ts_val: str | None = None
roster_ts_dt: datetime | None = None
roster_sha256_val: str | None = None
roster_donor_ids: list[str] = []
roster_set: frozenset[str] = frozenset()
roster_planned_n: int | None = None
roster_predeclared_n_by_donor: dict[str, int] = {}
roster_planned_looks_val: int | None = None
roster_single_look_locked = False
roster_sample_size_plan_mismatched_donors: set[str] = set()
_allowed_roster_keys = frozenset({
"roster_id",
"preregistration_timestamp_utc",
"outcome_blind_lock_attestation",
"single_look_fixed_horizon_plan_locked",
"planned_analysis_looks",
"roster_donor_ids",
"planned_t1d_donor_family_n",
"predeclared_per_donor_unit_count_n",
"predeclared_per_donor_unit_counts",
"roster_sha256",
"assay_readout_timestamp_utc",
})
if not isinstance(roster_obj, dict):
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
"Missing mandatory preregistered_donor_family_roster block (outcome-blind, SHA-256-pinned "
"pre-registered T1D donor roster locking donor membership, fixed per-donor sample size N, "
"and single-look fixed horizon is required for authorization-grade overall PASS or donor-based "
"FAIL; never defaults to submitted row count; independent valid non-donor SPR "
"FAIL remains fail-first FAIL)",
)
else:
roster_ok = True
extra_roster_keys = sorted(set(roster_obj.keys()) - _allowed_roster_keys)
if extra_roster_keys:
roster_ok = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"preregistered_donor_family_roster contains unexpected/untyped keys {extra_roster_keys}; "
f"strict closed schema required",
)
raw_rid = roster_obj.get("roster_id")
if type(raw_rid) is not str or not raw_rid or raw_rid != raw_rid.strip() or not _SHIELD_STRICT_ID_RE.match(raw_rid):
roster_ok = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"preregistered_donor_family_roster.roster_id must be a non-empty unpadded ID matching "
f"{_SHIELD_STRICT_ID_RE.pattern} (got {raw_rid!r})",
)
raw_ts = roster_obj.get("preregistration_timestamp_utc")
ts_dt, ts_err = _shield_parse_iso8601_utc(raw_ts, "preregistered_donor_family_roster.preregistration_timestamp_utc")
if ts_err is not None or ts_dt is None:
roster_ok = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", ts_err or "Invalid preregistration_timestamp_utc")
else:
roster_ts_dt = ts_dt
readout_ts_raw = (
observation.get("assay_readout_timestamp_utc")
if "assay_readout_timestamp_utc" in observation and observation["assay_readout_timestamp_utc"] is not None
else roster_obj.get("assay_readout_timestamp_utc")
)
if readout_ts_raw is not None:
rd_dt, rd_err = _shield_parse_iso8601_utc(readout_ts_raw, "assay_readout_timestamp_utc")
if rd_err is not None or rd_dt is None:
roster_ok = False
_escalate("HOLD_INVALID_OR_MISSING_INPUT", rd_err or "Invalid assay_readout_timestamp_utc")
elif roster_ts_dt is not None and not (roster_ts_dt < rd_dt):
roster_ok = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"preregistered_donor_family_roster.preregistration_timestamp_utc={raw_ts!r} must strictly precede "
f"assay_readout_timestamp_utc={readout_ts_raw!r} (outcome-blind pre-registration violated)",
)
if roster_obj.get("outcome_blind_lock_attestation") is not True:
roster_ok = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"preregistered_donor_family_roster.outcome_blind_lock_attestation must be literal boolean True "
f"(got {roster_obj.get('outcome_blind_lock_attestation')!r})",
)
# R16 Shared Blocker #3: Cryptographically lock single-look fixed horizon + fixed per-donor sample size N
if roster_obj.get("single_look_fixed_horizon_plan_locked") is not True:
roster_ok = False
_escalate(
"HOLD_INVALID_OR_MISSING_INPUT",
f"preregistered_donor_family_roster.single_look_fixed_horizon_plan_locked must be literal boolean True "
f"(got {roster_obj.get('single_look_fixed_horizon_plan_locked')!r}; unverified or adaptive stopping plans "