Skip to content

[Test Improver] Add unit tests for commands/_helpers.py I/O and config helpers#333

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/command-helpers-coverage-1773710009-d5146800ef1d3222
Draft

[Test Improver] Add unit tests for commands/_helpers.py I/O and config helpers#333
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/command-helpers-coverage-1773710009-d5146800ef1d3222

Conversation

@danielmeppiel
Copy link
Collaborator

🤖 Test Improver here — I'm an automated AI assistant focused on improving tests for this repository.

Goal and Rationale

src/apm_cli/commands/_helpers.py is a shared utility module used by every command (init, install, run, list, config, etc.). It was at 59% coverage despite containing critical I/O helpers. This PR adds targeted tests for the highest-value uncovered paths.

What's Tested

Function What's Covered
_atomic_write Normal write, overwrite, empty string, unicode, temp-file cleanup on error
_update_gitignore_for_apm_modules Creates file when absent, skips when entry exists, appends to existing, adds comment header, handles read error
_load_apm_config Returns None when no apm.yml, parses config, handles scripts section
_get_default_script Returns None when missing, returns "start" when present
_list_available_scripts Returns {} when no file/scripts, returns full scripts dict
_scan_installed_packages Dir absent, 2-level packages, 3-level packages, dot-named dirs, no-marker dirs
_check_and_notify_updates E2E env var skip, unknown version skip, no-op when up-to-date, warns with version, silently ignores exceptions

Coverage Impact

File Before After Δ
commands/_helpers.py 59% 80% +21pp
Total 58% 58% 0pp

Approach

  • Pure unit tests using tmp_path, monkeypatch, and unittest.mock.patch
  • No new dependencies
  • Each class tests one function; each test one behavior

Test Status

30 passed in 0.27s
1938 passed in 14.03s  # full suite

Commands

# Run new tests only
uv run pytest tests/unit/test_command_helpers.py -v

# Full suite
uv run pytest tests/unit/ --no-header -q

# With coverage
uv run pytest tests/unit/ --cov=apm_cli --cov-report=term-missing

Generated by Daily Test Improver ·

To install this agentic workflow, run

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

Cover _atomic_write, _update_gitignore_for_apm_modules, _load_apm_config,
_get_default_script, _list_available_scripts, _scan_installed_packages, and
_check_and_notify_updates. Coverage on _helpers.py: 59% → 80% (+21pp).

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