Add comprehensive tests increasing coverage from 53% to 99%#1
Conversation
Agent-Logs-Url: https://github.com/msalsas/llm-control/sessions/b8fcf81b-8250-4ba2-8516-b5576de570bb Co-authored-by: msalsas <4210017+msalsas@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a large suite of new/expanded tests to significantly increase coverage across CLI commands and backend service clients.
Changes:
- Added a new CLI integration test suite covering
monitor,models,load,unload,free-memory,status, andswitch. - Expanded SwarmUI client/monitor/manager tests to cover additional response shapes, retry/session behavior, and error handling.
- Expanded LMStudio client tests for async context management and retry behavior; added formatter parsing tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
tests/cli/test_main.py |
New end-to-end-ish Click CliRunner tests for all CLI commands and key error paths. |
tests/services/lmstudio/test_client.py |
Adds tests for async context manager and retry success/failure scenarios. |
tests/services/swarmui/test_client.py |
Adds tests for async context manager, session parsing/coercion, GET support, and retry/session reset behavior. |
tests/services/swarmui/test_manager.py |
Adds coverage for recursive model walking and free-memory exception handling. |
tests/services/swarmui/test_monitor.py |
Adds coverage for list_loaded_models when API returns string items. |
tests/test_formatter.py |
Adds coverage for parse_model_list handling multiple key variants and unknown types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| import pytest | ||
| from src.llm_control.utils.formatter import format_table, format_json | ||
| from src.llm_control.utils.formatter import format_table, format_json, parse_model_list |
There was a problem hiding this comment.
The test imports formatter utilities via src.llm_control..., but this project installs the package as llm_control (see pyproject.toml / src/llm_control). Importing src.llm_control will fail under pip install -e . (CI). Update the import to from llm_control.utils.formatter import ....
| from src.llm_control.utils.formatter import format_table, format_json, parse_model_list | |
| from llm_control.utils.formatter import format_table, format_json, parse_model_list |
| import pytest | ||
| from unittest.mock import AsyncMock | ||
| from llm_control.services.swarmui.monitor import SwarmUIMonitor | ||
| from llm_control.services.swarmui.monitor import SwarmUIMonitor, SwarmUIManager |
There was a problem hiding this comment.
SwarmUIManager is imported here but never used in this test module. This will trigger flake8 unused-import warnings (F401). Remove the unused import or use it if intended.
| from llm_control.services.swarmui.monitor import SwarmUIMonitor, SwarmUIManager | |
| from llm_control.services.swarmui.monitor import SwarmUIMonitor |
| call_count = 0 | ||
|
|
||
| original_invoke = runner.invoke | ||
|
|
||
| async def _limited_monitor(): | ||
| pass | ||
|
|
There was a problem hiding this comment.
This test defines unused variables/functions (call_count, original_invoke, _limited_monitor) that are never referenced. This will trigger flake8 F841 warnings and adds noise. Remove the unused definitions and keep only the asyncio.sleep patch used to stop the watch loop.
| call_count = 0 | |
| original_invoke = runner.invoke | |
| async def _limited_monitor(): | |
| pass |
| """Tests for CLI commands in main.py.""" | ||
|
|
||
| import json | ||
| import os |
There was a problem hiding this comment.
os is imported but not used directly in this test module (all references are via patch("os...") strings). This will trigger flake8 unused-import warnings (F401). Remove the unused import os.
| import os |
Summary
Added 67 new test cases across 6 files to increase overall code coverage from 53% → 99% (765 statements, only 7 lines remain uncovered).
Changes
New test file
tests/cli/test_main.py— Full CLI integration tests for all commands (monitor,models,load,unload,free-memory,status,switch) using Click'sCliRunnerExtended existing test files
tests/services/lmstudio/test_client.py— async context manager, retry-on-failure, retry-succeeds-on-second-attempttests/services/swarmui/test_client.py— context manager, session reuse, plain-string session ID, unknown-type session ID,get()method, retry-resets-session, all-failures-exhausted, empty session fallback (RuntimeError)tests/services/swarmui/test_monitor.py—list_loaded_modelswith string itemstests/services/swarmui/test_manager.py— recursive directory walk, non-dict response, non-dict file items, non-string folder items,free_memoryexception handlingtests/test_formatter.py—parse_model_listwith all key variants and unknown input typesCoverage by module (before → after)
main.pyswarmui/client.pyswarmui/monitor.pylmstudio/client.pyutils/formatter.pyRemaining uncovered lines (7 total)
main.py:251-252, 374-375— outerexcept Exceptionwrappers aroundasyncio.run()(only reached if the event loop itself fails)main.py:493-494—except Exceptionfor the full model-restore block inswitch(would requirecreate_clientto fail at restore time)main.py:505—if __name__ == "__main__"guard (not executable via pytest)