Skip to content

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

Open
danielmeppiel wants to merge 2 commits intomainfrom
test-assist/update-command-coverage-24221207307-9cbf3fb30797a8ce
Open

[Test Improver] test: expand coverage for update command (64% -> ~95%)#657
danielmeppiel wants to merge 2 commits 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>
@danielmeppiel danielmeppiel marked this pull request as ready for review April 18, 2026 02:56
Copilot AI review requested due to automatic review settings April 18, 2026 02:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands unit/integration-style test coverage for the apm update command, aiming to exercise platform helper functions and additional success/error branches in src/apm_cli/commands/update.py.

Changes:

  • Added unit tests for platform detection + installer URL/suffix/runner command helpers.
  • Added CLI-driven tests for dev-version behavior, version-fetch failures, already-up-to-date, --check behavior, installer failures, network errors, missing requests, and temp-file cleanup.
Show a summary per file
File Description
tests/unit/test_update_command.py Adds new test classes to cover platform helper utilities and more apm update command branches via CliRunner.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment on lines +169 to +170
def setUp(self):
self.runner = CliRunner()
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apm update writes the installer script into get_apm_temp_dir() (env var / user config dependent). These tests invoke the command without pinning that temp dir, so they can fail on developer machines where APM_TEMP_DIR or ~/.apm/config.json points to a non-writable/non-existent location. Consider setting APM_TEMP_DIR to a temporary directory (or otherwise patching get_apm_temp_dir) in setUp so the tests are hermetic across environments.

Copilot uses AI. Check for mistakes.
original_unlink = update_module.os.unlink

def tracking_unlink(path):
deleted_paths.append(path)
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

original_unlink is assigned but never used, and tracking_unlink does not call through to the real os.unlink. That means this test will leave the temporary installer script on disk, which can pollute the configured/system temp directory over repeated runs. Consider calling the original unlink inside the tracking wrapper (or avoid patching unlink and assert cleanup via filesystem state in an isolated temp dir).

Suggested change
deleted_paths.append(path)
deleted_paths.append(path)
original_unlink(path)

Copilot uses AI. Check for mistakes.
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.

2 participants