Skip to content

[Test Improver] test: add unit tests for RuntimeManager and runtime CLI commands (20%→92%, 49%→90%)#380

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/runtime-manager-coverage-23324556076-2111a21d57ba6a0f
Draft

[Test Improver] test: add unit tests for RuntimeManager and runtime CLI commands (20%→92%, 49%→90%)#380
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/runtime-manager-coverage-23324556076-2111a21d57ba6a0f

Conversation

@danielmeppiel
Copy link
Collaborator

🤖 Test Improver — automated AI assistant

Goal and Rationale

runtime/manager.py and commands/runtime.py had almost no test coverage (49% and 20% respectively), yet they implement user-facing CLI commands for managing AI runtimes (install/list/remove/status). These are critical-path operations users run when setting up the tool. Low coverage here means regressions go undetected.

Approach

Added tests/unit/test_runtime_manager.py with 53 focused unit tests covering:

RuntimeManager (runtime/manager.py):

  • Initialization: runtime directory, supported runtimes, platform-specific script extensions (.sh vs .ps1)
  • list_runtimes: all-uninstalled, binary in APM dir, binary in system PATH, version detection (success + exception fallback)
  • is_runtime_available: apm dir binary, directory (not file), system PATH fallback, unknown runtime
  • get_available_runtime: priority order, first-wins, none available
  • setup_runtime: unsupported runtime, success/failure/exception, version and vanilla flag forwarding
  • remove_runtime: unknown runtime, copilot npm (success/failure/exception), binary not installed, file removal, directory removal, LLM venv cleanup

commands/runtime CLI (commands/runtime.py):

  • setup: success, failure (exit 1), exception (exit 1), --version, --vanilla, invalid runtime name
  • list: exit 0, calls list_runtimes, exception (exit 1), Rich table fallback path showing runtime names
  • remove: success, failure (exit 1), exception (exit 1), invalid runtime name
  • status: available runtime, no runtime available, exception (exit 1)

Coverage Impact

Module Before After
src/apm_cli/commands/runtime.py 20% 92% (+72pp)
src/apm_cli/runtime/manager.py 49% 90% (+41pp)

Remaining uncovered lines: commands/runtime.py:171-182 (fallback status display with no Rich panel), runtime/manager.py:53-56,85-88,98-101,119-120,137-138,172-174 (PyInstaller bundle paths and Windows-specific script writing — these require platform-specific test environments).

Trade-offs

  • RuntimeManager tests use mocks for subprocess, shutil, and filesystem — fast and hermetic but don't test actual shell script execution (appropriate for unit tests; integration tested in CI scripts)
  • Windows-specific code paths (.ps1 scripts, PowerShell execution) not covered — would need platform-conditional tests or a Windows runner

Reproducibility

uv sync --extra dev
uv run pytest tests/unit/test_runtime_manager.py -v
# Full suite
uv run pytest tests/unit/ --no-header -q

Test Status

✅ All 53 new tests pass
✅ Full suite: 2157 tests pass (up from 2104 before this PR)
✅ No regressions

Generated by Daily Test Improver ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/daily-test-improver.md@b87234850bf9664d198f28a02df0f937d0447295

…→92%, 49%→90%)

- Add 53 tests covering commands/runtime.py and runtime/manager.py
- RuntimeManager: init, list_runtimes, is_runtime_available, get_available_runtime,
  setup_runtime (success/failure/exception/args), remove_runtime (copilot npm,
  binary file/dir, llm venv cleanup), get_embedded_script
- CLI commands: setup/list/remove/status success and error paths,
  argument validation, Rich table fallback path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant