Skip to content

Prompt: Run vitest less times, improve play functions#34662

Closed
Sidnioulz wants to merge 2 commits intoyann/prompt-optimized-testsfrom
sidnioulz/prompt-monorepo
Closed

Prompt: Run vitest less times, improve play functions#34662
Sidnioulz wants to merge 2 commits intoyann/prompt-optimized-testsfrom
sidnioulz/prompt-monorepo

Conversation

@Sidnioulz
Copy link
Copy Markdown
Member

@Sidnioulz Sidnioulz commented Apr 30, 2026

Closes #

What I did

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end 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

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make 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/core team 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

    • AI prompt now dynamically generates rules of engagement, including monorepo-aware guidance and package-manager specifics.
  • Documentation

    • Added a comprehensive Storybook setup guide for Nx monorepo React/Vite/TypeScript projects, including story generation and verification workflows.
  • Tests

    • Updated test mocks and imports to improve test consistency.
  • Chores

    • Simplified telemetry imports and internal module references for cleaner maintenance.

@Sidnioulz Sidnioulz force-pushed the sidnioulz/prompt-monorepo branch from 6bb95e1 to e008ab3 Compare April 30, 2026 08:21
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

Fails
🚫

PR is not labeled with one of: ["cleanup","BREAKING CHANGE","feature request","bug","documentation","maintenance","build","dependencies"]

🚫

PR is not labeled with one of: ["ci:normal","ci:merged","ci:daily","ci:docs"]

Generated by 🚫 dangerJS against 511cab7

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1fd6a2e1-1769-42b8-a4dc-6b4fcb5cecfc

📥 Commits

Reviewing files that changed from the base of the PR and between e008ab3 and 511cab7.

📒 Files selected for processing (1)
  • docs/configure/integration/eslint-plugin.mdx
✅ Files skipped from review due to trivial changes (1)
  • docs/configure/integration/eslint-plugin.mdx

📝 Walkthrough

Walkthrough

Imports 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

Cohort / File(s) Summary
Monorepo Type Module Migration
code/core/src/telemetry/storybook-metadata.ts, code/core/src/telemetry/types.ts, code/core/src/telemetry/storybook-metadata.test.ts
Switched imports for getMonorepoType / MonorepoType from local telemetry files to the shared utility at ../shared/utils/get-monorepo-type.ts and adjusted tests to mock the new path.
Shared Util Test Mock
code/core/src/shared/utils/get-monorepo-type.test.ts
Updated Vitest mock reference for node:fs to a different relative __mocks__/fs.ts path and aligned the vi.mocked<...> type parameter to match.
Telemetry Cleanup
code/core/src/telemetry/ai-setup-utils.ts
Removed an unused import (isTelemetryModuleEnabled) while preserving telemetry usage for firing ai-setup-evidence.
AI Prompt Enhancement
code/lib/cli-storybook/src/ai/prompt.ts
Refactored the "Rules of engagement" output from a fixed list to a generated, filtered/numbered list; integrates monorepo-specific rule via monorepoRules() (uses getMonorepoType()) and inserts package-manager rule.
New Evaluation Prompt
scripts/eval/prompts/monorepo.md
Added a comprehensive Nx monorepo Storybook setup prompt/document describing preview config, MSW handlers, story generation constraints, test workflow, and completion criteria.
Docs Formatting
docs/configure/integration/eslint-plugin.mdx
Consistent change to single quotes in JS/TS flat-config examples (imports, strings, rule keys/values).

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 @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
code/core/src/shared/utils/get-monorepo-type.test.ts (1)

8-8: ⚡ Quick win

Align 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 the spy: true option 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

📥 Commits

Reviewing files that changed from the base of the PR and between ec34264 and e008ab3.

📒 Files selected for processing (8)
  • code/core/src/shared/utils/get-monorepo-type.test.ts
  • code/core/src/shared/utils/get-monorepo-type.ts
  • code/core/src/telemetry/ai-setup-utils.ts
  • code/core/src/telemetry/storybook-metadata.test.ts
  • code/core/src/telemetry/storybook-metadata.ts
  • code/core/src/telemetry/types.ts
  • code/lib/cli-storybook/src/ai/prompt.ts
  • scripts/eval/prompts/monorepo.md

Comment on lines +13 to +30
| 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).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

@Sidnioulz
Copy link
Copy Markdown
Member Author

Integrated into the following branch

@Sidnioulz Sidnioulz closed this Apr 30, 2026
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.

1 participant