111 lines
4.5 KiB
Python
111 lines
4.5 KiB
Python
"""Independent byte/Git identity, raw position/named copy and graph checks."""
|
|
|
|
import datetime
|
|
import hashlib
|
|
import json
|
|
|
|
from build_definition import OUT, REF, REPO, build, canonical
|
|
from inventory import inventory
|
|
|
|
|
|
def main():
|
|
block = build()
|
|
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
|
|
for e in rows:
|
|
raw = (REF / e["local_file"]).read_bytes()
|
|
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
|
|
assert (
|
|
hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
== e["git_blob_sha1"]
|
|
)
|
|
t = json.loads((REF / (e["id"] + "-tree.json")).read_bytes())
|
|
assert t["sha"] == e["tree"] and not t["truncated"]
|
|
assert next(x["sha"] for x in t["tree"] if x["path"] == e["file"]) == e["git_blob_sha1"]
|
|
c = (REF / (e["id"] + "-commit.txt")).read_bytes()
|
|
assert (
|
|
hashlib.sha1(b"commit " + str(len(c)).encode() + b"\0" + c).hexdigest() == e["commit"]
|
|
)
|
|
assert c.decode().splitlines()[0] == "tree " + e["tree"]
|
|
tag = json.loads((REF / (e["id"] + "-tag.json")).read_bytes())
|
|
assert tag["commit"] == e["commit"]
|
|
tr = (REF / (e["id"] + "-tag.txt")).read_bytes()
|
|
if tag["object"] != tag["commit"]:
|
|
assert (
|
|
hashlib.sha1(b"tag " + str(len(tr)).encode() + b"\0" + tr).hexdigest()
|
|
== tag["object"]
|
|
)
|
|
assert tr.decode().startswith("object " + e["commit"] + "\n")
|
|
else:
|
|
assert tr == c
|
|
inv = inventory()
|
|
assert len(inv["fields"]) == 38 and len(inv["notes"]) == 2 and inv["named_nodes"] == 13
|
|
for a, f in zip(inv["fields"], block["fields"], strict=True):
|
|
assert (a["pointer"], a["scope"], a["json_type"], canonical(a["value"])) == (
|
|
f["pointer"],
|
|
f["scope"],
|
|
f["json_type"],
|
|
canonical(f["value"]),
|
|
)
|
|
assert canonical(f["named_value"]) == canonical(a["value"])
|
|
assert a["named"][f["field"]] == f["value"]
|
|
for a, n in zip(inv["notes"], block["comments"], strict=True):
|
|
assert a["value"] == n["text"] and a["pointer"] == n["pointer"]
|
|
g = json.loads((REPO / block["source_path"]).read_bytes())
|
|
sg = g["definitions"]["subgraphs"][0]
|
|
assert g["extra"]["frontendVersion"] == "1.48.7" and sg["widgets"] == []
|
|
assert len(sg["inputs"]) == 8 and len(sg["outputs"]) == 1
|
|
ns = {n["id"]: n for n in sg["nodes"]}
|
|
for e in sg["links"]:
|
|
src, dst = e["origin_id"], e["target_id"]
|
|
if src != -10:
|
|
assert e["id"] in ns[src]["outputs"][e["origin_slot"]]["links"]
|
|
else:
|
|
assert e["id"] in sg["inputs"][e["origin_slot"]]["linkIds"]
|
|
if dst != -20:
|
|
assert ns[dst]["inputs"][e["target_slot"]]["link"] == e["id"]
|
|
else:
|
|
assert e["id"] in sg["outputs"][e["target_slot"]]["linkIds"]
|
|
assert [n["id"] for n in sg["nodes"] if "widgets_values" not in n] == [10, 12]
|
|
assert g["links"] == [[42, 37, 0, 35, 0, "AUDIO"]]
|
|
assert len(sg["links"]) == 24 and all(n["mode"] == 0 for gr in [g, sg] for n in gr["nodes"])
|
|
missing = json.loads((REF / "missing-music-classes.json").read_bytes())
|
|
assert missing["returncode"] == 1 and missing["commit"] == rows[0]["commit"]
|
|
core = (REF / "core__nodes.py").read_text()
|
|
clip = core.split("class CLIPLoader:")[1].split("class DualCLIPLoader:")[0]
|
|
assert '"minimax"' in clip
|
|
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())
|
|
(OUT / "source-check.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
all_pass=True,
|
|
reverified_at=datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
source_files=len(rows),
|
|
citations=len(block["sources"]),
|
|
counts=block["counts"],
|
|
named_nodes=13,
|
|
pre_read_discrepancy="原件确有具名保存,不采用无具名预读",
|
|
missing_music_classes=missing,
|
|
upstream_executed=False,
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print(
|
|
(
|
|
"PASS 38 positions/38 name"
|
|
"d copies, 2 Notes, 25 edg"
|
|
"es including boundary, ex"
|
|
"act Git identities; missi"
|
|
"ng classes preserved"
|
|
)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|