Files
AR-VMS-Seaman/tests/runtime/test_client.py
T
alro65 7390d5cd51 sprint-6: Runtime desktop client (PySide6 + WebSocket + REST)
Cliente desktop completo conectado al Runtime server por HTTP+WebSocket.

vmssailor/runtime/client/api_client.py
- RuntimeApiClient: wrapper async httpx contra /health, /project, /tags,
  /tags/{id}, /tags/{id}/history, /alarms, /logbook, /alarms/{id}/ack
- RuntimeWebSocketClient: conexion ws://host:port/ws/realtime con
  reconexion automatica + heartbeats + on_event/on_state_change callbacks

vmssailor/runtime/client/app.py
- RuntimeClientApp QApplication con tema Deep Ocean (compartido con Studio)
- run_client() entry point

vmssailor/runtime/client/main_window.py
- Topbar: logo + vessel name + status pill (connecting/connected/disconnected)
  + alarm chip + user chip
- Sidebar lista: Overview, Mimicos, Alarmas, Trends, Trim, Log Book, Conexion
- QStackedWidget central conmuta vista segun sidebar
- Reloj live + statusbar con estado WS + version
- Sprint 6 trae 3 vistas funcionales (Overview, Alarmas, Conexion); resto stubs

vmssailor/runtime/client/views/connection_view.py
- _AsyncWorker QObject corre asyncio event loop en QThread separado
- Conecta API + WS, emite signals connectionStateChanged / eventReceived / projectLoaded
- Tabla con ultimos 500 eventos crudos del WebSocket
- Conecta/desconecta sin congelar la UI

vmssailor/runtime/client/views/overview_view.py
- Grid de tiles dinamicas que se crean al recibir tag_update events
- Cada tile muestra: descripcion, tag_id, valor formateado, quality, timestamp
- Layout 4 columnas con QScrollArea

vmssailor/runtime/client/views/alarms_view.py
- Tabla de alarmas activas con priority coloreada (emergency/high/low/info)
- Boton ACK por fila emite signal acknowledged(alarm_id)
- handle_event mantiene set vivo segun state=active/cleared

runtime_client_main.py
- Entry point: uv run python runtime_client_main.py

Tests (tests/runtime/test_client.py, 5 nuevos, total 157/157):
- main window builds with 7 stack pages
- overview handles tag_update
- alarms view shows + clears on state change
- connection view initial state

Para correr el sistema completo en vivo:
    # Terminal 1 — servidor:
    uv run python runtime_server_main.py --verbose
    # Terminal 2 — cliente:
    uv run python runtime_client_main.py

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 20:37:06 -04:00

92 lines
2.4 KiB
Python

"""Tests del cliente Runtime (Sprint 6)."""
from __future__ import annotations
import pytest
pytest.importorskip("PySide6")
def test_client_window_builds(qtbot):
from vmssailor.runtime.client.main_window import RuntimeClientWindow
w = RuntimeClientWindow()
qtbot.addWidget(w)
assert w._stack.count() == 7 # Overview, Mimicos, Alarmas, Trends, Trim, Logbook, Conexion
assert "VMS-Sailor Runtime" in w.windowTitle()
def test_overview_handles_tag_update(qtbot):
from vmssailor.runtime.client.views.overview_view import OverviewView
ov = OverviewView()
qtbot.addWidget(ov)
ov.handle_event(
{
"type": "tag_update",
"tag_id": "ME_PORT.OIL_PRESS",
"value": 4.8,
"quality": "good",
"timestamp": "2026-05-17T03:42:00",
}
)
assert "ME_PORT.OIL_PRESS" in ov._tiles
def test_alarms_view_handles_alarm_event(qtbot):
from vmssailor.runtime.client.views.alarms_view import AlarmsView
av = AlarmsView()
qtbot.addWidget(av)
av.handle_event(
{
"type": "alarm_event",
"alarm_id": "alm_1",
"tag_id": "ME_PORT.OIL_PRESS",
"priority": "emergency",
"state": "active",
"message": "Oil press low",
}
)
assert av._table.rowCount() == 1
def test_alarms_view_clears(qtbot):
from vmssailor.runtime.client.views.alarms_view import AlarmsView
av = AlarmsView()
qtbot.addWidget(av)
av.handle_event(
{
"type": "alarm_event",
"alarm_id": "alm_1",
"tag_id": "X",
"priority": "low",
"state": "active",
"message": "low msg",
}
)
assert av._table.rowCount() == 1
av.handle_event(
{
"type": "alarm_event",
"alarm_id": "alm_1",
"tag_id": "X",
"priority": "low",
"state": "cleared",
"message": "low msg",
}
)
assert av._table.rowCount() == 0
def test_connection_view_initial_state(qtbot):
from vmssailor.runtime.client.views.connection_view import ConnectionView
cv = ConnectionView()
qtbot.addWidget(cv)
assert cv._connect_btn.isEnabled()
assert not cv._disconnect_btn.isEnabled()
assert cv._host_input.text() == "127.0.0.1"
assert cv._port_input.value() == 8765