"Verify exact text, Git/package provenance and source graph without upstream imports." import ast import hashlib import json import zipfile import zlib 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 e["id"] == "rgthree": root = REF / e["identity_root"] member = next( m for m in json.loads((root / "rgthree-members.json").read_bytes()) if m["name"] == e["file"] ) assert zlib.crc32(raw) == member["crc"] == e["member_crc32"] assert json.loads((root / "rgthree-registry.json").read_bytes())["version"] == e["tag"] assert e["git_commit_binding"] == "unknown" proof = "Range necessary text CRC/SHA; full archive SHA/Git binding unknown" elif e["id"] == "essentials": root = REF / e["identity_root"] archive = root / "essentials-source.tar.gz" assert hashlib.sha256(archive.read_bytes()).hexdigest() == e["package_sha256"] with zipfile.ZipFile(archive) as z: assert z.read(e["file"]) == raw if "member_crc32" in e: assert z.getinfo(e["file"]).CRC == e["member_crc32"] == zlib.crc32(raw) assert ( json.loads((root / "essentials-registry.json").read_bytes())["version"] == "1.1.0" ) proof = ( "Exact1.1.0 original ZIP despite " ".tar.gz suffix, full SHA/member " "bytes; 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") proof = ( "Rehashed commit/tag/selected blo" "b; complete tree listing, not fu" "ll tree-object rehash" ) license_row = 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() == license_row["sha256"] ) checks.append(dict(id=e["id"], file=e["file"], sha256=e["sha256"], proof=proof)) assert len(inv["fields"]) == 47 and len(inv["notes"]) == 2 assert inv["scopes"][0]["nodes"] == 22 and inv["scopes"][0]["edges"] == 25 assert all(n["mode"] == 0 for n in inv["nodes"]) assert sum(f["json_type"] == "list" for f in inv["fields"]) == 1 assert {n["node"]: n["state"] for n in inv["empty"]} == { 84: "missing", 43: "empty_list", 58: "empty_list", 59: "empty_list", 91: "missing", 92: "missing", 82: "empty_list", } assert [(n["node"], len(n["text"])) for n in inv["notes"]] == [(83, 6), (35, 1128)] 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"] ] ns = {n["id"]: n for n in inv["nodes"]} for eid, a, ao, z, zi, kind in inv["links"]: 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"] assert ns[61]["outputs"] == [] and ns[87]["outputs"] == [] assert len(ns[76]["widgets_values"]) == 22 and len(ns[76]["inputs"]) == 24 assert len(ns[87]["widgets_values"]) == 1 and len(ns[87]["widgets_values"][0]) == 2 assert ( inv["extra"]["frontendVersion"] == "1.37.11" and inv["extra"]["workflowRendererVersion"] == "LG" ) tree = ast.parse((REF / "lanpaint__src__LanPaint__nodes.py").read_bytes()) mapping = next( n.value for n in tree.body if isinstance(n, ast.Assign) and any(isinstance(t, ast.Name) and t.id == "NODE_CLASS_MAPPINGS" for t in n.targets) ) registered = [k.value for k in mapping.keys] assert "LanPaint_KSamplerAdvanced" in registered and "LanPaint_MaskBlend" not in registered assert all( not isinstance(n, ast.ClassDef) or n.name != "LanPaint_MaskBlend" for n in ast.walk(tree) ) assert "cnr_id" not in ns[76]["properties"] and "ver" not in ns[76]["properties"] assert ns[60]["properties"]["ver"] == "4d3d5d17f0105b673df92da5b084cce567c9c712" registry = json.loads((REF / "lanpaint-registry.json").read_bytes()) assert registry["repository"] == "https://github.com/scraed/LanPaint" for e in block["sources"]: 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()) result = dict( sources=checks, counts=block["counts"], exact_lanpaint_registration=registered, maskblend_absent=True, physical_edges_checked=25, 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, 47 " "positions, 2 notes, 25 edges; Ma" "skBlend accurate-registration ga" "p preserved" ) ) if __name__ == "__main__": main()