101 lines
3.9 KiB
Python
101 lines
3.9 KiB
Python
"""Pinned API reference rejects changed audio paths, missing-key repairs and object mutations."""
|
|
|
|
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_Text2Video_20260813_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_every_saved_input_retains_original_type_and_unique_pointer(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",
|
|
[
|
|
"seed",
|
|
"primitive_type",
|
|
"output_index",
|
|
"audio",
|
|
"dict_on",
|
|
"dict_strength",
|
|
"first_frame",
|
|
"title",
|
|
"mode",
|
|
"colon_scope",
|
|
],
|
|
)
|
|
def test_source_mutation_cannot_inherit_reference_trust(mutation):
|
|
g = copy.deepcopy(SOURCE)
|
|
if mutation == "seed":
|
|
g["6061:4967"]["inputs"]["noise_seed"] = 43
|
|
elif mutation == "primitive_type":
|
|
g["221"]["inputs"]["value"] = 10.0
|
|
elif mutation == "output_index":
|
|
g["213"]["inputs"]["latent_image"][1] = 0
|
|
elif mutation == "audio":
|
|
g["5978"]["inputs"]["audio"] = ["209", 0]
|
|
elif mutation == "dict_on":
|
|
g["6010"]["inputs"]["lora_1"]["on"] = 1
|
|
elif mutation == "dict_strength":
|
|
g["6010"]["inputs"]["lora_1"]["strength"] = 1.0
|
|
elif mutation == "first_frame":
|
|
g["219"]["inputs"]["first_frame"] = None
|
|
elif mutation == "title":
|
|
g["5978"]["_meta"]["title"] = "forged"
|
|
elif mutation == "mode":
|
|
g["6059"]["mode"] = 0
|
|
else:
|
|
g["6061"] = {"nodes": [g.pop("6061:4969")]}
|
|
assert not document(g)["fixed_version"]["matched"]
|
|
|
|
|
|
@pytest.mark.parametrize("key", ["PowerLoraLoaderHeaderWidget", "lora_1"])
|
|
def test_complete_objects_are_not_flattened_into_saved_fields(key):
|
|
field = next(f for f in BLOCK["fields"] if f["node_id"] == "6010" and f["field"] == key)
|
|
assert field["json_type"] == "dict"
|
|
assert canonical(field["value"]) == canonical(SOURCE["6010"]["inputs"][key])
|
|
assert len(BLOCK["fields"]) == 72
|
|
assert sum(f["json_type"] == "dict" for f in BLOCK["fields"]) == 2
|
|
|
|
|
|
def test_editorial_cannot_replace_code_pin_or_enable_generation():
|
|
review = copy.deepcopy(REVIEW)
|
|
review["fixed_version_document"]["fields"][0]["value"] = "forged"
|
|
assert not document(review=review)["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_audio_origin_and_declared_missing_input_boundaries_stay_closed():
|
|
assert SOURCE["5978"]["inputs"]["audio"] == ["6063:4848", 0]
|
|
assert SOURCE["6063:4848"]["inputs"]["samples"] == ["6061:4973", 1]
|
|
assert SOURCE["6061:6075"]["inputs"]["audio"] == ["209", 0]
|
|
assert set(SOURCE["219"]["inputs"]) == {"prompt", "width", "height", "length", "clip", "vae"}
|
|
assert all(
|
|
n["scope"] == "root" and not n["implementation_verified"] for n in BLOCK["node_bindings"]
|
|
)
|
|
assert BLOCK["sources"] == BLOCK["comments"] == BLOCK["boundaries"] == []
|