test: final 6 agents — 172+ translate tests, llm_analysis 89%, git_plugin 100%, migration/deps/routes polished. 85-94% files pushed to 95%+. Bulk: backup/debug/maintenance plugins

This commit is contained in:
2026-06-15 22:04:40 +03:00
parent 8995d7beae
commit 7010c40102
35 changed files with 7811 additions and 49 deletions

View File

@@ -233,6 +233,96 @@ class TestMatchesFilters:
# #endregion test_matches_filters
class TestWebSocketMainLoopCoverage:
"""Cover the main loop lines 654, 658, 660-677 — non-terminal status, log filter, log forwarding, terminal log message."""
# #region test_non_terminal_status_continue [C:2] [TYPE Function]
@pytest.mark.asyncio
async def test_non_terminal_status_continue(self):
"""Non-terminal status (RUNNING) -> continue at line 654 is hit."""
from src.app import websocket_endpoint
ws = MagicMock(); ws.query_params = {"token": "valid"}
ws.send_json = AsyncMock(); ws.accept = AsyncMock(); ws.close = AsyncMock()
task = _make_mock_task("task-continue", "RUNNING")
# Put both a non-terminal status and then a terminal one to end the loop
lq, sq = asyncio.Queue(), asyncio.Queue()
await sq.put({"type": "task_status", "task_id": "task-continue", "task": {"status": "RUNNING"}})
await sq.put({"type": "task_status", "task_id": "task-continue", "task": {"status": "SUCCESS"}})
async def sl(t): return lq
async def ss(t): return sq
with (
patch("src.app._authenticate_websocket", return_value=True),
patch("src.app.get_task_manager") as mg,
):
tm = _make_task_manager_mock(task=task, logs=[])
tm.subscribe_logs = sl; tm.subscribe_status = ss; mg.return_value = tm
await websocket_endpoint(ws, "task-continue")
ws.accept.assert_called_once()
# #endregion test_non_terminal_status_continue
# #region test_log_filter_continue_and_forward [C:2] [TYPE Function]
@pytest.mark.asyncio
async def test_log_filter_continue_and_forward(self):
"""Log entry filtered out (line 658) + log entry forwarded (lines 660-662)."""
from src.app import websocket_endpoint
ws = MagicMock(); ws.query_params = {"token": "valid"}
ws.send_json = AsyncMock(); ws.accept = AsyncMock(); ws.close = AsyncMock()
task = _make_mock_task("task-filter", "RUNNING")
# Log entry that won't match source filter
filtered_log = _make_mock_log_entry(msg="Filtered out", source="superset_api", level="DEBUG")
# Log entry that will match
passed_log = _make_mock_log_entry(msg="Passed through", source="plugin", level="INFO")
lq, sq = asyncio.Queue(), asyncio.Queue()
# Non-terminal status first, then the two log entries, then terminal
await sq.put({"type": "task_status", "task_id": "task-filter", "task": {"status": "RUNNING"}})
await lq.put(filtered_log)
await lq.put(passed_log)
await sq.put({"type": "task_status", "task_id": "task-filter", "task": {"status": "SUCCESS"}})
async def sl(t): return lq
async def ss(t): return sq
with (
patch("src.app._authenticate_websocket", return_value=True),
patch("src.app.get_task_manager") as mg,
):
tm = _make_task_manager_mock(task=task, logs=[])
tm.subscribe_logs = sl; tm.subscribe_status = ss; mg.return_value = tm
await websocket_endpoint(ws, "task-filter")
ws.accept.assert_called_once()
# #endregion test_log_filter_continue_and_forward
# #region test_terminal_log_message_detected [C:2] [TYPE Function]
@pytest.mark.asyncio
async def test_terminal_log_message_detected(self):
"""Log entry with 'Task completed successfully' triggers delay at lines 669-677."""
from src.app import websocket_endpoint
ws = MagicMock(); ws.query_params = {"token": "valid"}
ws.send_json = AsyncMock(); ws.accept = AsyncMock(); ws.close = AsyncMock()
task = _make_mock_task("task-term-msg", "RUNNING")
term_log = _make_mock_log_entry(msg="Task completed successfully", source="plugin", level="INFO")
lq, sq = asyncio.Queue(), asyncio.Queue()
await sq.put({"type": "task_status", "task_id": "task-term-msg", "task": {"status": "RUNNING"}})
await lq.put(term_log)
await sq.put({"type": "task_status", "task_id": "task-term-msg", "task": {"status": "SUCCESS"}})
async def sl(t): return lq
async def ss(t): return sq
with (
patch("src.app._authenticate_websocket", return_value=True),
patch("src.app.get_task_manager") as mg,
patch("src.app.logger") as mock_logger,
):
tm = _make_task_manager_mock(task=task, logs=[])
tm.subscribe_logs = sl; tm.subscribe_status = ss; mg.return_value = tm
await websocket_endpoint(ws, "task-term-msg")
ws.accept.assert_called_once()
# #endregion test_terminal_log_message_detected
class TestWebSocketMainLoopExceptions:
"""Generic Exception re-raise in WS main loops."""