fix(host-agent): distinguish connected devices from busy-with-task in console
Tests / Test failed: 2, passed: 693
Tests / Test failed: 2, passed: 693
DeviceManager marks a device "busy" as soon as an Appium/WDA session is connected, which is unrelated to whether a task is currently executing on it. The Host Agent's local console displayed this raw status, making connected-but-idle devices look permanently busy. Cross-reference the device id against AgentStatusTracker's current_assignment (already tracked via mark_assignment_started/finished) to show "connected" unless a task is actually running on that device.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from cloud.internal_api.models import AssignmentModel
|
||||
from device.manager import DeviceManager
|
||||
from host_agent.config import HostAgentConfig
|
||||
from host_agent.history import ConsoleHistoryStore
|
||||
@@ -53,6 +55,7 @@ def _build_client(tmp_path, *, create_account: bool = True) -> tuple[TestClient,
|
||||
"local_account_store": local_account_store,
|
||||
"history_store": history_store,
|
||||
"session_manager": session_manager,
|
||||
"status_tracker": status_tracker,
|
||||
}
|
||||
return client, context
|
||||
|
||||
@@ -119,6 +122,52 @@ def test_login_with_correct_password_sets_cookie_and_dashboard_succeeds(
|
||||
assert "control.example" in response.text
|
||||
|
||||
|
||||
def test_connected_device_without_running_task_shows_connected_not_busy(
|
||||
tmp_path,
|
||||
) -> None:
|
||||
client, context = _build_client(tmp_path)
|
||||
_login(client)
|
||||
context["manager"].register_device(
|
||||
"device-a",
|
||||
lambda: object(), # type: ignore[arg-type,return-value]
|
||||
status="busy",
|
||||
)
|
||||
|
||||
dashboard_response = client.get("/")
|
||||
api_response = client.get("/api/status")
|
||||
|
||||
assert "connected" in dashboard_response.text
|
||||
assert "<td>busy</td>" not in dashboard_response.text
|
||||
assert api_response.json()["devices"][0]["status"] == "connected"
|
||||
|
||||
|
||||
def test_device_running_current_assignment_still_shows_busy(tmp_path) -> None:
|
||||
client, context = _build_client(tmp_path)
|
||||
_login(client)
|
||||
context["manager"].register_device(
|
||||
"device-a",
|
||||
lambda: object(), # type: ignore[arg-type,return-value]
|
||||
status="busy",
|
||||
)
|
||||
context["status_tracker"].mark_assignment_started(
|
||||
AssignmentModel(
|
||||
task_id="task-a",
|
||||
attempt=1,
|
||||
lease_id="lease-a",
|
||||
lease_expires_at=datetime(2026, 7, 12, tzinfo=UTC),
|
||||
host_id="host-a",
|
||||
device_id="device-a",
|
||||
goal="open settings",
|
||||
)
|
||||
)
|
||||
|
||||
dashboard_response = client.get("/")
|
||||
api_response = client.get("/api/status")
|
||||
|
||||
assert "<td>busy</td>" in dashboard_response.text
|
||||
assert api_response.json()["devices"][0]["status"] == "busy"
|
||||
|
||||
|
||||
def test_mutating_post_without_csrf_token_is_rejected_and_makes_no_change(
|
||||
tmp_path,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user