"Offline source identity, archives, lines and independent inventory verification." import hashlib import json import tarfile import zipfile from build_definition import OUT, REF, REPO, build from inventory import inventory def main(): b = build() seen = set() entries = list(b["sources"]) for manifest in ["sources.json", "package-sources.json"]: for e in json.loads((REF / manifest).read_bytes())["sources"]: entries.append( { **e, "local_file": "../vosr2-loop-reference/" + e["local_file"], "lines": [1, len((REF / e["local_file"]).read_text().splitlines())], } ) for e in entries: p = (OUT / e["local_file"]).resolve() raw = p.read_bytes() assert hashlib.sha256(raw).hexdigest() == e["sha256"] assert 1 <= e["lines"][0] <= e["lines"][1] <= len(raw.decode().splitlines()) if p in seen: continue seen.add(p) if "git_blob_sha1" in e: blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() assert blob == e["git_blob_sha1"] tree = p.parent / (e["id"] + "-tree.json") if tree.exists(): t = json.loads(tree.read_bytes()) assert t["sha"] == e["commit"] and not t["truncated"] assert next(x["sha"] for x in t["tree"] if x["path"] == e["file"]) == blob if "package_sha256" in e: archive = p.parent / e.get( "package_file", e["id"] + ("-source.tgz" if e["id"] == "litegraph" else "-source.zip"), ) # Historical VHS release uses its original archive name. if not archive.exists(): archive = next( a for a in p.parent.iterdir() if a.is_file() and a.suffix in [".zip", ".tgz", ".gz"] and hashlib.sha256(a.read_bytes()).hexdigest() == e["package_sha256"] ) assert hashlib.sha256(archive.read_bytes()).hexdigest() == e["package_sha256"] if archive.suffix == ".tgz": with tarfile.open(archive, "r:gz") as z: assert z.extractfile(e["file"]).read() == raw else: with zipfile.ZipFile(archive) as z: assert z.read(e.get("member", e["file"])) == raw for key in ["core-math", "core-video"]: tag = json.loads((REF / (key + "-tag.json")).read_bytes()) tree = json.loads((REF / (key + "-tree.json")).read_bytes()) assert tag["object"]["sha"] == tree["sha"] x = inventory() assert len(x["fields"]) == 89 and len(x["notes"]) == 3 assert [f["pointer"] for f in x["fields"]] == [f["pointer"] for f in b["fields"]] assert x["special_edge"]["target_slot"] == -3 assert x["boundary_outputs"][0]["linkIds"] == [143, 143] g = json.loads((REPO / b["source_path"]).read_bytes()) ns = {n["id"]: n for n in g["nodes"]} assert ns[3]["outputs"][0]["links"] == [] and ns[193]["widgets_values"] == {} for eid, src, slot, dst, inp, _ in g["links"]: assert eid in ns[src]["outputs"][slot]["links"] and ns[dst]["inputs"][inp]["link"] == eid sub = g["definitions"]["subgraphs"][0] sn = {n["id"]: n for n in sub["nodes"]} for e in sub["links"]: if e["origin_id"] != -10: assert e["id"] in sn[e["origin_id"]]["outputs"][e["origin_slot"]]["links"] if e["target_id"] != -20: assert sn[e["target_id"]]["inputs"][e["target_slot"]]["link"] == e["id"] assert all(n["mode"] == 0 for n in list(ns.values()) + list(sn.values())) assert sn[116]["inputs"][3]["link"] is None (OUT / "source-check.json").write_text( json.dumps( dict( all_pass=True, texts=len(seen), cited_texts=len({e["local_file"] for e in b["sources"]}), citations=len(b["sources"]), saved_positions=89, root_saved=62, internal_saved=27, history_objects=2, source_notes=3, root_nodes=36, root_edges=27, internal_nodes=9, internal_edges=22, local_file_base=str(OUT.relative_to(REPO)), special_endpoint_preserved=x["special_edge"], duplicate_declaration=[143, 143], upstream_executed=False, identity_conflicts=[ "Info第六口与准确五槽实现", "merge音频口与准确无音频接口", "SaveVideo四值动态口与准确三控件", ], ), ensure_ascii=False, indent=2, ) + "\n" ) print(("PASS exact source/archive/tree/blob/tag/line identities and 89 positions/3 notes")) if __name__ == "__main__": main()