Files
Sanctification/artifacts/cards/BP-020-ezekiel/review/finish-mask-trial-01/install-selected.py

111 lines
5.1 KiB
Python

#!/usr/bin/env python3
"""Select the reviewed contrast trial for Ezekiel's working assembly only."""
from pathlib import Path
import hashlib
import json
import shutil
import subprocess
import sys
HERE = Path(__file__).resolve().parent
REVISION = HERE.parents[1]
REPO = next(p for p in HERE.parents if (p / "docs/card-layer-pipeline.md").is_file())
VALIDATION = REVISION / "review/build-validation.json"
CARD = REVISION / "card.json"
BASELINE = HERE / "baseline"
PRINTINGS = ("normal", "borderless", "textless", "boundless")
WIDTHS = {"low": 500, "med": 1000, "high": 2000}
def digest(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def save(path, data):
path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n")
def main():
card = json.loads(CARD.read_text())
assert card["cardId"] == "BP-020" and card["selectedArtCandidate"] == "candidate-03"
assert card["artSHA256"] == digest(REPO / card["art"])
subprocess.run([sys.executable, str(HERE / "build-selected.py")], check=True)
trial = json.loads((HERE / "selected-validation.json").read_text())
assert trial["candidate"] == "gated-contrast" and trial["art"]["sha256"] == card["artSHA256"]
report = json.loads(VALIDATION.read_text())
assert report["status"] == "passed" and report["finishRecipe"]["id"] == "raw-ridges-v1"
assert report["inputs"]["art"]["sha256"] == card["artSHA256"]
BASELINE.mkdir(exist_ok=True)
backup_report = BASELINE / "build-validation-raw-ridges.json"
if backup_report.exists():
old = json.loads(backup_report.read_text())
assert old["finishRecipe"]["id"] == "raw-ridges-v1"
assert old["inputs"]["art"]["sha256"] == card["artSHA256"]
else:
shutil.copyfile(VALIDATION, backup_report)
changes = {}
for printing in PRINTINGS:
changes[printing] = {}
for export in report["printings"][printing]["exports"]:
label = export["resolution"]
width = WIDTHS[label]
target = REVISION / label / printing / "finish-mask.png"
source = HERE / "selected" / f"{printing}-{width}-finish-mask.png"
assert digest(target) == export["files"]["finish-mask.png"]
assert digest(source) == trial["printings"][printing]["files"][str(width)]["sha256"]
backup = BASELINE / f"{printing}-{width}-raw-ridges-finish-mask.png"
if backup.exists():
assert digest(backup) == digest(target)
else:
shutil.copyfile(target, backup)
old_sha = digest(target)
shutil.copyfile(source, target)
new_sha = digest(target)
assert new_sha == digest(source)
export["files"]["finish-mask.png"] = new_sha
changes[printing][str(width)] = {"baselineSHA256": old_sha, "selectedSHA256": new_sha}
for unchanged in ("card.png", "text-mask.png"):
unchanged_path = REVISION / label / printing / unchanged
assert digest(unchanged_path) == export["files"][unchanged]
old_recipe = report["finishRecipe"]
report["finishRecipe"] = {
"id": "ezekiel-gated-contrast-trial-v1",
"status": "user-selected for working assembly; final card and moving-light approval pending",
"userDirection": "Let's try the contrast one",
"trialRecipe": "review/finish-mask-trial-01/gated-trial.json",
"trialRecipeSHA256": digest(HERE / "gated-trial.json"),
"ridgeMap": "review/finish-mask-trial-01/gated-contrast-ridges-2000.png",
"ridgeMapSHA256": digest(HERE / "gated-contrast-ridges-2000.png"),
"trialBuilderSHA256": digest(HERE / "build-gated.py"),
"compilerSHA256": digest(HERE / "build-selected.py"),
"basePaneRecipe": old_recipe,
"baselineBuildValidation": "review/finish-mask-trial-01/baseline/build-validation-raw-ridges.json",
}
card["finishMaskSelection"] = {
"id": "ezekiel-gated-contrast-trial-v1",
"by": "user",
"note": "Let's try the contrast one",
"status": "working assembly trial; final visual approval pending",
"recipe": "review/finish-mask-trial-01/gated-trial.json",
}
save(CARD, card)
report["inputs"]["cardSHA256"] = digest(CARD)
report["visualReview"] = {"static": "contrast mask selected for assembly review", "movingLight": "not performed"}
report["finishMaskSelection"] = {"status": "trial selected", "changes": changes}
save(VALIDATION, report)
save(HERE / "installation.json", {
"status": "selected for BP-020 v01 working assembly, not final card approval",
"userDirection": "Let's try the contrast one",
"artSHA256": card["artSHA256"],
"baselineValidationSHA256": digest(backup_report),
"selectedTrialValidationSHA256": digest(HERE / "selected-validation.json"),
"changes": changes,
"cardFacesAndTextMasks": "unchanged and hash-verified",
"movingLightReview": "not performed",
})
print("BP-020 v01: gated-contrast finish maps selected for 12 working-assembly exports; card faces/text masks unchanged.")
if __name__ == "__main__":
main()