Skip to content

Add comprehensive tests increasing coverage from 53% to 99%#1

Merged
msalsas merged 1 commit into
mainfrom
copilot/add-new-tests-for-coverage
Apr 25, 2026
Merged

Add comprehensive tests increasing coverage from 53% to 99%#1
msalsas merged 1 commit into
mainfrom
copilot/add-new-tests-for-coverage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 25, 2026

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's CliRunner

Extended existing test files

  • tests/services/lmstudio/test_client.py — async context manager, retry-on-failure, retry-succeeds-on-second-attempt
  • tests/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.pylist_loaded_models with string items
  • tests/services/swarmui/test_manager.py — recursive directory walk, non-dict response, non-dict file items, non-string folder items, free_memory exception handling
  • tests/test_formatter.pyparse_model_list with all key variants and unknown input types

Coverage by module (before → after)

Module Before After
main.py 0% 98%
swarmui/client.py 65% 100%
swarmui/monitor.py 90% 100%
lmstudio/client.py 84% 100%
utils/formatter.py 96% 100%
Total 53% 99%

Remaining uncovered lines (7 total)

  • main.py:251-252, 374-375 — outer except Exception wrappers around asyncio.run() (only reached if the event loop itself fails)
  • main.py:493-494except Exception for the full model-restore block in switch (would require create_client to fail at restore time)
  • main.py:505if __name__ == "__main__" guard (not executable via pytest)

@msalsas msalsas marked this pull request as ready for review April 25, 2026 21:56
@msalsas msalsas merged commit 94e2bf8 into main Apr 25, 2026
7 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and switch.
  • 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.

Comment thread tests/test_formatter.py

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
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ....

Suggested change
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

Copilot uses AI. Check for mistakes.
import pytest
from unittest.mock import AsyncMock
from llm_control.services.swarmui.monitor import SwarmUIMonitor
from llm_control.services.swarmui.monitor import SwarmUIMonitor, SwarmUIManager
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
from llm_control.services.swarmui.monitor import SwarmUIMonitor, SwarmUIManager
from llm_control.services.swarmui.monitor import SwarmUIMonitor

Copilot uses AI. Check for mistakes.
Comment thread tests/cli/test_main.py
Comment on lines +905 to +911
call_count = 0

original_invoke = runner.invoke

async def _limited_monitor():
pass

Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
call_count = 0
original_invoke = runner.invoke
async def _limited_monitor():
pass

Copilot uses AI. Check for mistakes.
Comment thread tests/cli/test_main.py
"""Tests for CLI commands in main.py."""

import json
import os
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
import os

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants