Repository navigation
fix(vitest): don't bury vitest's subcommands under an injected run - #3680
dwin-gharibi wants to merge 1 commit into
Conversation
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.
amandeavor
left a comment
There was a problem hiding this comment.
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.
Closes #3679.
Summary
rtk vitestno longer buries vitest's own subcommands underrun.related,bench,list,typecheckandinitstay the leading token; everything else still getsrunso an agentnever lands in watch mode.
watch,dev,--watch) are still rewritten torun— a watcher would hang anon-interactive agent — but the substitution is now reported on stderr instead of being silent.
Test plan
cargo fmt --all && cargo clippy --all-targets && cargo testrtk <command>output inspectedUnit tests (added, TDD — red before green)
src/cmds/js/vitest_cmd.rs:vitest_subcommands_are_not_buried_under_run— each subcommand stays leading and norunisinjected. 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 keeprun.explicit_run_is_not_duplicated.watch_is_replaced_by_run_and_reported— watch still becomesrun, and the substitution isnow observable via
dropped_watch.Behavioural check with a
PATHshim recording vitest's argvvitest related src/a.tsrun --reporter=json related src/a.tsrelated --reporter=json src/a.tsvitest benchrun --reporter=json benchbench --reporter=jsonvitest listrun --reporter=json listlist --reporter=jsonvitest typecheckrun --reporter=json typechecktypecheck --reporter=jsonvitestrun --reporter=jsonvitest src/a.tsrun --reporter=json src/a.tsvitest run src/a.tsrun --reporter=json src/a.tsvitest --watchrun --reporter=json, silentvitest --coveragerun --reporter=json --coveragevitest -t mytestrun --reporter=json -t mytest