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…
sc_or_json["executable_stage0_and_conditional_gates"]["Gate_30_SHIELD_SPR"]["endpoints_and_3state_rules"][1]["pass_rule"] = (
sc_or_json["executable_stage0_and_conditional_gates"]["Gate_30_SHIELD_SPR"]["endpoints_and_3state_rules"][1]["pass_rule"].replace(
"AND off-target APC cytotoxicity U95 <= 5.0%",
"OR off-target APC cytotoxicity U95 <= 5.0%",
)
)
res_or_json = evaluate_iip0042_alignment(json.dumps(sc_or_json), md_good)
require_cond(res_or_json["aligned"] is False and "sc_unified_cytotoxicity_pass_and_hold_tiebreak" in res_or_json["gaps"], "Must fail when AND -> OR is flipped in JSON alone")
# Independent mutation test 6: flip AND -> OR in Markdown alone -> MUST FAIL!
md_or_only = md_good.replace(
"`0%` observed off-target APC cytotoxicity AND `U95 <= 5.0%`",
"`0%` observed off-target APC cytotoxicity OR `U95 <= 5.0%`",
)
res_or_md = evaluate_iip0042_alignment(json.dumps(sc_good), md_or_only)
require_cond(res_or_md["aligned"] is False and "md_unified_cytotoxicity_pass_and_hold_tiebreak" in res_or_md["gaps"], "Must fail when AND -> OR is flipped in Markdown alone")
# Independent mutation test 7 (B3 probe 1): JSON DQ2.2 entry altered to instruct omitting assay -> MUST FAIL!
sc_omit_dq22_prose = json.loads(json.dumps(sc_good))
sc_omit_dq22_prose["executable_stage0_and_conditional_gates"]["Gate_30_SHIELD_SPR"]["mandatory_on_target_spr_analytes"][2] = (
"HLA-DQ2.2 + HIP11 (omit this assay; optional)"
)
res_omit_dq22_prose = evaluate_iip0042_alignment(json.dumps(sc_omit_dq22_prose), md_good)
require_cond(
res_omit_dq22_prose["aligned"] is False and "sc_all_4_mandatory_on_target_analytes_and_qc" in res_omit_dq22_prose["gaps"],
"Must fail when JSON DQ2.2 row instructs reader to omit assay",
)
# Independent mutation test 8 (B3 probe 2): Markdown changed from all four complexes to only one optional complex -> MUST FAIL!
md_one_opt = md_good.replace("all four mandatory on-target complexes", "only one optional complex")
require_cond(md_one_opt != md_good, "md_one_opt mutation must modify md_good")
res_one_opt = evaluate_iip0042_alignment(json.dumps(sc_good), md_one_opt)
require_cond(
res_one_opt["aligned"] is False and "md_all_4_mandatory_on_target_analytes_and_qc" in res_one_opt["gaps"],
"Must fail when Markdown weakens all four mandatory complexes to only one optional complex",
)
# Independent mutation test 9 (B3 probe 3): Markdown APC cytotoxicity FAIL cutoff changed from > 5.0% to > 50.0% -> MUST FAIL!
md_l95_50 = md_good.replace(
"`simultaneous_worst_donor_bonferroni_lower_pct > 5.0%`",
"`simultaneous_worst_donor_bonferroni_lower_pct > 50.0%`",
)
require_cond(md_l95_50 != md_good, "md_l95_50 mutation must modify md_good")
res_l95_50 = evaluate_iip0042_alignment(json.dumps(sc_good), md_l95_50)
require_cond(
res_l95_50["aligned"] is False and "md_unified_cytotoxicity_pass_and_hold_tiebreak" in res_l95_50["gaps"],
"Must fail when Markdown changes APC cytotoxicity FAIL cutoff from > 5.0% to > 50.0%",
)
# Independent mutation test 10 (R05 probe 1): drop Comp1 off-targets from JSON -> MUST FAIL!
sc_drop_c1_off = json.loads(json.dumps(sc_good))
sc_drop_c1_off["executable_stage0_and_conditional_gates"]["Gate_30_SHIELD_SPR"]["mandatory_component1_off_target_spr_analytes_iip0044"] = []
res_drop_c1_off = evaluate_iip0042_alignment(json.dumps(sc_drop_c1_off), md_good)
require_cond(
res_drop_c1_off["aligned"] is False and "sc_comp1_all_4_offtarget_analytes" in res_drop_c1_off["gaps"],
"Must fail when Component 1 off-target controls are removed from IIP-0042 JSON",
)
# Independent mutation test 11 (R05 probe 2): drop GY-018 / SEC-MALS 95.0% from Markdown -> MUST FAIL!
md_drop_r05 = md_good.replace("GY-018", "unverified-cluster")
require_cond(md_drop_r05 != md_good, "md_drop_r05 mutation must modify md_good")
res_drop_r05 = evaluate_iip0042_alignment(json.dumps(sc_good), md_drop_r05)
require_cond(
res_drop_r05["aligned"] is False and "md_r05_quant_secmals_batch_hla_gy018_optional_1jk8" in res_drop_r05["gaps"],
"Must fail when GY-018 requirement is removed from IIP-0042 Markdown",
)
# Independent mutation test 12 (R06 B4): isolated Markdown mutation changing >= 3 linked batches to 1 linked batch -> MUST FAIL!
md_one_batch = md_good.replace(
"`>= 3` distinct linked passing Comp1 batches and `>= 3` distinct linked passing Comp2 batches",
"1 linked batch",
)
require_cond(md_one_batch != md_good, "md_one_batch mutation must modify md_good")
res_one_batch = evaluate_iip0042_alignment(json.dumps(sc_good), md_one_batch)
require_cond(
res_one_batch["aligned"] is False and "md_construct_bound_three_batch_clause_no_contradiction" in res_one_batch["gaps"],
"Must fail when Markdown replaces >= 3 linked batches with 1 linked batch while JSON is held fixed",
)
# Independent mutation test 13 (R06 B4b): appending contradictory 'single linked batch' permission to intact Markdown -> MUST FAIL!
md_contra_batch = md_good + "\nNote: a single linked batch is permitted for expedited runs.\n"
res_contra_batch = evaluate_iip0042_alignment(json.dumps(sc_good), md_contra_batch)
require_cond(
res_contra_batch["aligned"] is False and "md_construct_bound_three_batch_clause_no_contradiction" in res_contra_batch["gaps"],
"Must fail when Markdown appends contradictory single linked batch wording",
)
# Independent mutation test 14 (R07 B5a): ordinary-English 'a pair of linked passing expression batches is sufficient' -> MUST FAIL!
md_pair_batches = md_good + "\nNote: a pair of linked passing expression batches is sufficient for Comp1 on-target assays.\n"
res_pair_batches = evaluate_iip0042_alignment(json.dumps(sc_good), md_pair_batches)
require_cond(
res_pair_batches["aligned"] is False and "md_construct_bound_three_batch_clause_no_contradiction" in res_pair_batches["gaps"],
"Must fail when Markdown appends 'a pair of linked passing expression batches is sufficient'",
)
# Independent mutation test 15 (R07 B5b): ordinary-English 'two linked passing expression batches are adequate' -> MUST FAIL!
md_two_batches = md_good + "\nNote: two linked passing expression batches are adequate for Comp2 assays.\n"
res_two_batches = evaluate_iip0042_alignment(json.dumps(sc_good), md_two_batches)
require_cond(
res_two_batches["aligned"] is False and "md_construct_bound_three_batch_clause_no_contradiction" in res_two_batches["gaps"],
"Must fail when Markdown appends 'two linked passing expression batches are adequate'",
)
# Independent mutation test 16 (R08 B4c): Sol's exact post-noun batch reversal -> MUST FAIL!
md_as_low_as_two = md_good + "\nFor each component, the number of linked passing expression batches may be as low as two.\n"
res_as_low_as_two = evaluate_iip0042_alignment(json.dumps(sc_good), md_as_low_as_two)
require_cond(
res_as_low_as_two["aligned"] is False and "md_construct_bound_three_batch_clause_no_contradiction" in res_as_low_as_two["gaps"],
"Must fail when Markdown appends 'number of linked passing expression batches may be as low as two'",
)
# Independent mutation test 17 (R08 B4b): Sol's exact reversed en-dash 1JK8 conflation on BOTH JSON and MD -> MUST FAIL!
sol_1jk8_probe = "The 15-residue wild-type insulin B:9\u201323 peptide was crystallized in PDB 1JK8."
md_1jk8_rev = md_good + "\n" + sol_1jk8_probe + "\n"
res_1jk8_md = evaluate_iip0042_alignment(json.dumps(sc_good), md_1jk8_rev)
sc_1jk8_rev = json.loads(json.dumps(sc_good))
sc_1jk8_rev["executable_stage0_and_conditional_gates"]["Gate_30_SHIELD_SPR"]["mandatory_reagent_qc"] += " " + sol_1jk8_probe
res_1jk8_sc = evaluate_iip0042_alignment(json.dumps(sc_1jk8_rev), md_good)
require_cond(
res_1jk8_md["aligned"] is False and "md_register_1jk8_wt15_6dfx_separated" in res_1jk8_md["gaps"],
"Must fail on reversed en-dash 1JK8 conflation in Markdown",
)
require_cond(
res_1jk8_sc["aligned"] is False and "sc_register_1jk8_wt15_6dfx_separated" in res_1jk8_sc["gaps"],
"Must fail on reversed en-dash 1JK8 conflation in JSON",
)
# Independent mutation test 18 (R09 B3): reverting suppression rule to stale Student-t L95_t >= 70% in JSON/MD -> MUST FAIL!
sc_stale_t = json.loads(json.dumps(sc_good))
sc_stale_t["executable_stage0_and_conditional_gates"]["Gate_30_SHIELD_SPR"]["endpoints_and_3state_rules"][1]["pass_rule"] = (
"cohort L95_t >= 70.0% suppression AND 0% observed off-target APC cytotoxicity AND off-target APC cytotoxicity U95 <= 5.0%"
)
res_stale_t_sc = evaluate_iip0042_alignment(json.dumps(sc_stale_t), md_good)
md_stale_t = md_good.replace("`L95_CP(k_ge_70, N_roster) >= 70.0%`", "`L95_t >= 70.0%`")
res_stale_t_md = evaluate_iip0042_alignment(json.dumps(sc_good), md_stale_t)
require_cond(
res_stale_t_sc["aligned"] is False and res_stale_t_md["aligned"] is False,
"Must fail when suppression rule reverts to stale Student-t authorization in JSON or Markdown",
)
# Independent mutation test 19 (R09 B2): dropping mandatory preregistered_donor_family_roster requirement -> MUST FAIL!
sc_drop_roster = json.loads(json.dumps(sc_good))
sc_drop_roster["executable_stage0_and_conditional_gates"]["Gate_30_SHIELD_SPR"]["typed_evidence_contract"]["preregistered_donor_family_roster_mandatory"] = False
res_drop_roster_sc = evaluate_iip0042_alignment(json.dumps(sc_drop_roster), md_good)
md_drop_roster = md_good.replace("preregistered_donor_family_roster", "ad_hoc_donors")
res_drop_roster_md = evaluate_iip0042_alignment(json.dumps(sc_good), md_drop_roster)
require_cond(
res_drop_roster_sc["aligned"] is False and res_drop_roster_md["aligned"] is False,
"Must fail when mandatory preregistered_donor_family_roster is weakened in JSON or Markdown",
)
case_results = {
"unaligned_pre_s5_rejected": (not res_unaligned["aligned"]),
"aligned_post_s5_accepted": res_aligned["aligned"],
"side_contract_only_deletion_rejected": (not res_drop_sc["aligned"]),
"protocol_md_only_deletion_rejected": (not res_drop_md["aligned"]),
"missing_dq22_rejected": (not res_drop_dq22["aligned"]),
"missing_dq25_rejected": (not res_drop_dq25["aligned"]),
"json_and_to_or_flip_rejected": (not res_or_json["aligned"]),
"markdown_and_to_or_flip_rejected": (not res_or_md["aligned"]),
"json_dq22_omit_instruction_rejected": (not res_omit_dq22_prose["aligned"]),
"markdown_one_optional_complex_rejected": (not res_one_opt["aligned"]),
"markdown_cyto_l95_50pct_rejected": (not res_l95_50["aligned"]),
"json_missing_comp1_offtargets_rejected": (not res_drop_c1_off["aligned"]),
"markdown_missing_r05_gy018_rejected": (not res_drop_r05["aligned"]),
"markdown_single_linked_batch_mutation_rejected": (not res_one_batch["aligned"]),
"markdown_contradictory_single_batch_clause_rejected": (not res_contra_batch["aligned"]),
"markdown_pair_of_batches_sufficient_rejected": (not res_pair_batches["aligned"]),
"markdown_two_batches_adequate_rejected": (not res_two_batches["aligned"]),
"markdown_batches_as_low_as_two_rejected": (not res_as_low_as_two["aligned"]),
"markdown_reversed_endash_1jk8_conflation_rejected": (not res_1jk8_md["aligned"]),
"json_reversed_endash_1jk8_conflation_rejected": (not res_1jk8_sc["aligned"]),
"stale_student_t_suppression_reversion_rejected": (not res_stale_t_sc["aligned"] and not res_stale_t_md["aligned"]),
"missing_mandatory_preregistered_roster_rejected": (not res_drop_roster_sc["aligned"] and not res_drop_roster_md["aligned"]),
"aligned_iip0042_legacy_hygiene_clean": res_aligned["checks"]["iip0042_legacy_vendor_hygiene_compatible"],
}
return {
"total_cases": len(case_results),
**case_results,
"passed": True,
}
def resolve_repo_root(explicit_repo_root: Path | None, installed_check: bool) -> Path | None:
if explicit_repo_root is not None:
p = explicit_repo_root.expanduser().resolve()
if not (p.is_dir() and (p / "scripts" / "rank_islet1_stacks.py").is_file()):
raise FileNotFoundError(f"Invalid --repo-root (fail-closed): {explicit_repo_root.name}")
return p
if SCRIPT_DIR.name == "scripts" and (SCRIPT_DIR.parent / "scripts" / "rank_islet1_stacks.py").is_file():
return SCRIPT_DIR.parent
if installed_check:
raise FileNotFoundError("Installed check requires --repo-root pointing to a valid OpenIslet repository")
env_root = os.environ.get("OPENISLET_ROOT")
if env_root:
p = Path(env_root).expanduser().resolve()
if (p / "scripts" / "rank_islet1_stacks.py").is_file():
return p
if SCRIPT_DIR.name == "artifacts-carbon":
sibling = SCRIPT_DIR.parents[3] / "OpenIslet"
if (sibling / "scripts" / "rank_islet1_stacks.py").is_file():
return sibling
return None
def run_verification(
*,
repo_root: Path | None,
installed_check: bool,
) -> dict[str, Any]:
if installed_check:
require_cond(repo_root is not None, "Installed check requires a valid OpenIslet repository root")
assert_root = repo_root # type: ignore[assignment]
fasta_leads_path = assert_root / "data" / "constructs" / "openislet_cleanroom_v1_3_all_leads.fasta"
fasta_comp2_path = assert_root / "data" / "constructs" / "islet_shield_comp2_comparators_v1_3.fasta"
side_contract_path = assert_root / "data" / "protocols" / "iip0044_foundry_v1_3_biologics_side_contract_v0.8.0.json"
summary_path = assert_root / "data" / "extracted" / "iip0044_tier1_metrics_cleanroom_summary_v0.8.0.json"
protocol_path = assert_root / "docs" / "FOUNDRY-V1-3-CLEANROOM-BIOLOGICS-PROTOCOL.md"
dt_path = assert_root / "data" / "protocols" / "stage0_decision_tree_v1.json"
test39_path = assert_root / "tests" / "test_iip0044_foundry_v1_3_biologics.py"
mode_label = "INSTALLED_OPENISLET_CHECK"
else:
fasta_leads_path = SCRIPT_DIR / "openislet_cleanroom_v1_3_all_leads.fasta"
fasta_comp2_path = SCRIPT_DIR / "islet_shield_comp2_comparators_v1_3.fasta"
side_contract_path = SCRIPT_DIR / "iip0044_foundry_v1_3_biologics_side_contract_v0.8.0.json"
summary_path = SCRIPT_DIR / "iip0044_tier1_metrics_cleanroom_summary_v0.8.0.json"
protocol_path = SCRIPT_DIR / "FOUNDRY-V1-3-CLEANROOM-BIOLOGICS-PROTOCOL.md"
dt_path = SCRIPT_DIR / "iip0044_decision_tree_block_dec123.json"
test39_path = None
mode_label = "STAGING_ARTIFACTS_CHECK"
# 1. Verify both CC-BY-4.0 FASTAs and UniProt P07204[363..480] M406L identity
leads_check = verify_fasta_file(fasta_leads_path, EXPECTED_ALL_LEADS_FASTA_SHA256, EXPECTED_ALL_LEADS_SPECS)
comp2_check = verify_fasta_file(fasta_comp2_path, EXPECTED_COMP2_COMPS_FASTA_SHA256, EXPECTED_COMP2_COMPS_SPECS)
thbd_check = verify_thbd_p07204_m406l(EXPECTED_ALL_LEADS_SPECS["IsletGUARD_THBD_M406L"]["seq"])
# 2. Load and strictly verify pinned side-contract SHA-256, Tier-1 summary, decision-tree block, and protocol doc
actual_sc_file_sha = sha256_file(side_contract_path)
require_cond(
actual_sc_file_sha == EXPECTED_IIP0044_SIDE_CONTRACT_FILE_SHA256,
f"IIP-0044 side-contract file SHA-256 mismatch (fail-closed): {actual_sc_file_sha} != {EXPECTED_IIP0044_SIDE_CONTRACT_FILE_SHA256}",
)
side_contract = load_strict_json(side_contract_path)
summary = load_strict_json(summary_path)
dt_obj = load_strict_json(dt_path)
require_cond(
"foundry_v1_3_cleanroom_biologics_registration_iip_0044" in dt_obj,
f"Missing DEC-123 append-only block in {dt_path.name}",
)
dec123_entry = dt_obj["foundry_v1_3_cleanroom_biologics_registration_iip_0044"]