Skip to content

[Test Improver] test: expand view command coverage (66% -> 95%)#713

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/view-command-coverage-24431073040-85648ed5190f5d8a
Draft

[Test Improver] test: expand view command coverage (66% -> 95%)#713
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/view-command-coverage-24431073040-85648ed5190f5d8a

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

🤖 Test Improver - automated AI assistant

Goal

src/apm_cli/commands/view.py was at 66% coverage (67 missing statements). Key untested paths included the Rich rendering codepaths, lockfile ref/commit display, context file and workflow counts, hook display, and the --global scope flag.

What was tested

14 new tests across 4 new test classes added to tests/unit/test_view_command.py:

Class Tests Coverage gained
TestViewCommandRichDisplay 5 Rich panel + versions table rendering
TestViewLockfileRef 4 _lookup_lockfile_ref + ref/commit in output
TestViewHooks 3 Hook file display (plain + rich) + context files + workflows
TestViewGlobalScope 2 --global flag and user-scope resolution

Coverage

Before After
commands/view.py 66% (128/195) 95% (186/195)

Remaining 9 uncovered lines are defensive exception handlers (PathTraversalError from ensure_path_within, except Exception in lockfile lookup, and the outer except Exception in display_package_info) — not practical to trigger in unit tests.

Approach

  • Rich render tests omit _force_rich_fallback() so the Rich Panel/Table paths execute
  • Lockfile tests write a minimal apm.lock.yaml using yaml.safe_dump to exercise _lookup_lockfile_ref (lines 107–118)
  • Context file/workflow tests create .apm/instructions/ and .apm/prompts/ dirs to hit count > 0 branches
  • Global flag tests patch apm_cli.core.scope.get_apm_dir directly

Test status

All 3841 unit tests pass (up from 3827 on main, +14 new tests).

uv run pytest tests/unit tests/test_console.py -x -q
# 3841 passed

Commands to reproduce

pip install uv --break-system-packages
uv sync --extra dev
uv run pytest tests/unit/test_view_command.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 14 new tests covering:
- Rich panel rendering paths (display_package_info, display_versions)
- Lockfile ref/commit display (_lookup_lockfile_ref, lines 107-118)
- Context file and workflow counts in both Rich and plain-text paths
- Hook file display in both Rich and plain-text paths
- --global flag scope resolution (lines 354-356)
- Global scope missing apm_modules/ error handling

Coverage: 66% -> 95% (195 stmts, 9 remaining in exception guards)
Tests: 19 -> 33 (+14)

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