Skip to content

feat: add @rrlab/vitest-plugin and rr test passthrough#244

Merged
rqbazan merged 1 commit into
mainfrom
worktree-add-test-cmd-to-rr-cli
Jun 25, 2026
Merged

feat: add @rrlab/vitest-plugin and rr test passthrough#244
rqbazan merged 1 commit into
mainfrom
worktree-add-test-cmd-to-rr-cli

Conversation

@rqbazan

@rqbazan rqbazan commented Jun 25, 2026

Copy link
Copy Markdown
Member

What

Adds @rrlab/vitest-plugin and the rr test command — a pure passthrough to vitest, so projects can drop hand-rolled scripts like node --env-file-if-exists=.env ./node_modules/vitest/vitest.mjs "$@".

rr test                    # runs vitest, auto-loading .env.test or .env
rr test run --coverage     # every flag forwarded verbatim
rr test --project unit     # forwarded
rr test --help             # vitest's own help
rr test --env=.env.ci run  # override the env file
rr test doctor             # health check (only token reserved by rr)

How

test is categorically different from the existing verbs: lint/format/tsc/pack capture output into a task-board, but a test runner needs an inherited TTY (watch mode, colors, --help forwarding). So this adds a streaming capability.

Kernel (@rrlab/cli, additive — no existing plugin changes):

  • ToolService.runStreamed() — inherited-stdio sibling of runReport, returns an exit code.
  • TestRunner / TestRunOptions capability + test? in PluginServices.
  • test command: allowUnknownOption + passThroughOptions + helpOption(false) so flags and --help reach vitest; doctor subcommand; registered under a new "Testing:" group; vitest entry in the plugin directory.

Plugin (@rrlab/vitest-plugin):

  • Capability test, no config scaffolding. install() only adds the vitest peer.
  • Env file resolution: first-existing-wins (.env.test.env); explicit --env <path> missing → error (typo protection). Spawns node --env-file=<resolved> <vitest-bin> <args>.

⚠️ --env, not --env-file

Node has an early scanner that consumes a literal --env-file token from the entire argv regardless of position. Since the rr bin runs node src/run.ts "$@", a user's --env-file would be eaten by the rr process before Commander runs (and crash if the file is missing). --watch/--project/--import are unaffected. --env is not a node flag and vitest uses --environment, so it passes through cleanly. The child spawn still uses node's real --env-file= (there the flag precedes the script).

Design

Reviewed by arch-critic; recorded in decisions/016-vitest-passthrough-plugin.md. One deliberate divergence from the review: the capability is named test (not a generic run), since capability keys are the command's resolution key and a generic run would collide across passthrough plugins.

Tests / verification

  • New: 9 plugin unit tests (env-file resolution, install, tool-versions) + 8 cli integration tests (happy/failure/env-default/env-override/missing-file error/--help/doctor/missing-plugin hint).
  • Updated the two directory-enumerating assertions for the 5th plugin.
  • Green: pnpm build, pnpm test (143 cli + 9 plugin), pnpm rr check (biome + tsc type-aware across all 9 packages).
  • Changeset: minor for @rrlab/cli and @rrlab/vitest-plugin.

🤖 Generated with Claude Code

Introduce a streaming `test` capability so `rr test` is a pure passthrough to
vitest, replacing hand-rolled `node --env-file-if-exists=.env ./vitest.mjs` scripts.

- New package @rrlab/vitest-plugin: capability `test`, no config scaffolding.
  Loads an env file first (first-existing of .env.test, then .env; override with
  `--env <path>`, which errors when the named file is missing).
- Kernel: add `ToolService.runStreamed` (inherited-stdio sibling of runReport),
  the `TestRunner` capability returning an exit code, the `test` command (a
  passthrough: allowUnknownOption + passThroughOptions + helpOption(false), so
  flags and --help reach vitest), and the directory entry.

`--env` (not `--env-file`): Node's early scanner consumes a literal `--env-file`
token off the `rr` process's argv before Commander runs. See decisions/016.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9a2ee7f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@rrlab/vitest-plugin Minor
@rrlab/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rqbazan rqbazan added the preview Ready to run CI/CD label Jun 25, 2026
@vland-bot

vland-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Preview release

Latest commit: 9a2ee7f

Some packages have been released:

Package Version Install
@rrlab/cli 1.2.2-git-9a2ee7f.0 @rrlab/cli@1.2.2-git-9a2ee7f.0
@rrlab/vitest-plugin 0.0.1-git-9a2ee7f.0 @rrlab/vitest-plugin@0.0.1-git-9a2ee7f.0

Note

Use the PR number as tag to install any package. For instance:

pnpm add @rrlab/cli@pr-244

@rqbazan
rqbazan merged commit 42a8eb0 into main Jun 25, 2026
6 checks passed
@rqbazan
rqbazan deleted the worktree-add-test-cmd-to-rr-cli branch June 25, 2026 05:41
@vland-bot vland-bot Bot mentioned this pull request Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Ready to run CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant