HEL-892: add pinned controlnet aux reference widget conversion
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -18,6 +18,7 @@ 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 (
|
||||
AUX_PROFILE,
|
||||
PROFILE,
|
||||
resolve_reference_link,
|
||||
serialize_reference_widgets,
|
||||
@@ -25,7 +26,7 @@ from calliope.comfyui.serialization_reference import (
|
||||
from calliope.comfyui.ui2api import convert, convert_reference
|
||||
|
||||
|
||||
def audit(repo: Path) -> dict:
|
||||
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():
|
||||
@@ -44,7 +45,7 @@ def audit(repo: Path) -> dict:
|
||||
if node.get("type") in ("Reroute", "Note", "MarkdownNote"):
|
||||
continue
|
||||
try:
|
||||
values = serialize_reference_widgets(node)
|
||||
values = serialize_reference_widgets(node, profile)
|
||||
except ValueError as exc:
|
||||
unsupported.append({"node_id": nid, "type": node["type"], "reason": str(exc)})
|
||||
else:
|
||||
@@ -86,7 +87,7 @@ def audit(repo: Path) -> dict:
|
||||
"differences": differences(expected, endpoint),
|
||||
}
|
||||
)
|
||||
candidate = convert_reference(source)
|
||||
candidate = convert_reference(source, profile)
|
||||
rows.append(
|
||||
{
|
||||
"id": binding["id"],
|
||||
@@ -109,9 +110,19 @@ def audit(repo: Path) -> dict:
|
||||
}
|
||||
)
|
||||
return {
|
||||
"profile": PROFILE,
|
||||
"profile": profile,
|
||||
"authority": "public_reference_only_not_object_info",
|
||||
"comparison_scope": "supported root scalar widgets and legacy root link endpoints only",
|
||||
"reference_conditions": {
|
||||
"unmodified_frontend_widgets_assumed": True,
|
||||
"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,
|
||||
@@ -123,8 +134,9 @@ def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--repo", type=Path, required=True)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
parser.add_argument("--profile", choices=(PROFILE, AUX_PROFILE), default=PROFILE)
|
||||
args = parser.parse_args()
|
||||
report = audit(args.repo)
|
||||
report = 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"])}))
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""Small, explicit public-reference contract, never a target object_info snapshot.
|
||||
|
||||
Sources and limits: docs/hel-892/serialization-evidence/sources.json.
|
||||
Only unmodified scalar core widgets are covered. No plugin, dynamic prompt,
|
||||
seed controller, subgraph, bypass or custom serializeValue is inferred.
|
||||
Sources and limits: docs/hel-892/{serialization-evidence,controlnet-reference}/sources.json.
|
||||
Only explicitly pinned scalar layouts are covered. No dynamic prompt, seed
|
||||
controller, subgraph, bypass or custom serializeValue is inferred.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -10,6 +10,20 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
|
||||
PROFILE = "comfy-frontend-1.37.11-core-reference"
|
||||
AUX_PROFILE = "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference"
|
||||
AUX_COMMIT = "e8b689a513c3e6b63edc44066560ca5919c0576e"
|
||||
# pyproject declares 1.1.5 at AUX_COMMIT; registry artifact mapping and target
|
||||
# installation remain unknown. This opt-in profile assumes unmodified widgets,
|
||||
# including no UE serializer changes. It never verifies dynamic combo membership.
|
||||
_AUX_LAYOUTS = {
|
||||
"AIO_Preprocessor": (("preprocessor", str), ("resolution", int)),
|
||||
"DepthAnythingPreprocessor": (("ckpt_name", str), ("resolution", int)),
|
||||
}
|
||||
_DEPTH_CHECKPOINTS = (
|
||||
"depth_anything_vitl14.pth",
|
||||
"depth_anything_vitb14.pth",
|
||||
"depth_anything_vits14.pth",
|
||||
)
|
||||
|
||||
# Widget construction order, including workflow-only upload button. A None type
|
||||
# is a workflow-persisted widget with options.serialize=false in graphToPrompt.
|
||||
@@ -26,8 +40,8 @@ _LAYOUTS = {
|
||||
}
|
||||
|
||||
|
||||
def reference_definitions() -> dict[str, Any]:
|
||||
"""Only public core reference schemas; no model/file availability assertion."""
|
||||
def reference_definitions(profile: str = PROFILE) -> dict[str, Any]:
|
||||
"""Only opt-in public reference schemas; no model/file availability assertion."""
|
||||
|
||||
def spec(required, outputs, optional=None):
|
||||
return {
|
||||
@@ -38,7 +52,9 @@ def reference_definitions() -> dict[str, Any]:
|
||||
"output": outputs,
|
||||
}
|
||||
|
||||
return {
|
||||
if profile not in (PROFILE, AUX_PROFILE):
|
||||
raise ValueError("未知参考版本")
|
||||
definitions = {
|
||||
"Canny": spec(
|
||||
{"image": "IMAGE", "low_threshold": "FLOAT", "high_threshold": "FLOAT"}, ["IMAGE"]
|
||||
),
|
||||
@@ -57,9 +73,22 @@ def reference_definitions() -> dict[str, Any]:
|
||||
"PreviewImage": spec({"images": "IMAGE"}, []),
|
||||
}
|
||||
|
||||
if profile == AUX_PROFILE:
|
||||
for ct, layout in _AUX_LAYOUTS.items():
|
||||
definitions[ct] = spec(
|
||||
{"image": "IMAGE"},
|
||||
["IMAGE"],
|
||||
{name: "INT" if kind is int else "COMBO" for name, kind in layout},
|
||||
)
|
||||
return definitions
|
||||
|
||||
def serialize_reference_widgets(node: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
def serialize_reference_widgets(node: dict[str, Any], profile: str = PROFILE) -> dict[str, Any]:
|
||||
"""Apply only the pinned identity serializers; reject any extra/missing value."""
|
||||
if profile not in (PROFILE, AUX_PROFILE):
|
||||
raise ValueError("未知参考版本")
|
||||
if profile == AUX_PROFILE and node.get("type") in _AUX_LAYOUTS:
|
||||
return _serialize_aux(node)
|
||||
if node.get("mode", 0) != 0:
|
||||
raise ValueError("静音/旁路不在序列化参考契约内")
|
||||
properties = node.get("properties") or {}
|
||||
@@ -87,6 +116,48 @@ def serialize_reference_widgets(node: dict[str, Any]) -> dict[str, Any]:
|
||||
return result
|
||||
|
||||
|
||||
def _serialize_aux(node: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Pinned optional widget order; no defaults or guessed dynamic options.
|
||||
|
||||
AIO strings are serialized verbatim, with membership explicitly unverified.
|
||||
DepthAnything's static enum proves a declared name, never file availability.
|
||||
Resolution bounds are schema metadata, not a clamp/rounding serializer.
|
||||
"""
|
||||
properties = node.get("properties") or {}
|
||||
if (
|
||||
node.get("mode", 0) != 0
|
||||
or properties.get("cnr_id") != "comfyui_controlnet_aux"
|
||||
or properties.get("ver") != "1.1.5"
|
||||
):
|
||||
raise ValueError("节点提供方/声明版本/模式不符合固定 aux 参考")
|
||||
layout = _AUX_LAYOUTS[node["type"]]
|
||||
values = node.get("widgets_values")
|
||||
if not isinstance(values, list) or len(values) != len(layout):
|
||||
raise ValueError("aux 控件必须为固定的两个标量;不补默认值")
|
||||
result = {}
|
||||
for (name, kind), value in zip(layout, values):
|
||||
if type(value) is not kind:
|
||||
raise ValueError(f"{name} 的类型不符合 aux 标量契约")
|
||||
result[name] = value
|
||||
if (
|
||||
node["type"] == "DepthAnythingPreprocessor"
|
||||
and result["ckpt_name"] not in _DEPTH_CHECKPOINTS
|
||||
):
|
||||
raise ValueError("ckpt_name 不在固定源码静态枚举内")
|
||||
socket_types = {"image": "IMAGE", layout[0][0]: "COMBO", "resolution": "INT"}
|
||||
sockets = node.get("inputs", [])
|
||||
names = [s.get("name") for s in sockets]
|
||||
if len(names) != len(set(names)) or "image" not in names:
|
||||
raise ValueError("aux 输入槽重复或缺少 image")
|
||||
for socket in sockets:
|
||||
if socket.get("type") != socket_types.get(socket.get("name")):
|
||||
raise ValueError("aux 输入槽名称/类型不符合固定参考")
|
||||
widget = socket.get("widget")
|
||||
if widget is not None and widget != {"name": socket["name"]}:
|
||||
raise ValueError("aux 输入控件绑定不符合固定参考")
|
||||
return result
|
||||
|
||||
|
||||
def validate_reroute(node: dict[str, Any]) -> None:
|
||||
if (
|
||||
node.get("mode", 0) != 0
|
||||
|
||||
@@ -13,6 +13,7 @@ from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from .serialization_reference import (
|
||||
AUX_PROFILE,
|
||||
PROFILE,
|
||||
reference_definitions,
|
||||
resolve_reference_link,
|
||||
@@ -38,21 +39,27 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
|
||||
An unknown profile is rejected, not interpreted as a widget-order contract.
|
||||
Public reference definitions cannot establish target execution eligibility.
|
||||
"""
|
||||
if profile != PROFILE or not isinstance(source, dict) or "nodes" not in source:
|
||||
if (
|
||||
profile not in (PROFILE, AUX_PROFILE)
|
||||
or not isinstance(source, dict)
|
||||
or "nodes" not in source
|
||||
):
|
||||
return Conversion(
|
||||
None,
|
||||
[{"code": "invalid_reference_contract", "message": "未知参考版本或不是 UI 图"}],
|
||||
True,
|
||||
)
|
||||
try:
|
||||
result = _convert(source, reference_definitions(), reference=True)
|
||||
result = _convert(
|
||||
source, reference_definitions(profile), reference=True, reference_profile=profile
|
||||
)
|
||||
except (ValueError, TypeError, KeyError, AttributeError, IndexError) as exc:
|
||||
return Conversion(None, [{"code": "invalid_reference_contract", "message": str(exc)}], True)
|
||||
result.reference_only = True
|
||||
return result
|
||||
|
||||
|
||||
def _convert(source, object_info=None, *, reference=False) -> Conversion:
|
||||
def _convert(source, object_info=None, *, reference=False, reference_profile=PROFILE) -> Conversion:
|
||||
issues: list[dict[str, Any]] = []
|
||||
|
||||
def fail(code: str, message: str, node_id: Any = "") -> None:
|
||||
@@ -154,7 +161,7 @@ def _convert(source, object_info=None, *, reference=False) -> Conversion:
|
||||
inputs = {}
|
||||
if reference:
|
||||
try:
|
||||
inputs.update(serialize_reference_widgets(node))
|
||||
inputs.update(serialize_reference_widgets(node, reference_profile))
|
||||
if [s.get("type") for s in node.get("outputs", [])] != spec["output"]:
|
||||
raise ValueError("源输出槽不符合固定参考契约")
|
||||
names = [s.get("name") for s in node.get("inputs", [])]
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
"""Pinned-source contracts and real-source mutations, never target execution."""
|
||||
|
||||
import copy
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from calliope.comfyui.serialization_reference import (
|
||||
AUX_PROFILE,
|
||||
PROFILE,
|
||||
reference_definitions,
|
||||
resolve_reference_link,
|
||||
serialize_reference_widgets,
|
||||
)
|
||||
from calliope.comfyui.ui2api import convert, convert_reference
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def case01():
|
||||
record = json.loads((REPO / "docs/hel-892/supplied-api/manifest.json").read_text())["cases"][0]
|
||||
return json.loads((REPO / record["source_path"]).read_bytes())
|
||||
|
||||
|
||||
def by_id(graph, nid):
|
||||
return next(n for n in graph["nodes"] if n["id"] == nid)
|
||||
|
||||
|
||||
def test_real_full_candidate_includes_all_fields_and_preserves_raw_meta_differences(case01):
|
||||
api = json.loads((REPO / "docs/hel-892/supplied-api/01.api.json").read_bytes())
|
||||
before = copy.deepcopy(case01)
|
||||
result = convert_reference(case01, AUX_PROFILE)
|
||||
assert result.reference_only and not result.issues
|
||||
assert len(result.prompt) == len(api) == 22
|
||||
for nid, node in result.prompt.items():
|
||||
assert node["class_type"] == api[nid]["class_type"]
|
||||
assert node["inputs"] == api[nid]["inputs"]
|
||||
for name, value in node["inputs"].items():
|
||||
assert type(value) is type(api[nid]["inputs"][name])
|
||||
assert node["_meta"]["title"] == (
|
||||
by_id(case01, int(nid)).get("title") or node["class_type"]
|
||||
)
|
||||
assert sum(result.prompt[n]["_meta"] != api[n]["_meta"] for n in api) == 13
|
||||
assert case01 == before
|
||||
assert convert_reference(case01, PROFILE).prompt is None
|
||||
assert convert(case01).prompt is None
|
||||
assert convert(case01, reference_definitions(AUX_PROFILE)).prompt is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("nid", [1, 12, 18, 19, 20, 21, 33, 34, 4])
|
||||
def test_each_real_aux_node_serializes_changed_values_not_api_constants(case01, nid):
|
||||
original_image = convert_reference(case01, AUX_PROFILE).prompt[str(nid)]["inputs"]["image"]
|
||||
node = by_id(case01, nid)
|
||||
field = "ckpt_name" if nid == 4 else "preprocessor"
|
||||
selected = "depth_anything_vits14.pth" if nid == 4 else "none"
|
||||
node["widgets_values"] = [selected, 768]
|
||||
candidate = convert_reference(case01, AUX_PROFILE)
|
||||
assert not candidate.issues
|
||||
assert candidate.prompt[str(nid)]["inputs"][field] == selected
|
||||
assert candidate.prompt[str(nid)]["inputs"]["resolution"] == 768
|
||||
assert candidate.prompt[str(nid)]["inputs"]["image"] == original_image
|
||||
|
||||
|
||||
@pytest.mark.parametrize("nid", [1, 4])
|
||||
@pytest.mark.parametrize(
|
||||
"change",
|
||||
[
|
||||
"provider",
|
||||
"version",
|
||||
"missing_provider",
|
||||
"missing_version",
|
||||
"extra_widget",
|
||||
"missing_widget",
|
||||
"named_widgets",
|
||||
"bool_resolution",
|
||||
"float_resolution",
|
||||
"combo_type",
|
||||
"extra_socket",
|
||||
"wrong_socket_type",
|
||||
"wrong_binding",
|
||||
"duplicate_socket",
|
||||
"missing_image",
|
||||
"wrong_output",
|
||||
"bad_link",
|
||||
"bypass",
|
||||
],
|
||||
)
|
||||
def test_bad_aux_contract_fails_whole_graph(case01, nid, change):
|
||||
node = by_id(case01, nid)
|
||||
if change == "provider":
|
||||
node["properties"]["cnr_id"] = "same_name_other_plugin"
|
||||
elif change == "version":
|
||||
node["properties"]["ver"] = "1.1.6"
|
||||
elif change.startswith("missing_") and change in ("missing_provider", "missing_version"):
|
||||
node["properties"].pop("cnr_id" if change == "missing_provider" else "ver")
|
||||
elif change == "extra_widget":
|
||||
node["widgets_values"].append("unknown")
|
||||
elif change == "missing_widget":
|
||||
node["widgets_values"].pop()
|
||||
elif change == "named_widgets":
|
||||
node["widgets_values"] = {"resolution": 512}
|
||||
elif change == "bool_resolution":
|
||||
node["widgets_values"][1] = True
|
||||
elif change == "float_resolution":
|
||||
node["widgets_values"][1] = 512.0
|
||||
elif change == "combo_type":
|
||||
node["widgets_values"][0] = ["dynamic", "combo"]
|
||||
elif change == "extra_socket":
|
||||
node["inputs"].append({"name": "unknown", "type": "STRING", "link": None})
|
||||
elif change == "wrong_socket_type":
|
||||
node["inputs"][0]["type"] = "MASK"
|
||||
elif change == "wrong_binding":
|
||||
node["inputs"][1]["widget"] = {"name": "resolution"}
|
||||
elif change == "duplicate_socket":
|
||||
node["inputs"].append(copy.deepcopy(node["inputs"][0]))
|
||||
elif change == "missing_image":
|
||||
node["inputs"].pop(0)
|
||||
elif change == "wrong_output":
|
||||
node["outputs"][0]["type"] = "MASK"
|
||||
elif change == "bad_link":
|
||||
node["inputs"][0]["link"] = 9999
|
||||
elif change == "bypass":
|
||||
node["mode"] = 4
|
||||
result = convert_reference(case01, AUX_PROFILE)
|
||||
assert result.reference_only and result.prompt is None and result.issues
|
||||
|
||||
|
||||
def test_dynamic_combo_membership_is_unknown_and_static_enum_is_checked(case01):
|
||||
# Synthetic selection is deliberately NOT asserted to exist in any environment.
|
||||
by_id(case01, 1)["widgets_values"][0] = "UninstalledSyntheticPreprocessor"
|
||||
result = convert_reference(case01, AUX_PROFILE)
|
||||
assert result.prompt["1"]["inputs"]["preprocessor"] == "UninstalledSyntheticPreprocessor"
|
||||
assert result.reference_only
|
||||
assert convert(case01).prompt is None
|
||||
by_id(case01, 4)["widgets_values"][0] = "unlisted.pth"
|
||||
assert convert_reference(case01, AUX_PROFILE).prompt is None
|
||||
|
||||
|
||||
def test_unconnected_optional_slots_may_be_absent_but_values_are_never_defaulted(case01):
|
||||
by_id(case01, 4)["inputs"] = by_id(case01, 4)["inputs"][:1]
|
||||
assert convert_reference(case01, AUX_PROFILE).prompt is not None
|
||||
by_id(case01, 4)["widgets_values"] = []
|
||||
assert convert_reference(case01, AUX_PROFILE).prompt is None
|
||||
|
||||
|
||||
def test_aux_reroute_keeps_nonzero_source_slot_then_rejects_image_type(case01):
|
||||
# Synthetic mutation of the real path: LoadImage MASK output through Reroute.
|
||||
source = by_id(case01, 2)
|
||||
reroute = by_id(case01, 32)
|
||||
lid = reroute["inputs"][0]["link"]
|
||||
link = next(link for link in case01["links"] if link[0] == lid)
|
||||
source["outputs"][0]["links"].remove(lid)
|
||||
source["outputs"][1]["links"] = [lid]
|
||||
link[2] = 1
|
||||
endpoint = resolve_reference_link(
|
||||
{str(n["id"]): n for n in case01["nodes"]},
|
||||
{str(link[0]): link for link in case01["links"]},
|
||||
by_id(case01, 4)["inputs"][0]["link"],
|
||||
)
|
||||
assert endpoint == ["2", 1]
|
||||
result = convert_reference(case01, AUX_PROFILE)
|
||||
assert result.prompt is None
|
||||
assert "link_type_unverified" in {i["code"] for i in result.issues}
|
||||
|
||||
|
||||
def test_existing_reroute_guards_apply_to_extended_profile(case01):
|
||||
by_id(case01, 32)["inputs"][0]["link"] = None
|
||||
assert convert_reference(case01, AUX_PROFILE).prompt is None
|
||||
|
||||
|
||||
def test_unknown_named_node_is_never_globally_registered(case01):
|
||||
by_id(case01, 1)["type"] = "UnknownAux"
|
||||
assert convert_reference(case01, AUX_PROFILE).prompt is None
|
||||
with pytest.raises(ValueError):
|
||||
serialize_reference_widgets(by_id(case01, 4), "invented-profile")
|
||||
Reference in New Issue
Block a user