179 lines
6.4 KiB
Python
179 lines
6.4 KiB
Python
"IndexTTS 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/index-tts-document-evidence"
|
|
PATH = next(
|
|
p
|
|
for p in DEFINITIONS
|
|
if p.endswith("/index-TTS2-情绪控制-音频参考-文本控制-克隆-多人对话.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_94_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(16))
|
|
@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(13))
|
|
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"]
|
|
|
|
|
|
@pytest.mark.parametrize("generated", [False, True])
|
|
def test_exact_version_gaps_and_base_semantics_survive_in_actual_doc(generated):
|
|
b = runpy.run_path(str(OUT / "build_definition.py"))["build"]() if generated else BLOCK
|
|
assert canonical(b) == canonical(BLOCK)
|
|
assert len(b["fields"]) == 94 and b["counts"]["source_notes"] == 1
|
|
text = "\n".join(b["flow"])
|
|
for term in [
|
|
"9f1685ac0db7faa565efd5122a5db747502d142d",
|
|
"59b91cc1ee75791e7bb28a0294d0f02aab85cb5d",
|
|
"0.3.24",
|
|
"0.3.57",
|
|
"未注册",
|
|
"Engine不使用",
|
|
"没有将seed用于RNG",
|
|
"keep=False",
|
|
"SDK内部是否联网",
|
|
"Subtitle槽2",
|
|
"links=[]",
|
|
"mode4",
|
|
"准确树中缺正文",
|
|
"widgets_values=[values]",
|
|
"1.34.8",
|
|
"UE各节点7.8",
|
|
]:
|
|
# Chinese wording is anchored to the provenance report, never a live SDK call.
|
|
assert term in text
|
|
fields = {(f["node_id"], f["field"]): f for f in b["fields"]}
|
|
assert fields["215", "mode"]["limits"] == "Auto/Duration/Tokens"
|
|
assert "未使用" in fields["215", "mode"]["effect"]
|
|
assert "未下传infer" in fields["215", "seed"]["effect"]
|
|
assert "0回退120" in fields["215", "max_tokens_per_sentence"]["effect"]
|
|
for node in ["211", "212", "214", "216"]:
|
|
f = fields[node, "temperature"]
|
|
assert f["schema_default"].startswith("未知") and "不套Base" in f["effect"]
|
|
for node in ["168", "196", "217", "222"]:
|
|
assert fields[node, "saved_null_1"]["value"] is None
|
|
assert fields[node, "saved_null_2"]["value"] is None
|
|
assert not fields[node, "saved_null_1"]["input_pointer"].startswith("/")
|
|
assert "0:05.154" in fields["219", "history_text"]["value"]
|
|
assert not doc()["status"]["doc_done"] and not doc()["status"]["exec_verified"]
|
|
assert not b["counts"]["final_prompt_constructed"]
|
|
|
|
|
|
def test_complete_graph_and_schema_definition_digests_remain_code_owned():
|
|
assert len(DEFINITIONS) == 42
|
|
b = doc()["fixed_version"]
|
|
assert b["matched"] and len(b["fields"]) == 94
|
|
assert hashlib.sha256(canonical(BLOCK)).hexdigest() == DEFINITIONS[PATH]
|
|
s, r = copy.deepcopy(SOURCE), copy.deepcopy(REVIEW)
|
|
s["extra"]["node_versions"]["comfy-core"] = "0.3.57"
|
|
refuse(s, r)
|