Prompt: Run vitest less times, improve play functions#34662
Prompt: Run vitest less times, improve play functions#34662Sidnioulz wants to merge 2 commits intoyann/prompt-optimized-testsfrom
Conversation
6bb95e1 to
e008ab3
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughImports for monorepo type detection were moved from telemetry to a shared utility; tests and typings updated accordingly. The CLI Storybook AI prompt now builds its "Rules of engagement" list dynamically (including a monorepo-aware rule). A new monorepo evaluation prompt/document was added. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Review rate limit: 2/5 reviews remaining, refill in 24 minutes and 45 seconds. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
code/core/src/shared/utils/get-monorepo-type.test.ts (1)
8-8: ⚡ Quick winAlign this mock with the repo’s Vitest spy-mocking convention.
This factory mock does not use
spy: true, which deviates from the test-mocking rule used elsewhere in the repo. Please either switch to the convention or document this as an intentional exception in-file.As per coding guidelines: "Use
vi.mock()with thespy: trueoption for all package and file mocks in Vitest tests."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/core/src/shared/utils/get-monorepo-type.test.ts` at line 8, The vi.mock call in get-monorepo-type.test.ts should follow the repo convention by using the Vitest spy-mocking option; update the existing factory mock invocation of vi.mock('node:fs', ...) to include the spy: true option so the mock aligns with other tests (or, if intentionally different, add an in-file comment above the vi.mock call documenting why this file is an exception to the rule). Ensure you modify the vi.mock call (the unique symbol to change) or add the explanatory comment immediately adjacent so linters and reviewers recognize the adherence to the guideline.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@scripts/eval/prompts/monorepo.md`:
- Around line 13-30: The prompt file contains the literal token "unknown package
manager" (see the table row "Package Manager | unknown package manager" and the
Rule 7 line referencing "unknown package manager"), which will produce invalid
install/run instructions; edit scripts/eval/prompts/monorepo.md and replace that
exact token with a real fallback executable (e.g., "npm") or a consistent
placeholder like "<your-package-manager>" everywhere it appears (table and Rules
of engagement point 7), preserving casing and surrounding formatting so
downstream commands become valid.
---
Nitpick comments:
In `@code/core/src/shared/utils/get-monorepo-type.test.ts`:
- Line 8: The vi.mock call in get-monorepo-type.test.ts should follow the repo
convention by using the Vitest spy-mocking option; update the existing factory
mock invocation of vi.mock('node:fs', ...) to include the spy: true option so
the mock aligns with other tests (or, if intentionally different, add an in-file
comment above the vi.mock call documenting why this file is an exception to the
rule). Ensure you modify the vi.mock call (the unique symbol to change) or add
the explanatory comment immediately adjacent so linters and reviewers recognize
the adherence to the guideline.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 243270d2-aa22-461b-bd72-559f07d1b3c6
📒 Files selected for processing (8)
code/core/src/shared/utils/get-monorepo-type.test.tscode/core/src/shared/utils/get-monorepo-type.tscode/core/src/telemetry/ai-setup-utils.tscode/core/src/telemetry/storybook-metadata.test.tscode/core/src/telemetry/storybook-metadata.tscode/core/src/telemetry/types.tscode/lib/cli-storybook/src/ai/prompt.tsscripts/eval/prompts/monorepo.md
| | Package Manager | unknown package manager | | ||
| | Addons | @storybook/addon-onboarding, @storybook/addon-themes, @storybook/addon-docs, @storybook/addon-designs, @storybook/addon-vitest, @storybook/addon-a11y, storybook-addon-pseudo-states, @chromatic-com/storybook | | ||
|
|
||
| Your goal is to make Storybook fully functional in this project: configure `.storybook/preview.tsx` with the right decorators, add MSW for data, and write up to 10 colocated `*.stories.tsx` files. Add `play` functions only where they prove something non-trivial. | ||
|
|
||
| ## Rules of engagement (follow strictly — these are time budgets, not suggestions) | ||
|
|
||
| 1. **Discover with Glob/Grep/Read, not shell.** Never use `ls`, `find`, `cat`, `head`, `tail`, shell `grep`, `sed`, or `node -e` for discovery or for editing files in bulk — these are slower per call and violate caching. Substitute bash commands for the specific tool names listed below, or available tools with the closest semantics: | ||
| - List a directory → `Glob('src/components/*')` (alt names: `search_files`, `file_search`), not `ls src/components`. | ||
| - Search a string → `Grep('pattern', { path: 'src' })` (alt names: `grep_search`, `search_files`), not `grep -rn ...` or `find ... | xargs grep`. | ||
| - Read a file → `Read('path/to/file')` (alt names: `read_file`), not `cat`/`head`/`tail`. | ||
| - Bulk-edit many files → multiple `Edit` calls (alt names: `apply_patch`, `replace_in_file`, `replace`), or one `Edit` with `replace_all` (alt names: `replace` with `allow_multiple`), not `sed -i`. | ||
| 2. **Never read or grep inside `node_modules`.** The imports shown in this prompt are correct — don't verify them by introspecting installed packages. If something seems off, re-read this prompt, not `node_modules`. | ||
| 3. **Nx monorepo.** Don't initially look for config or existing Storybook content in other packages. Start exploring from config and tooling local to the package where you are asked to set up Storybook. If it uses local monorepo dependencies, build all dependencies found during discovery before writing stories or running tests. | ||
| 4. **Read budget: ~12 files for discovery.** Before writing any code you may Read at most ~12 files (`index.html`, entry, App, providers, routing, root CSS, 2–3 representative pages/components, 1–2 hooks, 1 test). If you need more, summarize and move on. | ||
| 5. **Edit > Write.** For any file you've Read, use `Edit`. Use `Write` only for new files. The project already has a `.storybook/preview.tsx` from `storybook init` — **Edit** it, do not overwrite. | ||
| 6. **Batch the test loop.** Write **all** stories first, then run vitest **once** across everything. No per-file vitest runs until after that first batch run reveals failures. | ||
| 7. **Use `unknown package manager` for every install** (detected from this project's lockfile). |
There was a problem hiding this comment.
Replace unknown package manager with an executable fallback token.
Using the literal unknown package manager in rules leads to invalid install/run instructions downstream. Prefer a real fallback (e.g., npm) or a consistent placeholder like <your-package-manager> everywhere commands are shown.
Suggested patch
-| Package Manager | unknown package manager |
+| Package Manager | <your-package-manager> |
@@
-7. **Use `unknown package manager` for every install** (detected from this project's lockfile).
+7. **Use `<your-package-manager>` for every install** (detected from this project's lockfile).
@@
-Then run the project's TypeScript check (use the script from `package.json` — typically `tsc --noEmit` or `unknown package manager run typecheck`). Read the raw output once; don't pipe it through repeated `grep`/`head` invocations to slice it.
+Then run the project's TypeScript check (use the script from `package.json` — typically `tsc --noEmit` or `<your-package-manager> run typecheck`). Read the raw output once; don't pipe it through repeated `grep`/`head` invocations to slice it.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@scripts/eval/prompts/monorepo.md` around lines 13 - 30, The prompt file
contains the literal token "unknown package manager" (see the table row "Package
Manager | unknown package manager" and the Rule 7 line referencing "unknown
package manager"), which will produce invalid install/run instructions; edit
scripts/eval/prompts/monorepo.md and replace that exact token with a real
fallback executable (e.g., "npm") or a consistent placeholder like
"<your-package-manager>" everywhere it appears (table and Rules of engagement
point 7), preserving casing and surrounding formatting so downstream commands
become valid.
|
Integrated into the following branch |
Closes #
What I did
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Caution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>Summary by CodeRabbit
New Features
Documentation
Tests
Chores