Skip to content

fix(vitest): don't bury vitest's subcommands under an injected run - #3680

Open
dwin-gharibi wants to merge 1 commit into
rtk-ai:developfrom
dwin-gharibi:fix/vitest-subcommand-injection
Open

dwin-gharibi wants to merge 1 commit into
rtk-ai:developfrom
dwin-gharibi:fix/vitest-subcommand-injection

Conversation

@dwin-gharibi

Copy link
Copy Markdown

Closes #3679.

Summary

  • rtk vitest no longer buries vitest's own subcommands under run. related, bench, list,
    typecheck and init stay the leading token; everything else still gets run so an agent
    never lands in watch mode.
  • Watch requests (watch, dev, --watch) are still rewritten to run — a watcher would hang a
    non-interactive agent — but the substitution is now reported on stderr instead of being silent.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • Manual testing: rtk <command> output inspected

Unit tests (added, TDD — red before green)

src/cmds/js/vitest_cmd.rs:

  • vitest_subcommands_are_not_buried_under_run — each subcommand stays leading and no run is
    injected. Red on the old behaviour with
    related must stay the leading subcommand, got ["run", "--reporter=json", "related", "src/a.ts"].
  • plain_invocation_still_gets_run — the plain and file-argument forms keep run.
  • explicit_run_is_not_duplicated.
  • watch_is_replaced_by_run_and_reported — watch still becomes run, and the substitution is
    now observable via dropped_watch.

Behavioural check with a PATH shim recording vitest's argv

Typed Before After
vitest related src/a.ts run --reporter=json related src/a.ts related --reporter=json src/a.ts
vitest bench run --reporter=json bench bench --reporter=json
vitest list run --reporter=json list list --reporter=json
vitest typecheck run --reporter=json typecheck typecheck --reporter=json
vitest run --reporter=json unchanged
vitest src/a.ts run --reporter=json src/a.ts unchanged
vitest run src/a.ts run --reporter=json src/a.ts unchanged
vitest --watch run --reporter=json, silent same argv + stderr notice
vitest --coverage run --reporter=json --coverage unchanged
vitest -t mytest run --reporter=json -t mytest unchanged

build_vitest_effective_args always started the argv with run. vitest has
subcommands of its own, and placing them after run changes what they mean:
vitest run related src/a.ts reads related as a test-file filter rather than
the related subcommand, so 'run the tests affected by my change' quietly
became 'run tests whose path contains the word related' -- usually none,
reported as a green empty run.

Keep a real subcommand as the leading token and inject run only for the
plain forms, so an agent still never lands in watch mode.

Watch requests are still rewritten to run, since a watcher would hang a
non-interactive agent, but the substitution is now reported on stderr
instead of the flag silently vanishing.
Copilot AI lite review requested due to automatic review settings August 23, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@amandeavor amandeavor 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.

I think typecheck should be removed from VITEST_SUBCOMMANDS.

In Vitest 4.1.11, the documented commands are run, related, watch, dev, bench, init, and list. Typechecking is enabled with the --typecheck option; a positional typecheck is still treated as a test-file filter. I confirmed this against the current CLI help.

With this patch, vitest typecheck changes from vitest run --reporter=json typecheck to vitest typecheck --reporter=json. That drops the non-interactive run mode even though no real subcommand was selected, which can put the command back into Vitest's default watch behavior.

Could you remove typecheck from the list and add a case asserting that it remains under run as a positional filter? The handling for the actual subcommands looks good.

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.

rtk vitest prepends run in front of vitest's own subcommands

3 participants