Skip to content

[Test Improver] test: add unit tests for uninstall engine helpers (0% -> ~70%)#678

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/uninstall-engine-coverage-24295572069-013dd7bcf23b8948
Draft

[Test Improver] test: add unit tests for uninstall engine helpers (0% -> ~70%)#678
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/uninstall-engine-coverage-24295572069-013dd7bcf23b8948

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 Test Improver — automated AI assistant

Goal and Rationale

src/apm_cli/commands/uninstall/engine.py (372 lines) contained 7 helper functions with 0% direct unit-test coverage. The existing uninstall tests (test_uninstall_reintegration.py, test_uninstall_transitive_cleanup.py) exercise higher-level integration paths but leave the engine helpers untested at the unit level.

These helpers handle critical uninstall logic: parsing dependency entries, matching packages to apm.yml, dry-run previews, disk removal with path-traversal protection, transitive orphan cleanup, and MCP server cleanup. Unit tests here catch regressions early with no I/O overhead.

Approach

Added tests/unit/test_uninstall_engine.py with 35 tests targeting each helper function directly:

Function Tests Key cases
_parse_dependency_entry 6 string, DependencyReference passthrough, dict, invalid types
_validate_uninstall_packages 8 matched, not-found, invalid format, empty lists, DependencyReference in deps
_dry_run_uninstall 4 pkg on disk, pkg missing, no packages, lockfile present
_remove_packages_from_disk 6 removal, missing pkg warning, absent dir, multiple pkgs, string fallback, PathTraversalError
_cleanup_transitive_orphans 7 no lockfile, chain orphans (A→B→C), still-needed deps excluded, not on disk
_cleanup_stale_mcp 4 no-op on empty, stale removal, all-remain no-op, exception in get_mcp_dependencies

Coverage Impact

File Before After (estimated)
commands/uninstall/engine.py ~71% (indirect) ~85%+ (direct helpers)

Coverage was not measured with --cov (causes PyYAML corruption); estimates based on function-level tracing.

Test Status

35 passed in 0.32s
3858 passed in 19.62s (full unit suite)

All existing tests continue to pass.

Reproducibility

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

Generated by Daily Test Improver ·

To install this agentic workflow, run

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

Adds 35 unit tests covering the helper functions in
src/apm_cli/commands/uninstall/engine.py:

- _parse_dependency_entry: string/DependencyReference/dict/invalid types
- _validate_uninstall_packages: matched/unmatched/invalid format/empty cases
- _dry_run_uninstall: packages on disk, missing, no packages
- _remove_packages_from_disk: removal, warnings, absent dir, traversal rejection
- _cleanup_transitive_orphans: no lockfile, chain orphans, still-needed deps
- _cleanup_stale_mcp: no-op, stale removal, exception 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