Skip to content

[Test Improver] test: expand coverage for update command (64% -> ~95%)#657

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/update-command-coverage-24221207307-9cbf3fb30797a8ce
Draft

[Test Improver] test: expand coverage for update command (64% -> ~95%)#657
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/update-command-coverage-24221207307-9cbf3fb30797a8ce

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 Test Improver automated PR — an AI assistant focused on improving test quality for this repository.

Goal and Rationale

The apm update command had only 3 tests (64% coverage) covering the success-path installer logic. Many important code paths were untested:

  • Platform detection helpers (_is_windows_platform, _get_update_installer_url, etc.)
  • Error paths: dev version detection, failed version fetch, already-up-to-date check
  • Edge cases: PowerShell not found on Windows, /bin/sh fallback on Unix, requests not installed
  • Temp file cleanup verification

These are real user-facing code paths that can silently fail (e.g., wrong installer URL served to the wrong platform, missing PowerShell erroring without a clear message).

Approach

Added 21 new tests in two new test classes alongside the existing TestUpdateCommand:

  • TestUpdatePlatformHelpers: Pure unit tests for all platform-detection helper functions. No mocking of subprocess or network — just platform patches.
  • TestUpdateCommandLogic: Integration-style tests via CliRunner covering the full command flow for each error/success branch.

Coverage Impact

File Before After
src/apm_cli/commands/update.py 64% (32 miss) ~95% (few lines in outer except)

Total tests: 3790 (main) → 3811 (branch, +21)

Trade-offs

  • Tests mock requests.get, subprocess.run, and get_version — standard patterns for CLI command testing in this repo.
  • The requests ImportError test uses builtins.__import__ patching, which is slightly more involved but accurately tests the fallback path.

Reproducibility

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

Test Status

All 3811 tests pass (3790 pre-existing + 21 new).

Generated by Daily Test Improver ·

To install this agentic workflow, run

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

Add 21 new tests covering previously untested paths in update.py:

- Platform helper tests: _is_windows_platform(), _get_update_installer_url(),
  _get_update_installer_suffix(), _get_manual_update_command() (Unix path)
- _get_installer_run_command(): /bin/sh fallback, pwsh fallback, no PowerShell error
- Update command logic: dev version (with/without --check), can't fetch latest,
  already on latest, update available with --check, installer failure (exit 1),
  requests not available (exit 1), network error (exit 1), temp file cleanup

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