"""Verify pinned bytes/provenance and independent inventory without upstream execution.""" import hashlib import json 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 = REF 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: raise AssertionError("Every new citation must have an exact Git blob") for key in ["qwen", "core", "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 ) tag = json.loads((REF / "core0100-tag.json").read_bytes()) assert tag["object"]["sha"] == "9d273d3ab1fb1d2c8b34de4d54cabe50a5a3e5bc" inv = inventory() assert len(inv["fields"]) == 38 and len(inv["notes"]) == 1 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"]) == 8 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_registration_schema_mismatch_preserved=True, core_tag_verified=True, sdk_semantics="unknown; not loaded", ), ensure_ascii=False, indent=2, ) + "\n" ) print("PASS pinned bytes/commit/tree/blob/tag; 38 positions, 1 complete Note, 10 edges") if __name__ == "__main__": main()