[Test Improver] test: add unit tests for prune command (14% -> 91%)#415
Merged
danielmeppiel merged 5 commits intomainfrom Mar 23, 2026
Merged
Conversation
20 tests covering: - Missing apm.yml (error + exit 1) - Missing apm_modules/ (no-op exit 0) - Clean state reporting - --dry-run shows orphans without removing - Orphan removal (single and multiple packages) - Declared packages preserved during prune - apm.yml parse error handling - safe_rmtree failure graceful handling - Lockfile entry cleanup for pruned packages - Deployed files cleanup from lockfile - Lockfile deletion when empty after prune - Lockfile preservation for remaining packages - Works without lockfile present Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…31-f0756e2a8bb295bf
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new unit test suite for the user-facing apm prune CLI command to substantially increase coverage around orphan removal, dry-run behavior, lockfile updates, and deployed-file cleanup.
Changes:
- Introduces
tests/unit/test_prune_command.pywith ClickCliRunnertests using real temp directories. - Covers key
prunescenarios: missingapm.yml, missingapm_modules/, clean state, dry-run, actual removal, YAML parse failure, andsafe_rmtreefailure handling. - Adds lockfile/deployed-file cleanup assertions for pruned dependencies.
Comments suppressed due to low confidence (1)
tests/unit/test_prune_command.py:393
- Docstring says "no apm.lock exists", but the current lockfile name is
apm.lock.yaml. Please update the wording so the test documentation matches the behavior under test.
def test_prune_works_without_lockfile(self):
"""prune removes orphaned packages even when no apm.lock exists."""
with self._chdir_tmp() as tmp:
(tmp / "apm.yml").write_text(_APM_YML_NO_DEPS)
orphan_dir = _make_package_dir(tmp, "orphan-org", "orphan-repo")
# No apm.lock created
Collaborator
Author
|
@copilot address pr review comments |
Contributor
|
@danielmeppiel I've opened a new pull request, #419, to work on those changes. Once the pull request is ready, I'll request review from you. |
7 tasks
* Initial plan * fix: address PR review comments on prune command tests Co-authored-by: danielmeppiel <51440732+danielmeppiel@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/apm/sessions/cad00612-e8f7-4f03-83f7-23a5cbdd84dc --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: danielmeppiel <51440732+danielmeppiel@users.noreply.github.com>
…31-f0756e2a8bb295bf
…31-f0756e2a8bb295bf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Test Improver - automated AI assistant for test improvements.
Goal and Rationale
The
apm prunecommand had only 14% test coverage despite being a user-facing CLI command that mutates the filesystem (removes package directories, cleans deployed integration files, and updates/deletes the lockfile). Low coverage on destructive commands is a high-risk gap.Approach
Added
tests/unit/test_prune_command.pywith 20 tests using the Click test runner and real temp directories (no mocking of filesystem operations, following the pattern used intest_deps_clean_command.py). Tests exercise:apm.yml→ exit 1 with error messageapm_modules/→ clean exit 0 with info--dry-runwith orphans → lists them but leaves files on disk; confirms "Dry run" in output--dry-runwith multiple orphans → all listedapm.yml→ exit 1 with errorsafe_rmtreefailure → error reported, no crashKey discovery: the current lockfile filename is
apm.lock.yaml(notapm.lock); tests use_write_lockfile()helper that writes to the correct path.Coverage Impact
src/apm_cli/commands/prune.pyRemaining uncovered lines (9/103): directory-cleanup branch inside deployed-file deletion loop, and the outer exception handler at line 148.
Test Status
All 2613 unit tests pass (20 new + 2593 existing).
Trade-offs
clear_apm_yml_cache()called in teardown to prevent cache leakage between tests