OpenIslet

scripts/verify_iip0057_foundry_v2_shield_invvax_insl82i_cuffv2.py

W6-C3 (Provisional Next-Free IIP-0057 / DEC-138 / GATE-36 / GY-035; staging slot iip0057,

script Release v0.8.0 gen-eb955f8266035aba 412 KB · 32 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0057_foundry_v2_shield_invvax_insl82i_cuffv2.py · SHA-256: 1c63dcf649c42be4…

    def _matched_ins_panel_probe(panel_donor_map: dict[str, list[str]], reactive_map: dict[str, list[str]] | None = None) -> dict[str, Any]:
        o = copy.deepcopy(auth_ins_ok)
        panels = copy.deepcopy(o["hla_allele_panel_records"])
        for al, dids in panel_donor_map.items():
            panels[al]["donor_ids"] = list(dids)
            panels[al]["donor_count"] = len(dids)
            if reactive_map is not None and al in reactive_map:
                panels[al]["reactive_donor_ids"] = list(reactive_map[al])
                panels[al]["reactive_donors"] = len(reactive_map[al])
        o["hla_allele_panel_records"] = copy.deepcopy(panels)
        o_m, st_m = _reseal_cur(o, {"hla_allele_panel_records": copy.deepcopy(panels), "unique_hla_donor_count": 12})
        return evaluate_gate34_ins_l82i_elisa_pe2max(o_m, arm_manifest, trusted_evidence_store=st_m)

    r_r8_ws = _matched_ins_panel_probe({
        "HLA-DRB1*04:01": ["DONOR_01", "DONOR_02", "DONOR_03", "DONOR_04"],
        "HLA-A*02:01": [" DONOR_01 ", " DONOR_02 ", " DONOR_03 ", " DONOR_04 "],
        "HLA-A*11:01": ["DONOR_01\t", "DONOR_02\t", "DONOR_03\t", "DONOR_04\t"],
    })
    require_cond(
        r_r8_ws["decision"] == "FAIL"
        and r_r8_ws["promotion_authorized"] is False
        and r_r8_ws["unique_hla_donors_verified"] == 4
        and abs(r_r8_ws["exact_one_sided_95pct_u95_pct"] - 52.7129) < 1e-3
        and any("INS_NONCANONICAL_DONOR_ID_REJECTED" in r for r in r_r8_ws["reasons"]),
        f"R8 whitespace-padded 4-donor probe failed expectation: {r_r8_ws}",
    )
    _rec("r8_ins_4donors_whitespace_padded_fail", r_r8_ws)

    r_r8_case = _matched_ins_panel_probe({
        "HLA-DRB1*04:01": ["DONOR_01", "DONOR_02", "DONOR_03", "DONOR_04"],
        "HLA-A*02:01": ["donor_01", "donor_02", "donor_03", "donor_04"],
        "HLA-A*11:01": ["Donor_01", "Donor_02", "Donor_03", "Donor_04"],
    })
    require_cond(
        r_r8_case["decision"] == "FAIL"
        and r_r8_case["promotion_authorized"] is False
        and r_r8_case["unique_hla_donors_verified"] == 4
        and abs(r_r8_case["exact_one_sided_95pct_u95_pct"] - 52.7129) < 1e-3,
        f"R8 case-variant 4-donor probe failed expectation: {r_r8_case}",
    )
    _rec("r8_ins_4donors_case_variants_fail", r_r8_case)

    r_r8_uni = _matched_ins_panel_probe({
        "HLA-DRB1*04:01": ["DONOR_01", "DONOR_02", "DONOR_03", "DONOR_04"],
        "HLA-A*02:01": ["DONOR_01\u200b", "DONOR_02\u00ad", "DONOR_03\u200b", "DONOR_04\u00ad"],
        "HLA-A*11:01": ["\uff24\uff2f\uff2e\uff2f\uff32_\uff10\uff11", "\uff24\uff2f\uff2e\uff2f\uff32_\uff10\uff12", "\uff24\uff2f\uff2e\uff2f\uff32_\uff10\uff13", "\uff24\uff2f\uff2e\uff2f\uff32_\uff10\uff14"],
    })
    require_cond(
        r_r8_uni["decision"] == "FAIL"
        and r_r8_uni["promotion_authorized"] is False
        and r_r8_uni["unique_hla_donors_verified"] == 4
        and abs(r_r8_uni["exact_one_sided_95pct_u95_pct"] - 52.7129) < 1e-3
        and any("INS_NONCANONICAL_DONOR_ID_REJECTED" in r for r in r_r8_uni["reasons"]),
        f"R8 unicode/NFKC 4-donor probe failed expectation: {r_r8_uni}",
    )
    _rec("r8_ins_4donors_unicode_nfkc_invisibles_fail", r_r8_uni)

    r_r8_sep = _matched_ins_panel_probe({
        "HLA-DRB1*04:01": ["DONOR_01", "DONOR_02", "DONOR_03", "DONOR_04"],
        "HLA-A*02:01": ["DONOR-01", "DONOR-02", "DONOR-03", "DONOR-04"],
        "HLA-A*11:01": ["DONOR.01", "DONOR.02", "DONOR.03", "DONOR.04"],
    })
    require_cond(
        r_r8_sep["decision"] == "FAIL"
        and r_r8_sep["promotion_authorized"] is False
        and r_r8_sep["unique_hla_donors_verified"] == 4
        and abs(r_r8_sep["exact_one_sided_95pct_u95_pct"] - 52.7129) < 1e-3,
        f"R8 separator-variant 4-donor probe failed expectation: {r_r8_sep}",
    )
    _rec("r8_ins_4donors_separator_variants_fail", r_r8_sep)

    r_r8_react = _matched_ins_panel_probe(
        {
            "HLA-DRB1*04:01": ["T1D_DON_001", "T1D_DON_002", "T1D_DON_003", "T1D_DON_004"],
            "HLA-A*02:01": ["T1D_DON_005", "T1D_DON_006", "T1D_DON_007", "T1D_DON_008"],
            "HLA-A*11:01": ["T1D_DON_009", "T1D_DON_010", "T1D_DON_011", "T1D_DON_012"],
        },
        reactive_map={"HLA-DRB1*04:01": [" T1D_DON_001\u200b"]},
    )
    require_cond(
        r_r8_react["decision"] == "FAIL"
        and r_r8_react["promotion_authorized"] is False
        and any("INS_NONCANONICAL_DONOR_ID_REJECTED" in r for r in r_r8_react["reasons"]),
        f"R8 reactive noncanonical donor ID probe failed expectation: {r_r8_react}",
    )
    _rec("r8_ins_reactive_noncanonical_donor_id_fail", r_r8_react)

    # Round-9 Audit R8-06 & Round-10 Audit R9-04: Separator-first -> numeric-padding-second canonical donor identity & mandatory positive canonical ASCII issuer on every present roster form
    def _both_mode_ins_roster_probe(
        panel_donor_map: dict[str, list[str]],
        *,
        primary_issuer: str | None = DEFAULT_INS_CANONICAL_ISSUER_ID,
        alias_issuer: str | None = DEFAULT_INS_CANONICAL_ISSUER_ID,
        cur_primary_issuer: str | None = "__SAME__",
        cur_alias_issuer: str | None = "__SAME__",
        issuer_field: str = "donor_issuer_id",
        include_alias_on_parent: bool = True,
        include_alias_on_archive: bool = True,
        store_key_mode: str = "both",
        claimed_unique: int = 12,
    ) -> dict[str, Any]:
        o, _ = make_authenticated_gate34_fixture_and_store("ins", arm_manifest=arm_manifest, store_key_mode=store_key_mode)
        base_panels = copy.deepcopy(o["hla_allele_panel_records"])
        for ifld in INS_DONOR_ISSUER_FIELDS:
            base_panels.pop(ifld, None)
        for al, dids in panel_donor_map.items():
            base_panels[al]["donor_ids"] = list(dids)
            base_panels[al]["donor_count"] = len(dids)
            for ifld in INS_DONOR_ISSUER_FIELDS:
                base_panels[al].pop(ifld, None)

        def _with_iss(iss: str | None) -> dict[str, Any]:
            p = copy.deepcopy(base_panels)
            if iss is not None:
                p[issuer_field] = iss
            return p

        p_obs_main = _with_iss(primary_issuer)
        p_obs_alias = _with_iss(alias_issuer)
        p_cur_main = _with_iss(primary_issuer if cur_primary_issuer == "__SAME__" else cur_primary_issuer)
        p_cur_alias = _with_iss(alias_issuer if cur_alias_issuer == "__SAME__" else cur_alias_issuer)

        o["hla_allele_panel_records"] = copy.deepcopy(p_obs_main)
        if include_alias_on_parent:
            o["per_allele_panels"] = copy.deepcopy(p_obs_alias)
        else:
            o.pop("per_allele_panels", None)
        cur_body = copy.deepcopy(o["current_assay_evidence_record"])
        cur_body["hla_allele_panel_records"] = copy.deepcopy(p_cur_main)
        if include_alias_on_archive:
            cur_body["per_allele_panels"] = copy.deepcopy(p_cur_alias)
        else:
            cur_body.pop("per_allele_panels", None)
        cur_body["unique_hla_donor_count"] = claimed_unique
        o["current_assay_evidence_record"] = seal_evidence_record(cur_body)
        u = o["upstream_lot_evidence_record"]
        c = o["current_assay_evidence_record"]
        if store_key_mode == "record_id":
            st = {u["record_id"]: copy.deepcopy(u), c["record_id"]: copy.deepcopy(c)}
        elif store_key_mode == "archive_sha256":
            st = {u["archive_sha256"]: copy.deepcopy(u), c["archive_sha256"]: copy.deepcopy(c)}
        else:
            st = {
                u["record_id"]: copy.deepcopy(u),
                u["archive_sha256"]: copy.deepcopy(u),
                c["record_id"]: copy.deepcopy(c),
                c["archive_sha256"]: copy.deepcopy(c),
            }
        return evaluate_gate34_ins_l82i_elisa_pe2max(o, arm_manifest, trusted_evidence_store=st)

    r_r9_digit_01 = _both_mode_ins_roster_probe({
        "HLA-DRB1*04:01": ["DONOR_01", "DONOR_02", "DONOR_03", "DONOR_04"],
        "HLA-A*02:01": ["DONOR_0-1", "DONOR_0-2", "DONOR_0-3", "DONOR_0-4"],
        "HLA-A*11:01": ["DONOR_0.1", "DONOR_0.2", "DONOR_0.3", "DONOR_0.4"],
    })
    require_cond(
        r_r9_digit_01["decision"] == "FAIL"
        and r_r9_digit_01["promotion_authorized"] is False
        and r_r9_digit_01["unique_hla_donors_verified"] == 4
        and abs(r_r9_digit_01["exact_one_sided_95pct_u95_pct"] - 52.7129) < 1e-3
        and any("INS_INCONSISTENT_DONOR_ID_FORMATTING_VARIANT" in r for r in r_r9_digit_01["reasons"]),
        f"R9 digit-separator 0_1/0-1/0.1 probe failed expectation: {r_r9_digit_01}",
    )
    _rec("r9_ins_4donors_digit_separator_0_1_both_rosters_fail", r_r9_digit_01)

    r_r9_digit_101 = _both_mode_ins_roster_probe({
        "HLA-DRB1*04:01": ["D-101", "D-102", "D-103", "D-104"],
        "HLA-A*02:01": ["D-10-1", "D-10-2", "D-10-3", "D-10-4"],
        "HLA-A*11:01": ["D-1-01", "D-1-02", "D-1-03", "D-1-04"],
    })
    require_cond(
        r_r9_digit_101["decision"] == "FAIL"
        and r_r9_digit_101["promotion_authorized"] is False
        and r_r9_digit_101["unique_hla_donors_verified"] == 4
        and abs(r_r9_digit_101["exact_one_sided_95pct_u95_pct"] - 52.7129) < 1e-3
        and any("INS_INCONSISTENT_DONOR_ID_FORMATTING_VARIANT" in r for r in r_r9_digit_101["reasons"]),
        f"R9 digit-separator D-101/D-10-1/D-1-01 probe failed expectation: {r_r9_digit_101}",
    )
    _rec("r9_ins_4donors_digit_separator_d101_both_rosters_fail", r_r9_digit_101)

    distinct12_r10 = {
        "HLA-DRB1*04:01": ["DONOR_01", "DONOR_02", "DONOR_03", "DONOR_04"],
        "HLA-A*02:01": ["DONOR_05", "DONOR_06", "DONOR_07", "DONOR_08"],
        "HLA-A*11:01": ["DONOR_09", "DONOR_10", "DONOR_11", "DONOR_12"],
    }

    r_r9_issuer_mis = _both_mode_ins_roster_probe(
        distinct12_r10,
        primary_issuer="BIOREPO_T1D_A",
        alias_issuer="BIOREPO_T1D_B",
    )
    require_cond(
        r_r9_issuer_mis["decision"] == "FAIL"
        and r_r9_issuer_mis["promotion_authorized"] is False
        and any("INS_ROSTER_DONOR_ISSUER_ID_MISMATCH" in r for r in r_r9_issuer_mis["reasons"]),
        f"R9 roster issuer mismatch probe failed expectation: {r_r9_issuer_mis}",
    )
    _rec("r9_ins_roster_issuer_identity_mismatch_fail", r_r9_issuer_mis)

    r_r9_12_ok = _both_mode_ins_roster_probe(
        distinct12_r10,
        primary_issuer="BIOREPO_T1D_V1",
        alias_issuer="BIOREPO_T1D_V1",
    )
    require_cond(
        r_r9_12_ok["decision"] == "PASS"
        and r_r9_12_ok["promotion_authorized"] is True
        and r_r9_12_ok["unique_hla_donors_verified"] == 12
        and abs(r_r9_12_ok["exact_one_sided_95pct_u95_pct"] - 22.0922) < 1e-3,
        f"R9 12 distinct canonical donors with shared roster issuer must PASS, got {r_r9_12_ok}",
    )
    _rec("r9_ins_12_distinct_donors_both_rosters_same_issuer_pass", r_r9_12_ok)

    # Round-10 Audit R9-04 & Round-11 Audit R10-03: Mandatory positive canonical ASCII HLA registry issuer on EVERY present roster form; HOLD & null verified stats when archive omits!
    for lk_mode in ("record_id", "archive_sha256"):
        r_r10_omit = _both_mode_ins_roster_probe(
            distinct12_r10,
            primary_issuer=None,
            alias_issuer=None,
            store_key_mode=lk_mode,
        )
        require_cond(
            r_r10_omit["decision"] == "HOLD"
            and r_r10_omit["promotion_authorized"] is False
            and r_r10_omit["unique_hla_donors_verified"] is None
            and r_r10_omit["total_reactive_donors"] is None
            and r_r10_omit["exact_one_sided_95pct_u95_pct"] is None
            and r_r10_omit["ins_statistics_derivation_source"] == "UNVERIFIED_HOLD_MISSING_ARCHIVED_ISSUER"
            and any("HOLD_MISSING_ARCHIVED_HLA_REGISTRY_ISSUER" in r for r in r_r10_omit["reasons"]),
            f"R10/R11 omitted issuer across both rosters ({lk_mode}) must HOLD with null official stats, got {r_r10_omit}",
        )
    _rec("r10_ins_both_rosters_omitted_issuer_hold", r_r10_omit)

    r_r10_single_omit = _both_mode_ins_roster_probe(
        distinct12_r10,
        primary_issuer=None,
        include_alias_on_parent=False,
        include_alias_on_archive=False,
    )
    require_cond(
        r_r10_single_omit["decision"] == "HOLD"
        and r_r10_single_omit["promotion_authorized"] is False
        and r_r10_single_omit["unique_hla_donors_verified"] is None
        and r_r10_single_omit["exact_one_sided_95pct_u95_pct"] is None
        and r_r10_single_omit["ins_statistics_derivation_source"] == "UNVERIFIED_HOLD_MISSING_ARCHIVED_ISSUER"
        and any("HOLD_MISSING_ARCHIVED_HLA_REGISTRY_ISSUER:hla_allele_panel_records" in r for r in r_r10_single_omit["reasons"]),
        f"R10/R11 single-form archived omitted issuer must HOLD with null official stats, got {r_r10_single_omit}",
    )
    _rec("r10_ins_single_form_archived_omitted_issuer_hold", r_r10_single_omit)