Skip to content

[Test Improver] test: add unit tests for uninstall CLI command (22 tests)#557

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/uninstall-cli-coverage-23929187646-d7e7ddd5cff57e9b
Draft

[Test Improver] test: add unit tests for uninstall CLI command (22 tests)#557
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/uninstall-cli-coverage-23929187646-d7e7ddd5cff57e9b

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 Test Improver here - automated AI assistant for test improvements.

Goal and Rationale

The apm uninstall CLI command (src/apm_cli/commands/uninstall/cli.py, 213 lines) orchestrates the entire uninstall flow — checking apm.yml exists, reading/writing YAML, removing packages from disk, updating the lockfile, syncing integrations, and MCP cleanup. Despite two existing engine-level test files (test_uninstall_reintegration.py, test_uninstall_transitive_cleanup.py), the CLI command itself had zero direct test coverage. This PR fills that gap.

Approach

22 end-to-end tests exercising the Click CLI command via CliRunner, following the same pattern as test_prune_command.py. Tests use a real temp directory (chdir pattern) for the project-scope path, and mock only the heavy integration/MCP sync callbacks.

Test cases:

  • Missing apm.yml → exit 1 (project and user scope)
  • Package not in apm.yml → warning + exit 0
  • --dry-run: shows what would be removed, leaves files untouched
  • Successful uninstall: removes from apm.yml + apm_modules/
  • Multiple packages in one invocation
  • Lockfile updated after partial removal
  • Lockfile deleted when last package removed
  • No lockfile present → succeeds gracefully
  • --global / user scope flag (missing manifest and successful removal)
  • --verbose flag accepted
  • Integration cleanup counts reported in output
  • YAML read/write error handling → exit 1

Coverage Impact

Scope Before After
uninstall/cli.py CLI command 0% (untested) ~80%+ (main orchestration path)
Total test count 3,545 3,567 (+22)

Note: No --cov flag used (known PyYAML global-state corruption with coverage plugin).

Reproducibility

pip install uv --break-system-packages
python3 -m uv sync --extra dev
python3 -m uv run pytest tests/unit/test_uninstall_cli.py -v
```

## Test Status

All 3,567 tests pass locally (unit suite + test_console.py):

```
3567 passed in 14.52s

Generated by Daily Test Improver ·

To install this agentic workflow, run

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

Tests cover the apm uninstall CLI command end-to-end:
- Missing apm.yml (project and user scope)
- Package not found in apm.yml (graceful warning)
- Dry-run: shows what would be removed, no side-effects
- Successful uninstall: removes from apm.yml + apm_modules/
- Multiple packages in one invocation
- Lockfile update after partial removal
- Lockfile deletion when last package removed
- --global / user scope flag
- --verbose flag
- Integration cleanup counts in output
- YAML read/write error handling

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