diff --git a/calliope-backend/scripts/audit_reference_conversion.py b/calliope-backend/scripts/audit_reference_conversion.py index a87365d..4f7b857 100644 --- a/calliope-backend/scripts/audit_reference_conversion.py +++ b/calliope-backend/scripts/audit_reference_conversion.py @@ -44,6 +44,7 @@ from calliope.comfyui.structure_reference import ( SETGET_COMMIT, SETGET_PROFILES, STRUCTURE_PROFILES, + VIDEOINFO_PROFILES, ) from calliope.comfyui.ui2api import convert, convert_reference @@ -299,6 +300,7 @@ REFERENCE_PROFILES = ( *CROP_SPLIT_PROFILES, *VHS_PROFILES, *SETGET_PROFILES, + *VIDEOINFO_PROFILES, ) @@ -502,6 +504,7 @@ def profile_attempt(source, profile): CASE04_PROFILE: "1.53.6", **VHS_PROFILES, **SETGET_PROFILES, + **VIDEOINFO_PROFILES, }.get(profile, "1.37.11") assumptions = { "frontend": expected, @@ -579,7 +582,7 @@ def profile_attempt(source, profile): "serialization-evidence/sources.json", ] base = {"profile": profile, "assumptions": assumptions} - if profile in SETGET_PROFILES: + if profile in (*SETGET_PROFILES, *VIDEOINFO_PROFILES): assumptions["setget_reference"] = { "commit": SETGET_COMMIT, "missing_version": "explicit_fixed_reference_assumption_only", @@ -603,7 +606,29 @@ def profile_attempt(source, profile): } for i, n in enumerate(source.get("nodes", [])) ] - if not any(n.get("type") in ("SetNode", "GetNode") for n in source.get("nodes", [])): + if profile in VIDEOINFO_PROFILES: + assumptions["videoinfo_reference"] = { + "commit": "537f3a02269e14ab4b0350d4189a52034e9a3b12", + "contract": "videoinfo-reference/contract.json", + "composition": "pinned VideoInfoLoaded + old KJ/root/VHS/core; no other versions", + "scalar_values": "unknown; no media or info dictionary evaluated", + } + assumptions["reference_sources"].insert(0, "videoinfo-reference/sources.json") + base["verified_reference_facts"] = "videoinfo-reference/contract.json" + if not any(n.get("type") == "VHS_VideoInfoLoaded" for n in source.get("nodes", [])): + return { + **base, + "status": "not_applicable", + "issues": [ + { + "code": "videoinfo_not_present", + "message": "新组合仅覆盖含VideoInfoLoaded的图", + } + ], + } + if profile in SETGET_PROFILES and not any( + n.get("type") in ("SetNode", "GetNode") for n in source.get("nodes", []) + ): return { **base, "status": "not_applicable", @@ -634,25 +659,26 @@ def profile_attempt(source, profile): ) assumptions["missing_frontend_policy"] = ( "explicit_1.37.11_reference_assumption" - if profile in SETGET_PROFILES + if profile in (*SETGET_PROFILES, *VIDEOINFO_PROFILES) else "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, *SETGET_PROFILES) and expected == "1.48.6": + if profile in (*VHS_PROFILES, *SETGET_PROFILES, *VIDEOINFO_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, *SETGET_PROFILES) + source, + include_aux=profile in (*CROP_SPLIT_PROFILES, *SETGET_PROFILES, *VIDEOINFO_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, *SETGET_PROFILES) + profile in (*VHS_PROFILES, *SETGET_PROFILES, *VIDEOINFO_PROFILES) and expected == "1.48.6" and declared_frontend is None ) or ( @@ -669,6 +695,7 @@ def profile_attempt(source, profile): *CROP_SPLIT_PROFILES, *VHS_PROFILES, *SETGET_PROFILES, + *VIDEOINFO_PROFILES, ) ) ): @@ -694,7 +721,7 @@ def profile_attempt(source, profile): "unresolved_boundaries": result.unresolved_boundaries, **( {"virtual_resolutions": result.virtual_resolutions} - if profile in SETGET_PROFILES + if profile in (*SETGET_PROFILES, *VIDEOINFO_PROFILES) else {} ), } @@ -710,7 +737,7 @@ def profile_attempt(source, profile): "candidate_prompt": result.prompt, **( {"virtual_resolutions": result.virtual_resolutions} - if profile in SETGET_PROFILES + if profile in (*SETGET_PROFILES, *VIDEOINFO_PROFILES) else {} ), **( @@ -798,7 +825,8 @@ def audit_library(repo: Path, profiles=REFERENCE_PROFILES, *, baseline_profiles= for issue in attempt["issues"]: gap_inventory = ( node_inventory(source, include_aux=True) - if attempt["profile"] in (*CROP_SPLIT_PROFILES, *SETGET_PROFILES) + if attempt["profile"] + in (*CROP_SPLIT_PROFILES, *SETGET_PROFILES, *VIDEOINFO_PROFILES) else inventory ) matches = [n for n in gap_inventory if n["node_id"] == issue.get("node_id")] @@ -824,7 +852,9 @@ def audit_library(repo: Path, profiles=REFERENCE_PROFILES, *, baseline_profiles= } if baseline_profiles is None: excluded_profiles = ( - SETGET_PROFILES + VIDEOINFO_PROFILES + if any(p in VIDEOINFO_PROFILES for p in profiles) + else SETGET_PROFILES if any(p in SETGET_PROFILES for p in profiles) else VHS_PROFILES if any(p in VHS_PROFILES for p in profiles) diff --git a/calliope-backend/src/calliope/comfyui/serialization_reference.py b/calliope-backend/src/calliope/comfyui/serialization_reference.py index 4bb01e2..31f87a3 100644 --- a/calliope-backend/src/calliope/comfyui/serialization_reference.py +++ b/calliope-backend/src/calliope/comfyui/serialization_reference.py @@ -14,7 +14,7 @@ import json import math from typing import Any -from .structure_reference import SETGET_PROFILES +from .structure_reference import SETGET_PROFILES, VIDEOINFO_PROFILES MP3_PROFILE = "comfy-frontend-1.37.11-mp3-core-0.11.0-reference" REEL_PROFILE = "comfy-frontend-1.37.11-layerstyle-mixed-core-0.4.0-reference" @@ -102,6 +102,8 @@ def reference_definitions(profile: str = PROFILE) -> dict[str, Any]: "output": outputs, } + if profile in VIDEOINFO_PROFILES: + return {**reference_definitions(next(iter(SETGET_PROFILES))), **videoinfo_definitions()} if profile in SETGET_PROFILES: return {**reference_definitions(PROFILE), **vhs_definitions()} if profile in VHS_PROFILES: @@ -180,6 +182,10 @@ def reference_definitions(profile: str = PROFILE) -> 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 in VIDEOINFO_PROFILES: + if node.get("type") == "VHS_VideoInfoLoaded": + return serialize_videoinfo_node(node) + return serialize_reference_widgets(node, next(iter(SETGET_PROFILES))) if profile in SETGET_PROFILES: if node.get("type") in vhs_definitions(): return serialize_vhs_node(node) @@ -1525,3 +1531,91 @@ def serialize_vhs_node(node): ): raise ValueError("VHS原输出槽索引冲突") return result + + +VIDEOINFO_COMMIT = "537f3a02269e14ab4b0350d4189a52034e9a3b12" +VIDEOINFO_OUTPUTS = ("FLOAT", "INT", "FLOAT", "INT", "INT") +VIDEOINFO_NAMES = ("fps🟦", "frame_count🟦", "duration🟦", "width🟦", "height🟦") + + +def videoinfo_definitions(): + return { + "VHS_VideoInfoLoaded": { + "input": {"required": {"video_info": ["VHS_VIDEOINFO"]}, "optional": {}}, + "output": list(VIDEOINFO_OUTPUTS), + } + } + + +def serialize_videoinfo_node(node): + """Fixed entity schema only; no info dictionary or media is read/evaluated. + + VHS useKVState applies to all VHS_ classes. With no widgets, its restore + is inert and serialize writes {}. LiteGraph's empty [] also restores none. + Sources: videoinfo-reference/sources.json; all five outputs are checked. + """ + props = node.get("properties") or {} + if ( + node.get("type") != "VHS_VideoInfoLoaded" + or props.get("cnr_id") != "comfyui-videohelpersuite" + or props.get("ver") != VIDEOINFO_COMMIT + or props.get("aux_id") is not None + or type(node.get("mode", 0)) is not int + or node.get("mode", 0) != 0 + ): + raise ValueError("VideoInfoLoaded提供方/完整提交/正常模式不符") + for container in (node, props): + if any( + k in container + for k in ( + "widgets", + "widgets_values_named", + "serializeValue", + "comfyDynamic", + "getInputLink", + "resolveInput", + "resolveOutput", + "onExecute", + "isVirtualNode", + "applyToGraph", + "onConfigure", + "onSerialize", + "onNodeCreated", + ) + ): + raise ValueError("VideoInfoLoaded自定义覆盖或额外控件未知") + ue = props.get("ue_properties") or {} + if any( + props.get(k) or ue.get(k) + for k in ( + "widget_ue_connectable", + "input_ue_unconnectable", + ) + ): + raise ValueError("VideoInfoLoaded未知UE绑定") + values = node.get("widgets_values") + if not (type(values) is dict and not values or type(values) is list and not values): + raise ValueError("VideoInfoLoaded仅接受无控件空对象或空数组") + sockets = node.get("inputs") + if not isinstance(sockets, list) or len(sockets) != 1: + raise ValueError("VideoInfoLoaded必须恰有一个video_info输入") + socket = sockets[0] + if ( + socket.get("name") != "video_info" + or socket.get("type") != "VHS_VIDEOINFO" + or socket.get("widget") is not None + or type(socket.get("link")) is not int + or socket["link"] < 0 + ): + raise ValueError("VideoInfoLoaded输入名/类型/绑定/连接不符") + outputs = node.get("outputs") + if not isinstance(outputs, list) or [s.get("type") for s in outputs] != list(VIDEOINFO_OUTPUTS): + raise ValueError("VideoInfoLoaded五个原输出槽类型/顺序不符") + for i, socket in enumerate(outputs): + if socket.get("name") != VIDEOINFO_NAMES[i]: + raise ValueError("VideoInfoLoaded出口原名字/槽顺序不符;不使用显示label推断") + if "slot_index" in socket and ( + type(socket["slot_index"]) is not int or socket["slot_index"] != i + ): + raise ValueError("VideoInfoLoaded原输出槽索引不符") + return {} diff --git a/calliope-backend/src/calliope/comfyui/structure_reference.py b/calliope-backend/src/calliope/comfyui/structure_reference.py index e571b7b..de98d03 100644 --- a/calliope-backend/src/calliope/comfyui/structure_reference.py +++ b/calliope-backend/src/calliope/comfyui/structure_reference.py @@ -18,6 +18,11 @@ SETGET_PROFILES = { f"comfy-frontend-{v}-kj-setget-ab72eda7-vhs-reference": v for v in ("1.37.11", "1.48.6") } +VIDEOINFO_PROFILES = { + f"comfy-frontend-{v}-videoinfo-537f3a02-kj-ab72eda7-vhs-core-reference": v + for v in ("1.37.11", "1.48.6") +} + STRUCTURE_PROFILES = { f"comfy-frontend-{version}-structure-reference": version for version in ("1.48.7", "1.53.6", "1.48.6") diff --git a/calliope-backend/src/calliope/comfyui/ui2api.py b/calliope-backend/src/calliope/comfyui/ui2api.py index bd20657..a7a0eeb 100644 --- a/calliope-backend/src/calliope/comfyui/ui2api.py +++ b/calliope-backend/src/calliope/comfyui/ui2api.py @@ -38,6 +38,7 @@ from .structure_reference import ( PROMOTED_PROFILES, SETGET_PROFILES, STRUCTURE_PROFILES, + VIDEOINFO_PROFILES, expand_reference_subgraphs, project_reference_setget, ) @@ -75,6 +76,7 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion: *CROP_SPLIT_PROFILES, *VHS_PROFILES, *SETGET_PROFILES, + *VIDEOINFO_PROFILES, AUX_PROFILE, PRIMITIVE_PROFILE, PREVIEW_PROFILE, @@ -91,8 +93,8 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion: True, ) try: - if profile in SETGET_PROFILES: - expected = SETGET_PROFILES[profile] + if profile in (*SETGET_PROFILES, *VIDEOINFO_PROFILES): + expected = {**SETGET_PROFILES, **VIDEOINFO_PROFILES}[profile] declared = (source.get("extra") or {}).get("frontendVersion") if declared != expected and not (declared is None and expected == "1.37.11"): raise ValueError("Set/Get前端声明不匹配;缺失仅显式选择1.37.11") @@ -256,6 +258,7 @@ def _convert( CASE04_PROFILE: "1.53.6", **VHS_PROFILES, **SETGET_PROFILES, + **VIDEOINFO_PROFILES, }.get(reference_profile, "1.37.11") if frontend_version is not None and frontend_version != expected_version: fail("reference_frontend_mismatch", "源图声明的前端版本与固定参考不一致") diff --git a/calliope-backend/tests/test_audio_separation_reference.py b/calliope-backend/tests/test_audio_separation_reference.py index 22a0809..386638c 100644 --- a/calliope-backend/tests/test_audio_separation_reference.py +++ b/calliope-backend/tests/test_audio_separation_reference.py @@ -362,7 +362,13 @@ def test_library_actual_delta_keeps_every_old_attempt_and_all_six_golden_compari profiles = tuple( p for p in audit.REFERENCE_PROFILES - if p not in (*audit.CROP_SPLIT_PROFILES, *audit.VHS_PROFILES, *audit.SETGET_PROFILES) + if p + not in ( + *audit.CROP_SPLIT_PROFILES, + *audit.VHS_PROFILES, + *audit.SETGET_PROFILES, + *audit.VIDEOINFO_PROFILES, + ) ) baseline = tuple(p for p in profiles if p != SEPARATION_PROFILE) old = audit.audit_library(REPO, baseline) diff --git a/calliope-backend/tests/test_crop_split_reference.py b/calliope-backend/tests/test_crop_split_reference.py index f41a9e7..f1a8a8d 100644 --- a/calliope-backend/tests/test_crop_split_reference.py +++ b/calliope-backend/tests/test_crop_split_reference.py @@ -352,7 +352,9 @@ def test_two_disjoint_instances_preserve_nodes_links_and_values(profile): def test_all_old_fourteen_profiles_attempts_gaps_and_six_differences_unchanged(): historical_profiles = tuple( - p for p in audit.REFERENCE_PROFILES if p not in (*VHS_PROFILES, *audit.SETGET_PROFILES) + p + for p in audit.REFERENCE_PROFILES + if p not in (*VHS_PROFILES, *audit.SETGET_PROFILES, *audit.VIDEOINFO_PROFILES) ) profiles = tuple(p for p in historical_profiles if p not in CROP_SPLIT_PROFILES) historical = json.loads((REPO / "docs/hel-892/separation-evidence/library.json").read_bytes()) diff --git a/calliope-backend/tests/test_setget_reference.py b/calliope-backend/tests/test_setget_reference.py index 8443015..a28732b 100644 --- a/calliope-backend/tests/test_setget_reference.py +++ b/calliope-backend/tests/test_setget_reference.py @@ -330,7 +330,7 @@ def test_wrong_frontend_missing_policy_and_profile_inventory(): g = synthetic() g["extra"] = {"frontendVersion": v} assert convert_reference(g, PROFILE).prompt is None - assert len(audit.REFERENCE_PROFILES) == 20 + assert len([p for p in audit.REFERENCE_PROFILES if p not in audit.VIDEOINFO_PROFILES]) == 20 @pytest.mark.parametrize("profile", SETGET_PROFILES) @@ -404,7 +404,11 @@ def test_combined_structure_rejects_other_graph_overrides_and_cycles(mutation): def test_historical_18_profiles_attempts_gaps_and_six_comparisons_unchanged(): old = json.loads((REPO / "docs/hel-892/vhs-evidence/library.json").read_bytes()) - baseline = tuple(p for p in audit.REFERENCE_PROFILES if p not in SETGET_PROFILES) + baseline = tuple( + p + for p in audit.REFERENCE_PROFILES + if p not in (*SETGET_PROFILES, *audit.VIDEOINFO_PROFILES) + ) now = audit.audit_library(REPO, baseline_profiles=baseline) actual_old = audit.audit_library(REPO, baseline) assert len(baseline) == 18 diff --git a/calliope-backend/tests/test_vhs_reference.py b/calliope-backend/tests/test_vhs_reference.py index 42a0963..9145340 100644 --- a/calliope-backend/tests/test_vhs_reference.py +++ b/calliope-backend/tests/test_vhs_reference.py @@ -287,7 +287,9 @@ def test_old_sixteen_attempts_gaps_candidates_and_six_comparisons_protected(): old = json.loads((REPO / "docs/hel-892/crop-split-evidence/library.json").read_bytes()) # Freeze this batch's 18-profile history; Set/Get has separate current protection. historical_profiles = tuple( - p for p in audit.REFERENCE_PROFILES if p not in audit.SETGET_PROFILES + p + for p in audit.REFERENCE_PROFILES + if p not in (*audit.SETGET_PROFILES, *audit.VIDEOINFO_PROFILES) ) profiles = tuple(p for p in historical_profiles if p not in VHS_PROFILES) baseline = audit.audit_library(REPO, profiles) diff --git a/calliope-backend/tests/test_videoinfo_reference.py b/calliope-backend/tests/test_videoinfo_reference.py new file mode 100644 index 0000000..2f2057e --- /dev/null +++ b/calliope-backend/tests/test_videoinfo_reference.py @@ -0,0 +1,317 @@ +"""Pinned schema and saved graph transformations; never evaluate media/history.""" + +from __future__ import annotations + +import ast +import copy +import json +from pathlib import Path + +import pytest +from scripts import audit_reference_conversion as audit +from scripts.verify_frontend_sources import verify + +from calliope.comfyui.serialization_reference import ( + VIDEOINFO_COMMIT, + VIDEOINFO_NAMES, + VIDEOINFO_OUTPUTS, + serialize_videoinfo_node, +) +from calliope.comfyui.structure_reference import VIDEOINFO_PROFILES +from calliope.comfyui.ui2api import convert, convert_reference +from tests.test_setget_reference import connect, virtual +from tests.test_vhs_reference import synthetic as vhs_graph + +REPO = Path(__file__).resolve().parents[2] +ROOT = REPO / "docs/hel-892/videoinfo-reference" +PROFILE = next(iter(VIDEOINFO_PROFILES)) + + +def entity(nid=546): + return { + "id": nid, + "type": "VHS_VideoInfoLoaded", + "mode": 0, + "properties": {"cnr_id": "comfyui-videohelpersuite", "ver": VIDEOINFO_COMMIT}, + "widgets_values": {}, + "inputs": [{"name": "video_info", "type": "VHS_VIDEOINFO", "link": None}], + "outputs": [ + {"name": name, "type": t, "links": []} + for name, t in zip(VIDEOINFO_NAMES, VIDEOINFO_OUTPUTS) + ], + } + + +def graph(slot=2): + g = vhs_graph() + g["nodes"] += [ + entity(), + virtual(568, "SetNode", "metric", "FLOAT"), + virtual(535, "GetNode", "metric", "FLOAT"), + ] + connect(g, 10, 17, 3, 546, 0, "VHS_VIDEOINFO") + connect(g, 11, 546, slot, 568, 0, "FLOAT") + connect(g, 12, 535, 0, 12, 4, "FLOAT") + return g + + +def test_original_schema_ast_and_full_registration_not_execution(): + assert len(verify(ROOT)["sources_verified"]) == 6 + tree = ast.parse((ROOT / "videohelpersuite__nodes.py").read_text()) + cls = next(n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == "VideoInfoLoaded") + assigns = {n.targets[0].id: n.value for n in cls.body if isinstance(n, ast.Assign)} + assert ast.literal_eval(assigns["RETURN_TYPES"]) == VIDEOINFO_OUTPUTS + assert ast.literal_eval(assigns["RETURN_NAMES"]) == ( + "fps🟦", + "frame_count🟦", + "duration🟦", + "width🟦", + "height🟦", + ) + schema = next(n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name == "INPUT_TYPES") + assert ast.literal_eval(schema.body[0].value) == { + "required": {"video_info": ("VHS_VIDEOINFO",)} + } + method = next( + n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name == "get_video_info" + ) + assert ast.literal_eval(method.body[0].value) == [ + "fps", + "frame_count", + "duration", + "width", + "height", + ] + assert "loaded_info.append(video_info[f'loaded_{key}'])" in ast.unparse(method) + assert ( + '"VHS_VideoInfoLoaded": VideoInfoLoaded,' + in (ROOT / "videohelpersuite__nodes.py").read_text() + ) + js = (ROOT / "web__js__VHS.core.js").read_text() + assert 'if(nodeData?.name?.startsWith("VHS_"))' in js + assert "info.widgets_values = {};" in js + assert "if (!this.widgets)" in js + + +@pytest.mark.parametrize("profile", VIDEOINFO_PROFILES) +@pytest.mark.parametrize("slot", [0, 2]) +@pytest.mark.parametrize("empty", [{}, []]) +def test_nonzero_slots_external_precedence_no_scalar_invention(profile, slot, empty): + g = graph(slot) + g["extra"] = {"frontendVersion": VIDEOINFO_PROFILES[profile]} + g["nodes"][2]["widgets_values"] = empty + original = copy.deepcopy(g) + r = convert_reference(g, profile) + assert r.prompt is not None, r.issues + assert r.prompt["546"]["inputs"] == {"video_info": ["17", 3]} + assert r.prompt["12"]["inputs"]["frame_rate"] == ["546", slot] + assert set(r.prompt) == {"12", "17", "546"} + assert "568" not in r.prompt and "535" not in r.prompt + assert r.reference_only and convert(g).prompt is None + assert g == original + g["nodes"][1]["widgets_values"]["frame_rate"] = 49 + assert convert_reference(g, profile).prompt["12"]["inputs"]["frame_rate"] == ["546", slot] + + +@pytest.mark.parametrize( + "mutation", + [ + "version", + "release", + "provider", + "aux", + "mode", + "bool_mode", + "missing_input", + "extra_input", + "name", + "type", + "widget", + "null_link", + "bool_link", + "extra_widgets", + "missing_widgets", + "null_widgets", + "scalar_widgets", + "output_order", + "output_count", + "same_type_swapped_names", + "unused_output_type", + "slot_bool", + "slot_wrong", + "output_bad_reverse", + "input_bad_reverse", + "edge_bool_slot", + "edge_type", + "node_override", + "props_override", + "ue", + "literal_aux", + "missing_set", + "duplicate_set", + "unknown_loader", + "frontend", + "nested", + ], +) +def test_mutations_close_whole_graph(mutation): + g = graph() + n = g["nodes"][2] + if mutation == "version": + n["properties"]["ver"] = "4ee72c065db22c9d96c2427954dc69e7b908444b" + elif mutation == "release": + n["properties"]["ver"] = "1.7.9" + elif mutation == "provider": + n["properties"]["cnr_id"] = "other" + elif mutation == "aux": + n["properties"]["aux_id"] = "VHS_VideoInfoLoaded" + elif mutation == "mode": + n["mode"] = 4 + elif mutation == "bool_mode": + n["mode"] = False + elif mutation == "missing_input": + n["inputs"] = [] + elif mutation == "extra_input": + n["inputs"].append(copy.deepcopy(n["inputs"][0])) + elif mutation == "name": + n["inputs"][0]["name"] = "info" + elif mutation == "type": + n["inputs"][0]["type"] = "ANY" + elif mutation == "widget": + n["inputs"][0]["widget"] = {"name": "video_info"} + elif mutation == "null_link": + n["inputs"][0]["link"] = None + elif mutation == "bool_link": + n["inputs"][0]["link"] = True + elif mutation == "extra_widgets": + n["widgets_values"] = {"fps": 30} + elif mutation == "missing_widgets": + n.pop("widgets_values") + elif mutation == "null_widgets": + n["widgets_values"] = None + elif mutation == "scalar_widgets": + n["widgets_values"] = "" + elif mutation == "output_order": + n["outputs"][0], n["outputs"][1] = n["outputs"][1], n["outputs"][0] + elif mutation == "same_type_swapped_names": + n["outputs"][0]["name"], n["outputs"][2]["name"] = ( + n["outputs"][2]["name"], + n["outputs"][0]["name"], + ) + elif mutation == "output_count": + n["outputs"].pop() + elif mutation == "unused_output_type": + n["outputs"][4]["type"] = "FLOAT" + elif mutation == "slot_bool": + n["outputs"][0]["slot_index"] = False + elif mutation == "slot_wrong": + n["outputs"][4]["slot_index"] = 3 + elif mutation == "output_bad_reverse": + n["outputs"][2]["links"] = [] + elif mutation == "input_bad_reverse": + n["inputs"][0]["link"] = 999 + elif mutation == "edge_bool_slot": + g["links"][2][4] = False + elif mutation == "edge_type": + g["links"][3][5] = "INT" + elif mutation == "node_override": + n["onConfigure"] = "custom" + elif mutation == "props_override": + n["properties"]["serializeValue"] = "custom" + elif mutation == "ue": + n["properties"]["ue_properties"] = {"widget_ue_connectable": {"x": True}} + elif mutation == "literal_aux": + g["nodes"][3]["properties"]["aux_id"] = "SetNode" + elif mutation == "missing_set": + g["nodes"][3]["widgets_values"] = ["else"] + elif mutation == "duplicate_set": + other = copy.deepcopy(g["nodes"][3]) + other["id"] = 569 + other["inputs"][0]["link"] = None + g["nodes"].append(other) + elif mutation == "unknown_loader": + g["nodes"][0]["properties"]["ver"] = VIDEOINFO_COMMIT + elif mutation == "frontend": + g["extra"] = {"frontendVersion": "1.53.6"} + elif mutation == "nested": + g["definitions"] = {"subgraphs": [{"id": "unknown"}]} + r = convert_reference(g, PROFILE) + assert r.prompt is None and r.issues, mutation + + +def test_multiple_entities_names_and_nonzero_reroute_do_not_cross(): + g = graph(2) + g["nodes"] += [ + entity(101), + virtual(104, "SetNode", "second", "FLOAT"), + virtual(121, "GetNode", "second", "FLOAT"), + { + "id": 600, + "type": "Reroute", + "widgets_values": [], + "inputs": [{"name": "", "type": "FLOAT", "link": None}], + "outputs": [{"name": "", "type": "FLOAT", "links": []}], + }, + ] + connect(g, 13, 17, 3, 101, 0, "VHS_VIDEOINFO") + connect(g, 14, 101, 0, 600, 0, "FLOAT") + connect(g, 15, 600, 0, 104, 0, "FLOAT") + assert convert_reference(g, PROFILE).prompt["12"]["inputs"]["frame_rate"] == ["546", 2] + g["nodes"][4]["widgets_values"] = ["second"] + r = convert_reference(g, PROFILE) + assert r.prompt is not None, r.issues + assert r.prompt["12"]["inputs"]["frame_rate"] == ["101", 0] + assert r.prompt["101"]["inputs"] == {"video_info": ["17", 3]} + + +def test_real_entities_strict_source_schema_and_old_profiles_stay_frozen(): + old = json.loads((REPO / "docs/hel-892/setget-evidence/library.json").read_bytes()) + for row in old["cases"]: + if "Scail-2" not in row["source_path"]: + continue + source = json.loads((REPO / row["source_path"]).read_bytes()) + n = next(n for n in source["nodes"] if n["type"] == "VHS_VideoInfoLoaded") + assert serialize_videoinfo_node(n) == {} + result = convert_reference(source, PROFILE) + assert result.prompt is None and result.issues + assert all(a["status"] != "complete_reference_candidate" for a in row["attempts"]) + assert len(audit.REFERENCE_PROFILES) == 22 + assert tuple(audit.REFERENCE_PROFILES[:20]) == tuple(old["profiles"]) + + +@pytest.mark.parametrize("slot", range(5)) +def test_all_five_types_propagate_through_known_alias_and_reroute(slot): + from calliope.comfyui.structure_reference import project_reference_setget + + g = graph() + typ = VIDEOINFO_OUTPUTS[slot] + for n in g["nodes"][3:]: + for socket in n["inputs"] + n["outputs"]: + socket["type"] = socket["name"] = typ + g["nodes"][2]["outputs"][2]["links"] = [] + g["nodes"][2]["outputs"][slot]["links"] = [11] + g["nodes"][1]["inputs"][4]["type"] = typ + g["links"][3][2] = slot + for edge in g["links"][3:]: + edge[5] = typ + g["nodes"].append( + { + "id": 600, + "type": "Reroute", + "widgets_values": [], + "inputs": [{"name": "", "type": typ, "link": 11}], + "outputs": [{"name": "", "type": typ, "links": [13]}], + } + ) + g["links"][3][3:5] = [600, 0] + g["nodes"][3]["inputs"][0]["link"] = 13 + g["links"].append([13, 600, 0, 568, 0, typ]) + projected = project_reference_setget(g) + assert projected.graph is not None, projected.issues + resolution = projected.resolved[0] + assert resolution["endpoint"] == ["546", slot] + node = next(n for n in projected.graph["nodes"] if n["id"] == 546) + assert node["outputs"][slot]["type"] == typ + # INT endpoints are typed topology evidence, not FLOAT coercion for Combine. + result = convert_reference(g, PROFILE) + assert (result.prompt is not None) == (typ == "FLOAT")