Files
aigc-home/docs/hel-892/sam3-document-evidence/verify_sources.py
T
2026-10-30 21:59:57 +08:00

110 lines
4.1 KiB
Python

"Verify exact Git blob bytes without importing upstream modules or reading media."
import hashlib
import json
from build_definition import OUT, REF, REPO, build
def main():
entries = json.loads((REF / "sources.json").read_bytes())["sources"]
for e in entries:
raw = (REF / e["local_file"]).read_bytes()
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"])
)
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
tags = {}
for key in ["core", "frontend"]:
tag = json.loads((REF / (key + "-tag.json")).read_bytes())
tree = json.loads((REF / (key + "-tree.json")).read_bytes())
assert tag["object"]["type"] == "commit" and tag["object"]["sha"] == tree["sha"]
tags[key] = dict(tag=tag["ref"], commit=tree["sha"], tree_truncated=tree["truncated"])
core_files = [e for e in entries if e["id"] == "core"]
checked = []
for e in core_files:
text = (REF / e["local_file"]).read_text()
hits = [i for i, line in enumerate(text.splitlines(), 1) if "SAM3_Detect" in line]
assert not hits
checked.append(dict(path=e["file"], sha256=e["sha256"], matches=hits))
tree = json.loads((REF / "core-tree.json").read_bytes())
paths = [e["path"] for e in tree["tree"]]
matches = [p for p in paths if "sam3" in p.lower()]
assert not matches
(OUT / "bounded-investigation.json").write_text(
json.dumps(
dict(
scope=(
"Complete core tree path names plus only "
"the listed necessary textual files. Not "
"all core source contents; no historical/"
"newer versions. SAM3 implementation rema"
"ins unknown."
),
tags=tags,
core_tree_paths=len(paths),
sam3_path_matches=matches,
sam3_detect_scanned_files=checked,
frontend_files=[e["file"] for e in entries if e["id"] == "frontend"],
unknown=[
"SAM3_Detect schema/default/range/units/coords/model support",
"target installation/UE/order",
"Muter provider/version",
"promoted final values",
],
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
b = build()
g = json.loads((REPO / b["source_path"]).read_bytes())
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())
graphs = dict(
source_path=b["source_path"],
raw_sha256=b["source_sha256"],
canonical_sha256=b["canonical_sha256"],
nodes=g["nodes"],
links=g["links"],
extra=g["extra"],
counts=b["counts"],
missing_widgets=[150],
definitions=g["definitions"],
)
(OUT / "source-graphs.json").write_text(json.dumps(graphs, ensure_ascii=False, indent=2) + "\n")
(OUT / "source-check.json").write_text(
json.dumps(
dict(
local_file_base="docs/hel-892/sam3-reference",
git_texts=len(entries),
registry_texts=0,
tree_metadata_json=2,
unique_commits=2,
files=entries,
citations=len(b["sources"]),
no_upstream_execution=True,
no_assets_fetched=True,
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
print(
f"PASS {len(entries)} Git text originals, 2 tree metadata JSON, "
f"{len(b['sources'])} citations"
)
if __name__ == "__main__":
main()