Skip to content

feat(cli): complete test commands and options from Vitest metadata - #3190

Open
RSS1102 wants to merge 17 commits into
voidzero-dev:mainfrom
RSS1102:feat/vitest-cli-completion
Open

RSS1102 wants to merge 17 commits into
voidzero-dev:mainfrom
RSS1102:feat/vitest-cli-completion

Conversation

@RSS1102

@RSS1102 RSS1102 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2953
Based on the createCLI() approach discussed with Vitest.

Implementation

  1. Generate at build time: read the public command and option definitions from vitest/node.createCLI() and package them as dist/completion/test.json.
  2. Follow the selected toolchain: prefer the runnable project-local Vite+ package, including the directory selected by -C; use the global package when no runnable local CLI exists.
  3. Complete in Rust: read and validate the packaged metadata without starting Node.js, loading project configuration, or triggering installation. Missing, invalid, unsupported, or version-mismatched metadata falls back to the existing completion behavior.

Capabilities

Area Support
Shells Bash, Zsh, Fish, and PowerShell through vp env setup
Commands Implicit vp test and run, watch, dev, related, bench, list, doctor
Options Long names, short aliases, negative spellings (--no-color), and nested options (--coverage.reporter)
Scope and descriptions Command-specific options and descriptions, displayed where supported by the shell
Argument handling Options after file filters; required/optional value positions and -- respected

Examples: vp test --reporte<Tab> → --reporter; vp test list --filesO<Tab> → --filesOnly.

Support boundary

  • Both the global CLI and selected Vite+ package need a build containing this feature. No extra Vitest configuration is required.
  • Support follows Vite+'s paired Vitest 5.x toolchain, currently validated with 5.0.5. Each paired dependency upgrade is checked by contract and consumer tests; arbitrary Vitest replacements are outside this guarantee.
  • Older toolchains without matching metadata, including Vitest 3/4 fallback cases, retain the original completion behavior.
  • Command and option-name completion only: this first implementation follows Vite+'s existing shell completion behavior. It does not provide Vitest option-value candidates (such as reporter or environment names), test/project names, or init/complete expansion. Nushell changes and test execution compatibility are outside this PR.

@RSS1102
RSS1102 force-pushed the feat/vitest-cli-completion branch from 67aab9c to fb794e5 Compare October 24, 2026 21:17
@RSS1102
RSS1102 marked this pull request as ready for review October 29, 2026 11:02
@RSS1102

RSS1102 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@liangmiQwQ @fengmk2 cc

@liangmiQwQ
liangmiQwQ self-requested a review October 29, 2026 12:35
@fengmk2

fengmk2 commented Nov 3, 2026

Copy link
Copy Markdown
Member

Could you demonstrate this new feature in a video?

@liangmiQwQ liangmiQwQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry for late responding 🙇

I'll start by pointing out a few nitpicks, and then I'll use agents tools to check for any edge cases.

I think the most important part of this PR is to ensure the structure of test.json remains as stable as possible. One Rust vp global CLI needs to be compatible with multiple vite-plus local cli. It would possibly bring legacy if the schema changes in the later version for cross-version composition.

Comment thread package.json Resolved
Comment thread CONTRIBUTING.md Resolved
Comment thread docs/guide/env.md Resolved
@liangmiQwQ
liangmiQwQ requested a review from fengmk2 November 7, 2026 14:28
@liangmiQwQ

liangmiQwQ commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

According to the the discussion, this PR essentially is not an integration with vitest complete. It actually gets CLI definition by running createCLI to complete commands. In actual use, the experience might also be slightly inferior to original vitest complete. I'm not sure if this direction is right.

This overall LGTM as the first version. However, since completion data is released with vite-plus local package, while vp global cli with a different version of vite-plus local package composition is allowed, if we want to implement a further integration like fully vitest complete support, it would bring legacy logic to ensure the compatibility for cross-version uses.

In my opinion, if we proceed with this approach, we could also introduce vp pack, vp dev and others' shell completion. This might slightly improve the efficiency of human command input, which is still important, which is still important to me.

cc @fengmk2 needs your determination 🙇

@RSS1102

RSS1102 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

🤔 Did I misunderstand the requirements? I thought it was about integrating with vitest (they already support vitest complete, and then we use it based on their supported capabilities).
I'll follow up and resolve the current code conflicts and demo effects this weekend. Sorry, I'm a bit busy on weekdays.

@RSS1102

RSS1102 commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Video demo of the feature introduced in this PR.

completion-demo.mp4

@fengmk2 fengmk2 self-assigned this Nov 21, 2026
@fengmk2

fengmk2 commented Nov 21, 2026

Copy link
Copy Markdown
Member

According to the the discussion, this PR essentially is not an integration with vitest complete. It actually gets CLI definition by running createCLI to complete commands. In actual use, the experience might also be slightly inferior to original vitest complete. I'm not sure if this direction is right.

packages/cli/build/completion-metadata.ts Looking at the code, the meta data is generated based on vitest, so there shouldn't be any problem, right? @liangmiQwQ

Comment thread crates/vp_global_cli/src/completion.rs Resolved

@liangmiQwQ liangmiQwQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this. I found four completion problems. Only the first one blocks merging:

  1. Blocking: with VP_COMPLETE=0 (or empty), a normal command can run in the wrong directory (main.rs:440, completion.rs:53).
  2. Kebab-case Vitest spellings aren't in the completion grammar, and the hand-written alias table is already out of date for Vitest 5.1.1.
  3. Optional <boolean> values on nested options are marked as required.
  4. Follow-up: -C <dir> breaks when the directory name is also a subcommand. This comes from upstream clap_complete and already happens on main.

I'd fix 1–3 in this PR and leave 4 for a follow-up issue or a note in the PR description. Locally, the Rust tests, integration tests and JS unit tests all pass.

🤖 Generated with Codex and Claude Code

Comment thread crates/vp_global_cli/src/main.rs Resolved
Comment thread crates/vp_global_cli/src/completion.rs Resolved
}

/// Only the leading global -C grammar belongs to the launcher.
pub(crate) fn command_words(words: &[String]) -> Option<&[String]> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not blocking, can be a follow-up: -C completion breaks when the directory name is also a top-level subcommand. vp -C dev test --reporte<Tab> returns nothing, while vp -C ./dev test --reporte<Tab> returns --reporter.

The cause is upstream. clap_complete 4.6.11 (src/engine/complete.rs:63) checks whether a word is a subcommand name before it checks whether the word is a pending option's value. So dev is read as vp dev, and test becomes one of its positional arguments. vp -C dev run <Tab> breaks the same way on main today.

A related older case: in bash, -C "team web" reaches us with the quote marks still in the word, so chdir fails and completion falls back to the default.

The PR description lists -C as supported, so either note this limitation there and open an issue, or work around it. One workaround is to rewrite the -C value (for example to its resolved absolute path) and call try_complete with the rewritten arguments. Rewriting in place keeps _CLAP_COMPLETE_INDEX correct.

🤖 Generated with Codex and Claude Code

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.

Integrate vitest complete

3 participants