HEL-892: document pinned Z-Image ControlNet outpaint workflow

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
leefer
2026-10-31 15:14:30 +08:00
co-authored by multica-agent
parent c93966eea6
commit e5af206c82
190 changed files with 121072 additions and 1 deletions
@@ -15,6 +15,9 @@ DEFINITION_SHA256 = "c4c7f04fde29dc7485a341207397fcf6191e3fcbe89ecc2d238f4a4f5bc
# Explicit path allowlist; a recomputed caller-supplied digest cannot extend trust.
DEFINITIONS = {
(
"example_ComfyUI_workflows/3-图像生成/Z-Image/7_Z-image+Controlnet_图像扩展.json"
): "8269ab3997361a558eac9cdfdee111c1509d361ca91a26d468c4f45d5c6c0b03",
(
"example_ComfyUI_workflows/3-图像生成/Z-Image/6_Z-image_局部重绘.json"
): "f77d2387a242346c82be09f1b3795f24a8531876e7f4dceabd46297aedf5979d",
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,162 @@
"Exact graph binding, all saved positions, dual scopes and closed eligibility."
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
REPO = Path(__file__).resolve().parents[2]
OUT = REPO / "docs/hel-892/zimage-outpaint-document-evidence"
PATH = "example_ComfyUI_workflows/3-图像生成/Z-Image/7_Z-image+Controlnet_图像扩展.json"
RAW = (REPO / PATH).read_bytes()
SOURCE = json.loads(RAW)
REVIEW = review_for(PATH, hashlib.sha1(RAW).hexdigest())
BLOCK = REVIEW["fixed_version_document"]
def pointer(obj, p):
for x in p.strip("/").split("/"):
obj = obj[int(x)] if isinstance(obj, list) else obj[x]
return obj
def doc(s=SOURCE, r=REVIEW):
return build_document(PATH, s, None, None, [], r)
@pytest.mark.parametrize("f", BLOCK["fields"], ids=lambda f: f["node_id"] + "." + f["field"])
def test_each_saved_position_and_citation(f):
assert canonical(pointer(SOURCE, f["pointer"])) == canonical(f["value"])
assert type(pointer(SOURCE, f["pointer"])).__name__ == f["json_type"]
assert "无widgets_values_named" in f["named_pointer"] and "named_value" not in f
assert all(
f[k] for k in ["label", "unit", "limits", "schema_default", "effect", "execution_note"]
)
if f["input_pointer"].startswith("/"):
assert pointer(SOURCE, f["input_pointer"])["name"] == f["input_name"]
for i in f["evidence"]:
e = BLOCK["sources"][i]
raw = (OUT / e["local_file"]).read_bytes()
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
assert 1 <= e["lines"][0] <= e["lines"][1] <= len(raw.decode().splitlines())
@pytest.mark.parametrize("f", BLOCK["fields"], ids=lambda f: f["node_id"] + "." + f["field"])
@pytest.mark.parametrize("variant", ["source", "text"])
def test_caller_rehash_cannot_expand_trust(f, variant):
s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW)
if variant == "text":
r["fixed_version_document"]["fields"][BLOCK["fields"].index(f)]["effect"] = "forged"
else:
p, _, key = f["pointer"].rpartition("/")
pointer(s, p)[int(key)] = "forged"
r["fixed_version_document"]["canonical_sha256"] = hashlib.sha256(canonical(s)).hexdigest()
assert not doc(s, r)["fixed_version"]["matched"]
@pytest.mark.parametrize("key", ["extra", "links", "id", "groups", "version"])
def test_whole_graph_mutations_fail_closed(key):
source, review = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW)
source[key] = "forged"
review["fixed_version_document"]["canonical_sha256"] = hashlib.sha256(
canonical(source)
).hexdigest()
assert not doc(source, review)["fixed_version"]["matched"]
@pytest.mark.parametrize("key", ["mode", "properties", "inputs", "outputs"])
@pytest.mark.parametrize("index", [0, 4, 12, 15])
def test_node_identity_and_state_fail_closed(key, index):
source, review = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW)
source["nodes"][index][key] = "forged"
review["fixed_version_document"]["canonical_sha256"] = hashlib.sha256(
canonical(source)
).hexdigest()
assert not doc(source, review)["fixed_version"]["matched"]
def test_exact_build_and_qualification():
assert canonical(runpy.run_path(str(OUT / "build_definition.py"))["build"]()) == canonical(
BLOCK
)
assert len(DEFINITIONS) == 67 and doc()["fixed_version"]["matched"]
assert BLOCK["counts"]["saved_fields"] == BLOCK["counts"]["root_saved_fields"] == 121
assert BLOCK["counts"]["source_notes"] == 1 and len(BLOCK["comments"]) == 1
assert not doc()["status"]["doc_done"] and not doc()["status"]["exec_verified"]
sys.path.insert(0, str(OUT))
try:
runpy.run_path(str(OUT / "verify_sources.py"))["main"]()
finally:
sys.path.remove(str(OUT))
def test_exact_outpaint_graph_and_identity_gaps():
ns = {n["id"]: n for n in SOURCE["nodes"]}
assert sum(n["mode"] == 4 for n in SOURCE["nodes"]) == 6
assert ns[562]["outputs"][1]["links"] == []
assert ns[566]["inputs"][0]["link"] == 2991
assert "link" not in ns[566]["inputs"][1]
assert ns[595]["widgets_values"] == [256, 0, 256, 0, 50]
assert ns[661]["widgets_values"] == [1.0000000000000002]
assert ns[715]["inputs"][3]["link"] == 3488
assert not any(n["type"] == "SetLatentNoiseMask" for n in SOURCE["nodes"])
assert ns[593]["properties"]["ver"] == "6109df6591a4cf2bc9d3b113d03f7297fa9248e9"
assert [x["link"] for x in ns[593]["inputs"][:3]] == [3330, 3331, 3231]
assert ns[592]["properties"]["ver"] != ns[706]["properties"]["ver"]
assert ns[591]["outputs"][0]["type"] == ns[707]["outputs"][0]["type"] == "IMAGE"
flow = "\n".join(BLOCK["flow"])
for word in [
"别名恢复次序未知",
"没有显式SetLatentNoiseMask",
"原MASK未接",
"1.0000000000000002",
"245字符",
"299,299,299",
"LG",
"1.23.0",
]:
assert word in flow
for f in BLOCK["fields"]:
if f["node_id"] == "710":
assert f["input_name"] is None and f["field"].startswith("saved_position_")
@pytest.mark.parametrize("note", BLOCK["comments"])
def test_full_notes_and_note_forgery(note):
assert pointer(SOURCE, note["pointer"]) == note["text"]
source, review = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW)
review["fixed_version_document"]["comments"][0]["text"] = "forged"
assert not doc(source, review)["fixed_version"]["matched"]
def test_path_and_source_binding_cannot_be_extended():
from calliope.comfyui.fixed_document import fixed_document_for
assert fixed_document_for(PATH + "forged", SOURCE, REVIEW) is None
review = copy.deepcopy(REVIEW)
review["source_sha"] = "forged"
assert not doc(SOURCE, review)["fixed_version"]["matched"]
@pytest.mark.parametrize("suffix", [b"\n", b" ", b"\t"])
def test_original_byte_identity_rejects_equivalent_json(suffix):
altered = RAW + suffix
assert json.loads(altered) == SOURCE
assert review_for(PATH, hashlib.sha1(altered).hexdigest()) is None
@pytest.mark.parametrize("key", ["user_overview", "source_sha256", "sources", "flow", "counts"])
def test_editorial_or_citation_rehash_cannot_replace_code_owned_pin(key):
source, review = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW)
review["fixed_version_document"][key] = "forged"
review["fixed_version_document"]["canonical_sha256"] = hashlib.sha256(
canonical(source)
).hexdigest()
assert not doc(source, review)["fixed_version"]["matched"]