Files
aigc-home/docs/hel-892/animate-time-correction/check_delta.py
T

116 lines
4.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Complete typed JSON pointer delta relative to e420, plus frozen values and resources."""
import hashlib
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
OUT = Path(__file__).resolve().parent
BASE = "e420c312e8f7ad226661db6a20608af816c719ab"
RESOURCE = "calliope-backend/src/calliope/comfyui/source_reviews.json"
def changes(a, b, path=""):
if type(a) is not type(b):
return [dict(pointer=path, before=a, after=b)]
if isinstance(a, dict):
assert a.keys() == b.keys(), path
return [
r
for k in a
for r in changes(a[k], b[k], path + "/" + k.replace("~", "~0").replace("/", "~1"))
]
if isinstance(a, list):
assert len(a) == len(b), path
return [
r
for i, (x, y) in enumerate(zip(a, b, strict=True))
for r in changes(x, y, path + "/" + str(i))
]
return [] if a == b else [dict(pointer=path, before=a, after=b)]
def main():
old = json.loads(subprocess.check_output(["git", "show", BASE + ":" + RESOURCE]))
new = json.loads((ROOT / RESOURCE).read_bytes())
targets = [p for p in old if old[p] != new[p]]
assert len(targets) == 1
path = targets[0]
assert {k: v for k, v in old[path].items() if k != "fixed_version_document"} == {
k: v for k, v in new[path].items() if k != "fixed_version_document"
}
a, b = old[path]["fixed_version_document"], new[path]["fixed_version_document"]
delta = changes(a, b)
expected = {f"/sources/{i}/{k}" for i in [116, 117, 127] for k in ["reverified_at", "claim"]}
assert {r["pointer"] for r in delta} == expected
manifest_path = "docs/hel-892/animate-reference/sources.json"
old_manifest = json.loads(subprocess.check_output(["git", "show", BASE + ":" + manifest_path]))
new_manifest = json.loads((ROOT / manifest_path).read_bytes())
manifest_delta = changes(old_manifest, new_manifest)
assert {r["pointer"] for r in manifest_delta} == {
f"/sources/{i}/reverified_at" for i in [116, 117, 127]
}
for i in [116, 117, 127]:
assert (
b["sources"][i]["claim"]
== a["sources"][i]["claim"] + ";本次复核UTC:" + b["sources"][i]["reverified_at"]
)
before_doc = json.loads(
(OUT.parent / "animate-document-evidence/actual-get.json").read_bytes()
)["doc_json"]
docs = list(OUT.glob("actual-Wan*.json"))
assert len(docs) == 1
after_doc = json.loads(docs[0].read_bytes())
doc_delta = changes(before_doc, after_doc)
assert {r["pointer"] for r in doc_delta} == {"/fixed_version" + p for p in expected} | {
"/source_review_sha"
}
assert a["fields"] == b["fields"] and not changes(a["fields"], b["fields"])
assert not changes(a["comments"], b["comments"])
original_checks = json.loads(
(OUT.parent / "animate-document-evidence/originals-163-check.json").read_bytes()
)
for row in original_checks["files"]:
assert hashlib.sha256((ROOT / row["path"]).read_bytes()).hexdigest() == row["sha256"]
inherited = []
for name in [
"animate-frontend-build.txt",
"browser-results.json",
"screenshot-review.json",
"animate-tests-final.txt",
]:
p = OUT.parent / "animate-document-evidence" / name
assert p.read_bytes() == subprocess.check_output(
["git", "show", BASE + ":" + str(p.relative_to(ROOT))]
)
inherited.append(
dict(
path=str(p.relative_to(ROOT)),
sha256=hashlib.sha256(p.read_bytes()).hexdigest(),
rerun=False,
)
)
result = dict(
base=BASE,
changed_review=path,
fixed_block_delta=delta,
source_manifest_delta=manifest_delta,
actual_doc_delta=doc_delta,
saved_values_typed_frozen=270,
notes_frozen=1,
originals_frozen=163,
old_blocks_frozen=142,
other_reviews_frozen=155,
inherited=inherited,
)
(OUT / "pointer-delta.json").write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
print(
"PASS complete delta:6 fixed-block pointers/7 actual-doc pointers; "
"only3 timestamps/date displays/hash; values/types/Note/all originals frozen"
)
if __name__ == "__main__":
main()