Files
wise-validator/src/wisevalidator/reporter.py
tegwick 8d509fc6f1 Implement SAND-WP-0003: validation meta-framework extraction
Port e2e-framework schema, runner, and reporter into wise-validator with
sand-boxer CLI integration, validate run CLI, unit tests, registry capability,
and operator docs.
2026-06-23 21:37:07 +02:00

53 lines
1.7 KiB
Python

"""Push validation run results to State Hub as progress events."""
from __future__ import annotations
import json
import os
import urllib.error
import urllib.request
from wisevalidator.models import RunResult
STATE_HUB_URL = os.environ.get("STATE_HUB_URL", "http://127.0.0.1:8000")
def report(result: RunResult, workstream_id: str | None = None) -> bool:
"""POST result to state-hub /progress/. Returns True on success."""
body = {
"event_type": "e2e_result",
"repo": result.repo,
"sandbox_id": result.sandbox_id,
"passed": result.passed,
"exit_code": result.exit_code,
"duration_s": round(result.duration_s, 1),
}
if result.error:
body["error"] = result.error
if result.health_outcomes:
body["health_outcomes"] = result.health_outcomes
payload = {
"summary": (
f"E2E {'PASSED' if result.passed else 'FAILED'}: {result.repo} "
f"(sandbox={result.sandbox_id}, {result.duration_s:.0f}s)"
),
"details": json.dumps(body),
"event_type": "e2e_result",
}
if workstream_id:
payload["workstream_id"] = workstream_id
try:
req = urllib.request.Request(
f"{STATE_HUB_URL}/progress/",
data=json.dumps(payload).encode(),
headers={"Content-Type": "application/json"},
method="POST",
)
with urllib.request.urlopen(req, timeout=10) as resp:
print(f"[reporter] progress event recorded (status={resp.status})")
return True
except urllib.error.URLError as exc:
print(f"[reporter] WARNING: could not reach state-hub: {exc}")
return False