"Flux2 editorial source binding, distinct saved states and unchanged eligibility." import copy import hashlib import json import runpy 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/flux2-xiaozhi-document-evidence") PATH = "example_ComfyUI_workflows/3-图像生成/Flux/3_flux2_klein_图生图一致性增强(小志lora).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 part in p.strip("/").split("/"): obj = obj[int(part)] if isinstance(obj, list) else obj[part] return obj def doc(s=SOURCE, r=REVIEW): return build_document(PATH, s, None, None, [], r) def refuse(s, r): r["fixed_version_document"]["canonical_sha256"] = hashlib.sha256(canonical(s)).hexdigest() assert not doc(s, r)["fixed_version"]["matched"] @pytest.mark.parametrize("f", BLOCK["fields"], ids=lambda f: f["node_id"] + "." + f["field"]) def test_every_saved_position_json_type_and_exact_citations(f): assert canonical(pointer(SOURCE, f["pointer"])) == canonical(f["value"]) assert type(pointer(SOURCE, f["pointer"])).__name__ == f["json_type"] assert "named_value" not in f and "无widgets_values_named" in f["named_pointer"] 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", ["position", "editorial"]) def test_caller_rehash_cannot_expand_trust(f, variant): s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW) if variant == "editorial": r["fixed_version_document"]["fields"][BLOCK["fields"].index(f)]["effect"] = "forged" else: parent, _, key = f["pointer"].rpartition("/") pointer(s, parent)[int(key)] = "forged" refuse(s, r) @pytest.mark.parametrize("index", range(25)) @pytest.mark.parametrize("variant", ["mode", "identity", "named"]) def test_all_nodes_bound(index, variant): s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW) n = s["nodes"][index] if variant == "mode": n["mode"] = 0 if n["mode"] == 4 else 4 elif variant == "identity": n["properties"]["ver"] = "forged" else: n["widgets_values_named"] = {"forged": 0} refuse(s, r) @pytest.mark.parametrize("index", range(31)) def test_all_edges_bound(index): s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW) s["links"][index][3] = 9999 refuse(s, r) @pytest.mark.parametrize("node", [103, 141, 140, 139, 104, 143, 136, 135]) @pytest.mark.parametrize("variant", ["missing", "empty", "null", "added"]) def test_missing_empty_null_distinct(node, variant): s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW) n = next(n for n in s["nodes"] if n["id"] == node) old = copy.deepcopy(n) if variant == "missing": n.pop("widgets_values", None) else: n["widgets_values"] = {"empty": [], "null": None, "added": [0]}[variant] if n != old: refuse(s, r) @pytest.mark.parametrize( "variant", ["overview", "citation", "sha", "frontend", "counts", "tab", "ue", "unconnected-output"], ) def test_metadata_and_unconnected_branch_bound(variant): s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW) b = r["fixed_version_document"] if variant == "overview": b["user_overview"] = "forged" elif variant == "citation": b["sources"][0]["sha256"] = "forged" elif variant == "sha": r["source_sha"] = "forged" elif variant == "frontend": s["extra"]["frontendVersion"] = "1.52.7" elif variant == "counts": b["counts"]["final_prompt_constructed"] = True elif variant == "tab": s["nodes"][0]["properties"]["tabWidth"] = 99 elif variant == "ue": s["nodes"][0]["properties"]["ue_properties"]["version"] = "7.8" else: next(n for n in s["nodes"] if n["id"] == 103)["outputs"][1]["links"] = [999] assert not doc(s, r)["fixed_version"]["matched"] def test_actual_document_overrides_and_status(): b = runpy.run_path(str(OUT / "build_definition.py"))["build"]() assert canonical(b) == canonical(BLOCK) assert len(DEFINITIONS) == 48 and len(b["fields"]) == 36 and len(b["comments"]) == 1 assert sum(f["role"] == "linked_saved_cache" for f in b["fields"]) == 6 assert sum(f["role"] == "frontend_reference_only" for f in b["fields"]) == 3 f = {(x["node_id"], x["field"]): x for x in b["fields"]} assert f["102", "cfg"]["json_type"] == "int" assert f["101", "steps"]["limits"] == "1~4096" assert f["148", "custom_width"]["limits"].startswith("64~8192,step1") assert f["148", "use_custom_resolution"]["value"] is False assert f["108", "text"]["value"] == ( "Transform the image to realistic photo" "graph. add realistic details to the co" "rrupted image. restore high frequency " "details from the corrupted image." ) assert f["109", "text"]["value"] == "" assert f["147", "pad_color"]["value"] == "0, 0, 0" history = f["145", "rgthree_comparer"] assert history["json_type"] == "list" and len(history["value"]) == 2 assert ( history["value"] == next(n for n in SOURCE["nodes"] if n["id"] == 145)["widgets_values"][0] ) assert BLOCK["comments"][0]["text"] == SOURCE["nodes"][0]["widgets_values"][0] assert len(BLOCK["comments"][0]["text"]) == 1396 d = doc() assert d["fixed_version"]["matched"] assert not d["status"]["doc_done"] and not d["status"]["exec_verified"] assert hashlib.sha256(canonical(BLOCK)).hexdigest() == DEFINITIONS[PATH] for term in [ "mode0", "1.36.13", "0.21.1", "无LICENSE", "四处1024", "B直接来自76", "无IMAGE出口", "Git绑定未知", ]: assert term in "\n".join(b["flow"] + b["versions"]) @pytest.mark.parametrize( "variant", ["note", "nested-history", "slide", "clipspace", "label-identity", "lora-mode"] ) def test_complete_history_note_and_independent_identity_bound(variant): s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW) ns = {n["id"]: n for n in s["nodes"]} if variant == "note": ns[97]["widgets_values"][0] += "forged" elif variant == "nested-history": ns[145]["widgets_values"][0][1]["url"] = "forged" elif variant == "slide": ns[145]["properties"]["comparer_mode"] = "Click" elif variant == "clipspace": ns[76]["properties"]["image"] = "forged" elif variant == "label-identity": ns[143]["properties"]["cnr_id"] = "rgthree-comfy" else: ns[142]["mode"] = 4 refuse(s, r) def test_physical_topology_and_exact_version_schema_conflicts(): ns = {n["id"]: n for n in SOURCE["nodes"]} edges = {(a, b, c, d, e) for _, a, b, c, d, e in SOURCE["links"]} for edge in [ (104, 0, 145, 0, "IMAGE"), (76, 0, 145, 1, "IMAGE"), (141, 0, 140, 1, "LATENT"), (141, 0, 139, 1, "LATENT"), (111, 0, 103, 4, "LATENT"), (147, 1, 135, 0, "INT"), (147, 2, 136, 0, "INT"), ]: assert edge in edges assert ns[76]["outputs"][1]["links"] is None assert ns[147]["inputs"][1]["link"] is None assert ns[147]["outputs"][3]["links"] == [] assert ns[142]["mode"] == 0 and ns[103]["outputs"][1]["links"] == [] assert ns[9]["outputs"][0]["type"] == "IMAGE" assert "RETURN_TYPES = ()" in (OUT.parent / "flux2-img-reference/core__nodes.py").read_text() assert {e["tag"] for e in BLOCK["sources"] if e["id"] == "frontend"} == {"v1.36.13"} assert {e["tag"] for e in BLOCK["sources"] if e["id"] == "lora"} == {"v0.21.1"} def test_xiaozhi_active_lora_crop_and_source_specific_values(): f = {(x["node_id"], x["field"]): x for x in BLOCK["fields"]} assert f["142", "lora_name"]["value"] == ( "Flux\\Flux2-Klein-9B_lcs_consist_20260415_一致性小志版.safetensors" ) assert f["142", "strength_model"]["value"] == 0.8 assert "非零" in f["142", "strength_model"]["effect"] assert "safe_load" in f["142", "lora_name"]["effect"] assert f["101", "steps"]["value"] == 20 assert f["105", "noise_seed"]["value"] == 1001572801433320 assert f["76", "image"]["value"] == "微信图片_20260522211935_20_155.jpg" assert f["147", "upscale_method"]["value"] == "lanczos" assert f["147", "keep_proportion"]["value"] == "crop" assert f["147", "divisible_by"]["value"] == 8 assert "narrow" in f["147", "keep_proportion"]["effect"] assert "因数8" in f["147", "width"]["effect"] assert "gpu+lanczos" in f["147", "upscale_method"]["effect"] history = f["145", "rgthree_comparer"]["value"] assert [x["name"] for x in history] == ["A", "B"] assert all(x["selected"] is True and "temp_acghq" in x["url"] for x in history) ns = {n["id"]: n for n in SOURCE["nodes"]} assert all(n["mode"] == 0 for n in ns.values()) edges = {(a, b, c, d, e) for _, a, b, c, d, e in SOURCE["links"]} assert (106, 0, 142, 0, "MODEL") in edges assert (142, 0, 102, 0, "MODEL") in edges assert (148, 0, 147, 2, "INT") in edges assert (148, 1, 147, 3, "INT") in edges assert all("旁路" not in x["effect"] for x in BLOCK["fields"])