"""Compare bounded public-reference behavior to six supplied APIs, never mark ready. PYTHONPATH=src python scripts/audit_reference_conversion.py --repo .. --output report.json The report intentionally includes only supported fields/legacy links, alongside whole-graph blockers. It is not a substitute for compare_frontend_exports.py's source/version binding checks or a target node snapshot. """ from __future__ import annotations import argparse import hashlib import json from collections import Counter, defaultdict from pathlib import Path try: from scripts.compare_frontend_exports import differences except ModuleNotFoundError: from compare_frontend_exports import differences from calliope.comfyui.companions import load_companions from calliope.comfyui.delivery_scope import exclusion_for from calliope.comfyui.serialization_reference import ( ASR_PROFILE, AUX_PROFILE, CASE04_PROFILE, CROP_SPLIT_PROFILES, MEDIA_PROFILES, MP3_PROFILE, PREVIEW_PROFILE, PRIMITIVE_PROFILE, PROFILE, REEL_PROFILE, SEPARATION_PROFILE, VHS_PROFILES, resolve_reference_link, serialize_case04_node, serialize_promoted_node, serialize_reference_widgets, ) from calliope.comfyui.structure_reference import PROMOTED_PROFILES, STRUCTURE_PROFILES from calliope.comfyui.ui2api import convert, convert_reference def saved_named_pointer(source, nid, name): """Locate immutable original named bytes by scoped IDs, never API values.""" graph, prefix = source, "" definitions = (source.get("definitions") or {}).get("subgraphs", []) parts = nid.split(":") for depth, part in enumerate(parts): index, node = next((i, n) for i, n in enumerate(graph["nodes"]) if str(n["id"]) == part) if depth == len(parts) - 1: if name in (node.get("widgets_values_named") or {}): escaped = name.replace("~", "~0").replace("/", "~1") return prefix + f"/nodes/{index}/widgets_values_named/" + escaped return None dindex, graph = next((i, d) for i, d in enumerate(definitions) if d["id"] == node["type"]) prefix = f"/definitions/subgraphs/{dindex}" def audit(repo: Path, profile: str = PROFILE) -> dict: rows = [] records = load_companions(repo / "docs/hel-892/supplied-api/manifest.json") for path, record in records.items(): binding = record["binding"] if exclusion_for(path): continue raw = (repo / path).read_bytes() assert hashlib.sha1(raw).hexdigest() == binding["source_sha"] assert hashlib.sha256(raw).hexdigest() == binding["source_sha256"] source, api = json.loads(raw), json.loads(record["raw"]) assert convert(api).prompt is not None selected = profile if profile in ( "structure-batch-reference", "promoted-batch-reference", "case04-batch-reference", ): version = source.get("extra", {}).get("frontendVersion") structural = f"comfy-frontend-{version}-structure-reference" selected = ( structural if (source.get("definitions") or {}).get("subgraphs") and structural in STRUCTURE_PROFILES else PRIMITIVE_PROFILE if any(n.get("type") == "PrimitiveNode" for n in source["nodes"]) else AUX_PROFILE ) if profile in ("promoted-batch-reference", "case04-batch-reference"): selected = ( selected.replace("-structure-reference", "-promoted-reference") if selected.replace("-structure-reference", "-promoted-reference") in PROMOTED_PROFILES else PREVIEW_PROFILE if selected == PRIMITIVE_PROFILE else selected ) if profile == "case04-batch-reference" and binding["id"] == "04": selected = CASE04_PROFILE candidate = convert_reference(source, selected) projected = candidate.diagnostic_graph or source nodes = {str(n["id"]): n for n in projected["nodes"]} links = { str(link[0]): link for link in projected.get("links", []) if isinstance(link, list) and len(link) == 6 } fields, edges, unsupported, metadata, node_types, api_only = [], [], [], [], [], [] for nid, node in nodes.items(): if node.get("type") in ("Reroute", "Note", "MarkdownNote"): continue try: values = ( serialize_case04_node(node) if selected == CASE04_PROFILE else serialize_promoted_node(node, PROMOTED_PROFILES[selected]) if selected in PROMOTED_PROFILES else serialize_reference_widgets(node, selected) ) for boundary in candidate.resolved_boundaries: if boundary["node_id"] == nid: values[boundary["input_name"]] = boundary["value"] except ValueError as exc: unsupported.append({"node_id": nid, "type": node["type"], "reason": str(exc)}) else: for name, value in values.items(): expected = api.get(nid, {}).get("inputs", {}).get(name) fields.append( { "node_id": nid, "field": name, "source_reference": value, **( { "source_value_pointer": next( ( b["value_pointer"] for b in candidate.resolved_boundaries if b["node_id"] == nid and b["input_name"] == name ), saved_named_pointer(source, nid, name), ), "serializer_contract": "case04-reference/sources.json; " "case04-reference/contracts.json", } if selected == CASE04_PROFILE else {} ), "api": expected, "differences": ( differences({}, {name: value}) if selected in (PREVIEW_PROFILE, CASE04_PROFILE, *PROMOTED_PROFILES) and name not in api.get(nid, {}).get("inputs", {}) else differences(expected, value) ), } ) linked = {s["name"] for s in node.get("inputs", []) if s.get("link") is not None} api_only.extend( {"node_id": nid, "field": name, "api_value": value} for name, value in api.get(nid, {}).get("inputs", {}).items() if name not in values and name not in linked ) metadata.append( { "node_id": nid, "differences": differences( api.get(nid, {}).get("_meta"), {"title": node.get("title") or node["type"]} ), } ) node_types.append( { "node_id": nid, "source_type": node["type"], "api_type": api.get(nid, {}).get("class_type"), "differences": differences(api.get(nid, {}).get("class_type"), node["type"]), } ) for socket in node.get("inputs", []): lid = socket.get("link") if lid is None: continue try: endpoint = resolve_reference_link(nodes, links, lid) except (ValueError, KeyError, TypeError, AttributeError) as exc: edges.append( { "node_id": nid, "input": socket["name"], "status": "unsupported", "reason": str(exc), } ) continue expected = api.get(nid, {}).get("inputs", {}).get(socket["name"]) edges.append( { "node_id": nid, "input": socket["name"], "via_reroute": nodes[str(links[str(lid)][1])]["type"] == "Reroute", "source_reference": endpoint, "api": expected, "differences": differences(expected, endpoint), } ) rows.append( { "id": binding["id"], "selected_profile": selected, "source_path": path, "source_sha256": binding["source_sha256"], "api_sha256": binding["export_sha256"], "source_frontend_version": source.get("extra", {}).get("frontendVersion"), "export_frontend_version": binding["frontend_version"], "whole_prompt_available": candidate.prompt is not None, "serialization_stage": candidate.serialization_stage, "candidate_prompt": candidate.prompt if profile in ("promoted-batch-reference", "case04-batch-reference", CASE04_PROFILE) else None, "whole_prompt_differences": differences(api, candidate.prompt) if candidate.prompt is not None else None, "whole_prompt_issues": candidate.issues, "production_prompt_available": convert(source).prompt is not None, "serialized_fields": fields, "topology_edges": edges, "unsupported_widget_nodes": unsupported, "diagnostic_graph": candidate.diagnostic_graph, "unresolved_boundaries": candidate.unresolved_boundaries, "resolved_boundaries": [ { **v, "api": api.get(v["node_id"], {}).get("inputs", {}).get(v["input_name"]), "differences": differences( api.get(v["node_id"], {}).get("inputs", {}).get(v["input_name"]), v["value"], ), } for v in candidate.resolved_boundaries ], "node_types": node_types, "metadata": metadata, "api_only_fields_for_supported_nodes": api_only, "comparison_is_complete": candidate.prompt is not None, "executable": False, "execution_verified": False, } ) return { "profile": profile, "authority": "public_reference_only_not_object_info", "comparison_scope": "explicit supported scalar widgets and projected endpoints only; " "diagnostic structures never prove widget values, full equivalence or execution", "reference_conditions": { "unmodified_frontend_widgets_assumed": True, "promoted_named_positional": ( "1.53.6 requires both representations to agree when named values exist; " "1.48.7 ignores unknown named keys" ), "case04_stage": "restored_saved_state_before_queue_hooks; fixed controls only", "case04_uncovered": "queue history/settings, non-fixed seed, other dynamic branches, " "dynamic text/filename expressions, unknown extension overrides", "promoted_missing_or_null": "no silent default; typed scalar consumption rejects null", "primitive_inside_promoted_profile": "unsupported; whole prompt remains closed", "combo_availability": "not evaluated; fixed scalar constructor only", "ue_extension_serializer_match": "unknown", "aux_release_artifact_commit_match": "unknown" if profile == AUX_PROFILE else "not_used", "aio_combo_membership": "unknown_not_evaluated", "model_and_media_files_available": "unknown", "resolution_bounds": "schema metadata only; integer values serialized without clamping", }, "target_version_match": "unknown", "whole_source_equivalence_verified": False, "execution_verified": False, "cases": rows, } REFERENCE_PROFILES = ( PROFILE, AUX_PROFILE, PRIMITIVE_PROFILE, PREVIEW_PROFILE, *STRUCTURE_PROFILES, *PROMOTED_PROFILES, CASE04_PROFILE, ASR_PROFILE, *MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES, *VHS_PROFILES, ) def canonical_sha(value): """SHA256 of UTF-8 JSON, sorted keys, compact separators, no ASCII escaping.""" return hashlib.sha256( json.dumps( value, sort_keys=True, separators=(",", ":"), ensure_ascii=False, allow_nan=False, ).encode("utf-8") ).hexdigest() def node_inventory(source, *, include_aux=False): rows = [] graphs = [("", source)] + [ (f"/definitions/subgraphs/{i}", graph) for i, graph in enumerate((source.get("definitions") or {}).get("subgraphs", [])) ] for prefix, graph in graphs: for i, node in enumerate(graph.get("nodes", [])): props = node.get("properties") or {} rows.append( { "pointer": f"{prefix}/nodes/{i}", "node_id": str(node.get("id")), "type": node.get("type"), "provider": props.get("cnr_id") or (props.get("aux_id") if include_aux else None), "version": props.get("ver"), "mode": node.get("mode", 0), "widget_count": len(node.get("widgets_values", [])), "widget_layout": type(node.get("widgets_values", [])).__name__, "ue_version": (props.get("ue_properties") or {}).get("version"), } ) return rows def asr_field_evidence(source, prompt): """Bind every final ASR-profile input to original bytes or fixed UI rules.""" fields = [] for index, node in enumerate(source["nodes"]): nid = str(node["id"]) if nid not in prompt: continue names = { "AILab_Qwen3ASR": ("model", "precision", "language", "hints", "unload_models"), "LoadAudio": ("audio",), "PreviewAny": ("previewMode",), }[node["type"]] for name, value in prompt[nid]["inputs"].items(): socket = next((s for s in node.get("inputs", []) if s["name"] == name), {}) if socket.get("link") is not None: li, link = next( (i, link) for i, link in enumerate(source["links"]) if link[0] == socket["link"] ) expected = [str(link[1]), link[2]] pointer, rule = f"/links/{li}", "upstream ID to string; original output slot" elif name in names: wi = names.index(name) expected = node["widgets_values"][wi] pointer, rule = f"/nodes/{index}/widgets_values/{wi}", "fixed constructor identity" else: assert name in ("audioUI", "preview") expected = "" pointer, rule = None, "1.37.11 DOM without getValue; options.serialize boundary" assert value == expected and type(value) is type(expected) fields.append( { "node_id": nid, "class_type": node["type"], "field": name, "value": value, "json_type": type(value).__name__, "source_pointer": pointer, "rule": rule, } ) return fields def media_field_evidence(source, prompt, profile): """Independent final byte pointers, including every class/input/title/link.""" layouts = { "LoadAudio": ("audio",), "SaveAudioMP3": ("filename_prefix", "quality"), "PreviewAudio": (), "AudioSeparation": ("chunk_fade_shape", "chunk_length", "chunk_overlap"), "AudioCrop": ("start_time", "end_time"), "GuHaiAutoImageSplit": ( "保存目录", "水平张数", "垂直张数", "移除画布边缘", "移除描边", "文件名前缀", "保存格式", ), "LoadImage": ("image",), "PreviewImage": (), "LayerUtility: ImageReel": ( "image1_text", "image2_text", "image3_text", "image4_text", "reel_height", "border", ), "LayerUtility: ImageReelComposit": ("font_file", "font_size", "border", "color_theme"), } fields = [] for index, node in enumerate(source["nodes"]): nid = str(node["id"]) if nid not in prompt: continue actual = prompt[nid] assert actual["class_type"] == node["type"] assert actual["_meta"] == {"title": node.get("title") or node["type"]} names = layouts[node["type"]] for name, value in actual["inputs"].items(): socket = next((s for s in node["inputs"] if s["name"] == name), {}) if socket.get("link") is not None: li, link = next( (i, link) for i, link in enumerate(source["links"]) if link[0] == socket["link"] ) expected = [str(link[1]), link[2]] pointer, rule = f"/links/{li}", "original final endpoint ID/slot" elif name in names: wi = names.index(name) expected = node["widgets_values"][wi] pointer, rule = f"/nodes/{index}/widgets_values/{wi}", "fixed constructor identity" else: assert name == "audioUI" expected = "" pointer, rule = None, "1.37.11 DOM getter without getValue; not a descriptor" assert type(value) is type(expected) and value == expected fields.append( { "node_id": nid, "class_type": node["type"], "class_pointer": f"/nodes/{index}/type", "title_pointer": f"/nodes/{index}/title" if node.get("title") else f"/nodes/{index}/type", "field": name, "value": value, "json_type": type(value).__name__, "source_pointer": pointer, "rule": rule, "profile": profile, "contract_manifest": "crop-split-reference/contract.json" if profile in CROP_SPLIT_PROFILES else "separation-reference/contract.json" if profile == SEPARATION_PROFILE else "media-reference/contract.json", } ) return fields def vhs_field_evidence(source, prompt): """Re-read every final field from named source bytes or original links.""" fields = [] for i, node in enumerate(source["nodes"]): nid = str(node["id"]) assert prompt[nid]["class_type"] == node["type"] assert prompt[nid]["_meta"] == {"title": node.get("title") or node["type"]} for name, value in prompt[nid]["inputs"].items(): socket = next(s for s in node["inputs"] if s["name"] == name) if socket.get("link") is not None: li, link = next( (j, edge) for j, edge in enumerate(source["links"]) if edge[0] == socket["link"] ) expected = [str(link[1]), link[2]] pointer = f"/links/{li}" else: expected = node["widgets_values"][name] pointer = f"/nodes/{i}/widgets_values/{name}" assert type(value) is type(expected) and value == expected fields.append( { "node_id": nid, "class_type": node["type"], "field": name, "value": value, "json_type": type(value).__name__, "source_pointer": pointer, } ) return fields def profile_attempt(source, profile): expected = { **STRUCTURE_PROFILES, **PROMOTED_PROFILES, CASE04_PROFILE: "1.53.6", **VHS_PROFILES, }.get(profile, "1.37.11") assumptions = { "frontend": expected, "unmodified_frontend_and_widgets": True, "target_version_match": "unknown", "ue_serializer_match": "unknown", "dynamic_options_and_files_available": "unknown", "qwen_commit": "b037d7be121111a1ba6f40a4d99f6b43ac6411b6" if profile in (ASR_PROFILE, PREVIEW_PROFILE, PRIMITIVE_PROFILE) else None, "qwen_missing_declaration": "explicit_reference_assumption_only", "aux_commit": "e8b689a513c3e6b63edc44066560ca5919c0576e" if profile == AUX_PROFILE else None, "aux_release_artifact_match": "unknown" if profile == AUX_PROFILE else "not_used", "media_reference": ( {"core": "0.11.0@09725967cf76304371c390ca1d6483e04061da48"} if profile == MP3_PROFILE else { "core": "0.4.0@fc657f471a29d07696ca16b566000e8e555d67d1", "ImageReel": "4f4d5cbbe40e030a5a0bb474fb65c4032585bc3c", "ImageReelComposit": "42ccdd8f75ab312285eaa77073a5cc20bdba484c", } if profile == REEL_PROFILE else None ), "reference_sources": [ "media-reference/sources.json", "serialization-evidence/sources.json", "structure-reference/sources.json", "controlnet-reference/sources.json", "promoted-reference/sources.json", "case04-reference/sources.json", ], } if profile == SEPARATION_PROFILE: assumptions["separation_reference"] = { "LoadAudio_and_PreviewAudio": "0.3.68@265adad858e1f31b66cd3523a02b16f5d34ced52", "SaveAudioMP3": "0.3.71@c55fd7481626d8bee8044ea7512ea996d13a1b90", "AudioSeparation": "1.4.0@5291831d7c321ab7a5192374482f9848dffee75b", "registry_source_bytes_match": True, "registry_commit_binding": "unknown; API exposes no commit", "plugin_license": "unknown; LICENSE referenced but absent at pinned version", "numeric_policy": ( "finite int/float within frontend UI [0,2048]; saved values unchanged" ), } assumptions["reference_sources"] = [ "separation-reference/sources.json", *assumptions["reference_sources"], ] if profile in CROP_SPLIT_PROFILES: assumptions["crop_split_reference"] = { "selected_profile": profile, "node_contracts": "crop-split-reference/contract.json", "unmodified_plugin_and_frontend": True, "target_node_version_and_UE_match": "unknown", "registry_commit_binding": "unknown", } assumptions["reference_sources"] = [ "crop-split-reference/sources.json", "separation-reference/sources.json", *assumptions["reference_sources"], ] if profile in VHS_PROFILES: assumptions["vhs_reference"] = { "contracts": "vhs-reference/contract.json", "unmodified_pinned_plugin_and_format_files": True, "extension_overrides_and_target_installation": "unknown", "named_mirror": "if present, assumed inert and required equal to VHS map", "array_migration": "unsupported; never fill missing fields from defaults", } assumptions["reference_sources"] = [ "vhs-reference/sources.json", "serialization-evidence/sources.json", ] base = {"profile": profile, "assumptions": assumptions} if profile in (*CROP_SPLIT_PROFILES, *VHS_PROFILES): base["source_declarations"] = [ { "pointer": f"/nodes/{i}", **{k: (n.get("properties") or {}).get(k) for k in ("cnr_id", "aux_id", "ver")}, } for i, n in enumerate(source.get("nodes", [])) ] base["verified_reference_facts"] = ( "vhs-reference/contract.json" if profile in VHS_PROFILES else "crop-split-reference/verified-facts.json" ) declared_frontend = (source.get("extra") or {}).get("frontendVersion") assumptions["source_frontend_declaration"] = declared_frontend if profile in VHS_PROFILES: assumptions["vhs_reference"]["missing_frontend_policy"] = ( "explicit_1.37.11_reference_assumption" if expected == "1.37.11" else "requires_explicit_1.48.6" ) assumptions["missing_frontend_policy"] = ( "explicit_media_reference_assumption" if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES, *VHS_PROFILES) else "explicit_legacy_reference_assumption" if profile in (PROFILE, AUX_PROFILE, PRIMITIVE_PROFILE) else "requires_explicit_declaration" ) if profile in VHS_PROFILES and expected == "1.48.6": assumptions["missing_frontend_policy"] = "requires_explicit_1.48.6" assumptions["missing_node_declarations"] = [ n["pointer"] for n in node_inventory(source, include_aux=profile in CROP_SPLIT_PROFILES) if n["type"] not in ("Note", "MarkdownNote", "Reroute", "PrimitiveNode") and (n["provider"] is None or n["version"] is None) ] if (profile in VHS_PROFILES and expected == "1.48.6" and declared_frontend is None) or ( declared_frontend != expected and not ( declared_frontend is None and profile in ( PROFILE, AUX_PROFILE, PRIMITIVE_PROFILE, *MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES, *VHS_PROFILES, ) ) ): return { **base, "status": "not_applicable", "issues": [ { "code": "frontend_not_applicable", "message": "前端声明缺失或版本不匹配", } ], } result = convert_reference(source, profile) if result.prompt is None: return { **base, "status": "rejected", "rejection_class": "missing_contract" if any(i["code"] == "reference_node_unsupported" for i in result.issues) else "serializer_or_structure_rejected", "issues": result.issues, "unresolved_boundaries": result.unresolved_boundaries, } # Legacy core serializers explicitly assume absent declarations. Record # that assumption instead of implying that a type-name match proved it. return { **base, "status": "complete_reference_candidate", "issues": [], "serialization_stage": result.serialization_stage or "restored_saved_state_before_queue_hooks", "candidate_sha256": canonical_sha(result.prompt), "candidate_prompt": result.prompt, **( {"field_evidence": asr_field_evidence(source, result.prompt)} if profile == ASR_PROFILE else {"field_evidence": vhs_field_evidence(source, result.prompt)} if profile in VHS_PROFILES else {"field_evidence": media_field_evidence(source, result.prompt, profile)} if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES, *VHS_PROFILES) else {} ), } def audit_library(repo: Path, profiles=REFERENCE_PROFILES, *, baseline_profiles=None): """Actually invoke every version-applicable profile; never choose first success. The immutable manifest/SHA binding and delivery_scope define the partition. Candidates remain embedded in this isolated report, never the production DB. """ manifest = json.loads((repo / "docs/hel-892/offline/manifest.json").read_text()) source_paths = { p.relative_to(repo).as_posix() for p in (repo / "example_ComfyUI_workflows").rglob("*") if p.is_file() } manifest_paths = [r["path"] for r in manifest] if len(manifest_paths) != len(set(manifest_paths)) or set(manifest_paths) != source_paths: raise ValueError("源目录与manifest集合不一致或路径重复") companions = load_companions(repo / "docs/hel-892/supplied-api/manifest.json") rows, excluded, api_paths, gap_groups = [], [], [], defaultdict(list) for record in manifest: path = record["path"] raw = (repo / path).read_bytes() if hashlib.sha1(raw).hexdigest() != record["source_sha"]: raise ValueError(f"源SHA与固定manifest不符:{path}") if exclusion_for(path): excluded.append(path) continue source = json.loads(raw) if "nodes" not in source: api_paths.append(path) continue inventory = node_inventory(source) attempts = [profile_attempt(source, profile) for profile in profiles] complete = [a for a in attempts if a["status"] == "complete_reference_candidate"] hashes = sorted({a["candidate_sha256"] for a in complete}) status = ( "candidate_conflict" if len(hashes) > 1 else ("complete_reference_candidate" if complete else "blocked") ) companion = companions.get(path) row = { "source_path": path, "source_sha1": record["source_sha"], "source_sha256": hashlib.sha256(raw).hexdigest(), "frontend_version": (source.get("extra") or {}).get("frontendVersion"), "cohort": "with_companion" if companion else "without_companion", "comparison_status": "comparison_available" if companion else "comparison_unavailable", "status": status, "inventory": inventory, "attempts": attempts, "complete_profiles": [a["profile"] for a in complete], "candidate_hashes": hashes, "target_version_match": "unknown", "production_prompt_available": convert(source).prompt is not None, "execution_verified": False, } if companion: api = json.loads(companion["raw"]) row["comparisons"] = [ { "profile": a["profile"], "api_sha256": companion["binding"]["export_sha256"], "differences": differences(api, a["candidate_prompt"]), } for a in complete ] rows.append(row) if status == "blocked": for attempt in attempts: if attempt["status"] != "rejected": continue for issue in attempt["issues"]: gap_inventory = ( node_inventory(source, include_aux=True) if attempt["profile"] in CROP_SPLIT_PROFILES else inventory ) matches = [n for n in gap_inventory if n["node_id"] == issue.get("node_id")] for node in matches or [{}]: key = ( node.get("type"), node.get("provider"), node.get("version"), attempt["profile"], issue["code"], issue["message"], ) gap_groups[key].append( { "source_path": path, "node_pointer": node.get("pointer"), "node_id": node.get("node_id"), } ) summary = { cohort: dict(Counter(r["status"] for r in rows if r["cohort"] == cohort)) for cohort in ("without_companion", "with_companion") } if baseline_profiles is None: excluded_profiles = ( VHS_PROFILES if any(p in VHS_PROFILES for p in profiles) else CROP_SPLIT_PROFILES ) baseline_profiles = tuple(p for p in profiles if p not in excluded_profiles) old_complete = { row["source_path"] for row in rows if any( a["status"] == "complete_reference_candidate" and a["profile"] in baseline_profiles for a in row["attempts"] ) } now_complete = {row["source_path"] for row in rows if row["complete_profiles"]} return { "authority": "public_reference_only_not_object_info", "source_total": len(manifest), "target_total": len(rows) + len(api_paths), "coverage_delta": { "baseline": "explicit baseline profile subset; applied this run", "baseline_profiles": list(baseline_profiles), "previous_complete_paths": sorted(old_complete), "current_complete_paths": sorted(now_complete), "new_complete_paths": sorted(now_complete - old_complete), }, "ui_total": len(rows), "api_paths": api_paths, "excluded": excluded, "summary": summary, "profiles": list(profiles), "cases": rows, "gap_groups": [ { "type": k[0], "provider": k[1], "version": k[2], "profile": k[3], "code": k[4], "rule_gap": k[5], "occurrences": v, } for k, v in sorted(gap_groups.items(), key=lambda item: str(item[0])) ], "production_state_changed": False, "execution_verified": False, } def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--library", action="store_true", help="Audit current manifest UI scope") parser.add_argument("--repo", type=Path, required=True) parser.add_argument("--output", type=Path, required=True) parser.add_argument( "--profile", choices=( ASR_PROFILE, *MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES, *VHS_PROFILES, PROFILE, AUX_PROFILE, PRIMITIVE_PROFILE, PREVIEW_PROFILE, *STRUCTURE_PROFILES, *PROMOTED_PROFILES, CASE04_PROFILE, "case04-batch-reference", "promoted-batch-reference", "structure-batch-reference", ), default=PROFILE, ) args = parser.parse_args() report = audit_library(args.repo) if args.library else audit(args.repo, args.profile) args.output.parent.mkdir(parents=True, exist_ok=True) args.output.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n") print(json.dumps({"reference_only": True, "active_cases": len(report["cases"])})) if __name__ == "__main__": main()