_w6_edge_sem_digests = json.loads('{"PMID:1334978:L1": {"materialized_sha256": "ba77d6f37e4a05cee55b9f2dd59522a20fe1fb5a99d7d31f2c50aaaa6daa1bbc", "raw_sha256": "ba77d6f37e4a05cee55b9f2dd59522a20fe1fb5a99d7d31f2c50aaaa6daa1bbc"}, "PMID:17130499:L1": {"materialized_sha256": "6d820248e8c32be2de16d7312bd27505a3de39b6a6606a77b6245ffbbc3000ab", "raw_sha256": "779a421ad8cf4d8d4173552f79ff961ab8fef18e9e7b74a7633630d811d66adf"}, "PMID:17503968:L1": {"materialized_sha256": "71b5a6af2719204956f130472537140869ba06f46429200ddd576718f4582b51", "raw_sha256": "8016c349b967307cad81ae4549c996433d8e58b1c5ac232fc581ac1c4ffbf857"}, "PMID:17503968:L2": {"materialized_sha256": "cb2fbae0d28c550cfcedf79953fba5cb20e15d795d2340ac6e46329ab5c85e8a", "raw_sha256": "91d4dbf1ed20da61b7ae95c3fa9fc801c4c51f517926bbf2fb7edc62a8fdb1a7"}, "PMID:21912932:L1": {"materialized_sha256": "f784160dfa3973e767d86aaa62d9c7f31bc1bd65b4b6d4ff93367b199c6c22e7", "raw_sha256": "f784160dfa3973e767d86aaa62d9c7f31bc1bd65b4b6d4ff93367b199c6c22e7"}, "PMID:22315720:L1": {"materialized_sha256": "60c8c96cfe3aec7a77a76b0548e139eb3a87cbe282113082b2e1fdde7a41b086", "raw_sha256": "60c8c96cfe3aec7a77a76b0548e139eb3a87cbe282113082b2e1fdde7a41b086"}, "PMID:23572523:L1": {"materialized_sha256": "b0a41c25703bc1b76cb9c76ac4a582e005c929f9f1929cb21ff69ca94dc69328", "raw_sha256": "7a99c46ba28bf621d3164bb7d1fded582ac822d84c479aa538d73361c0123fc0"}, "PMID:23616575:L1": {"materialized_sha256": "e931c6d0bd386f6f61e75da432e41bd52c2c496591b14143edd5a437539d15ee", "raw_sha256": "e931c6d0bd386f6f61e75da432e41bd52c2c496591b14143edd5a437539d15ee"}, "PMID:23935835:L1": {"materialized_sha256": "adbcdaef4fff2a8fd900d3c833a351a7fa6f359199ee3584f8853277112e4aee", "raw_sha256": "412d7cc788e66ad3f9d69bec4b971977b109b67b2aa07baee4168171790f87a6"}, "PMID:23935835:L2": {"materialized_sha256": "865a20ad23cdac5fc5e3e63c5d8b063130f822647d030ff73503f8b4663972bd", "raw_sha256": "1ba0a2a6dab5f9119b92290da249795d6f0bc55d6edfc343a639bc5e0ea1100b"}, "PMID:23935835:L3": {"materialized_sha256": "082261bdd48106bdaf8b05ab38329636c5dd9841282d6d9def919f1be0aa2888", "raw_sha256": "86b4e4d3767ccdc339665904ff68b3680c76c0ba2c07e14fddec2557ab73c576"}, "PMID:30449685:L1": {"materialized_sha256": "efeb6e6182278053485d5cde341839a166dd6e3fc6f2ff91abeaa2a5406517d2", "raw_sha256": "b3810d3666fff295357ed7f19ccbd9d47614360425b2840792fb5b5e02e618f4"}, "PMID:30449685:L2": {"materialized_sha256": "5dcf9e33ead3eef4ca9e9a8c62e7d86321f7e874bd757d16d91e63dbaabacc28", "raw_sha256": "d33298e470b1b913c5d989bca91d09c43b82fbe913e131d637473f4f72df27be"}, "PMID:32433410:L1": {"materialized_sha256": "43dad4fab3d945c692df887a014ec596ef5ecb85b66e60c98b2f65e1fdfebcf1", "raw_sha256": "d78d4dccfb1cdf897aa8d930685821c577fef1cf0f8abd723b2dce0a0516d06b"}, "PMID:32433410:L2": {"materialized_sha256": "26ff2ebb89c67698939b96671b890d57520b253446d31bab836d33188e60e4b3", "raw_sha256": "f32ea72ffbf2a94192c683b8fe8db972ad9242b3536c1c7397dcb13c4a69a5db"}, "PMID:33722583:L1": {"materialized_sha256": "53b3bd13d72e58b145b59dc9525a4a4bb5bfaebeddad37be0ca8a90d96b0b630", "raw_sha256": "8bbfc245edfe1cf6b84a142c0fd2e2a6b1a7c19cb1ce90f9c86272deeb0f7b25"}, "PMID:34033222:L1": {"materialized_sha256": "0f5a17eba40844fd9414258b62d582538c63ea74f83147b29393e759ac67ca59", "raw_sha256": "0f5a17eba40844fd9414258b62d582538c63ea74f83147b29393e759ac67ca59"}, "PMID:35046043:L1": {"materialized_sha256": "00c821b7fa5943149930a6d0c7e8a5a972cd235308b9500178c63207bd6365a7", "raw_sha256": "d06dc3ec9674271f0fbba3a312b7e506263429efae2ed8cf80ab51ff85b95d4f"}, "PMID:35725270:L1": {"materialized_sha256": "54434bd52ca0c2e3269f67c6fa9ff615be4cf42eb2a9deb5ecf889a001a25a38", "raw_sha256": "86d6af540f2f89dd0c62ac407aadae599d32e6ddaf9f16f75eff495c66e4b09b"}, "PMID:36560629:L1": {"materialized_sha256": "4269671d03a3fe6e83873f1545bf112008f84d9c05c38b6c7bdd97fe7838fdde", "raw_sha256": "15596dfe8cf862ad01244ac8bad32e6971255db4e10fc5fbc2bae249968aa3f6"}, "PMID:37106062:L1": {"materialized_sha256": "145f3d4d677c30a68d6ae9e200372fb43d301c61ca476ff035ba3674d55a74d2", "raw_sha256": "145f3d4d677c30a68d6ae9e200372fb43d301c61ca476ff035ba3674d55a74d2"}, "PMID:37306457:L1": {"materialized_sha256": "bc5dfd9228074c74fc7cffa362697039a20bf8ac064f2e0449a353b3facfa73d", "raw_sha256": "c8997755f4cc1f0766e6d5ce3b93d53226ae234bf62c24d9b38a3e76427dc176"}, "PMID:37679570:L1": {"materialized_sha256": "282cca550f14c1763059835a36140af73129bf27ef47d266ceb446d4becf3917", "raw_sha256": "a89335d1df01f46aa28eb6789b1d77fea7a29b0de18422ce5800ae25ff9f3b4b"}, "PMID:38135691:L1": {"materialized_sha256": "a28d22fc0bf38ee8b95c8368afcab2ea2526b650d45dd089abfc7541a5660d67", "raw_sha256": "77c6b3d37b026d503ab7b9869d89b647fc38104ea771c05793511245cf603aa0"}, "PMID:38768856:L1": {"materialized_sha256": "9c99bc55d156c5767421210d8f5ea3ad2fb0172ffc79c62f8b8449d26990b66b", "raw_sha256": "e68834f53ab8fbf14b909eed56cc7e814a871c34bd6b6efbb955bcfce9820f71"}, "PMID:38848367:L1": {"materialized_sha256": "fd8694fa06853a72c1be59d9a6cdfebc5ff631de781b61c471922b143e1ba33b", "raw_sha256": "e3ab0170c3a2fd77eb53ab43eabee48b01fd561b6913629ec5995b441d8f6bc2"}, "PMID:38848367:L2": {"materialized_sha256": "008c69f2505b58caed948141e40200d5ee96f0669010fdb342cf90a8e083969d", "raw_sha256": "11f8ad3d44d3f8d53c1901a18b8895dd0865553ab90156ee945505e93b0ecdff"}, "PMID:38848367:L3": {"materialized_sha256": "0788b3f52156e62b1449d5fa06c78fab1d9c4ae3143a46367af58cef107c60f7", "raw_sha256": "efd580c8d5abe05e61595f3b1e7ff370f4a69a1492d7c4aca31605026a2f9e0f"}, "PMID:39647511:L1": {"materialized_sha256": "c8d1948ebc063ca1ebea8621fd5d001ea91ab57278f7c2238c0a4e2141a00697", "raw_sha256": "f926a6ab75ec2584dabd4e2710ba6c95a67fea0ac0557ac5138b8fbcdcb9523a"}, "PMID:40066448:L1": {"materialized_sha256": "8c2ae4f12c5b2350d79af2542a6b8fb74dd91beafde8dd0c257d7f2ea9fa440d", "raw_sha256": "bb2f7a96c9c446c844bcfdc0c891b5155e9a9056ee4969b89e936bb3d9a5fe17"}, "PMID:41118637:L1": {"materialized_sha256": "518f092d3544a7e2fa518d4d2e625f1242edec63f3f5a0fe82dc3a75509524ee", "raw_sha256": "b418227f0dd48b65c27807d0a9e60603313bb55f6e4c5bc706eb7ea458ecdc75"}, "PMID:8384206:L1": {"materialized_sha256": "ec0d04afd80e71cf2771363126bcc8e5bf7db8b770a01ceb5d90d975a71df315", "raw_sha256": "ec0d04afd80e71cf2771363126bcc8e5bf7db8b770a01ceb5d90d975a71df315"}}') _w6_expected_pmids_set = frozenset(_w6_expected_qid_to_pmid.values()) _w6_seen_study_sem: set[str] = set() _w6_actual_study_digests: dict[str, str] = {} _w6_actual_study_phases: dict[str, str] = {} for _wqid_s, _wst_s in sorted(studies.items()): if ( _wqid_s not in _w6_expected_qid_to_pmid and _wst_s.get("queue_id") not in _w6_expected_qid_to_pmid and _study_pmid(_wst_s) not in _w6_expected_pmids_set ): continue if _wqid_s not in _w6_study_sem_digests or _wst_s.get("queue_id") != _wqid_s: raise ValueError(f"WAVE6_STUDY_SEMANTIC_CLAIM_MISMATCH: unexpected or miskeyed Wave-6 study {_wqid_s!r}") if _wst_s.get("dec124_certification_status") != _w6_exp_study_status: raise ValueError( f"WAVE6_STUDY_SEMANTIC_CLAIM_MISMATCH: study {_wqid_s} dec124_certification_status={_wst_s.get('dec124_certification_status')!r} " f"mismatches active governed phase status={_w6_exp_study_status!r}" ) # Audit R8-01: Hash FULL study object INCLUDING dec124_certification_status and all phase/certification fields! _wst_sem_sha = _sha256_str(json.dumps(_wst_s, sort_keys=True, ensure_ascii=False, separators=(",", ":"))) _wst_exp_pair = _w6_study_sem_digests[_wqid_s] if _wst_sem_sha not in (_wst_exp_pair["raw_sha256"], _wst_exp_pair["materialized_sha256"]): raise ValueError( f"WAVE6_STUDY_SEMANTIC_CLAIM_MISMATCH: Wave-6 study {_wqid_s} full semantic/phase digest {_wst_sem_sha} " f"mismatches pinned raw/materialized digests (dec124_certification_status/phase/pmid/fidelity_tier/record_class/title/year tamper rejected)" ) _w6_actual_study_digests[_wqid_s] = _wst_sem_sha _w6_actual_study_phases[_wqid_s] = _wst_s["dec124_certification_status"] _w6_seen_study_sem.add(_wqid_s) if _w6_seen_study_sem != set(_w6_study_sem_digests.keys()) or len(_w6_seen_study_sem) != 25: raise ValueError(f"WAVE6_STUDY_SEMANTIC_CLAIM_MISMATCH: verified {len(_w6_seen_study_sem)}/25 Wave-6 studies") _w6_seen_arm_sem: set[str] = set() _w6_actual_arm_digests: dict[str, str] = {} for _wvid_s, _wa_s in sorted(arms.items()): if _wvid_s not in _w6_arm_sem_digests and _wa_s.get("queue_id") not in _w6_expected_qid_to_pmid: continue if _wvid_s not in _w6_arm_sem_digests or _wa_s.get("variable_id") != _wvid_s: raise ValueError(f"WAVE6_ARM_SEMANTIC_CLAIM_MISMATCH: unexpected or miskeyed Wave-6 arm {_wvid_s!r}") _wa_sem_sha = _sha256_str(json.dumps(_wa_s, sort_keys=True, ensure_ascii=False, separators=(",", ":"))) _wa_exp_pair = _w6_arm_sem_digests[_wvid_s] if _wa_sem_sha not in (_wa_exp_pair["raw_sha256"], _wa_exp_pair["materialized_sha256"]): raise ValueError( f"WAVE6_ARM_SEMANTIC_CLAIM_MISMATCH: Wave-6 arm {_wvid_s} semantic digest {_wa_sem_sha} " f"mismatches pinned raw/materialized digests (label/n_donors_or_animals/edits/role tamper rejected)" ) _w6_actual_arm_digests[_wvid_s] = _wa_sem_sha _w6_seen_arm_sem.add(_wvid_s) if _w6_seen_arm_sem != set(_w6_arm_sem_digests.keys()) or len(_w6_seen_arm_sem) != 61: raise ValueError(f"WAVE6_ARM_SEMANTIC_CLAIM_MISMATCH: verified {len(_w6_seen_arm_sem)}/61 Wave-6 arms") _w6_seen_out_sem: set[str] = set() _w6_actual_out_digests: dict[str, str] = {} for _woid_s, _wo_s in sorted(outcomes.items()): if _woid_s not in _w6_out_sem_digests and (not isinstance(_wo_s, dict) or _wo_s.get("queue_id") not in _w6_expected_qid_to_pmid): continue if _woid_s not in _w6_out_sem_digests or _wo_s.get("outcome_node_id") != _woid_s: raise ValueError(f"WAVE6_OUTCOME_SEMANTIC_CLAIM_MISMATCH: unexpected or miskeyed Wave-6 outcome {_woid_s}") _wo_sem_body = {k: v for k, v in _wo_s.items() if k != "cited_by_edge_ids"} _wo_sem_sha = _sha256_str(json.dumps(_wo_sem_body, sort_keys=True, ensure_ascii=False, separators=(",", ":"))) if _wo_sem_sha != _w6_out_sem_digests[_woid_s]: raise ValueError( f"WAVE6_OUTCOME_SEMANTIC_CLAIM_MISMATCH: Wave-6 outcome {_woid_s} semantic digest {_wo_sem_sha} " f"mismatches pinned {_w6_out_sem_digests[_woid_s]} (summary/direction/horizon/transfer/tier/pin tamper rejected)" ) _w6_actual_out_digests[_woid_s] = _wo_sem_sha _w6_seen_out_sem.add(_woid_s) if _w6_seen_out_sem != set(_w6_out_sem_digests.keys()) or len(_w6_seen_out_sem) != 46: raise ValueError(f"WAVE6_OUTCOME_SEMANTIC_CLAIM_MISMATCH: verified {len(_w6_seen_out_sem)}/46 Wave-6 outcomes") _w6_seen_edge_sem: set[str] = set() _w6_actual_edge_digests: dict[str, str] = {} for _we_s in edges: _weid_s = str(_we_s.get("edge_id") or "") if _weid_s not in _w6_edge_sem_digests and _we_s.get("queue_id") not in _w6_expected_qid_to_pmid: continue if _weid_s not in _w6_edge_sem_digests: raise ValueError(f"WAVE6_EDGE_SEMANTIC_CLAIM_MISMATCH: unexpected unpinned Wave-6 edge {_weid_s}") if _weid_s in _w6_seen_edge_sem: raise ValueError(f"WAVE6_EDGE_SEMANTIC_CLAIM_MISMATCH: duplicate Wave-6 edge {_weid_s}") _we_sem_sha = _sha256_str(json.dumps(_we_s, sort_keys=True, ensure_ascii=False, separators=(",", ":"))) _we_exp_pair = _w6_edge_sem_digests[_weid_s] if _we_sem_sha not in (_we_exp_pair["raw_sha256"], _we_exp_pair["materialized_sha256"]): raise ValueError( f"WAVE6_EDGE_SEMANTIC_CLAIM_MISMATCH: Wave-6 edge {_weid_s} semantic/authority digest {_we_sem_sha} " f"mismatches pinned raw/materialized digests (claim_summary/polarity/horizon/transfer_limits/authority tamper rejected)" ) _w6_actual_edge_digests[_weid_s] = _we_sem_sha _w6_seen_edge_sem.add(_weid_s) if _w6_seen_edge_sem != set(_w6_edge_sem_digests.keys()) or len(_w6_seen_edge_sem) != 32: raise ValueError(f"WAVE6_EDGE_SEMANTIC_CLAIM_MISMATCH: verified {len(_w6_seen_edge_sem)}/32 Wave-6 edges") # Audit R8-01: Verify exact whole-graph digest (25 full studies + 61 arms + 46 outcomes + 32 edges + 25 study phases) # against the verified phase-specific governed approval receipt in BOTH modes! _w6_actual_graph_digest = _sha256_str( json.dumps( { "study_digests": dict(sorted(_w6_actual_study_digests.items())), "arm_digests": dict(sorted(_w6_actual_arm_digests.items())), "outcome_digests": dict(sorted(_w6_actual_out_digests.items())), "edge_digests": dict(sorted(_w6_actual_edge_digests.items())), "study_certification_statuses": dict(sorted(_w6_actual_study_phases.items())), }, sort_keys=True, ensure_ascii=False, separators=(",", ":"), ) ) if _w6_actual_graph_digest != _w6_approval_rec.get("approved_wave6_graph_digest"): raise ValueError( f"WAVE6_CERTIFICATION_APPROVAL_MISMATCH: actual Wave-6 graph digest {_w6_actual_graph_digest} " f"mismatches approval receipt approved_wave6_graph_digest={_w6_approval_rec.get('approved_wave6_graph_digest')!r}" ) return { "studies": len(studies), "arms": len(arms), "outcomes": len(outcomes), "edges": len(edges), "effectors": len(effectors), "graveyard_index": len(graveyard), } def verify_ceg_payload_detailed( ceg: dict[str, Any], repo_root: Path = REPO_ROOT, *, require_sources: bool = False, ) -> dict[str, Any]: """Run verify_ceg_payload and return explicit verification_mode alongside counts.""" counts = verify_ceg_payload(ceg, repo_root=repo_root, require_sources=require_sources) _dos_dir = repo_root / "data" / "dossiers" _p34 = ["17375075", "39696686", "42020736", "42056515", "42749803"] _p35 = ["2642862", "31427818", "35953586", "36944335", "38843830", "39753706", "41201433", "41436438", "41690310", "41764741", "41999746"] _q35 = frozenset({"M0189", "M1407", "PMID:36944335", "PMID:39753706", "PMID:41436438", "PMID:41999746"}) has_src_34 = _dos_dir.is_dir() and all((_dos_dir / f"{pm}.json").is_file() for pm in _p34) has_src_35 = _dos_dir.is_dir() and all((_dos_dir / f"{pm}.json").is_file() for pm in _p35) _verified_35_oids = ( sorted(oid for oid, o in (ceg.get("outcomes") or {}).items() if isinstance(o, dict) and o.get("queue_id") in _q35) if has_src_35 else [] ) _w6_qids_sorted = sorted(["PMID:1334978", "PMID:17130499", "PMID:17503968", "PMID:21912932", "PMID:22315720", "PMID:23572523", "PMID:23616575", "PMID:23935835", "PMID:30449685", "PMID:32433410", "PMID:33722583", "PMID:34033222", "PMID:35046043", "PMID:35725270", "PMID:36560629", "PMID:37106062", "PMID:37306457", "PMID:37679570", "PMID:38135691", "PMID:38768856", "PMID:38848367", "PMID:39647511", "PMID:40066448", "PMID:41118637", "PMID:8384206"]) _w6_src_dir_det = repo_root / "data" / "wave6_sources" has_src_w6 = _w6_src_dir_det.is_dir() and (_w6_src_dir_det / "efetch_60.json").is_file() _w6_prim_cnt = sum(1 for oid, o in (ceg.get("outcomes") or {}).items() if isinstance(o, dict) and o.get("queue_id") in set(_w6_qids_sorted)) _w6_sec_abs_cnt = sum( 1 for o in (ceg.get("outcomes") or {}).values() if isinstance(o, dict) and o.get("queue_id") in set(_w6_qids_sorted) for sp in (o.get("secondary_source_pins") or []) if isinstance(sp, dict) and sp.get("source_type") == "abstract" ) _w6_sec_ft_cnt = sum( 1 for o in (ceg.get("outcomes") or {}).values() if isinstance(o, dict) and o.get("queue_id") in set(_w6_qids_sorted) for sp in (o.get("secondary_source_pins") or []) if isinstance(sp, dict) and sp.get("source_type") != "abstract" ) _mode = ( "iip0035_11dossiers_and_wave6_25studies_55spans_verified" if (has_src_35 and len(_verified_35_oids) == 8 and has_src_w6 and _w6_prim_cnt == 46 and (_w6_sec_abs_cnt + _w6_sec_ft_cnt) == 9) else ( "iip0035_11dossiers_8new_exact_spans_verified" if (has_src_35 and len(_verified_35_oids) == 8) else ("iip0034_5dossiers_8new_exact_spans_verified" if has_src_34 else "structural_public_only") ) ) _e35_ids = sorted([ "M0051:L4", "M0154:L3", "M0159:L3", "M0189:L1", "M0206:L3", "M0241:L3", "M1407:L1", "PMID:36944335:L1", "PMID:39753706:L1", "PMID:41436438:L1", "PMID:41999746:L1", ]) return { "counts": counts, "verification_mode": _mode, "iip0034_dossiers_verified": _p34 if has_src_34 else [], "iip0035_dossiers_verified": _p35 if has_src_35 else [], "iip0035_verified_exact_span_outcome_ids": _verified_35_oids, "iip0035_verified_exact_span_outcome_count": len(_verified_35_oids), "iip0035_sourceguard_executed": bool(has_src_35), "iip0035_sourceguard_scanned_study_ids": sorted(_q35) if has_src_35 else [], "iip0035_sourceguard_scanned_edge_ids": _e35_ids if has_src_35 else [], "iip0035_sourceguard_scanned_touched_legacy_outcome_ids": ( sorted([ "M0051:O1", "M0051:O2", "M0051:O3", "M0051:O4", "M0051:O5", "M0051:O6", "M0154:O1", "M0154:O2", "M0154:O3", "M0154:O4", "M0159:O1", "M0159:O2", "M0159:O3", "M0206:O1", "M0206:O2", "M0206:O9", "M0206:O10", "M0206:O11", "M0206:O12", "M0206:O13", "M0206:O14", "M0206:O16", "M0206:O17", "M0241:O1", "M0241:O2", "M0241:O3", "M0241:O4", ]) if has_src_35 else [] ), "iip0035_sourceguard_scanned_adjudicated_legacy_edge_ids": (