257 lines
9.4 KiB
Python
257 lines
9.4 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"] == "c208883f17eb873063a4febaef636f0fa065131fc82bc4b0b26eff41f442719a"
|
|
assert [(s["nodes"], s["edges"], s["named_nodes"]) for s in inv["scopes"]] == [(28, 31, 0)]
|
|
assert len(inv["fields"]) == 42 and len(inv["notes"]) == 8
|
|
assert [n["node"] for n in inv["notes"]] == [100, 101, 102, 106, 105, 104, 103, 107]
|
|
assert [n["characters"] for n in inv["notes"]] == [238, 280, 343, 555, 105, 684, 396, 33]
|
|
assert [z["node"] for z in inv["empty"]] == [54, 112, 73, 92] and all(
|
|
z["state"] == "empty_list" for z in inv["empty"]
|
|
)
|
|
assert inv["extra"]["frontendVersion"] == "1.45.19" and inv["definition_boundary"] == []
|
|
for a, b in zip(inv["fields"], block["fields"], strict=True):
|
|
assert (
|
|
a["pointer"] == b["pointer"]
|
|
and a["json_type"] == b["json_type"]
|
|
and canonical(a["value"]) == canonical(b["value"])
|
|
)
|
|
assert sum(type(f["value"]) is list for f in block["fields"]) == 1
|
|
assert [(a["pointer"], a["text"]) for a in inv["notes"]] == [
|
|
(b["pointer"], b["text"]) for b in block["comments"]
|
|
]
|
|
from build_definition import PATHS, REPO
|
|
|
|
g = json.loads((REPO / PATHS[0]).read_bytes())
|
|
nodes = {n["id"]: n for n in g["nodes"]}
|
|
assert {n["id"] for n in g["nodes"] if n["mode"] == 4} == {90, 114, 92}
|
|
assert all(n["mode"] == 0 for n in g["nodes"] if n["id"] not in (90, 114, 92))
|
|
assert "definitions" not in g and all(
|
|
"widgets_values" in n and "widgets_values_named" not in n for n in g["nodes"]
|
|
)
|
|
for eid, a, ao, z, zi, _kind in g["links"]:
|
|
assert eid in nodes[a]["outputs"][ao]["links"] and nodes[z]["inputs"][zi]["link"] == eid
|
|
edges = {e[0]: e for e in g["links"]}
|
|
for eid, ends in {
|
|
55: (55, 0, 71, 0),
|
|
2: (71, 0, 79, 0),
|
|
3: (79, 0, 53, 0),
|
|
24: (82, 0, 53, 3),
|
|
15: (73, 0, 79, 1),
|
|
21: (92, 0, 79, 2),
|
|
30: (112, 0, 82, 0),
|
|
31: (112, 1, 82, 1),
|
|
53: (113, 0, 111, 0),
|
|
54: (29, 0, 111, 1),
|
|
26: (54, 0, 29, 0),
|
|
42: (114, 0, 85, 2),
|
|
43: (114, 0, 84, 2),
|
|
44: (114, 0, 79, 6),
|
|
}.items():
|
|
assert tuple(edges[eid][1:5]) == ends
|
|
assert nodes[83]["widgets_values"] == ["2:3 (Portrait Photo)", 1, 8] and [
|
|
o["links"] for o in nodes[83]["outputs"]
|
|
] == [[], []]
|
|
assert nodes[82]["widgets_values"] == [1024, 1024, 1]
|
|
assert nodes[84]["widgets_values"] == [
|
|
"给线稿上色成彩色动漫,保持签名文字不变,纯色背景。",
|
|
768,
|
|
"",
|
|
]
|
|
assert nodes[85]["widgets_values"] == ["", 768, ""] and nodes[79]["widgets_values"] == [
|
|
4,
|
|
1,
|
|
"fit",
|
|
]
|
|
assert all(
|
|
i["link"] is None
|
|
for i in nodes[79]["inputs"]
|
|
if i["name"] in ("target_latent", "ref_boost_mask")
|
|
)
|
|
assert nodes[53]["widgets_values"] == [
|
|
517913762219781,
|
|
"randomize",
|
|
10,
|
|
1,
|
|
"euler",
|
|
"simple",
|
|
1,
|
|
]
|
|
assert (
|
|
nodes[111]["properties"]["comparer_mode"] == "Slide"
|
|
and len(nodes[111]["widgets_values"][0]) == 2
|
|
)
|
|
assert all(
|
|
"temp_ljaum" in h["url"] and h["selected"] is True for h in nodes[111]["widgets_values"][0]
|
|
)
|
|
assert {e["id"] for e in rows} == {"core0260", "core0280", "kreaedit", "rgthree", "frontend"}
|
|
reg = json.loads((REF / "krea-registry.json").read_bytes())
|
|
assert (
|
|
reg["id"] == "comfyui-krea2edit"
|
|
and reg["repository"] == "https://github.com/lbouaraba/comfyui-krea2edit"
|
|
)
|
|
|
|
def classes(key, file):
|
|
e = next(e for e in rows if e["id"] == key and e["file"] == file)
|
|
return {
|
|
c.name: c
|
|
for c in ast.parse((REF / e["local_file"]).read_bytes()).body
|
|
if isinstance(c, ast.ClassDef)
|
|
}
|
|
|
|
core = classes("core0260", "nodes.py")
|
|
save = core["SaveImage"]
|
|
ret = next(
|
|
c.value
|
|
for c in save.body
|
|
if isinstance(c, ast.Assign)
|
|
and any(isinstance(n, ast.Name) and n.id == "RETURN_TYPES" for n in c.targets)
|
|
)
|
|
assert ast.literal_eval(ret) == ("IMAGE",)
|
|
assert any(
|
|
isinstance(c, ast.Dict)
|
|
and any(isinstance(k, ast.Constant) and k.value == "result" for k in c.keys)
|
|
for c in ast.walk(save)
|
|
)
|
|
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 any("krea2" in v for v in enums)
|
|
plugin = classes("kreaedit", "__init__.py")
|
|
patch = plugin["Krea2EditModelPatch"]
|
|
method = next(c for c in patch.body if isinstance(c, ast.FunctionDef) and c.name == "patch")
|
|
assert "target_latent" not in [a.arg for a in method.args.args]
|
|
assert "target_latent" not in [n.value for n in ast.walk(patch) if isinstance(n, ast.Constant)]
|
|
ptext = (REF / "kreaedit____init__.py").read_text()
|
|
assert (
|
|
'"Krea2EditModelPatch": Krea2EditModelPatch' in ptext
|
|
and '"Krea2EditGroundedEncode": Krea2EditGroundedEncode' in ptext
|
|
)
|
|
comparer = classes("rgthree", "py/image_comparer.py")["RgthreeImageComparer"]
|
|
assert ast.unparse(comparer.bases[0]) == "PreviewImage"
|
|
assert not any(isinstance(c, ast.Constant) and c.value == "result" for c in ast.walk(comparer))
|
|
assert (
|
|
"RgthreeImageComparer.NAME: RgthreeImageComparer"
|
|
in (REF / "rgthree____init__.py").read_text()
|
|
)
|
|
|
|
def f(nid, name):
|
|
return next(f for f in block["fields"] if f["node_id"] == str(nid) and f["field"] == name)
|
|
|
|
assert (
|
|
f(79, "ref_boost")["schema_default"] == "1.0" and f(79, "ref_boost")["json_type"] == "int"
|
|
)
|
|
assert (
|
|
f(79, "ref_boost_a")["schema_default"] == "1.0"
|
|
and f(79, "fit_mode")["schema_default"] == "'fit'"
|
|
)
|
|
assert (
|
|
f(113, "megapixels")["schema_default"] == "1.0"
|
|
and f(113, "resolution_steps")["schema_default"] == "1"
|
|
)
|
|
assert (
|
|
f(71, "strength_model")["json_type"] == "int"
|
|
and f(71, "strength_model")["schema_default"] == "1.0"
|
|
)
|
|
assert len(block["node_bindings"]) == 20 and len(block["zero_saved_nodes"]) == 4
|
|
(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,
|
|
source_fields=42,
|
|
source_notes=8,
|
|
physical_edges=31,
|
|
all_checks_pass=True,
|
|
upstream_imported=False,
|
|
save0260_has_image_result=True,
|
|
clip0260_krea2_enum_present=True,
|
|
target_latent_interface_gap=True,
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print(
|
|
(
|
|
"PASS exact Git sources"
|
|
", 20 version bindings,"
|
|
" 42 raw fields, eight "
|
|
"notes, 31 edges, Save/"
|
|
"Comparer/interface dif"
|
|
"ferences"
|
|
)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|