"Validate source-byte inventory and fixed Git/package evidence without imports." 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"] if "artifact_sha256" in e: package = json.loads((REF / (e["id"] + "-package.json")).read_bytes()) registry = json.loads((REF / (e["id"] + "-registry.json")).read_bytes()) assert registry["node_id"] == e["id"] and registry["version"] == "1.0.0" assert package["sha256"] == e["artifact_sha256"] assert package["bytes"] == e["artifact_size"] assert package["download_url"] == registry["downloadUrl"] == e["url"] member = next(m for m in package["members"] if m["path"] == e["file"]) assert member["sha256"] == e["sha256"] and member["size"] == len(raw) if e["license_file"].startswith("未知"): assert not any("license" in m["path"].lower() for m in package["members"]) proof = ( "exact1.0.0 registry package member " "SHA rehash; full package SHA acquis" "ition record; Git binding unknown" ) else: 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") if e["license_file"].startswith("未知"): assert not any( t["path"].lower().split("/")[-1].startswith(("license", "licence")) for t in tree["tree"] ) proof = ( "raw commit/tag and selected blob re" "hashed; complete tree listing not f" "ull tree-object rehash" ) if not e["license_file"].startswith("未知"): lic = next( x for x in rows if x["id"] == e["id"] and x["local_file"] == e["license_file"] ) assert ( hashlib.sha256((REF / e["license_file"]).read_bytes()).hexdigest() == lic["sha256"] ) checks.append(dict(id=e["id"], file=e["file"], sha256=e["sha256"], proof=proof)) assert len(inv["fields"]) == 69 and len(inv["notes"]) == 3 assert inv["scopes"][0]["nodes"] == 25 and inv["scopes"][0]["edges"] == 22 assert [(n["id"], n["mode"]) for n in inv["nodes"] if n["mode"] != 0] == [(86, 4)] for a, f in zip(inv["fields"], block["fields"], strict=True): assert (a["pointer"], a["json_type"], canonical(a["value"])) == ( f["pointer"], f["json_type"], canonical(f["value"]), ) assert [(n["node"], n["pointer"], n["text"]) for n in inv["notes"]] == [ (int(n["node_id"]), n["pointer"], n["text"]) for n in block["comments"] ] assert [(n["node"], n["state"]) for n in inv["empty"]] == [(65, "empty_list"), (89, "missing")] ns = {n["id"]: n for n in inv["nodes"]} endpoints = [] for edge in inv["links"]: eid, a, ao, z, zi, kind = edge src, dst = ns[a]["outputs"][ao], ns[z]["inputs"][zi] assert eid in src["links"] and dst["link"] == eid assert src["type"] == "*" or kind == src["type"] assert dst["type"] == "*" or kind == dst["type"] endpoints.append(dict(edge=edge, source_backref=True, target_backref=True)) assert ns[9]["outputs"] == [] assert [ ns[n]["inputs"][i]["link"] for n, i in [(80, 5), (80, 6), (67, 1), (77, 0), (77, 1)] ] == [92, 100, 93, 98, 99] assert [(n, len(ns[n]["widgets_values"][0])) for n in [90, 81, 67]] == [ (90, 8254), (81, 2418), (67, 245), ] sampler = ast.parse((REF / "patch__comfy__samplers.py").read_bytes()) names = next( n.value for n in sampler.body if isinstance(n, ast.Assign) and any(isinstance(t, ast.Name) and t.id == "KSAMPLER_NAMES" for t in n.targets) ) assert "res_multistep" in ast.literal_eval(names) assert ( '"simple": SchedulerHandler(simple_scheduler)' in (REF / "patch__comfy__samplers.py").read_text() ) for e in block["sources"]: data = (OUT / e["local_file"]).read_bytes() assert hashlib.sha256(data).hexdigest() == e["sha256"] assert 1 <= e["lines"][0] <= e["lines"][1] <= len(data.decode().splitlines()) result = dict( sources=checks, counts=block["counts"], physical_endpoints=endpoints, inventory_matches_definition=True, no_upstream_execution=True, ) (OUT / "source-check.json").write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n") print( ( "PASS exact Git/package text, 69 pos" "itions, 3 comments, 22 endpoints; n" "o upstream execution" ) ) if __name__ == "__main__": main()