216 lines
7.8 KiB
Python
216 lines
7.8 KiB
Python
"""Clone notes preserve declared-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/tts-clone-document-evidence"
|
|
PATH = next(p for p in DEFINITIONS if p.endswith("/Qwen3-TTS_语音设计+语音克隆.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(15))
|
|
@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(10))
|
|
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["zero_saved_nodes"][0]["effect"] = "forged"
|
|
else:
|
|
b["counts"]["final_prompt_constructed"] = True
|
|
assert not doc(s, r)["fixed_version"]["matched"]
|
|
|
|
|
|
@pytest.mark.parametrize("generated", [False, True])
|
|
def test_clone_specific_semantics_and_unknowns_are_actual_doc(generated):
|
|
b = runpy.run_path(str(OUT / "build_definition.py"))["build"]() if generated else BLOCK
|
|
assert canonical(b) == canonical(BLOCK)
|
|
assert b["counts"]["saved_fields"] == 38 and b["counts"]["source_notes"] == 1
|
|
ns = {n["id"]: n for n in SOURCE["nodes"]}
|
|
assert all(ns[i]["widgets_values"] == [] for i in [7, 10, 30])
|
|
assert "widgets_values" not in ns[43]
|
|
assert all(ns[i]["mode"] == 4 for i in [20, 21, 7, 17, 22, 23, 10, 12])
|
|
assert all(ns[i]["mode"] == 0 for i in [19, 24, 31, 30, 15, 33, 43])
|
|
assert "x_vecotr_only_mode" in b["comments"][0]["text"]
|
|
assert not b["counts"]["final_prompt_constructed"] and not b["boundaries"]
|
|
|
|
def f(node, name):
|
|
return next(x for x in b["fields"] if x["node_id"] == str(node) and x["field"] == name)
|
|
|
|
assert f(31, "x_vector_only_mode")["value"] is False
|
|
assert "无此参数" in f(31, "x_vector_only_mode")["schema_default"]
|
|
assert f(21, "instruct")["value"] == "" and f(21, "speaker")["value"] == "Ryan"
|
|
assert f(19, "audio")["value"] == "ComfyUI_temp_acghq_00001_.flac"
|
|
for k in [1, 2]:
|
|
assert f(19, "saved_null_" + str(k))["value"] is None
|
|
assert not f(19, "saved_null_" + str(k))["input_pointer"].startswith("/")
|
|
for node in [20, 22, 24]:
|
|
assert f(node, "auto_download")["value"] is False
|
|
assert "无此输入" in f(node, "auto_download")["schema_default"]
|
|
assert f(node, "download_source")["value"] == "ModelScope"
|
|
flow = "\n".join(b["flow"])
|
|
for phrase in [
|
|
"没有TD别名",
|
|
"无auto_download",
|
|
"speaker为STRING",
|
|
"无x_vector_only_mode",
|
|
"temp FLAC",
|
|
"purge_cache变量未读",
|
|
"返回anything",
|
|
"SDK语义未证",
|
|
"7个mode0",
|
|
"UE7.3/7.7",
|
|
]:
|
|
assert phrase in flow or phrase in b["comments"][0]["meaning"]
|
|
text = (OUT.parent / "tts-clone-reference/qwen__nodes.py").read_text()
|
|
# Cross-check the exact upstream text without importing or running it.
|
|
import ast
|
|
|
|
module = ast.parse(text)
|
|
mapping = next(
|
|
n.value
|
|
for n in module.body
|
|
if isinstance(n, ast.Assign)
|
|
and any(isinstance(t, ast.Name) and t.id == "NODE_CLASS_MAPPINGS" for t in n.targets)
|
|
)
|
|
assert all(not k.value.startswith("TD") for k in mapping.keys)
|
|
assert (
|
|
"auto_download" not in text
|
|
and "download_source" not in text
|
|
and "x_vector_only_mode" not in text
|
|
)
|
|
actual = doc()["fixed_version"]
|
|
assert actual["matched"] and actual["fields"] == b["fields"]
|
|
assert actual["comments"] == b["comments"] and actual["user_overview"] == b["user_overview"]
|
|
|
|
|
|
def test_40_existing_blocks_and_all_other_reviews_frozen():
|
|
import subprocess
|
|
|
|
resource = "calliope-backend/src/calliope/comfyui/source_reviews.json"
|
|
base = json.loads(
|
|
subprocess.check_output(
|
|
["git", "show", "4e8a16c4d0f548dab411f456a9287cbc588f5d27:" + resource], cwd=REPO
|
|
)
|
|
)
|
|
now = json.loads((REPO / resource).read_bytes())
|
|
blocks = [r["fixed_version_document"] for r in base.values() if "fixed_version_document" in r]
|
|
assert len(blocks) == 40 and sum(len(b["fields"]) for b in blocks) == 1451
|
|
assert (
|
|
sum(
|
|
len(
|
|
build_document(p, json.loads((REPO / p).read_bytes()), None, None, [], base[p])[
|
|
"source_notes"
|
|
]
|
|
)
|
|
for p in DEFINITIONS
|
|
if p != PATH
|
|
)
|
|
== 43
|
|
)
|
|
for p, r in base.items():
|
|
if p != PATH:
|
|
assert now[p] == r
|
|
now[PATH].pop("fixed_version_document")
|
|
assert now == base
|