Files
aigc-home/docs/hel-892/history-attribution-correction/collect.py
T

77 lines
2.0 KiB
Python

"""Collect this correction's explicit command keys and unmodified raw streams."""
import hashlib
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
HERE = Path(__file__).resolve().parent
LOCAL = ROOT / ".local-evidence/history-attribution-correction"
KEYS = [
"preflight",
"contracts-initial",
"rebuild-initial",
"contracts-role-forms",
"rebuild-role-forms",
"contracts-joint-role",
"rebuild-joint-role",
"format-write",
"lint-initial",
"contracts-final",
"rebuild-final",
"verify-publish",
"format-delivery",
"lint-final",
"format-check",
"ast-diff-check",
"historical-resource-check",
"format-resource",
"lint-resource",
"ast-resource",
]
def main():
logs = HERE / "logs"
logs.mkdir(exist_ok=True)
records = []
for key in KEYS:
r = json.loads((LOCAL / "records" / (key + ".json")).read_bytes())
if key != "lint-initial":
assert r["returncode"] == 0
for log in r["logs"]:
raw = (ROOT / log["path"]).read_bytes()
assert len(raw) == log["bytes"]
assert hashlib.sha256(raw).hexdigest() == log["sha256"]
path = logs / Path(log["path"]).name
if path.exists():
assert path.read_bytes() == raw
else:
with path.open("xb") as f:
f.write(raw)
records.append(r)
with (HERE / "completed-log-records.json").open("x") as f:
json.dump(
dict(
explicit_keys=KEYS,
records=records,
failures=[r["key"] for r in records if r["returncode"]],
no_old_glob_or_log_overwrite=True,
),
f,
ensure_ascii=False,
indent=2,
)
f.write("\n")
print(
"PASS",
len(records),
"explicit commands;",
len(records) * 2,
"raw streams; failures retained",
)
if __name__ == "__main__":
main()