Skip to content

Conversation

@yumibagge
Copy link

@yumibagge yumibagge commented Nov 12, 2025

Summary

This PR expands the cover-mcp server's capabilities beyond test creation by adding two new dcover commands: refactor (aliased as fix-build) and issues. This enables an AI assistant to have a complete workflow: diagnosing project health, fixing build issues, and then generating tests.

The Feature

  • Implements a new refactor tool that exposes dcover refactor (or fix-build).
  • Implements a new issues tool that exposes dcover issues, with parameters for limiting, skipping, and requesting prompts.
  • Refactors the common command-running logic into a single _run_dcover_command helper function for consistency in logging, execution, and error handling.
  • Addresses PR Feedback:
    • The _run_dcover_command helper now accepts **kwargs to centralize all tool-specific argument processing.
    • A new _build_tool_args helper is extracted to resolve Ruff PLR0912 (Too many branches) warnings.
    • Ruff PLR0913 (Too many arguments) is now suppressed with a noqa comment on the main helper.
    • Ruff PLR0917 (Too many positional arguments) is suppressed on the wrapper tools.

How to Test

  1. Run the MCP server.
  2. Call the refactor tool and verify it executes dcover refactor with the correct arguments (e.g., --dry-run).
  3. Call the issues tool and verify it executes dcover issues with the correct arguments (e.g., --limit 5, --prompt).
  4. Call the existing create tool and verify it still functions correctly after the refactor.
  5. All 23 tests should pass (uv run coverage run -m pytest -v).
  6. The linter should pass (uv run ruff check).

Related Ticket

[Link to Jira/GitHub Issue]

This commit refactors the core execution logic into a shared
`_run_dcover_command` helper function. This new function now
encapsulates:
- Finding the `dcover` executable
- Assembling the command
- Appending environment variable options (`DIFFBLUE_COVER_OPTIONS`)
- Calling `executor.execute`
- Streaming output to the MCP context
- Centralized `ToolError` handling

The existing `create` tool has been refactored to be a thin wrapper
around this new helper. This prepares the codebase for adding the
`refactor` and `issues` tools without code duplication.
Adds the new `refactor` tool to the MCP server. This tool exposes
the `dcover refactor` (also known as `fix-build`) command.

This implementation follows the refactored pattern, acting as a thin
wrapper around the `_run_dcover_command` helper. It includes
support for the `--dry-run` argument.

Unit tests are added to `test/test_server.py` to validate
the new tool's command assembly for both default and dry-run cases.
Adds the new `issues` tool to the MCP server, exposing the
`dcover issues` command.

This tool allows a user to programmatically query a project
for a prioritized list of issues. It includes support for
all of `issues`' specific arguments, such as `--limit`, `--skip`,
`--prompt`, `--cover-json`, and `--dry-run`.

Unit tests are added to `test/test_server.py` to validate
the new tool's command assembly, including a test for all
arguments combined.
Addresses PR feedback by refactoring the `_run_dcover_command`
helper to accept `**kwargs`.

This change centralizes all tool-specific argument processing
(for `create`, `refactor`, and `issues`) inside the helper,
making the tool functions themselves simpler wrappers.

The existing test suite (23 tests) passes without modification,
confirming this refactor is behavior-preserving.
This commit completes the feature by:
1.  Adding the new `issues` tool to the MCP server, exposing the
    `dcover issues` command.
2.  Adding corresponding unit tests for the `issues` tool, including
    a test for all its specific arguments.
3.  Refactoring the `_run_dcover_command` helper to accept `**kwargs`,
    addressing PR feedback. This centralizes all argument-building
    logic.
4.  Creating a new `_build_tool_args` helper function to resolve
    `PLR0912 (Too many branches)` linting errors.
5.  Adding a `noqa` directive for `PLR0913 (Too many arguments)`
    on the helper, as all arguments are necessary for its function.
Adds `noqa: PLR0917` (Too many positional arguments) to the
`create` and `refactor` tool function signatures.

This rule is intentionally suppressed as these functions are
 wrappers that must pass a consistent set of arguments to the
 underlying helper.
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.

2 participants