99 lines
4.0 KiB
Python
99 lines
4.0 KiB
Python
"Verify graph-specific exact Git identities and bidirectional physical endpoints."
|
|
|
|
import hashlib
|
|
import json
|
|
|
|
from build_definition import OUT, PATHS, REF, REPO, build, canonical
|
|
from inventory import inventory
|
|
|
|
|
|
def main():
|
|
b = build()
|
|
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
|
|
for e in rows:
|
|
raw = (REF / e["local_file"]).read_bytes()
|
|
license_row = next(v for v in rows if v["id"] == e["id"] and v["file"] == "LICENSE")
|
|
assert (
|
|
hashlib.sha256((REF / e["license_file"]).read_bytes()).hexdigest()
|
|
== license_row["sha256"]
|
|
)
|
|
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
|
|
blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
assert blob == e["git_blob_sha1"]
|
|
root = REF / e["identity_root"]
|
|
key = e["identity_key"]
|
|
tree = json.loads((root / (key + "-tree.json")).read_bytes())
|
|
assert tree["sha"] == e["tree"] and not tree["truncated"]
|
|
assert next(t["sha"] for t in tree["tree"] if t["path"] == e["file"]) == blob
|
|
commit = (root / (key + "-commit.txt")).read_bytes()
|
|
assert (
|
|
hashlib.sha1(b"commit " + str(len(commit)).encode() + b"\0" + commit).hexdigest()
|
|
== e["commit"]
|
|
)
|
|
assert commit.decode().splitlines()[0] == "tree " + e["tree"]
|
|
tag = json.loads((root / (key + "-tag.json")).read_bytes())
|
|
assert tag["commit"] == e["commit"]
|
|
rawtag = (root / (key + "-tag.txt")).read_bytes()
|
|
if tag["object"] != tag["commit"]:
|
|
assert (
|
|
hashlib.sha1(b"tag " + str(len(rawtag)).encode() + b"\0" + rawtag).hexdigest()
|
|
== tag["object"]
|
|
)
|
|
assert rawtag.decode().startswith("object " + e["commit"] + "\n")
|
|
else:
|
|
assert rawtag == commit
|
|
inv = inventory()
|
|
assert len(inv["fields"]) == 29 and inv["nodes"] == 25 and inv["edges"] == 32
|
|
assert inv["notes"] == 1 and inv["named_nodes"] == 0 and set(inv["modes"]) == {0}
|
|
assert {v["node"]: v["state"] for v in inv["empty"]} == {
|
|
k: "empty_list" for k in (123, 144, 142, 140, 139, 143, 128, 124, 141)
|
|
}
|
|
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"]),
|
|
)
|
|
assert f["evidence"]
|
|
for e in b["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())
|
|
g = json.loads((REPO / PATHS[0]).read_bytes())
|
|
ns = {n["id"]: n for n in g["nodes"]}
|
|
edges = []
|
|
for edge in g["links"]:
|
|
eid, a, ao, z, zi, kind = edge
|
|
source = ns[a]["outputs"][ao]
|
|
target = ns[z]["inputs"][zi]
|
|
assert eid in (source.get("links") or []) and target.get("link") == eid
|
|
assert source["type"] == target["type"] == kind
|
|
edges.append(dict(edge=edge, source_backref=True, target_backref=True))
|
|
assert ns[123]["outputs"][1]["links"] == [] and ns[128]["outputs"][2]["links"] == []
|
|
assert ns[76]["outputs"][1]["links"] is None and ns[81]["outputs"][1]["links"] is None
|
|
assert ns[94]["outputs"] == []
|
|
result = dict(
|
|
all_pass=True,
|
|
source_files=len(rows),
|
|
citations=len(b["sources"]),
|
|
counts=b["counts"],
|
|
physical_endpoint_checks=edges,
|
|
upstream_executed=False,
|
|
source_protocol_conflicts_retained=[
|
|
"GetImageSize description promises passthrough but returns three INT"
|
|
],
|
|
saveimage_source_outputs_empty_matches_exact_return_types=True,
|
|
)
|
|
(OUT / "source-check.json").write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
|
|
print(
|
|
"PASS",
|
|
len(rows),
|
|
"text hashes;",
|
|
len(b["sources"]),
|
|
"citations; 29 positions and 32 bidirectional edges",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|