85 lines
3.6 KiB
Python
85 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Run and record the selected-case publication verification commands."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
OUTPUT = Path("coverage/release-verification.report.json")
|
|
|
|
COMMANDS = (
|
|
("baseline", ("python3", "scripts/validate_baseline.py")),
|
|
("pointer", ("python3", "scripts/validate_task_pointer.py", "nextTask1.md", "--lock", "context-lock.json")),
|
|
("wasm_build", ("scripts/build-wasm.sh",)),
|
|
("t7_gate_tests", ("python3", "scripts/test_wasm_simulation_release_gate_t7.py")),
|
|
("selected_case", ("node", "web/worker/test_axis3_selected_case.mjs")),
|
|
("selected_case_visible", ("node", "web/worker/test_axis3_visible_completion.mjs")),
|
|
("selected_case_program", ("node", "web/worker/test_axis3_tutorial_program.mjs")),
|
|
("wasm_canonical_state", ("node", "web/worker/test_wasm_canonical_state.mjs")),
|
|
("wasm_canonical_checkpoint", ("node", "web/worker/test_wasm_canonical_state_checkpoint.mjs")),
|
|
("react_typecheck", ("npm", "--prefix", "web/react", "run", "typecheck")),
|
|
("react_build", ("npm", "--prefix", "web/react", "run", "build")),
|
|
)
|
|
|
|
|
|
def canonical(value: Any) -> str:
|
|
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
|
|
|
|
def digest(value: Any) -> str:
|
|
return hashlib.sha256(canonical(value).encode("utf-8")).hexdigest()
|
|
|
|
|
|
def generate(root: Path, output: Path = OUTPUT) -> dict[str, Any]:
|
|
root = root.resolve()
|
|
runs: list[dict[str, Any]] = []
|
|
for name, command in COMMANDS:
|
|
completed = subprocess.run(command, cwd=root, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=False)
|
|
output_text = completed.stdout
|
|
runs.append({
|
|
"name": name,
|
|
"command": list(command),
|
|
"exit_code": completed.returncode,
|
|
"status": "passed" if completed.returncode == 0 else "failed",
|
|
"output_bytes": len(output_text.encode("utf-8")),
|
|
"output_sha256": hashlib.sha256(output_text.encode("utf-8")).hexdigest(),
|
|
})
|
|
passed = all(item["status"] == "passed" for item in runs)
|
|
report: dict[str, Any] = {
|
|
"schema": "release-verification.v1",
|
|
"task_id": "RELEASE-VERIFICATION-01",
|
|
"status": "verified" if passed else "blocked",
|
|
"scope": "selected_case_web_wasm_simulation",
|
|
"commands": runs,
|
|
"required_command_count": len(COMMANDS),
|
|
"passed_command_count": sum(item["status"] == "passed" for item in runs),
|
|
"release_action": "ALLOW_RELEASE" if passed else "STOP_RELEASE",
|
|
"report_sha256": None,
|
|
}
|
|
report["report_sha256"] = digest({key: value for key, value in report.items() if key != "report_sha256"})
|
|
destination = output if output.is_absolute() else root / output
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
destination.write_text(json.dumps(report, ensure_ascii=False, sort_keys=True, indent=2) + "\n", encoding="utf-8")
|
|
return report
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--repo-root", type=Path, default=ROOT)
|
|
parser.add_argument("--output", type=Path, default=OUTPUT)
|
|
args = parser.parse_args()
|
|
report = generate(args.repo_root.resolve(), args.output)
|
|
print(f"release_verification={report['status']} passed={report['passed_command_count']}/{report['required_command_count']}")
|
|
return 0 if report["status"] == "verified" else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|