Skip to content

feat(run): add apm run --list for the scripts in apm.yml - #5806

Open
Daniel Meppiel (danielmeppiel) wants to merge 6 commits into
mainfrom
danielmeppiel-didactic-disco
Open

Daniel Meppiel (danielmeppiel) wants to merge 6 commits into
mainfrom
danielmeppiel-didactic-disco

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

apm run --list prints the scripts in apm.yml exactly as apm list prints them today
(the "Available Scripts" table, or the "No scripts found" panel), exits 0 and runs nothing.
This is part 1 of #5756: once scripts have this home, bare apm list can switch to the
agent-config inventory in 0.40 (part 2, a separate PR).

What changes:

  • apm run --list has its own scripts renderer in commands/run.py, producing the same
    bytes as apm list today (checked on the scripts table, the no-scripts panel, no
    apm.yml, and a broken apm.yml, exit 1). It does not import from list_cmd.py, whose
    scripts body goes away in part 2. With a SCRIPT_NAME or --param it refuses with a
    usage error (exit 2) and runs nothing.
  • The script-not-found hint now says Run 'apm run --list' to see each script and its command.
  • Docs point scripts readers to apm run --list: reference/cli/run.md (option, example,
    exit codes, Related), reference/cli/preview.md, troubleshooting/index.md,
    troubleshooting/common-errors.md, consumer/install-packages.md, and the apm-usage guide.
  • Bare apm list is unchanged here. Its row in the guide and reference/cli/list.md stay
    until part 2 switches it.

Issue and approved scope

Issue: Refs #5756

Human scope-approval comment: #5756 (comment)

Does this PR complete the issue, or what remains? Partial. Remaining for #5756: the switch of
bare apm list to the inventory, with the one stderr line pointing to apm run --list while
apm.yml has scripts, and its J13 assertion.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Red first. The test commit (3e66aa9) lands before the fix (543fe6a); 5e95bcf
moves the renderer into run.py and ports the tests/unit/test_list_command.py cases.

promise: P-LAW-list.scripts_transition (#5745 promise 3) -- `apm run --list` stdout and exit
  equal the previous release's `apm list` byte-for-byte and run nothing
  (source: #5756 scope record; list test plan)
cell: OP=run --list SCOPE=project SCRIPTS={2 scripts | none | no apm.yml}
owner: src/apm_cli/commands/run.py (renderer: commands/list_cmd.py, imported)
instrument: today journey -> tests/lifecycle/journeys/test_journeys.py::test_journey[J13]
  (extends: step 1 retargeted, O1 golden goldens/J13/01.txt added)
  + unit -> tests/unit/commands/test_run_list.py (new: frozen 0.39 raw bytes for the table,
    the panel and no apm.yml; plain-text fallback bytes; the list_cmd cases ported)
oracles: [O1 golden, O9 files: [], FORBID, I5, I8]
  decisive: J13 step 1 O1 transcript == goldens/J13/01.txt (stdout and exit; the journey
  normalizer strips ANSI and trailing spaces), unit output == frozen raw bytes, and I5:
  the read-only step writes nothing (no .apm/compiled)
failing-before: pytest "tests/lifecycle/journeys/test_journeys.py::test_journey[J13]" -n 0
  -> O5: 'apm run --list' exited 2, step expects 0 / O1: transcript differs ...
     +Error: No such option: --list
  pytest tests/unit/commands/test_run_list.py tests/unit/core/test_runnable_prompts.py -n 0
  -> 6 failed (Error: No such option: --list; the hint still says 'apm list')
passing-after: same commands -> 53 passed (with tests/unit/test_list_command.py)
guard+mutation: n/a     ledger: n/a
diagnostic-mutation: src/apm_cli/commands/run.py:52 column "Script" -> "Name"
  -> J13 O1: transcript differs: -|     | Script       | Command  ... (and the unit byte test)
diagnostic-mutation: src/apm_cli/commands/run.py:50 title " Available Scripts" -> "Available Scripts"
  -> unit: assert result.output == expected (title line centring differs)
diagnostic-mutation: src/apm_cli/commands/run.py:108 drop the `return` after _list_scripts(...)
  -> J13 I5: read-only run wrote project:['.apm', '.apm/compiled', '.apm/compiled/review.txt']
diagnostic-mutation: src/apm_cli/core/script_runner.py:127 hint back to 'apm list'
  -> J13 step 4 O8b: advice 'apm run --list' is not printed
hints executed: J13 step 4 runs the printed `apm run --list` advice -> lists `cat review.prompt.md`

The golden goldens/J13/01.txt was recorded with regen_goldens.py J13 while step 1 still
ran apm list on main (bb90fc7). Only the $ apm list command line was then relabelled
$ apm run --list. list_cmd.py, _helpers.py and utils/console.py have no diff since
v0.39.4, so these bytes are the previous release's output.

Lint mirror (ruff 0.15.12 check and format, pylint R0801, auth signals, complexity ratchet,
tm006 --changed) is clean locally. Quality gates run: test_journey_index.py,
test_cli_docs_surface.py, test_cli_command_literals.py, test_promise_obligations.py,
test_test_taxonomy.py.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

Agent assessment

  • Change confidence: High. A small additive flag that reuses the existing renderer; byte
    equality is pinned by a golden recorded from the current output, and a run-nothing check
    is pinned by the journey write-set oracle.

J13 step 1 now runs 'apm run --list' against an O1 golden captured from
today's 'apm list' (the 0.39 scripts table), and asserts it runs nothing.
Step 4's diagnose advice moves to 'apm run --list'.

Refs #5756

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
'apm run --list' prints the 'apm list' scripts table or the No scripts
found panel byte-for-byte, exits 0 and runs nothing, so bare 'apm list'
can switch to the agent-config inventory. The script-not-found hint and
the docs now point to 'apm run --list'.

Refs #5756

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 22:20
Refs #5756

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Tests are misclassified as unit tests despite filesystem and CLI use, and documentation incorrectly claims that apm list lists installed packages.

2 open issues
What changed in this PR

Adds apm run --list as the scripts-listing entry point for #5756, preparing for a later inventory-focused apm list. Bare apm list remains unchanged.

Changes:

  • Reuses the existing renderer and rejects script names or parameters with --list.
  • Updates script-discovery hints and documentation.
  • Adds frozen-output tests and lifecycle coverage for listing without execution.
File Description
tests/​unit/​core/​test_runnable_prompts.py Updates the expected discovery hint.
tests/​unit/​commands/​test_run_list.py Tests output, argument rejection, and no execution.
tests/​quality/​generated_obligations.json Registers the J13 golden assertion.
tests/​lifecycle/​journeys/​index.yaml Retargets J13 to run --list.
tests/​lifecycle/​journeys/​goldens/​J13/​01.txt Captures expected listing output.
tests/​lifecycle/​journeys/​consumer/​J13-run-scripts.yaml Checks listing and updated recovery advice.
src/​apm_cli/​core/​script_runner.py Updates the script-not-found hint.
src/​apm_cli/​commands/​run.py Adds the listing flag and delegation.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Adds the command to the usage guide.
docs/​src/​content/​docs/​troubleshooting/​index.md Updates scripts and packages guidance.
docs/​src/​content/​docs/​troubleshooting/​common-errors.md Updates script-discovery advice.
docs/​src/​content/​docs/​reference/​cli/​run.md Documents the option, examples, and exit codes.
docs/​src/​content/​docs/​reference/​cli/​preview.md Links to the new listing entry point.
docs/​src/​content/​docs/​consumer/​install-packages.md Distinguishes script and package listings.
changelog.d/​5806.added.md Announces the new command option.

Review effort: Balanced

Comment thread tests/unit/commands/test_run_list.py Resolved
'apm run --list' no longer imports from list_cmd, whose scripts body goes
away when bare 'apm list' switches to the inventory. The renderer lives
in run.py (a new module would need an architecture owner); output stays
byte-identical. The list_cmd unit cases are ported to test_run_list.py.

Refs #5756

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mark test_run_list.py as component (it writes apm.yml and drives Click),
and keep the docs truthful while bare 'apm list' still lists scripts.

Refs #5756

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Dec 3, 2026
…t (S141)

D removed the scripts table from list_cmd (run.py is its single owner, #5806).
TestListCmd in tests/integration/test_coverage_phase4.py patched
list_cmd._list_available_scripts/_get_console and is deleted. Each of its
seven behaviours already has an exact oracle in tests/unit/commands/test_run_list.py:

- test_no_scripts_shows_warning_and_example -> test_run_list_prints_the_0_39_list_output_and_runs_nothing[no-scripts-panel] (exact bytes) + test_no_scripts_panel_gets_the_example_block
- test_scripts_shown_via_fallback_no_console -> test_plain_fallback_without_console[start-is-default, no-default] (exact output)
- test_start_script_marked_as_default -> test_run_list_prints_the_0_39_list_output_and_runs_nothing[scripts-table] (exact "[>] | start" row) + test_plain_fallback_without_console[start-is-default]
- test_scripts_shown_via_rich_console -> test_rich_console_prints_table_then_default_note (console.print call count) + [scripts-table] exact table
- test_exception_in_list_scripts_exits_1 -> test_read_error_exits_1_with_the_error (exit 1 + "[x] Error listing scripts: disk error")
- test_no_scripts_rich_panel_import_error_fallback -> test_no_scripts_panel_fallback_on_import_or_name_error (exact output, ImportError and NameError)
- test_rich_console_exception_falls_back_to_simple -> test_rich_failure_falls_back_to_plain_once (one plain listing, every name, default note)

Stale text after the bare apm list switch: the canvas page's "not shown by
apm list", and a lifecycle test docstring that said apm list never reads the
lock. (troubleshooting/index.md is B's hunk; fixed there to avoid a merge conflict.)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The failed `apm run missing` prints the exact stderr line
"Run 'apm run --list' to see each script and its command." The test
runs that step, checks that it reaches the scripts table, and checks
that it changes no durable state.

Docs: the troubleshooting entry and the run reference no longer say
what bare `apm list` shows. The entry points to `apm run --list` for
scripts, so it stays true before and after the inventory switch.

Refs #5756

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Dec 3, 2026
Merges B's signed head (no rebase) so D merges cleanly after B on main.
packages/apm-guide/.apm/skills/apm-usage/commands.md, Scripts table, resolved to
exactly two rows after `apm preview SCRIPT`: B's `apm run --list` row as B has
it, then D's `apm list [NAME]` inventory row. The stale "`apm list` | List
available scripts" row is removed (S141); no other "List available scripts" or
apm-list-means-scripts text remains in the tree.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants