[Test Improver] test: add unit tests for drift-detection helpers (0% -> ~100%)#727
Conversation
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>
…4511-e6485df22d208295
There was a problem hiding this comment.
Pull request overview
Adds dedicated unit coverage for the pure drift-detection helpers in apm_cli.drift, ensuring core apm install drift decisions (ref changes, orphan cleanup, config drift, and reproducible download refs) are validated in isolation.
Changes:
- Introduces a new
tests/unit/test_drift_detection.pysuite coveringdetect_ref_change,detect_orphans,detect_config_drift, andbuild_download_ref. - Uses small in-file lockfile/locked-dependency stubs to keep the tests fast and dependency-free.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_drift_detection.py | Adds unit tests for drift-detection helper functions, including ref drift, orphan detection, config drift, and download-ref construction. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 2
| import unittest | ||
| from dataclasses import dataclass, field | ||
| from typing import Dict, List, Optional | ||
| from unittest.mock import MagicMock |
There was a problem hiding this comment.
Unused import: MagicMock is imported but never used in this test module. Please remove it to keep the test file clean and avoid potential lint failures.
| from unittest.mock import MagicMock |
| dep = _dep(reference="v2.0.0") | ||
| self.assertFalse(detect_ref_change(dep, locked, update_refs=True)) | ||
|
|
||
| def test_update_refs_false_no_lockfile(self): |
There was a problem hiding this comment.
Test name/docstring mismatch: this test passes update_refs=True but is named test_update_refs_false_no_lockfile, which makes the intent harder to follow. Consider renaming the test (or updating its docstring) so it consistently reflects the exercised behavior.
| def test_update_refs_false_no_lockfile(self): | |
| def test_update_refs_true_no_lockfile_returns_false(self): |
…4511-e6485df22d208295
🤖 Test Improver — automated AI assistant
Goal and Rationale
src/apm_cli/drift.pycontains four pure, stateless functions that drive every diff-awareapm installdecision: 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:
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.detect_ref_changeupdate_refsbypass, new package, same/added/removed/changed ref, hash-based pinsdetect_orphansNonetreated as emptydetect_config_driftbuild_download_refupdate_refs,ref_changed, locked commit SHA,'cached'sentinel skipped, proxy host+prefix restored, proxy fallback ref, key missingCoverage Impact
src/apm_cli/drift.pyTest Status
All 3865 tests pass (3830 baseline + 35 new):
Reproducibility