294 lines
11 KiB
Python
294 lines
11 KiB
Python
"""Independent raw graph, exact Git identity and schema checks; never import upstream."""
|
|
|
|
import ast
|
|
import hashlib
|
|
import json
|
|
|
|
from build_definition import OUT, REF, build, canonical
|
|
from inventory import inventory
|
|
|
|
|
|
def object_hash(kind, raw):
|
|
return hashlib.sha1(kind.encode() + b" " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
|
|
|
|
def main():
|
|
block, inv = build(), inventory()
|
|
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
|
|
checks = []
|
|
for e in rows:
|
|
raw = (REF / e["local_file"]).read_bytes()
|
|
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
|
|
root = REF / e["identity_root"]
|
|
key = e["identity_key"]
|
|
commit = (root / (key + "-commit.txt")).read_bytes()
|
|
tree = json.loads((root / (key + "-tree.json")).read_bytes())
|
|
assert object_hash("commit", commit) == e["commit"]
|
|
assert commit.decode().splitlines()[0] == "tree " + e["tree"] == "tree " + tree["sha"]
|
|
assert not tree["truncated"]
|
|
assert (
|
|
next(t["sha"] for t in tree["tree"] if t["path"] == e["file"])
|
|
== e["git_blob_sha1"]
|
|
== object_hash("blob", raw)
|
|
)
|
|
tag = json.loads((root / (key + "-tag.json")).read_bytes())
|
|
tag_raw = (root / (key + "-tag.txt")).read_bytes()
|
|
assert tag["commit"] == e["commit"]
|
|
if tag["object"] == e["commit"]:
|
|
assert tag_raw == commit
|
|
else:
|
|
assert object_hash("tag", tag_raw) == tag["object"]
|
|
assert tag_raw.decode().startswith("object " + e["commit"] + "\n")
|
|
license_row = next(
|
|
x
|
|
for x in rows
|
|
if x["id"] == e["id"]
|
|
and (REF / x["local_file"]).resolve() == (REF / e["license_file"]).resolve()
|
|
)
|
|
assert (
|
|
hashlib.sha256((REF / e["license_file"]).read_bytes()).hexdigest()
|
|
== license_row["sha256"]
|
|
)
|
|
checks.append(
|
|
dict(
|
|
id=e["id"],
|
|
file=e["file"],
|
|
sha256=e["sha256"],
|
|
proof=(
|
|
"rehashed commit/tag/se"
|
|
"lected blob; complete "
|
|
"tree listing, not tree"
|
|
"-object rehash"
|
|
),
|
|
reverified_at=e["reverified_at"],
|
|
)
|
|
)
|
|
assert inv["sha256"] == "50433cee0d5bab60a2cce44d73adbe5fe9b486c039bc89e1caef640fe6e0b28d"
|
|
assert [(s["nodes"], s["edges"], s["named_nodes"]) for s in inv["scopes"]] == [
|
|
(6, 4, 0),
|
|
(15, 29, 0),
|
|
]
|
|
assert len(inv["fields"]) == 51 and [(n["node"], n["characters"]) for n in inv["notes"]] == [
|
|
(285, 95),
|
|
(278, 95),
|
|
]
|
|
assert [(z["node"], z["state"]) for z in inv["empty"]] == [
|
|
(286, "missing"),
|
|
(251, "empty_list"),
|
|
(248, "empty_list"),
|
|
]
|
|
assert inv["extra"]["frontendVersion"] == "1.45.19"
|
|
from build_definition import PATHS, REPO
|
|
|
|
g = json.loads((REPO / PATHS[0]).read_bytes())
|
|
sg = g["definitions"]["subgraphs"][0]
|
|
nodes = {n["id"]: n for n in g["nodes"]}
|
|
internal = {n["id"]: n for n in sg["nodes"]}
|
|
for a, b in zip(inv["fields"], block["fields"], strict=True):
|
|
assert a["pointer"] == b["pointer"] and a["json_type"] == b["json_type"]
|
|
assert canonical(a["value"]) == canonical(b["value"]) and "named_value" not in b
|
|
assert "无此具名保存键" in b["named_pointer"]
|
|
assert type(b["value"]) not in (list, dict)
|
|
assert all(
|
|
n["mode"] == 0 and "widgets_values_named" not in n
|
|
for n in list(nodes.values()) + list(internal.values())
|
|
)
|
|
assert len(nodes[283]["widgets_values"]) == len(nodes[283]["inputs"]) == len(sg["inputs"]) == 10
|
|
assert "proxyWidgets" not in nodes[283] and sg["widgets"] == []
|
|
assert len(nodes[282]["widgets_values"][0]) == 958
|
|
assert nodes[282]["widgets_values"][0].endswith("\n")
|
|
assert 289 not in nodes
|
|
assert not any(e["file"] == "comfy_extras/nodes_string.py" for e in rows)
|
|
assert len(nodes[283]["widgets_values"][0]) == len(internal[60]["widgets_values"][0]) == 399
|
|
assert nodes[285]["widgets_values"][0] == internal[278]["widgets_values"][0]
|
|
assert (
|
|
len(block["comments"]) == 2
|
|
and block["comments"][0]["pointer"] != block["comments"][1]["pointer"]
|
|
)
|
|
edges = {e[0]: e for e in g["links"]}
|
|
for eid, ends in {
|
|
566: (282, 0, 283, 0),
|
|
580: (287, 0, 283, 7),
|
|
581: (287, 1, 283, 8),
|
|
569: (283, 0, 263, 0),
|
|
}.items():
|
|
assert tuple(edges[eid][1:5]) == ends
|
|
for eid, a, ao, z, zi, _ in g["links"]:
|
|
assert eid in nodes[a]["outputs"][ao]["links"] and nodes[z]["inputs"][zi]["link"] == eid
|
|
assert sum(e["id"] == 525 for e in sg["links"]) == 1
|
|
outlet = next(e for e in sg["links"] if e["id"] == 525)
|
|
assert (
|
|
outlet["target_id"] == -20
|
|
and outlet["target_slot"] == -1
|
|
and sg["outputs"][0]["linkIds"] == [525, 525]
|
|
)
|
|
for e in sg["links"]:
|
|
if e["origin_id"] == -10:
|
|
assert e["id"] in sg["inputs"][e["origin_slot"]]["linkIds"]
|
|
else:
|
|
assert e["id"] in internal[e["origin_id"]]["outputs"][e["origin_slot"]]["links"]
|
|
if e["target_id"] == -20:
|
|
assert e["id"] == 525 and e["target_slot"] == -1
|
|
else:
|
|
assert internal[e["target_id"]]["inputs"][e["target_slot"]]["link"] == e["id"]
|
|
se = {e["id"]: e for e in sg["links"]}
|
|
for eid, a, z in [
|
|
(529, 264, 254),
|
|
(517, 254, 259),
|
|
(518, 259, 255),
|
|
(507, 255, 251),
|
|
(545, 16, 272),
|
|
(582, 272, 288),
|
|
(583, 288, 254),
|
|
(584, 288, 255),
|
|
(559, 279, 254),
|
|
(560, 279, 255),
|
|
(550, 60, 273),
|
|
(551, 273, 254),
|
|
(552, 273, 255),
|
|
(476, 60, 248),
|
|
(497, 248, 254),
|
|
(504, 248, 255),
|
|
]:
|
|
assert se[eid]["origin_id"] == a and se[eid]["target_id"] == z
|
|
assert internal[254]["widgets_values"] == [
|
|
477786237165895,
|
|
"randomize",
|
|
8,
|
|
1,
|
|
"euler",
|
|
"beta57",
|
|
1,
|
|
]
|
|
assert internal[255]["widgets_values"] == [
|
|
552380068141577,
|
|
"randomize",
|
|
6,
|
|
1,
|
|
"er_sde",
|
|
"simple",
|
|
0.6,
|
|
]
|
|
assert (
|
|
internal[279]["widgets_values"] == [23212346779852, "fixed"]
|
|
and nodes[283]["widgets_values"][5] == 23212346779852
|
|
)
|
|
assert len(nodes[283]["widgets_values"][9]) == len(internal[273]["widgets_values"][1]) == 58
|
|
assert (
|
|
internal[273]["widgets_values"][0] == "detail"
|
|
and type(internal[273]["widgets_values"][2]) is int
|
|
)
|
|
assert "v3.1" in nodes[283]["widgets_values"][2] and "v2" in internal[272]["widgets_values"][0]
|
|
assert all("links" not in o for o in nodes[263]["outputs"])
|
|
|
|
def source(key, file):
|
|
return (
|
|
REF / next(e for e in rows if e["id"] == key and e["file"] == file)["local_file"]
|
|
).read_bytes()
|
|
|
|
def classes(key, file):
|
|
return {c.name: c for c in ast.parse(source(key, file)).body if isinstance(c, ast.ClassDef)}
|
|
|
|
core = classes("core0375", "nodes.py")
|
|
enums = [
|
|
ast.literal_eval(c)
|
|
for c in ast.walk(core["CLIPLoader"])
|
|
if isinstance(c, ast.List)
|
|
and all(isinstance(x, ast.Constant) and isinstance(x.value, str) for x in c.elts)
|
|
]
|
|
assert all("krea2" not in v for v in enums)
|
|
save = classes("core0260", "nodes.py")["SaveImage"]
|
|
ret = next(
|
|
c.value
|
|
for c in save.body
|
|
if isinstance(c, ast.Assign)
|
|
and any(isinstance(t, ast.Name) and t.id == "RETURN_TYPES" for t in c.targets)
|
|
)
|
|
assert ast.literal_eval(ret) == ("IMAGE",)
|
|
assert any(isinstance(c, ast.Constant) and c.value == "result" for c in ast.walk(save))
|
|
sampler = ast.parse(source("core0260", "comfy/samplers.py"))
|
|
handlers = next(
|
|
c.value
|
|
for c in sampler.body
|
|
if isinstance(c, ast.Assign)
|
|
and any(isinstance(t, ast.Name) and t.id == "SCHEDULER_HANDLERS" for t in c.targets)
|
|
)
|
|
assert "beta57" not in [ast.literal_eval(k) for k in handlers.keys]
|
|
samplers = next(
|
|
c.value
|
|
for c in sampler.body
|
|
if isinstance(c, ast.Assign)
|
|
and any(isinstance(t, ast.Name) and t.id == "KSAMPLER_NAMES" for t in c.targets)
|
|
)
|
|
assert all(name in ast.literal_eval(samplers) for name in ["euler", "er_sde"])
|
|
seed = source("core0270", "comfy_extras/nodes_seed.py").decode()
|
|
assert (
|
|
'node_id="SeedNode"' in seed
|
|
and "return [SeedNode]" in seed
|
|
and "return SeedExtension()" in seed
|
|
and "control_after_generate=io.ControlAfterGenerate.fixed" in seed
|
|
)
|
|
assert '"nodes_seed.py"' in source("core0270", "nodes.py").decode()
|
|
registry = json.loads((REF / "rebalance-registry.json").read_bytes())
|
|
assert (
|
|
registry["id"] == "comfyui-krea2-conditioning"
|
|
and registry["repository"] == "https://github.com/huwhitememes/comfyui-krea2-conditioning"
|
|
)
|
|
assert (
|
|
'"ConditioningKrea2Rebalance": ConditioningKrea2Rebalance'
|
|
in source("rebalance", "__init__.py").decode()
|
|
)
|
|
reb = classes("rebalance", "nodes.py")["ConditioningKrea2Rebalance"]
|
|
method = next(c for c in reb.body if isinstance(c, ast.FunctionDef) and c.name == "rebalance")
|
|
custom = next(c for c in method.body if isinstance(c, ast.If))
|
|
assert ast.unparse(custom.test) == "preset == 'custom'"
|
|
assert "parse_weights(per_layer_weights)" in ast.unparse(
|
|
custom.body[0]
|
|
) and "PRESET_WEIGHTS.get" in ast.unparse(custom.orelse[0])
|
|
assert (
|
|
len(block["node_bindings"]) == 19
|
|
and len(block["zero_saved_nodes"]) == 3
|
|
and len(block["boundaries"]) == 1
|
|
)
|
|
assert sum(f["scope"] == "root" for f in block["fields"]) == 15
|
|
(OUT / "node-version-bindings.json").write_text(
|
|
json.dumps(block["node_bindings"], ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
(OUT / "source-check.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
files=checks,
|
|
all_checks_pass=True,
|
|
source_fields=51,
|
|
source_notes=2,
|
|
physical_edges=33,
|
|
upstream_imported=False,
|
|
seed0270_registered=True,
|
|
scheduler0260_beta57_present=False,
|
|
sampler0260_er_sde_present=True,
|
|
clip0375_krea2_enum_present=False,
|
|
unique_physical525=True,
|
|
duplicate_boundary_link_ids_preserved=[525, 525],
|
|
negative_output_slot_preserved=-1,
|
|
rebalance_detail_uses_preset_not_saved_string=True,
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print(
|
|
(
|
|
"PASS exact identities, 51 positi"
|
|
+ "onal scalars, two separate 95-co"
|
|
+ "depoint notes, SeedNode registra"
|
|
+ "tion, negative slot/duplicate bo"
|
|
+ "undary and version gaps preserve"
|
|
+ "d"
|
|
)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|