"ACE notes preserve exact-version schema gaps and cannot enable execution." 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/ace-qwen-document-evidence" PATH = next(p for p in DEFINITIONS if p.endswith("/ace_step_1.5+Qwen3.5_自动歌词音乐生成.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, path): for part in path.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_all_77_positions_keep_raw_types_separate_ports_and_citations(f): assert canonical(pointer(SOURCE, f["pointer"])) == canonical(f["value"]) assert type(pointer(SOURCE, f["pointer"])).__name__ == f["json_type"] assert not f["named_pointer"].startswith("/") and "named_value" not in f if f["input_pointer"].startswith("/"): assert pointer(SOURCE, f["input_pointer"])["name"] == f["input_name"] assert "未知" in f["execution_note"] 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", "definition"]) def test_caller_rehash_cannot_bypass_saved_values_or_editorial_text(f, variant): s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW) if variant == "source": parent, _, key = f["pointer"].rpartition("/") pointer(s, parent)[int(key)] = "forged" else: r["fixed_version_document"]["fields"][BLOCK["fields"].index(f)]["effect"] = "forged" refuse(s, r) @pytest.mark.parametrize("ni", range(22)) @pytest.mark.parametrize("variant", ["mode", "identity", "named-values"]) def test_modes_exact_or_absent_identity_and_named_values_bound(ni, variant): s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW) n = s["nodes"][ni] 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("ei", range(24)) def test_every_physical_edge_bound(ei): s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW) s["links"][ei][3] = 99999 refuse(s, r) @pytest.mark.parametrize( "variant", [ "overview", "citation", "source_sha", "missing", "empty", "frontend", "notes", "zero", "counts", ], ) def test_all_metadata_fail_closed(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 == "source_sha": r["source_sha"] = "forged" elif variant == "missing": r.pop("fixed_version_document") elif variant == "empty": r["fixed_version_document"] = {} elif variant == "frontend": s["extra"]["frontendVersion"] = "1.52.7" elif variant == "notes": b["comments"][0]["text"] = "forged" elif variant == "zero": b["fields"][0]["unit"] = "forged" else: b["counts"]["final_prompt_constructed"] = True assert not doc(s, r)["fixed_version"]["matched"] def test_exact_version_conflicts_and_linked_caches_survive_actual_doc(): b = runpy.run_path(str(OUT / "build_definition.py"))["build"]() assert canonical(b) == canonical(BLOCK) assert len(DEFINITIONS) == 44 and len(b["fields"]) == 77 f = {(f["node_id"], f["field"]): f for f in b["fields"]} assert f["116", "from_right"]["value"] == "false" assert f["116", "from_right"]["json_type"] == "str" assert sum(x["role"] == "linked_saved_cache" for x in b["fields"]) == 9 assert sum(x["role"] == "frontend_reference_only" for x in b["fields"]) == 5 for nid in ["109", "110", "111"]: for field in b["fields"]: if field["node_id"] == nid: assert "准确Git提交fetch拒绝" in field["effect"] assert "未知" in field["limits"] assert f["110", "model"]["value"] == "Qwen3.5-9b-heretic-v2-q8_0.gguf" assert "presence_penalty" in f["111", "presence_penalty"]["effect"] assert f["99", "value"]["value"] == 120 assert f["102", "value"]["value"] == 966457091644585 assert "FLOAT" in f["99", "value"]["unit"] assert "INT" in f["102", "value"]["unit"] for name in ["tags", "lyrics"]: assert "物理外线覆盖" in f["94", name]["effect"] assert "qscale=1" in f["107", "quality"]["effect"] assert f["107", "filename_prefix"]["value"] == "audio/ComfyUI" assert ( "中文" in f["118", "history_text"]["value"] or "假如" in f["118", "history_text"]["value"] ) assert f["112", "prompt"]["value"].startswith("# ACE Step 1.5") assert f["113", "prompt"]["value"] == "假如没有学AI就好了,中文歌词" assert {x["node_id"] for x in b["zero_saved_nodes"]} == {"47", "18"} assert all("1.44.0" not in x["execution_note"] for x in b["fields"]) text = "\n".join(b["flow"]) for term in [ "1.38.0", "没有TextEncodeAceStepAudio1.5", "schema默认V0", "未新增API候选", "完整定稿0/实跑0/新增转换0", "not our ref", "7/13/10", "UE7.8/7.5.2", ]: assert term in text d = doc() assert d["fixed_version"]["matched"] assert hashlib.sha256(canonical(BLOCK)).hexdigest() == DEFINITIONS[PATH] assert not d["status"]["doc_done"] and not d["status"]["exec_verified"] @pytest.mark.parametrize("node", [47, 18]) @pytest.mark.parametrize("variant", ["missing", "null", "one"]) def test_empty_array_is_distinct_from_missing_null_and_added_slot(node, variant): s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW) n = next(n for n in s["nodes"] if n["id"] == node) if variant == "missing": del n["widgets_values"] else: n["widgets_values"] = None if variant == "null" else [0] refuse(s, r) def test_exact_split_missing_delimiter_returns_capture_list_without_running_upstream(): import ast path = OUT.parent / "ace-qwen-reference/various__comfyui_primitive_ops.py" module = ast.parse(path.read_text()) func = next( n for n in module.body if isinstance(n, ast.FunctionDef) and isinstance(n.body[-1], ast.Match) ) case = func.body[-1].cases[-1] assert isinstance(case.pattern, ast.MatchAs) and case.pattern.name == "a" result = case.body[0].value assert isinstance(result, ast.Tuple) assert isinstance(result.elts[0], ast.Name) and result.elts[0].id == "a" assert isinstance(result.elts[1], ast.Constant) and result.elts[1].value == "" field = next(f for f in BLOCK["fields"] if f["node_id"] == "116") assert "返回列表与空串" in field["effect"] and "STRING槽冲突" in field["effect"]