120 lines
4.4 KiB
Python
120 lines
4.4 KiB
Python
"""Offline byte/identity/license/archive/line and independent source inventory checks."""
|
|
|
|
import base64
|
|
import hashlib
|
|
import json
|
|
import tarfile
|
|
import zipfile
|
|
|
|
from build_definition import OUT, REF, REPO, build
|
|
|
|
|
|
def main():
|
|
b = build()
|
|
entries = json.loads((REF / "sources.json").read_bytes())["sources"]
|
|
for e in entries:
|
|
raw = (REF / e["local_file"]).read_bytes()
|
|
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
|
|
if "package_sha256" in e:
|
|
archive = REF / (
|
|
e["id"]
|
|
+ (
|
|
"-source.tgz"
|
|
if e["id"] == "litegraph"
|
|
else "-source.tar.gz"
|
|
if e["id"] == "essentials"
|
|
else "-source.zip"
|
|
)
|
|
)
|
|
a = archive.read_bytes()
|
|
assert hashlib.sha256(a).hexdigest() == e["package_sha256"]
|
|
if e["id"] == "litegraph":
|
|
with tarfile.open(archive, "r:gz") as z:
|
|
assert z.extractfile(e["file"]).read() == raw
|
|
lock = json.loads((REF / "frontend__package-lock.json").read_bytes())["packages"][
|
|
"node_modules/@comfyorg/litegraph"
|
|
]
|
|
assert (
|
|
"sha512-" + base64.b64encode(hashlib.sha512(a).digest()).decode()
|
|
== lock["integrity"]
|
|
)
|
|
else:
|
|
with zipfile.ZipFile(archive) as z:
|
|
assert z.read(e["file"]) == raw
|
|
assert e["git_commit_binding"] == "unknown"
|
|
else:
|
|
t = json.loads((REF / (e["id"] + "-tree.json")).read_bytes())
|
|
assert t["sha"] == e["commit"] and not t["truncated"]
|
|
assert (
|
|
hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
== e["git_blob_sha1"]
|
|
== next(x["sha"] for x in t["tree"] if x["path"] == e["file"])
|
|
)
|
|
if e["id"] == "frontend":
|
|
assert (
|
|
json.loads((REF / "frontend-tag.json").read_bytes())["object"]["sha"]
|
|
== e["commit"]
|
|
)
|
|
for e in b["sources"]:
|
|
assert (
|
|
1
|
|
<= e["lines"][0]
|
|
<= e["lines"][1]
|
|
<= len((OUT / e["local_file"]).read_text().splitlines())
|
|
)
|
|
missing = []
|
|
for key in ["literals", "cr"]:
|
|
t = json.loads((REF / (key + "-tree.json")).read_bytes())
|
|
assert not any(
|
|
"license" in x["path"].lower() or "copying" in x["path"].lower() for x in t["tree"]
|
|
)
|
|
missing.append(dict(id=key, commit=t["sha"], license_text="未发现;许可未知,不借最新版"))
|
|
g = json.loads((REPO / b["source_path"]).read_bytes())
|
|
pointers = [
|
|
f"/nodes/{i}/widgets_values/{j}"
|
|
for i, n in enumerate(g["nodes"])
|
|
for j in (
|
|
list(n["widgets_values"])
|
|
if isinstance(n["widgets_values"], dict)
|
|
else range(len(n["widgets_values"]))
|
|
)
|
|
]
|
|
assert pointers == [f["pointer"] for f in b["fields"]] and len(pointers) == 37
|
|
assert (
|
|
len(g["nodes"]) == 10
|
|
and len(g["links"]) == 10
|
|
and not b["comments"]
|
|
and "definitions" not in g
|
|
)
|
|
assert all(n["mode"] == 0 and "widgets_values_named" not in n for n in g["nodes"])
|
|
assert g["extra"]["frontendVersion"] == "1.23.0"
|
|
ns = {n["id"]: n for n in g["nodes"]}
|
|
assert ns[103]["outputs"][0]["links"] == []
|
|
for eid, src, slot, dst, inp, _ in g["links"]:
|
|
assert ns[dst]["inputs"][inp]["link"] == eid and eid in ns[src]["outputs"][slot]["links"]
|
|
(OUT / "source-check.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
all_pass=True,
|
|
texts=len(entries),
|
|
citations=len(b["sources"]),
|
|
saved_positions=37,
|
|
scalar_positions=35,
|
|
history_objects=2,
|
|
source_notes=0,
|
|
missing_license=missing,
|
|
local_file_base=str(OUT.relative_to(REPO)),
|
|
frontend="准确源声明1.23.0;组合恢复未知",
|
|
upstream_executed=False,
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print("PASS exact source/archive/tag/tree/blob/line/license inventory; 37 positions/0 notes")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|