#!/usr/bin/env python3 """Build a browsable HTML report for one VM run. Combines `results.json` (structured checks) with `screenshot-manifest.json` (per-capture metadata) into a single page that links each check to its screenshots. Output goes next to the run directory's artifacts and is meant to stay outside git. python3 installer/tests/vm/report.py /var/tmp/phoebus-vm/ """ from __future__ import annotations import html import json import sys from pathlib import Path STATUS_CLASS = { "PASS": "pass", "FAIL": "fail", "BLOCKED": "blocked", "SKIPPED": "skip", "NOT RUN": "skip", } def build(run_dir: Path) -> Path: results = json.loads((run_dir / "results.json").read_text()) manifest_path = run_dir / "screenshot-manifest.json" manifest = json.loads(manifest_path.read_text()) if manifest_path.exists() else [] def esc(value) -> str: return html.escape(str(value)) rows = [] for check in results.get("checks", []): cls = STATUS_CLASS.get(check["status"], "skip") detail = f'{esc(check.get("detail", ""))}' if check.get("detail") else "" rows.append( f'{esc(check["status"])}' f'{esc(check["name"])}{detail}' ) shots = [] for shot in manifest: png = shot.get("png") rel = None if png: try: rel = str(Path(png).relative_to(run_dir)) except ValueError: rel = Path(png).name image = f'' if rel else "no image" shots.append( "
" f'{image}
{esc(shot.get("ui_state"))}
' f'{esc(shot.get("action"))} → expected: {esc(shot.get("expected"))}; ' f'observed: {esc(shot.get("observed"))}
' ) counts = results.get("counts", {}) summary = " · ".join(f"{k}={v}" for k, v in counts.items() if v) page = f""" Phoebus VM report · {esc(results.get('run_id'))}

Phoebus VM report · {esc(results.get('run_id'))}

scenario: {esc(results.get('scenario'))} · exit_code: {esc(results.get('exit_code'))} · {esc(summary)}

Checks

{''.join(rows) or ''}
no checks

Screenshots ({len(shots)})

""" out = run_dir / "report.html" out.write_text(page) return out def main() -> int: if len(sys.argv) != 2: print(__doc__) return 2 run_dir = Path(sys.argv[1]) if not (run_dir / "results.json").exists(): print(f"no results.json in {run_dir}", file=sys.stderr) return 1 print(build(run_dir)) return 0 if __name__ == "__main__": sys.exit(main())