Skip to content

[Test Improver] test: add unit tests for run and preview commands (14% -> 83%)#430

Draft
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/run-command-coverage-23468043826-42722e3c71d22d1f
Draft

[Test Improver] test: add unit tests for run and preview commands (14% -> 83%)#430
danielmeppiel wants to merge 1 commit intomainfrom
test-assist/run-command-coverage-23468043826-42722e3c71d22d1f

Conversation

@danielmeppiel
Copy link
Collaborator

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

Goal and Rationale

The run and preview commands are user-facing entry points that had only 14% test coverage. These commands handle script execution, parameter parsing, graceful degradation when ScriptRunner is unavailable, and the complete preview flow. Tests here catch regressions in core CLI interaction flows.

Approach

Added 20 focused unit tests across two classes (TestRunCommand, TestPreviewCommand) using CliRunner and unittest.mock.patch to mock ScriptRunner at the lazy import path (apm_cli.core.script_runner.ScriptRunner).

Tests cover:

  • run with no script name: no start script defined → lists available scripts + exits 1
  • run with no script name: start script present → uses default
  • run with explicit script: success (exit 0) and failure (exit 1)
  • run parameter parsing via --param name=value; params without = silently ignored
  • run ImportError graceful degradation (exits 0, no crash)
  • run ScriptRunner.run_script exception → exits 1
  • run --verbose flag accepted
  • preview with no start script → exits 1
  • preview for non-existent script → exits 1
  • preview with compiled .prompt.md files
  • preview with no compiled files (warning path)
  • preview using default start script
  • preview ImportError graceful degradation
  • preview unexpected exception → exits 1
  • preview --param forwarding and --verbose flag

Coverage Impact

File Before After
src/apm_cli/commands/run.py 14% 83%

Remaining uncovered: rich table display path for listing scripts (lines 54-59), verbose param logging (93-94), and fallback text display in preview when rich import fails (185-208).

Test Status

2677 passed in 11.64s

All existing 2657 tests continue to pass; 20 new tests added.

Reproducibility

uv sync --extra dev
uv run pytest tests/unit/test_run_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 20 unit tests covering the run and preview CLI commands:
- run: no start script defined, explicit script success/failure
- run: parameter parsing, import error graceful degradation
- run: verbose flag, ScriptRunner exception handling
- preview: no script/start, script not found, compiled files
- preview: no compiled files, param forwarding, import error

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