Updated by fix-consistency on 2026-03-27: - update .custodian-brief.md for the-custodian
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""
|
|
Push e2e run results to the state-hub as a progress event.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import urllib.request
|
|
import urllib.error
|
|
from .runner import RunResult
|
|
|
|
STATE_HUB_URL = "http://127.0.0.1:8000"
|
|
|
|
|
|
def report(result: RunResult, workstream_id: str | None = None) -> bool:
|
|
"""POST result to state-hub add_progress_event. 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
|
|
|
|
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
|