97 lines
3.6 KiB
Python
97 lines
3.6 KiB
Python
"""Character Sheet API reference preserves missing keys and rejects forged execution assumptions."""
|
|
|
|
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/krea2_T2I_CharSheetV1_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_named_value_type_and_unique_pointer(field):
|
|
value = SOURCE[field["node_id"]]["inputs"][field["field"]]
|
|
assert type(value).__name__ == field["json_type"]
|
|
assert canonical(value) == 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",
|
|
[
|
|
"scalar",
|
|
"type",
|
|
"model",
|
|
"title",
|
|
"mode",
|
|
"identity",
|
|
"widget",
|
|
"node_id",
|
|
"pixels",
|
|
"latent",
|
|
],
|
|
)
|
|
def test_mutated_source_cannot_inherit_reference_trust(mutation):
|
|
source = copy.deepcopy(SOURCE)
|
|
if mutation == "scalar":
|
|
source["85"]["inputs"]["grounding_px"] = 0
|
|
elif mutation == "type":
|
|
source["120"]["inputs"]["ref_boost"] = 1.0
|
|
elif mutation == "model":
|
|
source["53"]["inputs"]["model"] = ["159", 0]
|
|
elif mutation == "title":
|
|
source["119"]["_meta"]["title"] = "forged"
|
|
elif mutation == "mode":
|
|
source["117"]["mode"] = 0
|
|
elif mutation == "identity":
|
|
source["123"]["properties"] = {"ver": "forged-core"}
|
|
elif mutation == "widget":
|
|
source["135"]["widgets_values"] = [1536, 1024, 1]
|
|
elif mutation == "node_id":
|
|
source["171:153"] = source.pop("153")
|
|
elif mutation == "pixels":
|
|
source["117"]["inputs"]["pixels"] = None
|
|
else:
|
|
source["53"]["inputs"]["latent_image"] = ["73", 0]
|
|
assert not document(source)["fixed_version"]["matched"]
|
|
|
|
|
|
def test_editorial_rehash_cannot_replace_pin_or_unlock_qualification():
|
|
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_second_latent_patch_missing_pixels_and_true_switch_remain_distinct():
|
|
assert SOURCE["53"]["inputs"]["latent_image"] == ["135", 0]
|
|
assert SOURCE["120"]["inputs"]["source_latent"] == ["73", 0]
|
|
assert "pixels" not in SOURCE["117"]["inputs"]
|
|
assert not {"117", "121"}.intersection(e["source_node_id"] for e in BLOCK["api_references"])
|
|
assert SOURCE["161"]["inputs"]["value"] is True
|
|
assert SOURCE["156"]["inputs"]["value"] == ""
|
|
assert SOURCE["85"]["inputs"]["grounding_px"] == 768
|
|
assert SOURCE["119"]["inputs"]["grounding_px"] == 0
|
|
assert all(
|
|
n["node_id"].isdecimal() and n["scope"] == "root" and not n["implementation_verified"]
|
|
for n in BLOCK["node_bindings"]
|
|
)
|
|
assert BLOCK["sources"] == BLOCK["comments"] == BLOCK["boundaries"] == []
|