136 lines
5.7 KiB
Python
136 lines
5.7 KiB
Python
"""Every original typed value and scope survives, while trust stays closed to mutations."""
|
|
|
|
import copy
|
|
import hashlib
|
|
import json
|
|
import runpy
|
|
import sys
|
|
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/6-动作迁移/Wan2.2_Animate_人物遮罩替换(官流整理).json"
|
|
OUT = ROOT / "docs/hel-892/animate-mask-document-evidence"
|
|
RAW = (ROOT / PATH).read_bytes()
|
|
SOURCE = json.loads(RAW)
|
|
REVIEW = review_for(PATH, hashlib.sha1(RAW).hexdigest())
|
|
BLOCK = REVIEW["fixed_version_document"]
|
|
|
|
|
|
def at(obj, pointer):
|
|
for k in pointer.strip("/").split("/"):
|
|
key = k.replace("~1", "/").replace("~0", "~")
|
|
obj = obj[int(key)] if isinstance(obj, list) else obj[key]
|
|
return obj
|
|
|
|
|
|
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_value_has_its_original_pointer_and_type(field):
|
|
value = at(SOURCE, field["pointer"])
|
|
assert type(value).__name__ == field["json_type"]
|
|
assert canonical(value) == canonical(field["value"])
|
|
assert field["named_state"] == "missing"
|
|
assert "named_pointer" not in field and "named_value" not in field
|
|
rendered = document()["fixed_version"]["fields"]
|
|
assert next(f for f in rendered if f["pointer"] == field["pointer"]) == field
|
|
|
|
|
|
@pytest.mark.parametrize("note", BLOCK["comments"], ids=lambda n: n["node_id"])
|
|
def test_complete_note_utf8_and_line_endings_survive(note):
|
|
original = at(SOURCE, note["pointer"])
|
|
assert original == note["text"]
|
|
exported = next(n for n in document()["source_notes"] if str(n["node_id"]) == note["node_id"])
|
|
assert exported["content"] == [original]
|
|
assert (
|
|
hashlib.sha256(exported["content"][0].encode()).digest()
|
|
== hashlib.sha256(original.encode()).digest()
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("mutation", ["value", "proxy", "boundary", "note", "unknown_mode"])
|
|
def test_original_graph_mutations_do_not_inherit_trust(mutation):
|
|
source = copy.deepcopy(SOURCE)
|
|
if mutation == "value":
|
|
source["nodes"][0]["widgets_values"][0] += 1
|
|
elif mutation == "proxy":
|
|
host = next(n for n in source["nodes"] if n["id"] == 232)
|
|
host["properties"]["proxyWidgets"][0][1] = "forged"
|
|
elif mutation == "boundary":
|
|
source["definitions"]["subgraphs"][0]["outputs"][0]["linkIds"].append(99999)
|
|
elif mutation == "note":
|
|
next(n for n in source["nodes"] if n["id"] == 161)["widgets_values"][0] += "\n"
|
|
else:
|
|
next(n for n in source["nodes"] if n["id"] == 430)["mode"] = 0
|
|
assert not document(source)["fixed_version"]["matched"]
|
|
assert not document(source)["status"]["exec_verified"]
|
|
|
|
|
|
def test_rehashed_editorial_cannot_replace_code_owned_pin():
|
|
review = copy.deepcopy(REVIEW)
|
|
review["fixed_version_document"]["user_overview"] = "forged"
|
|
review["fixed_version_document"]["canonical_sha256"] = hashlib.sha256(
|
|
canonical(SOURCE)
|
|
).hexdigest()
|
|
assert not document(review=review)["fixed_version"]["matched"]
|
|
|
|
|
|
def test_exact_build_source_audit_and_closed_qualification():
|
|
assert (
|
|
hashlib.sha256(RAW).hexdigest()
|
|
== "394c3c31ad05255d3eb130f309d8445764f4d3772b40fa07fbf19708bfcc1002"
|
|
)
|
|
sys.path.insert(0, str(OUT))
|
|
try:
|
|
build = runpy.run_path(str(OUT / "build_definition.py"))["build"]
|
|
assert canonical(build()) == canonical(BLOCK)
|
|
runpy.run_path(str(OUT / "verify_sources.py"))["main"]()
|
|
finally:
|
|
sys.path.remove(str(OUT))
|
|
assert DEFINITIONS[PATH] == hashlib.sha256(canonical(BLOCK)).hexdigest()
|
|
doc = document()
|
|
assert doc["fixed_version"]["matched"]
|
|
assert not doc["status"]["doc_done"] and not doc["status"]["exec_verified"]
|
|
assert doc["dependencies"]["check_state"] == "unchecked"
|
|
|
|
|
|
def test_proxy_empty_hosts_and_definition_values_are_separate():
|
|
assert [len(b["proxy_mappings"]) for b in BLOCK["boundaries"]] == [9, 10, 11]
|
|
for boundary in BLOCK["boundaries"]:
|
|
assert boundary["host"]["widgets_values"] == boundary["widgets"] == []
|
|
for mapping in boundary["proxy_mappings"]:
|
|
assert not mapping["host_value_generated"]
|
|
assert canonical(at(SOURCE, mapping["internal_saved_pointer"])) == canonical(
|
|
mapping["internal_saved_value"]
|
|
)
|
|
first, second, third = BLOCK["boundaries"]
|
|
assert "cfg" in [p["field"] for p in first["proxy_mappings"]]
|
|
assert "cfg" not in [p["field"] for p in second["proxy_mappings"]]
|
|
assert "cfg" in [p["field"] for p in third["proxy_mappings"]]
|
|
|
|
|
|
def test_three_exact_entry_gaps_remain_specific_and_do_not_borrow_later_versions():
|
|
gaps = [n for n in BLOCK["node_bindings"] if n["source_id"].startswith("unresolved-")]
|
|
assert {n["node_id"] for n in gaps} == {"232:62", "375:362", "409:428"}
|
|
assert all(n["source_version"] == "0.3.59" and not n["candidates"] for n in gaps)
|
|
unknown = [n for n in BLOCK["node_bindings"] if n["node_id"] == "430"][0]
|
|
assert unknown["source_id"] == "unknown-no-version"
|
|
|
|
|
|
def test_points_negative_output_empty_video_info_and_cache_types_stay_distinct():
|
|
nodes = {n["id"]: n for n in SOURCE["nodes"]}
|
|
assert nodes[229]["outputs"][0]["links"] == [438]
|
|
assert all(o["links"] is None for o in nodes[229]["outputs"][1:])
|
|
assert nodes[229]["widgets_values"][-2:] == ["", None]
|
|
assert nodes[417]["widgets_values"] == {}
|
|
assert type(nodes[412]["widgets_values"][0]) is int
|
|
assert type(nodes[416]["widgets_values"][0]) is str
|
|
assert nodes[416]["widgets_values"][0] == "16.0"
|