Skip to content

feat(cli): Add init command to generate baseline eval config#75

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
feat/cli-init
Open

feat(cli): Add init command to generate baseline eval config#75
sentry-junior[bot] wants to merge 2 commits into
mainfrom
feat/cli-init

Conversation

@sentry-junior
Copy link
Copy Markdown
Contributor

@sentry-junior sentry-junior Bot commented May 23, 2026

What

Adds vitest-evals init — a zero-dependency CLI that generates the baseline eval setup in a user's project, matching the Configure Vitest section of the public docs exactly.

After npm install -D vitest-evals, users can run:

pnpm exec vitest-evals init

This writes vitest.evals.config.ts and adds evals / evals:record scripts to package.json.

Behavior

  • Idempotent — safe to rerun; identical existing content is left unchanged.
  • Conflict detection — before writing anything, checks for differing vitest.evals.config.ts or conflicting script values and exits non-zero with a clear message.
  • --force — overwrites conflicting config and scripts while preserving all other package.json fields.
  • --cwd <dir> — targets a different project root (useful for monorepos and tests).
  • No new runtime dependencies; uses Node built-ins only.

Files

  • packages/vitest-evals/src/cli.ts — CLI entry point (bin: vitest-evals)
  • packages/vitest-evals/src/cli/init.ts — pure init logic + output wrapper
  • packages/vitest-evals/src/cli/init.test.ts — 11 unit tests covering all branches
  • packages/vitest-evals/package.json — adds bin field
  • packages/docs/src/content/docs/docs.mdx — documents init before the manual config block
  • packages/vitest-evals/README.md — adds Init section

Verified

  • pnpm typecheck — pass
  • pnpm exec biome lint — pass
  • pnpm exec vitest run packages/vitest-evals/src/cli/init.test.ts — 11/11 pass
  • pnpm --filter vitest-evals run builddist/cli.js emitted, shebang intact
  • Manual smoke: node dist/cli.js init --cwd <tmp> generates expected files

Action taken on behalf of David Cramer.


View Session in Sentry

Adds `vitest-evals init` — a zero-dependency CLI command that generates
`vitest.evals.config.ts` and adds the `evals` and `evals:record` scripts to
`package.json`, exactly matching the Configure Vitest section in the public docs.

The command is idempotent (safe to rerun), detects and reports conflicts before
writing, and accepts `--force` to overwrite differing config or scripts.
`--cwd` targets a different project directory.

Co-authored-by: David Cramer <david@sentry.io>

---
[View Session in Sentry](https://sentry.sentry.io/traces/?project=4510944073809921&query=gen_ai.conversation.id%3A%22slack%3AC0B595QDZLL%3A1779502924.003319%22)
@vercel
Copy link
Copy Markdown

vercel Bot commented May 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vitest-evals-docs Ready Ready Preview, Comment May 23, 2026 2:37am

Request Review

Co-authored-by: David Cramer <david@sentry.io>
@sentry-junior sentry-junior Bot marked this pull request as ready for review May 23, 2026 02:37
Comment on lines +51 to +55
case "--cwd": {
const value = args[++i];
if (!value) throw new Error("Missing value for --cwd");
cwd = value;
break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The argument parser for --cwd consumes the next token as its value, even if it's another flag like --force, causing the flag to be ignored.
Severity: MEDIUM

Suggested Fix

Before assigning the next argument to cwd, add a check to ensure the value does not start with - or --. If it does, it's another flag, and you should throw an error for a missing --cwd value or handle it as an invalid input.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/vitest-evals/src/cli.ts#L51-L55

Potential issue: The argument parsing logic for the `--cwd` flag unconditionally
consumes the subsequent token as its value. If another flag, such as `--force`,
immediately follows `--cwd`, it will be incorrectly interpreted as the directory path
for `cwd`. This causes the intended flag (`--force`) to be ignored and can lead to
confusing errors like `"no-package-json"` when the system tries to resolve a
non-existent path like `./--force`.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

0 participants