119 lines
4.3 KiB
Python
119 lines
4.3 KiB
Python
"Verify exact source bytes, objects, citations and every graph binding offline."
|
|
|
|
import datetime
|
|
import hashlib
|
|
import json
|
|
import zlib
|
|
|
|
from build_definition import OUT, REF, REPO, build, canonical
|
|
from inventory import inventory
|
|
|
|
|
|
def main():
|
|
b = build()
|
|
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
|
|
identity = REF.parent / "flux2-img-reference"
|
|
for e in rows:
|
|
raw = (REF / e["local_file"]).read_bytes()
|
|
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
|
|
if e["id"] in ["kj", "rgthree"]:
|
|
info = next(
|
|
x
|
|
for x in json.loads((identity / (e["id"] + "-members.json")).read_bytes())
|
|
if x["name"] == e["file"]
|
|
)
|
|
assert zlib.crc32(raw) == info["crc"] == e["member_crc32"]
|
|
assert e["git_commit_binding"] == "unknown"
|
|
assert (
|
|
json.loads((identity / (e["id"] + "-registry.json")).read_bytes())["version"]
|
|
== e["tag"]
|
|
)
|
|
continue
|
|
blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
assert blob == e["git_blob_sha1"]
|
|
tree = json.loads((identity / (e["id"] + "-tree.json")).read_bytes())
|
|
assert tree["sha"] == e["tree"] and not tree["truncated"]
|
|
assert next(x["sha"] for x in tree["tree"] if x["path"] == e["file"]) == blob
|
|
c = (identity / (e["id"] + "-commit.txt")).read_bytes()
|
|
assert (
|
|
hashlib.sha1(b"commit " + str(len(c)).encode() + b"\0" + c).hexdigest() == e["commit"]
|
|
)
|
|
assert c.decode().splitlines()[0] == "tree " + e["tree"]
|
|
tag = json.loads((identity / (e["id"] + "-tag.json")).read_bytes())
|
|
tr = (identity / (e["id"] + "-tag.txt")).read_bytes()
|
|
assert tag["commit"] == e["commit"]
|
|
if tag["object"] != tag["commit"]:
|
|
assert (
|
|
hashlib.sha1(b"tag " + str(len(tr)).encode() + b"\0" + tr).hexdigest()
|
|
== tag["object"]
|
|
)
|
|
assert tr.decode().startswith("object " + e["commit"] + "\n")
|
|
else:
|
|
assert tr == c
|
|
inv = inventory()
|
|
assert (len(inv["fields"]), inv["nodes"], inv["edges"], inv["notes"], inv["named_nodes"]) == (
|
|
28,
|
|
29,
|
|
33,
|
|
3,
|
|
0,
|
|
)
|
|
assert {x["node"]: x["state"] for x in inv["empty"]} == {
|
|
103: "empty_list",
|
|
141: "empty_list",
|
|
140: "empty_list",
|
|
139: "empty_list",
|
|
104: "empty_list",
|
|
157: "empty_list",
|
|
161: "empty_list",
|
|
143: "missing",
|
|
151: "missing",
|
|
152: "missing",
|
|
153: "missing",
|
|
}
|
|
for a, f in zip(inv["fields"], b["fields"], strict=True):
|
|
assert (a["pointer"], a["json_type"], canonical(a["value"])) == (
|
|
f["pointer"],
|
|
f["json_type"],
|
|
canonical(f["value"]),
|
|
)
|
|
g = json.loads((REPO / b["source_path"]).read_bytes())
|
|
ns = {n["id"]: n for n in g["nodes"]}
|
|
for edge, src, slot, dst, port, kind in g["links"]:
|
|
assert edge in ns[src]["outputs"][slot]["links"]
|
|
assert ns[dst]["inputs"][port]["link"] == edge
|
|
assert ns[src]["outputs"][slot]["type"] == kind
|
|
assert all(n["mode"] == 0 for n in g["nodes"]) and not g.get("definitions")
|
|
assert ns[103]["outputs"][1]["links"] == [] and g["extra"]["frontendVersion"] == "1.36.13"
|
|
for e in b["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())
|
|
(OUT / "source-check.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
all_pass=True,
|
|
reverified_at=datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
source_files=len(rows),
|
|
citations=len(b["sources"]),
|
|
counts=b["counts"],
|
|
inventory=inv,
|
|
upstream_executed=False,
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print(
|
|
"PASS",
|
|
len(rows),
|
|
"exact source texts;",
|
|
len(b["sources"]),
|
|
"citations; 28 positions, 3 Notes, 33 edges",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|