Skip to content

[Test Improver] test: add unit tests for mcp command group (search/show/list)#483

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/mcp-command-coverage-23698265699-1ce0b0b11b08ca76
Draft

[Test Improver] test: add unit tests for mcp command group (search/show/list)#483
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/mcp-command-coverage-23698265699-1ce0b0b11b08ca76

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

Summary

🤖 Test Improver here - I'm an automated AI assistant. This PR was created automatically to improve test coverage.

Adds 22 new unit tests for src/apm_cli/commands/mcp.py — the apm mcp search, apm mcp show, and apm mcp list commands — which had no dedicated test file.

Goal and Rationale

The mcp command group is a user-facing feature for registry discovery. It had zero dedicated unit tests. These commands involve network calls (RegistryIntegration), Rich console output, and fallback plain-text paths — all of which benefit from being tested in isolation.

Approach

  • Mock RegistryIntegration at apm_cli.registry.integration.RegistryIntegration (lazy import inside function bodies — not patchable at apm_cli.commands.mcp).
  • Mock _get_console to toggle between the Rich console path and the non-Rich fallback path.
  • Use Click's CliRunner via the cli entry point for realistic invocation.
  • Cover: no results, results found, network error, limit-hint logic, description/package-name truncation, verbose flag.

Coverage Impact

File Before After (est.)
src/apm_cli/commands/mcp.py ~0% ~75%

Test Status

3130 passed in 12.33s  (was 3108 before this PR: +22 tests)

All 22 new tests pass. No regressions.

Reproducibility

uv run pytest tests/unit/test_mcp_command.py -v
uv run pytest tests/unit tests/test_console.py -x -q

Trade-offs

  • RegistryIntegration must be patched at its source module, not at mcp. This is documented as a comment in the test file to avoid future confusion.
  • No coverage of full Rich table rendering internals — the mock captures console.print calls and asserts they are made, which is the right level of abstraction for CLI command tests.

Generated by Daily Test Improver ·

To install this agentic workflow, run

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

22 new tests covering:
- mcp search: no results, results found, network error (rich + fallback paths)
- mcp show: server not found, full detail with packages/remotes, network error
- mcp list: no results, results found, limit hint, verbose flag
- Description truncation and package name truncation edge cases

RegistryIntegration is lazily imported inside function bodies; tests patch
at apm_cli.registry.integration.RegistryIntegration (the source module).

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