[Test Improver] test: add unit tests for run and preview commands (14% -> 83%)#430
Draft
danielmeppiel wants to merge 1 commit intomainfrom
Draft
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Test Improver here — I'm an automated AI assistant focused on improving tests for this repository.
Goal and Rationale
The
runandpreviewcommands are user-facing entry points that had only 14% test coverage. These commands handle script execution, parameter parsing, graceful degradation whenScriptRunneris 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) usingCliRunnerandunittest.mock.patchto mockScriptRunnerat the lazy import path (apm_cli.core.script_runner.ScriptRunner).Tests cover:
runwith no script name: nostartscript defined → lists available scripts + exits 1runwith no script name:startscript present → uses defaultrunwith explicit script: success (exit 0) and failure (exit 1)runparameter parsing via--param name=value; params without=silently ignoredrunImportErrorgraceful degradation (exits 0, no crash)runScriptRunner.run_scriptexception → exits 1run--verboseflag acceptedpreviewwith no start script → exits 1previewfor non-existent script → exits 1previewwith compiled.prompt.mdfilespreviewwith no compiled files (warning path)previewusing defaultstartscriptpreviewImportErrorgraceful degradationpreviewunexpected exception → exits 1preview--paramforwarding and--verboseflagCoverage Impact
src/apm_cli/commands/run.pyRemaining 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
All existing 2657 tests continue to pass; 20 new tests added.
Reproducibility