Skip to content

[Test Improver] test: add unit tests for drift-detection helpers (0% -> ~100%)#727

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/drift-detection-coverage-24486614511-e6485df22d208295
Draft

[Test Improver] test: add unit tests for drift-detection helpers (0% -> ~100%)#727
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/drift-detection-coverage-24486614511-e6485df22d208295

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 Test Improver — automated AI assistant

Goal and Rationale

src/apm_cli/drift.py contains four pure, stateless functions that drive every diff-aware apm install decision: which packages need re-downloading, which files should be cleaned up, and how to build reproducible download references.

The module's own docstring says these helpers are "easy to test in isolation" — yet they had no dedicated test file. A silent bug in any of these functions can cause:

  • packages to be silently skipped when they should be re-downloaded (missed updates)
  • orphaned files to accumulate on disk (drift not cleaned up)
  • proxy/Artifactory installs to use the wrong auth token

Approach

Tests use minimal in-file dataclass stubs (_LockedDep, _LockFile) to keep the test file self-contained and dependency-free. No mocking framework or I/O required.

Function Tests Key scenarios
detect_ref_change 11 update_refs bypass, new package, same/added/removed/changed ref, hash-based pins
detect_orphans 7 partial install guard, no lockfile, all kept, single and multi orphans, empty manifest, None treated as empty
detect_config_drift 7 empty inputs, unchanged, changed, new entries ignored, multi-entry partial drift, stored superset not flagged
build_download_ref 10 no lockfile, update_refs, ref_changed, locked commit SHA, 'cached' sentinel skipped, proxy host+prefix restored, proxy fallback ref, key missing

Coverage Impact

File Before After
src/apm_cli/drift.py ~0% ~100%

Test Status

All 3865 tests pass (3830 baseline + 35 new):

uv run pytest tests/unit tests/test_console.py -x -q
3865 passed in 16.13s

Reproducibility

uv run pytest tests/unit/test_drift_detection.py -v

Generated by Daily Test Improver ·

To install this agentic workflow, run

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

Add 35 new tests for apm_cli.drift -- pure stateless helpers that
drive diff-aware apm install decisions:

- detect_ref_change: update_refs mode, new package (None locked), same ref,
  ref added/removed/changed, hash-based pin changes (11 tests)
- detect_orphans: partial install guard, no-lockfile first install, all
  packages present, single and multiple orphaned packages, empty manifest,
  None only_packages treated as empty (7 tests)
- detect_config_drift: empty inputs, unchanged config, changed config,
  brand-new entries ignored, multi-entry partial drift, stored superset
  not flagged (7 tests)
- build_download_ref: no lockfile, update_refs mode, ref_changed, locked
  commit SHA used, 'cached' sentinel not used, proxy host+prefix restored,
  proxy fallback ref, proxy with existing ref not overridden, non-proxy
  host diff, key missing from lockfile (10 tests)

These helpers are documented as 'easy to test in isolation' yet had no
dedicated test file.  They are on the critical path of every apm install
run -- a bug here can silently prevent re-downloads or incorrectly
trigger them.

Tests: 3830 -> 3865 (+35)

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