174 lines
6.4 KiB
Python
174 lines
6.4 KiB
Python
"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-document-evidence"
|
|
PATH = next(p for p in DEFINITIONS if p.endswith("/ace_step1_5_xl_turbo_8Step极速音乐生成.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_38_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(13))
|
|
@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(14))
|
|
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) == 43 and len(b["fields"]) == 38
|
|
f = {(f["node_id"], f["field"]): f for f in b["fields"]}
|
|
assert f["94", "timesignature"]["value"] == "4"
|
|
assert f["94", "cfg_scale"]["json_type"] == "int" and f["3", "cfg"]["value"] == 1
|
|
assert f["99", "value"]["json_type"] == "int" and "FLOAT" in f["99", "value"]["unit"]
|
|
assert {x["node_id"] for x in b["zero_saved_nodes"]} == {"47", "18"}
|
|
assert sum(x["role"] == "linked_saved_cache" for x in b["fields"]) == 4
|
|
assert sum(x["role"] == "frontend_reference_only" for x in b["fields"]) == 4
|
|
for node in ["94", "98"]:
|
|
for field in b["fields"]:
|
|
if field["node_id"] == node and field["field"] != "fixed":
|
|
assert field["schema_default"].startswith("未知")
|
|
assert "不含ace" in f["105", "type"]["limits"]
|
|
assert "qscale=1" in f["107", "quality"]["effect"]
|
|
assert "128k" in f["107", "quality"]["schema_default"]
|
|
assert len(f["94", "tags"]["value"]) == 244 and len(f["94", "lyrics"]["value"]) == 825
|
|
assert len(b["comments"][0]["text"]) == 1649
|
|
assert f["104", "unet_name"]["value"] == r"AceStep\acestep_v1.5_xl_turbo_bf16.safetensors"
|
|
text = "\n".join(b["flow"])
|
|
for term in [
|
|
"0.11.1",
|
|
"0.18.1",
|
|
"1.44.0",
|
|
"UE7.8",
|
|
"没有TextEncodeAceStepAudio1.5",
|
|
"schema默认V0",
|
|
"缓存int120",
|
|
"未新增API候选",
|
|
"完整定稿0/实跑0/新增转换0",
|
|
]:
|
|
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)
|