97 lines
3.9 KiB
Python
97 lines
3.9 KiB
Python
"""Verify pinned bytes/provenance and independent inventory without upstream execution."""
|
|
|
|
import hashlib
|
|
import json
|
|
import zipfile
|
|
|
|
from build_definition import OUT, REF, REPO, build, canonical
|
|
from inventory import inventory
|
|
|
|
|
|
def main():
|
|
b = build()
|
|
seen = set()
|
|
for e in b["sources"]:
|
|
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())
|
|
seen.add(str(p))
|
|
if "git_blob_sha1" in e:
|
|
assert (
|
|
hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
== e["git_blob_sha1"]
|
|
)
|
|
root = OUT.parent / "moge3-reference" if e["id"] == "frontend" else p.parent
|
|
t = json.loads((root / (e["id"] + "-tree.json")).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"]) == e["git_blob_sha1"]
|
|
else:
|
|
assert e["id"] == "impact"
|
|
archive = REF / "impact-source.zip"
|
|
assert hashlib.sha256(archive.read_bytes()).hexdigest() == e["package_sha256"]
|
|
with zipfile.ZipFile(archive) as z:
|
|
assert z.read(e["file"]) == raw
|
|
for key in ["loader", "dialog", "core", "cr", "layer"]:
|
|
c = json.loads((REF / (key + "-commit.json")).read_bytes())
|
|
t = json.loads((REF / (key + "-tree.json")).read_bytes())
|
|
assert t["sha"] == c["sha"] and not t["truncated"]
|
|
assert all(
|
|
e["tree"] == c["tree"]["sha"]
|
|
for e in json.loads((REF / "sources.json").read_bytes())["sources"]
|
|
if e["id"] == key and "tree" in e
|
|
)
|
|
tag = json.loads((OUT.parent / "sdpose-reference/core0150-tag.json").read_bytes())
|
|
assert tag["object"]["sha"] == "b874bd2b8c324d58cfc37bff0754dd16815a8f3c"
|
|
registry = json.loads((REF / "impact-registry.json").read_bytes())
|
|
assert registry["version"] == "8.28.2" and "/8.28.2/" in registry["downloadUrl"]
|
|
inv = inventory()
|
|
assert len(inv["fields"]) == 70 and len(inv["notes"]) == 2
|
|
for a, f in zip(inv["fields"], b["fields"], strict=True):
|
|
assert (a["pointer"], a["scope"], a["json_type"], canonical(a["value"])) == (
|
|
f["pointer"],
|
|
f["scope"],
|
|
f["json_type"],
|
|
canonical(f["value"]),
|
|
)
|
|
for a, n in zip(inv["notes"], b["comments"], strict=True):
|
|
assert a["pointer"] == n["pointer"] and a["value"] == n["text"]
|
|
g = json.loads((REPO / b["source_path"]).read_bytes())
|
|
ns = {n["id"]: n for n in g["nodes"]}
|
|
assert "frontendVersion" not in g["extra"] and not g.get("definitions")
|
|
assert all("widgets_values_named" not in n for n in g["nodes"])
|
|
assert sum(n["mode"] == 4 for n in g["nodes"]) == 9
|
|
for eid, src, slot, dst, inp, _ in g["links"]:
|
|
assert eid in ns[src]["outputs"][slot]["links"] and ns[dst]["inputs"][inp]["link"] == eid
|
|
(OUT / "source-check.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
all_pass=True,
|
|
cited_texts=len(seen),
|
|
citations=len(b["sources"]),
|
|
counts=b["counts"],
|
|
local_file_base=str(OUT.relative_to(REPO)),
|
|
upstream_executed=False,
|
|
source_frontend="undeclared",
|
|
qwen_commits_separate=True,
|
|
core_tag_verified=True,
|
|
impact_git_binding="unknown",
|
|
cr_license="absent in original tree",
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print(
|
|
(
|
|
"PASS pinned source bytes, trees/blobs/tag/packag"
|
|
"e members, 70 positions, 2 complete notes and 26"
|
|
" physical edges"
|
|
)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|