164 lines
7.2 KiB
Python
164 lines
7.2 KiB
Python
"Validate source-byte inventory and fixed Git/package evidence without imports."
|
|
|
|
import ast
|
|
import hashlib
|
|
import json
|
|
|
|
from build_definition import OUT, REF, build, canonical
|
|
from inventory import inventory
|
|
|
|
|
|
def object_hash(kind, raw):
|
|
return hashlib.sha1(kind.encode() + b" " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
|
|
|
|
def main():
|
|
block, inv = build(), inventory()
|
|
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
|
|
checks = []
|
|
for e in rows:
|
|
raw = (REF / e["local_file"]).read_bytes()
|
|
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
|
|
if e["id"] == "llama-unavailable":
|
|
report = json.loads(raw)
|
|
assert report["requested_commit"] == e["commit"]
|
|
assert report["registry_id"] == "llama-cpp_vllm"
|
|
assert report["attempts"] == [
|
|
"git fetch exact commit: upload-pack not our ref",
|
|
"pinned raw nodes.py: HTTP 404",
|
|
]
|
|
checks.append(
|
|
dict(id=e["id"], sha256=e["sha256"], proof="第63批负面记录原字节重核;无新网络调查")
|
|
)
|
|
continue
|
|
if "artifact_sha256" in e:
|
|
package = json.loads((REF / (e["id"] + "-package.json")).read_bytes())
|
|
registry = json.loads((REF / (e["id"] + "-registry.json")).read_bytes())
|
|
assert registry["node_id"] == e["id"] and registry["version"] == "1.0.0"
|
|
assert package["sha256"] == e["artifact_sha256"]
|
|
assert package["bytes"] == e["artifact_size"]
|
|
assert package["download_url"] == registry["downloadUrl"] == e["url"]
|
|
member = next(m for m in package["members"] if m["path"] == e["file"])
|
|
assert member["sha256"] == e["sha256"] and member["size"] == len(raw)
|
|
if e["license_file"].startswith("未知"):
|
|
assert not any("license" in m["path"].lower() for m in package["members"])
|
|
proof = (
|
|
"exact1.0.0 registry package member "
|
|
"SHA rehash; full package SHA acquis"
|
|
"ition record; Git binding unknown"
|
|
)
|
|
else:
|
|
root = REF / e["identity_root"]
|
|
key = e["identity_key"]
|
|
commit = (root / (key + "-commit.txt")).read_bytes()
|
|
tree = json.loads((root / (key + "-tree.json")).read_bytes())
|
|
assert object_hash("commit", commit) == e["commit"]
|
|
assert commit.decode().splitlines()[0] == "tree " + e["tree"] == "tree " + tree["sha"]
|
|
assert not tree["truncated"]
|
|
assert (
|
|
next(t["sha"] for t in tree["tree"] if t["path"] == e["file"])
|
|
== e["git_blob_sha1"]
|
|
== object_hash("blob", raw)
|
|
)
|
|
tag = json.loads((root / (key + "-tag.json")).read_bytes())
|
|
tag_raw = (root / (key + "-tag.txt")).read_bytes()
|
|
assert tag["commit"] == e["commit"]
|
|
if tag["object"] == e["commit"]:
|
|
assert tag_raw == commit
|
|
else:
|
|
assert object_hash("tag", tag_raw) == tag["object"]
|
|
assert tag_raw.decode().startswith("object " + e["commit"] + "\n")
|
|
if e["license_file"].startswith("未知"):
|
|
assert not any(
|
|
t["path"].lower().split("/")[-1].startswith(("license", "licence"))
|
|
for t in tree["tree"]
|
|
)
|
|
proof = (
|
|
"raw commit/tag and selected blob re"
|
|
"hashed; complete tree listing not f"
|
|
"ull tree-object rehash"
|
|
)
|
|
if not e["license_file"].startswith("未知"):
|
|
lic = next(
|
|
x for x in rows if x["id"] == e["id"] and x["local_file"] == e["license_file"]
|
|
)
|
|
assert (
|
|
hashlib.sha256((REF / e["license_file"]).read_bytes()).hexdigest() == lic["sha256"]
|
|
)
|
|
checks.append(dict(id=e["id"], file=e["file"], sha256=e["sha256"], proof=proof))
|
|
assert len(inv["fields"]) == 74 and len(inv["notes"]) == 2
|
|
assert inv["scopes"][0]["nodes"] == 24 and inv["scopes"][0]["edges"] == 19
|
|
assert [(n["id"], n["mode"]) for n in inv["nodes"] if n["mode"] != 0] == []
|
|
for a, f in zip(inv["fields"], block["fields"], strict=True):
|
|
assert (a["pointer"], a["json_type"], canonical(a["value"])) == (
|
|
f["pointer"],
|
|
f["json_type"],
|
|
canonical(f["value"]),
|
|
)
|
|
assert [(n["node"], n["pointer"], n["text"]) for n in inv["notes"]] == [
|
|
(int(n["node_id"]), n["pointer"], n["text"]) for n in block["comments"]
|
|
]
|
|
assert [(n["node"], n["state"]) for n in inv["empty"]] == [(65, "empty_list"), (87, "missing")]
|
|
ns = {n["id"]: n for n in inv["nodes"]}
|
|
endpoints = []
|
|
for edge in inv["links"]:
|
|
eid, a, ao, z, zi, kind = edge
|
|
src, dst = ns[a]["outputs"][ao], ns[z]["inputs"][zi]
|
|
assert eid in src["links"] and dst["link"] == eid
|
|
assert src["type"] == "*" or kind == src["type"]
|
|
assert dst["type"] == "*" or kind == dst["type"]
|
|
endpoints.append(dict(edge=edge, source_backref=True, target_backref=True))
|
|
assert ns[9]["outputs"] == []
|
|
assert ns[81]["inputs"][2]["link"] == 100
|
|
assert ns[81]["inputs"][3]["link"] is None
|
|
assert [ns[81]["inputs"][i]["link"] for i in [5, 6]] == [None, None]
|
|
assert ns[93]["outputs"][0]["links"] is None and ns[89]["outputs"][0]["links"] == []
|
|
assert [(n, len(ns[n]["widgets_values"][0])) for n in [93, 89, 82, 67]] == [
|
|
(93, 8254),
|
|
(89, 847),
|
|
(82, 2323),
|
|
(67, 245),
|
|
]
|
|
assert ns[82]["outputs"][0]["links"] == []
|
|
assert ns[84]["inputs"][0]["link"] == 92
|
|
assert all(ns[77]["inputs"][i]["link"] is None for i in range(3))
|
|
for nid in [78, 79, 81]:
|
|
assert ns[nid]["properties"]["ver"] == "20571a3cf504b8308781d3cad2e432444ec3d75b"
|
|
assert ns[nid]["properties"]["cnr_id"] == "llama-cpp_vllm"
|
|
assert "cnr_id" not in ns[92]["properties"] and "ver" not in ns[92]["properties"]
|
|
sampler = ast.parse((REF / "../zimage-qwen-reference/patch__comfy__samplers.py").read_bytes())
|
|
names = next(
|
|
n.value
|
|
for n in sampler.body
|
|
if isinstance(n, ast.Assign)
|
|
and any(isinstance(t, ast.Name) and t.id == "KSAMPLER_NAMES" for t in n.targets)
|
|
)
|
|
assert "euler" in ast.literal_eval(names)
|
|
assert (
|
|
'"simple": SchedulerHandler(simple_scheduler)'
|
|
in (REF / "../zimage-qwen-reference/patch__comfy__samplers.py").read_text()
|
|
)
|
|
for e in block["sources"]:
|
|
data = (OUT / e["local_file"]).read_bytes()
|
|
assert hashlib.sha256(data).hexdigest() == e["sha256"]
|
|
assert 1 <= e["lines"][0] <= e["lines"][1] <= len(data.decode().splitlines())
|
|
result = dict(
|
|
sources=checks,
|
|
counts=block["counts"],
|
|
physical_endpoints=endpoints,
|
|
inventory_matches_definition=True,
|
|
no_upstream_execution=True,
|
|
)
|
|
(OUT / "source-check.json").write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
|
|
print(
|
|
(
|
|
"PASS exact Git/package text, 74 pos"
|
|
"itions, 2 comments, 19 endpoints; n"
|
|
"o upstream execution"
|
|
)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|