"""Extend reference trust preserves null, independent references and execution boundaries.""" import copy import hashlib import json from pathlib import Path import pytest from calliope.comfyui.fixed_document import DEFINITIONS, canonical from calliope.comfyui.library import build_document from calliope.comfyui.source_reviews import review_for ROOT = Path(__file__).resolve().parents[2] PATH = "example_ComfyUI_workflows/MiniMax-H3-Turbo-R2V-Extend-2Refs1Vid_API.json" RAW = (ROOT / PATH).read_bytes() SOURCE = json.loads(RAW) REVIEW = review_for(PATH, hashlib.sha1(RAW).hexdigest()) BLOCK = REVIEW["fixed_version_document"] def document(source=SOURCE, review=REVIEW): return build_document(PATH, source, None, None, [], review) @pytest.mark.parametrize("field", BLOCK["fields"], ids=lambda f: f["pointer"]) def test_original_type_and_unique_named_pointer_including_null(field): original = SOURCE[field["node_id"]]["inputs"][field["field"]] assert type(original).__name__ == field["json_type"] assert canonical(original) == canonical(field["value"]) assert field["pointer"] == f"/{field['node_id']}/inputs/{field['field']}" assert not {"named_value", "named_pointer", "widget_index"}.intersection(field) assert document()["fixed_version"]["matched"] @pytest.mark.parametrize( "mutation", [ "swap_references", "missing_null", "empty_null", "wrong_context", "video_audio_zero", "video_audio_one", "latent_zero", "save_false", "trigger_l", "trim", "delimiter_empty", "fps_direct", "dimensions_external", "flatten_reference", "primitive_type", "title", "mode", ], ) def test_mutated_source_never_inherits_trust(mutation): g = copy.deepcopy(SOURCE) if mutation == "swap_references": g["6188"]["inputs"]["image_1"], g["6188"]["inputs"]["image_2"] = ["6091", 0], ["6090", 0] elif mutation == "missing_null": g["6188"]["inputs"].pop("Update inputs") elif mutation == "empty_null": g["6188"]["inputs"]["Update inputs"] = "" elif mutation == "wrong_context": g["6187"]["inputs"]["context_latent"] = ["6190", 1] elif mutation in {"video_audio_zero", "video_audio_one"}: g["6190"]["inputs"]["audio"][1] = 0 if mutation.endswith("zero") else 1 elif mutation == "latent_zero": g["125"]["inputs"]["latent_image"][1] = 0 elif mutation == "save_false": g["6110"]["inputs"]["save_output"] = False elif mutation == "trigger_l": g["6127"]["inputs"]["string_a"] = g["6127"]["inputs"]["string_a"].replace( "r34i1sm", "r34l1sm" ) elif mutation == "trim": g["6127"]["inputs"]["string_a"] = g["6127"]["inputs"]["string_a"].strip() elif mutation == "delimiter_empty": g["6127"]["inputs"]["delimiter"] = "" elif mutation == "fps_direct": g["6110"]["inputs"]["frame_rate"] = 24 elif mutation == "dimensions_external": g["6090"]["inputs"]["width"] = ["115", 0] elif mutation == "flatten_reference": g["6187"]["inputs"]["ref_images.ref_image_0"] = g["6187"]["inputs"].pop("ref_images") elif mutation == "primitive_type": g["132"]["inputs"]["value"] = 12.0 elif mutation == "title": g["6190"]["_meta"]["title"] = "forged" else: g["125"]["mode"] = 0 assert not document(g)["fixed_version"]["matched"] def test_editorial_rehash_cannot_replace_code_pin_or_enable_execution(): r = copy.deepcopy(REVIEW) r["fixed_version_document"]["fields"][0]["value"] = "forged" assert not document(review=r)["fixed_version"]["matched"] assert DEFINITIONS[PATH] == hashlib.sha256(canonical(BLOCK)).hexdigest() assert not document()["status"]["doc_done"] and not document()["status"]["exec_verified"] def test_extend_null_audio_and_final_decode_are_independent_original_facts(): assert SOURCE["6188"]["inputs"]["Update inputs"] is None assert SOURCE["6190"]["inputs"]["audio"] == ["6191", 2] assert SOURCE["125"]["inputs"]["latent_image"] == ["6187", 1] assert SOURCE["6187"]["inputs"]["ref_images"] == ["6188", 0] assert SOURCE["6110"]["inputs"]["frame_rate"] == ["5650", 0] assert SOURCE["6110"]["inputs"]["audio"] == ["6193", 0] assert SOURCE["6110"]["inputs"]["save_output"] is True assert SOURCE["6147"]["inputs"]["image"] == SOURCE["6148"]["inputs"]["image"] assert SOURCE["6127"]["inputs"]["string_a"] == "r34i1sm , ultra realistic video. " assert SOURCE["6127"]["inputs"]["delimiter"] == " " and SOURCE["138"]["inputs"]["value"] == "" assert BLOCK["sources"] == BLOCK["comments"] == BLOCK["boundaries"] == []