HEL-892: add bounded UI widget serialization and Reroute reference conversion

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
leefer
2026-10-29 23:28:15 +08:00
co-authored by multica-agent
parent f62786f4a0
commit d3c8ab1238
40 changed files with 15372 additions and 3 deletions
@@ -0,0 +1,134 @@
"""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 pathlib import Path
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 (
PROFILE,
resolve_reference_link,
serialize_reference_widgets,
)
from calliope.comfyui.ui2api import convert, convert_reference
def audit(repo: Path) -> 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
nodes = {str(n["id"]): n for n in source["nodes"]}
links = {str(link[0]): link for link in source.get("links", [])}
fields, edges, unsupported = [], [], []
for nid, node in nodes.items():
if node.get("type") in ("Reroute", "Note", "MarkdownNote"):
continue
try:
values = serialize_reference_widgets(node)
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,
"api": expected,
"differences": differences(expected, value),
}
)
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),
}
)
candidate = convert_reference(source)
rows.append(
{
"id": binding["id"],
"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,
"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,
"executable": False,
"execution_verified": False,
}
)
return {
"profile": PROFILE,
"authority": "public_reference_only_not_object_info",
"comparison_scope": "supported root scalar widgets and legacy root link endpoints only",
"target_version_match": "unknown",
"whole_source_equivalence_verified": False,
"execution_verified": False,
"cases": rows,
}
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--repo", type=Path, required=True)
parser.add_argument("--output", type=Path, required=True)
args = parser.parse_args()
report = audit(args.repo)
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()
@@ -0,0 +1,51 @@
"""Verify pinned frontend/core source bytes; never import or execute upstream code."""
from __future__ import annotations
import argparse
import hashlib
import json
from pathlib import Path
from urllib.request import urlopen
def verify(directory: Path, fetch: bool = False) -> dict:
manifest = json.loads((directory / "sources.json").read_text())
verified = []
for source in manifest["sources"]:
path = directory / source["local_file"]
if fetch:
with urlopen(source["raw_url"], timeout=30) as response:
raw = response.read()
else:
raw = path.read_bytes()
if hashlib.sha256(raw).hexdigest() != source["sha256"]:
raise ValueError(f"哈希不一致:{source['id']}")
lines = raw.decode("utf-8").splitlines()
for start, end in source["lines"]:
if not 1 <= start <= end <= len(lines):
raise ValueError(f"行号越界:{source['id']}")
if fetch:
path.write_bytes(raw)
verified.append({"id": source["id"], "sha256": source["sha256"]})
return {
"authority": "public_reference_only",
"sources_verified": verified,
"upstream_code_executed": False,
"target_version_match": "unknown",
}
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--source-dir", type=Path, required=True)
parser.add_argument("--fetch", action="store_true")
parser.add_argument("--output", type=Path, required=True)
args = parser.parse_args()
report = verify(args.source_dir, args.fetch)
args.output.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n")
print(f"verified {len(report['sources_verified'])} sources; no upstream execution")
if __name__ == "__main__":
main()