feat(cli): Add init command to generate baseline eval config#75
Open
sentry-junior[bot] wants to merge 2 commits into
Open
feat(cli): Add init command to generate baseline eval config#75sentry-junior[bot] wants to merge 2 commits into
sentry-junior[bot] wants to merge 2 commits into
Conversation
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)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: David Cramer <david@sentry.io>
Comment on lines
+51
to
+55
| case "--cwd": { | ||
| const value = args[++i]; | ||
| if (!value) throw new Error("Missing value for --cwd"); | ||
| cwd = value; | ||
| break; |
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 initThis writes
vitest.evals.config.tsand addsevals/evals:recordscripts topackage.json.Behavior
vitest.evals.config.tsor conflicting script values and exits non-zero with a clear message.--force— overwrites conflicting config and scripts while preserving all otherpackage.jsonfields.--cwd <dir>— targets a different project root (useful for monorepos and tests).Files
packages/vitest-evals/src/cli.ts— CLI entry point (bin:vitest-evals)packages/vitest-evals/src/cli/init.ts— pure init logic + output wrapperpackages/vitest-evals/src/cli/init.test.ts— 11 unit tests covering all branchespackages/vitest-evals/package.json— addsbinfieldpackages/docs/src/content/docs/docs.mdx— documentsinitbefore the manual config blockpackages/vitest-evals/README.md— adds Init sectionVerified
pnpm typecheck— passpnpm exec biome lint— passpnpm exec vitest run packages/vitest-evals/src/cli/init.test.ts— 11/11 passpnpm --filter vitest-evals run build—dist/cli.jsemitted, shebang intactnode dist/cli.js init --cwd <tmp>generates expected filesAction taken on behalf of David Cramer.
View Session in Sentry