feat(host-agent): report assignment outcomes

This commit is contained in:
2026-07-12 19:09:07 +08:00
parent ec1e8c20d8
commit 91f08509a7
4 changed files with 166 additions and 1 deletions
@@ -1,6 +1,7 @@
from __future__ import annotations
import asyncio
import json
from datetime import UTC, datetime
import httpx
@@ -131,3 +132,37 @@ def test_stale_lease_response_raises_typed_error_without_retry() -> None:
asyncio.run(scenario())
assert attempts == 1
def test_result_report_retries_identical_payload_after_response_loss() -> None:
payloads: list[dict[str, object]] = []
def handler(request: httpx.Request) -> httpx.Response:
payloads.append(json.loads(request.content))
if len(payloads) == 1:
raise httpx.ReadError("response lost", request=request)
return httpx.Response(200, json={"status": "already_recorded"})
async def scenario() -> None:
async with httpx.AsyncClient(
transport=httpx.MockTransport(handler),
base_url="https://control.example",
) as http_client:
client = HostAgentClient(
_config(),
http_client=http_client,
sleep=lambda delay: asyncio.sleep(0),
)
response = await client.report_result(
_assignment(),
status="failed",
failure_reason="planner unavailable",
result={"runtime_status": "failed"},
)
assert response.status == "already_recorded"
asyncio.run(scenario())
assert len(payloads) == 2
assert payloads[0] == payloads[1]
assert payloads[0]["failure_reason"] == "planner unavailable"