Skip to content

[Test Improver] test: add unit tests for deps/_utils.py helpers (~50% -> ~95%)#686

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/deps-utils-coverage-24321072248-885ea646f60b6330
Draft

[Test Improver] test: add unit tests for deps/_utils.py helpers (~50% -> ~95%)#686
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/deps-utils-coverage-24321072248-885ea646f60b6330

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 Test Improver — automated AI assistant focused on improving tests for this repository.

Goal and Rationale

src/apm_cli/commands/deps/_utils.py contains 8 pure utility functions used across the deps command group (list, tree, info, update). These functions scan the filesystem for installed packages, count primitives, and build display/info dicts. Despite being used widely, they had no dedicated unit tests (~50% coverage from integration-level tests in other files).

Adding direct unit tests here:

  • Catches regressions in directory scanning logic (GitHub 2-level vs ADO 3-level layouts)
  • Documents subtle behavior (e.g. _scan_installed_packages does NOT recursively skip children of hidden directories, only the hidden directory itself; APMPackage.source is not populated from apm.yml)
  • Enables safe refactoring of these shared helpers

Approach

  • 48 tests using pytest.tmp_path for filesystem isolation — no mocking of IO
  • Each function has its own TestXxx class; tests cover happy path, empty inputs, edge cases, and error handling
  • unittest.mock.patch used only for exception-path tests (verifying graceful fallback)

Coverage Impact

File Before After
src/apm_cli/commands/deps/_utils.py ~50% ~95%

Test suite: 3823 → 3871 passing (+48)

Trade-offs

  • Tests are filesystem-based (use tmp_path); fast and hermetic, no network/subprocess
  • Explicit coverage of the "hidden dir" behavioral quirk documents current behavior as-is (not a bug fix)

Reproducibility

pip install uv --break-system-packages
python3 -m uv sync --extra dev
python3 -m uv run pytest tests/unit/test_deps_utils.py -v
# Full unit suite:
python3 -m uv run pytest tests/unit tests/test_console.py -x -q

Test Status

All 3871 unit tests pass locally on this branch.

Generated by Daily Test Improver ·

To install this agentic workflow, run

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

Add 48 unit tests covering all 8 helper functions in
src/apm_cli/commands/deps/_utils.py:
- _scan_installed_packages: directory traversal for GitHub/ADO layouts
- _is_nested_under_package: sub-package detection
- _count_primitives: counts prompts, instructions, agents, skills, hooks
- _count_package_files: context and workflow file counting
- _count_workflows: wrapper around _count_package_files
- _get_detailed_context_counts: per-type breakdown of context files
- _get_package_display_info: display string from apm.yml
- _get_detailed_package_info: full info dict including error handling

Tests use tmp_path fixtures for filesystem isolation. Includes edge
cases: missing directories, empty dirs, hidden dirs, exception handling,
and directory naming quirks (context vs contexts).

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