This commit is contained in:
@@ -6,6 +6,7 @@ from datetime import UTC, datetime
|
||||
from cloud.internal_api.models import AssignmentModel, TerminalResultResponse
|
||||
from host_agent.assignment import AssignmentExecutionResult
|
||||
from host_agent.processor import AssignmentProcessor
|
||||
from host_agent.status import AgentStatusTracker
|
||||
|
||||
|
||||
def _assignment() -> AssignmentModel:
|
||||
@@ -85,3 +86,69 @@ def test_processor_preserves_runtime_failure_reason() -> None:
|
||||
}
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def test_status_tracker_sees_started_then_finished_even_on_raise() -> None:
|
||||
async def scenario() -> None:
|
||||
tracker = AgentStatusTracker()
|
||||
snapshots: list[dict[str, object]] = []
|
||||
|
||||
class RaisingExecutor:
|
||||
async def run(self, assignment):
|
||||
snapshots.append(tracker.snapshot())
|
||||
raise RuntimeError("executor exploded")
|
||||
|
||||
class RecordingClient:
|
||||
async def report_result(self, assignment, **kwargs):
|
||||
return TerminalResultResponse(status="recorded")
|
||||
|
||||
processor = AssignmentProcessor(
|
||||
RecordingClient(), # type: ignore[arg-type]
|
||||
RaisingExecutor(),
|
||||
status_tracker=tracker,
|
||||
)
|
||||
|
||||
try:
|
||||
await processor.process(_assignment())
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
assert snapshots[0]["current_assignment"] is not None
|
||||
assert snapshots[0]["current_assignment"]["task_id"] == "task-a"
|
||||
assert tracker.snapshot()["current_assignment"] is None
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def test_on_result_receives_assignment_and_result_and_swallows_exceptions() -> None:
|
||||
async def scenario() -> None:
|
||||
received: list[tuple[object, object]] = []
|
||||
|
||||
class SuccessfulExecutor:
|
||||
async def run(self, assignment):
|
||||
return AssignmentExecutionResult(
|
||||
status="done",
|
||||
failure_reason=None,
|
||||
metadata={},
|
||||
)
|
||||
|
||||
class RecordingClient:
|
||||
async def report_result(self, assignment, **kwargs):
|
||||
return TerminalResultResponse(status="recorded")
|
||||
|
||||
def on_result(assignment, result) -> None:
|
||||
received.append((assignment, result))
|
||||
raise RuntimeError("history recording exploded")
|
||||
|
||||
assignment = _assignment()
|
||||
processor = AssignmentProcessor(
|
||||
RecordingClient(), # type: ignore[arg-type]
|
||||
SuccessfulExecutor(),
|
||||
on_result=on_result,
|
||||
)
|
||||
|
||||
result = await processor.process(assignment)
|
||||
|
||||
assert received == [(assignment, result)]
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
Reference in New Issue
Block a user