76 lines
3.0 KiB
Python
76 lines
3.0 KiB
Python
"""Verify exact static source bytes, tag/tree identities and evidence lines offline."""
|
|
|
|
import hashlib
|
|
import json
|
|
import zipfile
|
|
|
|
from build_definition import OUT, REF, build
|
|
|
|
|
|
def main():
|
|
es = json.loads((REF / "sources.json").read_bytes())["sources"]
|
|
counts = {"git_texts": 0, "package_texts": 0, "reused_reference_texts": 0}
|
|
for e in es:
|
|
raw = (REF / e["local_file"]).read_bytes()
|
|
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
|
|
if e["id"] == "rtx":
|
|
assert e["git_commit_binding"] == "unknown"
|
|
assert (
|
|
e["package_sha256"] == json.loads((REF / "rtx-package.json").read_bytes())["sha256"]
|
|
)
|
|
package = (REF / "rtx-0.1.0-source.zip").read_bytes()
|
|
assert hashlib.sha256(package).hexdigest() == e["package_sha256"]
|
|
with zipfile.ZipFile(REF / "rtx-0.1.0-source.zip") as z:
|
|
assert z.read(e["file"]) == raw
|
|
counts["package_texts"] += 1
|
|
elif e["id"] == "rgthree":
|
|
assert e["commit"] == "449c58fcdd612f7733e54c51f6758ead63fa180b"
|
|
tree = json.loads((REF / "rgthree-tree.json").read_bytes())
|
|
blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
assert tree["sha"] == e["commit"] and not tree["truncated"]
|
|
assert blob == next(x["sha"] for x in tree["tree"] if x["path"] == e["file"])
|
|
counts["reused_reference_texts"] += 1
|
|
else:
|
|
tree = json.loads((REF / (e["id"] + "-tree.json")).read_bytes())
|
|
assert tree["sha"] == e["commit"] and not tree["truncated"]
|
|
blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
assert (
|
|
blob
|
|
== e["git_blob_sha1"]
|
|
== next(x["sha"] for x in tree["tree"] if x["path"] == e["file"])
|
|
)
|
|
counts["git_texts"] += 1
|
|
tags = {}
|
|
for key in ["core", "frontend"]:
|
|
t = json.loads((REF / (key + "-tag.json")).read_bytes())
|
|
assert t["object"]["type"] == "commit" and t["object"]["sha"] == next(
|
|
e["commit"] for e in es if e["id"] == key
|
|
)
|
|
tags[key] = t["object"]["sha"]
|
|
b = build()
|
|
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())
|
|
(OUT / "source-check.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
**counts,
|
|
citations=len(b["sources"]),
|
|
tags=tags,
|
|
package_git_binding="unknown",
|
|
comparer_identity="unknown; fixed reference only",
|
|
all_pass=True,
|
|
local_file_base="docs/hel-892/rtx-document-evidence",
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print("PASS exact sources", counts)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|