89 lines
5.0 KiB
Python
89 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate deterministic FE-M1 frontend vertical-slice evidence."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
|
|
CONTEXT = Path("context-lock.json")
|
|
PYTHON = Path("coverage/python-worker-bridge.report.json")
|
|
SESSION = Path("coverage/workspace-session-integration.report.json")
|
|
GATE = Path("coverage/release-candidate-gate.report.json")
|
|
FILES = (Path("web/app/index.html"), Path("web/app/app.mjs"), Path("web/app/worker-client.mjs"), Path("web/app/styles.css"), Path("web/app/test_frontend_m1.mjs"))
|
|
OUTPUT = Path("coverage/frontend-m1.report.json")
|
|
|
|
|
|
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 artifact(root: Path, path: Path, role: str) -> dict[str, Any]:
|
|
full = root / path
|
|
if not full.is_file(): return {"path": path.as_posix(), "role": role, "status": "missing"}
|
|
return {"path": path.as_posix(), "role": role, "status": "present", "bytes": full.stat().st_size, "sha256": hashlib.sha256(full.read_bytes()).hexdigest()}
|
|
|
|
|
|
def run_smoke(root: Path) -> dict[str, Any]:
|
|
result = subprocess.run(["node", "web/app/test_frontend_m1.mjs"], cwd=root, check=False, capture_output=True, text=True)
|
|
return {"status": "passed" if result.returncode == 0 else "blocked", "exit_code": result.returncode, "stdout": result.stdout.strip(), "stdout_sha256": digest(result.stdout), "stderr_sha256": digest(result.stderr)}
|
|
|
|
|
|
def generate(root: Path, output: Path = OUTPUT) -> dict[str, Any]:
|
|
root = root.resolve()
|
|
lock = json.loads((root / CONTEXT).read_text(encoding="utf-8"))
|
|
python = json.loads((root / PYTHON).read_text(encoding="utf-8"))
|
|
session = json.loads((root / SESSION).read_text(encoding="utf-8"))
|
|
gate = json.loads((root / GATE).read_text(encoding="utf-8"))
|
|
files = [artifact(root, path, "frontend_source") for path in FILES]
|
|
app_source = (root / "web/app/app.mjs").read_text(encoding="utf-8") if (root / "web/app/app.mjs").is_file() else ""
|
|
client_source = (root / "web/app/worker-client.mjs").read_text(encoding="utf-8") if (root / "web/app/worker-client.mjs").is_file() else ""
|
|
smoke = run_smoke(root)
|
|
checks = {
|
|
"source_files": {"status": "verified" if all(row["status"] == "present" for row in files) else "blocked", "files": files},
|
|
"worker_boundary": {"status": "verified" if "WorkerClient" in app_source and "postMessage" in client_source and "_sim_" not in app_source else "blocked"},
|
|
"protocol_workflow": {"status": "verified" if all(token in client_source for token in ("HELLO", "SESSION_ATTACH", "LOAD_WORKSPACE", "SIM_STEP", "SNAPSHOT_REQUEST")) else "blocked"},
|
|
"dependency_chain": {"status": "verified" if python.get("implementation_status") == "verified" and session.get("implementation_status") == "verified" else "blocked"},
|
|
"browser_smoke": {"status": "verified" if smoke["status"] == "passed" else "blocked", "stdout": smoke["stdout"]},
|
|
"release_stop_preserved": {"status": "verified" if gate.get("release_action") == "STOP_RELEASE" and gate.get("candidate_eligible") is False else "blocked", "release_action": gate.get("release_action")},
|
|
}
|
|
checks_ok = all(row["status"] == "verified" for row in checks.values())
|
|
report: dict[str, Any] = {
|
|
"schema": "frontend-m1.v1",
|
|
"context_id": lock.get("context_id"),
|
|
"task_id": "FE-M1",
|
|
"status": "partial" if checks_ok else "blocked",
|
|
"implementation_status": "verified" if checks_ok else "blocked",
|
|
"candidate_eligible": False,
|
|
"release_action": "STOP_RELEASE",
|
|
"inputs": [artifact(root, CONTEXT, "context_lock"), artifact(root, PYTHON, "python_worker_bridge"), artifact(root, SESSION, "workspace_session_integration"), artifact(root, GATE, "release_candidate_gate")],
|
|
"outputs": files,
|
|
"checks": checks,
|
|
"smoke": smoke,
|
|
"next_transition": "execute FE-M2 core operation controls and state panels",
|
|
"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(description=__doc__)
|
|
parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parents[1])
|
|
parser.add_argument("--output", type=Path, default=OUTPUT)
|
|
args = parser.parse_args()
|
|
report = generate(args.repo_root.resolve(), args.output)
|
|
print(f"frontend_m1={report['status']} smoke={report['checks']['browser_smoke']['status']}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__": raise SystemExit(main())
|