feat(cloud-sdk): expose distributed task status
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from cloud.config import CloudConfig
|
||||
@@ -92,6 +94,47 @@ def test_unknown_task_id_returns_404(tmp_path) -> None:
|
||||
assert resp.status_code == 404, resp.text
|
||||
|
||||
|
||||
def test_task_status_exposes_distributed_metadata_without_lease_secret(
|
||||
tmp_path,
|
||||
) -> None:
|
||||
app, pool, scheduler, _ = _build_app(tmp_path)
|
||||
pool.sync_host_devices(
|
||||
"host-a",
|
||||
[Device(id="device-a", driver_type="wda", status="idle")], # type: ignore[arg-type]
|
||||
)
|
||||
task_id = scheduler.submit(goal="remote task")
|
||||
scheduler.assign()
|
||||
|
||||
active = _client_for(app).get(f"/v1/tasks/{task_id}").json()
|
||||
|
||||
assert active["status"] == "assigned"
|
||||
assert active["assigned_host_id"] == "host-a"
|
||||
assert active["assigned_device_id"] == "device-a"
|
||||
assert active["attempt_count"] == 1
|
||||
assert active["lease_expires_at"] is not None
|
||||
assert active["failure_reason"] is None
|
||||
assert "lease_id" not in active
|
||||
|
||||
task = scheduler.store.get_task(task_id)
|
||||
scheduler.store.record_task_result(
|
||||
task_id=task_id,
|
||||
attempt=task.attempt_count,
|
||||
lease_id=task.lease_id or "",
|
||||
host_id=task.assigned_host_id or "",
|
||||
status="failed",
|
||||
failure_reason="planner unavailable",
|
||||
terminal_result={"runtime_status": "failed"},
|
||||
completed_at=datetime.now(UTC),
|
||||
)
|
||||
|
||||
failed = _client_for(app).get(f"/v1/tasks/{task_id}").json()
|
||||
|
||||
assert failed["status"] == "failed"
|
||||
assert failed["attempt_count"] == 1
|
||||
assert failed["failure_reason"] == "planner unavailable"
|
||||
assert "lease_id" not in failed
|
||||
|
||||
|
||||
def test_device_and_host_listing_reflect_pool_state(tmp_path) -> None:
|
||||
app, pool, _, _ = _build_app(tmp_path)
|
||||
pool.sync_host_devices(
|
||||
|
||||
Reference in New Issue
Block a user