94 lines
3.5 KiB
Python
94 lines
3.5 KiB
Python
"""Rehash every baseline blob except the two authorized product resources."""
|
|
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
|
|
from build_definition import OUT, REPO, canonical
|
|
from rebuild import BASE, RESOURCE
|
|
|
|
|
|
def main():
|
|
allowed = {RESOURCE, "calliope-backend/src/calliope/comfyui/fixed_document.py"}
|
|
entries = subprocess.check_output(["git", "ls-tree", "-rz", BASE], cwd=REPO)
|
|
frozen = []
|
|
originals = []
|
|
for entry in entries.rstrip(b"\0").split(b"\0"):
|
|
meta, path = entry.split(b"\t", 1)
|
|
name = path.decode()
|
|
if name in allowed:
|
|
continue
|
|
mode, kind, digest = meta.decode().split()
|
|
assert kind == "blob"
|
|
raw = (REPO / name).read_bytes()
|
|
actual = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
assert actual == digest, name
|
|
item = dict(path=name, git_blob_sha1=digest, sha256=hashlib.sha256(raw).hexdigest())
|
|
frozen.append(item)
|
|
if name.startswith("example_ComfyUI_workflows/") or (
|
|
name.startswith("docs/hel-892/supplied-api/") and name.endswith(".api.json")
|
|
):
|
|
originals.append(item)
|
|
assert len(originals) == 163
|
|
for filename, data in [
|
|
("baseline-frozen-files.json", dict(base=BASE, count=len(frozen), files=frozen)),
|
|
("originals-163-check.json", dict(base=BASE, count=163, files=originals)),
|
|
]:
|
|
(OUT / filename).write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n")
|
|
previous = json.loads(subprocess.check_output(["git", "show", BASE + ":" + RESOURCE]))
|
|
current = json.loads((REPO / RESOURCE).read_bytes())
|
|
changed = [p for p in previous if previous[p] != current[p]]
|
|
assert len(changed) == 1
|
|
target = changed[0]
|
|
objects = []
|
|
for path, before in previous.items():
|
|
after = current[path]
|
|
old_block = before.get("fixed_version_document")
|
|
if old_block is not None:
|
|
assert after["fixed_version_document"] == old_block
|
|
if path != target:
|
|
assert after == before
|
|
objects.append(
|
|
dict(
|
|
path=path,
|
|
other_review_unchanged=path != target,
|
|
before_review_sha256=hashlib.sha256(canonical(before)).hexdigest(),
|
|
after_review_sha256=hashlib.sha256(canonical(after)).hexdigest(),
|
|
old_fixed_block_sha256=hashlib.sha256(canonical(old_block)).hexdigest()
|
|
if old_block is not None
|
|
else None,
|
|
)
|
|
)
|
|
assert sum(e["old_fixed_block_sha256"] is not None for e in objects) == 137
|
|
(OUT / "object-digests.json").write_text(
|
|
json.dumps(
|
|
dict(base=BASE, old_blocks=137, other_reviews=155, objects=objects),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
added = dict(current[target])
|
|
added.pop("fixed_version_document")
|
|
assert added == previous[target]
|
|
(OUT / "json-pointer-delta.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
base=BASE,
|
|
path=target,
|
|
only_added_key="fixed_version_document",
|
|
other_review_objects_unchanged=155,
|
|
other_baseline_blobs_unchanged=len(frozen),
|
|
allowed_product_resources=sorted(allowed),
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print("PASS baseline blobs", len(frozen), "originals", len(originals))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|