Skip to content

Maintenance: Enhance ghost stories internal tests#34707

Merged
yannbf merged 5 commits into
nextfrom
yann/fix-observability
May 5, 2026
Merged

Maintenance: Enhance ghost stories internal tests#34707
yannbf merged 5 commits into
nextfrom
yann/fix-observability

Conversation

@yannbf
Copy link
Copy Markdown
Member

@yannbf yannbf commented May 4, 2026

Closes #

What I did

In an agentic session the ghost stories run shouldn’t trigger the vitest reporter used for self healing

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 pull request has been released as version 0.0.0-pr-34707-sha-66dc6ff5. Try it out in a new sandbox by running npx storybook@0.0.0-pr-34707-sha-66dc6ff5 sandbox or in an existing project with npx storybook@0.0.0-pr-34707-sha-66dc6ff5 upgrade.

More information
Published version 0.0.0-pr-34707-sha-66dc6ff5
Triggered by @yannbf
Repository storybookjs/storybook
Branch yann/fix-observability
Commit 66dc6ff5
Datetime Tue May 5 05:22:26 UTC 2026 (1777958546)
Workflow run 25359357306

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=34707

Summary by CodeRabbit

  • Chores

    • Telemetry reporter activation refined to run only for active agent sessions and be skipped for internal dev-server test runs.
    • Environment handling unified for dev-server-initiated test runs.
    • Onboarding flag now always returned as a boolean for consistent onboarding behavior.
  • Refactor

    • Test-result analysis now emits cumulative statistics only when cumulative data is provided; cumulative fields are optional.
  • Tests

    • Updated tests to expect the internal test-run marker for dev-server-initiated runs.

@yannbf yannbf requested a review from Sidnioulz May 4, 2026 18:29
@yannbf yannbf self-assigned this May 4, 2026
@yannbf yannbf added bug maintenance User-facing maintenance tasks ci:normal labels May 4, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

📝 Walkthrough

Walkthrough

Dev-server–spawned Vitest runs are marked with STORYBOOK_INTERNAL_TEST_RUN and the Vitest addon only installs AgentTelemetryReporter when an agent is active and that env var is absent. Tests and ghost-stories runner were updated accordingly. Separately, test-analysis now omits cumulative fields unless cumulativeResults are provided and the TestRunAnalysis cumulative fields are optional.

Changes

Internal Test Run Telemetry Gating

Layer / File(s) Summary
Environment Variable & Comments
code/core/src/core-server/utils/ghost-stories/run-story-tests.ts
runStoryTests always sets STORYBOOK_INTERNAL_TEST_RUN: '1' in the spawned Vitest env and documents that this marks dev-server-initiated runs; conditionally adds STORYBOOK_COMPONENT_PATHS when options?.ghostRun is true.
Telemetry Reporter Gating
code/addons/vitest/src/vitest-plugin/index.ts
configureVitest only injects AgentTelemetryReporter when an agent is active AND process.env.STORYBOOK_INTERNAL_TEST_RUN is not set; comments clarified to exclude internal dev-server runs.
Tests / Assertions
code/core/src/core-server/server-channel/ghost-stories-channel.test.ts
Tests updated to assert mockCommon.executeCommand includes STORYBOOK_INTERNAL_TEST_RUN: '1' in the env for discovery run cases.
Minor Behavior / State Handling
code/lib/cli-storybook/src/ai/index.ts
aiSetup now reads onboarding-pending with a typed boolean default (cache.get<boolean>('onboarding-pending', false)), ensuring needsUserOnboarding is always a boolean.

Test Result Analysis & Types

Layer / File(s) Summary
Types
code/core/src/shared/utils/test-result-types.ts
TestRunAnalysis cumulative fields made optional (cumulative*?: ...) and JSDoc updated to describe agent-driven per-story history/timestamp selection.
Core Logic
code/core/src/shared/utils/analyze-test-results.ts
analyzeTestResults now constructs run* fields always and only appends cumulative* fields when cumulativeResults is provided; JSDoc updated to reflect conditional emission.
Unit Tests (parsing)
code/core/src/core-server/utils/ghost-stories/parse-vitest-report.test.ts
Updated expectations to use run* naming for error/CSS-check summary properties in basic vitest-results test.
Unit Tests (analysis)
code/core/src/shared/utils/analyze-test-results.test.ts
Tests updated to expect cumulative fields are omitted (undefined) when cumulativeResults is not provided; zero-tests case updated accordingly.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant GhostRunner as GhostStories Runner
    participant DevServer as Dev Server
    participant Vitest as Vitest Process
    participant VitestPlugin as Vitest Addon (AgentTelemetryReporter)
    participant Telemetry as Telemetry System

    GhostRunner->>DevServer: request ghost-story test run
    DevServer->>Vitest: spawn "npx vitest run" with env (STORYBOOK_INTERNAL_TEST_RUN=1, maybe STORYBOOK_COMPONENT_PATHS)
    Vitest->>VitestPlugin: vitest config hook executes (reads process.env)
    alt STORYBOOK_INTERNAL_TEST_RUN set
        VitestPlugin-->>Vitest: skip AgentTelemetryReporter installation
    else not set and agent active
        VitestPlugin->>Telemetry: install AgentTelemetryReporter (emit telemetry)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

@Sidnioulz Sidnioulz removed the bug label May 5, 2026
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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@code/core/src/shared/utils/analyze-test-results.test.ts`:
- Around line 129-140: The test for analyzeTestResults that "omits all
cumulative fields when no cumulative results are provided" is missing assertions
for cumulativePassedButEmptyRender and cumulativeSuccessRateWithoutEmptyRender;
update the test that calls analyzeTestResults(results) to also assert that
analysis.cumulativePassedButEmptyRender and
analysis.cumulativeSuccessRateWithoutEmptyRender are undefined so all cumulative
properties returned by analyzeTestResults are covered.
🪄 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: dced9f58-445a-4d27-9778-52d31899b6c3

📥 Commits

Reviewing files that changed from the base of the PR and between 0f08c00 and 1df1a39.

📒 Files selected for processing (5)
  • code/core/src/core-server/server-channel/ghost-stories-channel.test.ts
  • code/core/src/core-server/utils/ghost-stories/parse-vitest-report.test.ts
  • code/core/src/shared/utils/analyze-test-results.test.ts
  • code/core/src/shared/utils/analyze-test-results.ts
  • code/core/src/shared/utils/test-result-types.ts
💤 Files with no reviewable changes (1)
  • code/core/src/core-server/utils/ghost-stories/parse-vitest-report.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/core/src/core-server/server-channel/ghost-stories-channel.test.ts

Comment on lines +129 to +140
it('omits all cumulative fields when no cumulative results are provided', () => {
const results: StoryTestResult[] = [
{ storyId: 's1', status: 'PASS' },
{ storyId: 's2', status: 'FAIL', error: 'oops' },
];
const analysis = analyzeTestResults(results);
expect(analysis.cumulativeTotal).toBe(analysis.runTotal);
expect(analysis.cumulativePassed).toBe(analysis.runPassed);
expect(analysis.cumulativeSuccessRate).toBe(analysis.runSuccessRate);
expect(analysis.cumulativeUniqueErrorCount).toBe(analysis.runUniqueErrorCount);
expect(analysis.cumulativeTotal).toBeUndefined();
expect(analysis.cumulativePassed).toBeUndefined();
expect(analysis.cumulativeSuccessRate).toBeUndefined();
expect(analysis.cumulativeUniqueErrorCount).toBeUndefined();
expect(analysis.cumulativeCategorizedErrors).toBeUndefined();
expect(analysis.cumulativeCssCheck).toBeUndefined();
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

“All cumulative fields” test misses two cumulative properties.

At Line 129 the test claims full coverage, but cumulativePassedButEmptyRender and cumulativeSuccessRateWithoutEmptyRender are not asserted.

Suggested patch
       expect(analysis.cumulativeTotal).toBeUndefined();
       expect(analysis.cumulativePassed).toBeUndefined();
+      expect(analysis.cumulativePassedButEmptyRender).toBeUndefined();
       expect(analysis.cumulativeSuccessRate).toBeUndefined();
+      expect(analysis.cumulativeSuccessRateWithoutEmptyRender).toBeUndefined();
       expect(analysis.cumulativeUniqueErrorCount).toBeUndefined();
       expect(analysis.cumulativeCategorizedErrors).toBeUndefined();
       expect(analysis.cumulativeCssCheck).toBeUndefined();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('omits all cumulative fields when no cumulative results are provided', () => {
const results: StoryTestResult[] = [
{ storyId: 's1', status: 'PASS' },
{ storyId: 's2', status: 'FAIL', error: 'oops' },
];
const analysis = analyzeTestResults(results);
expect(analysis.cumulativeTotal).toBe(analysis.runTotal);
expect(analysis.cumulativePassed).toBe(analysis.runPassed);
expect(analysis.cumulativeSuccessRate).toBe(analysis.runSuccessRate);
expect(analysis.cumulativeUniqueErrorCount).toBe(analysis.runUniqueErrorCount);
expect(analysis.cumulativeTotal).toBeUndefined();
expect(analysis.cumulativePassed).toBeUndefined();
expect(analysis.cumulativeSuccessRate).toBeUndefined();
expect(analysis.cumulativeUniqueErrorCount).toBeUndefined();
expect(analysis.cumulativeCategorizedErrors).toBeUndefined();
expect(analysis.cumulativeCssCheck).toBeUndefined();
it('omits all cumulative fields when no cumulative results are provided', () => {
const results: StoryTestResult[] = [
{ storyId: 's1', status: 'PASS' },
{ storyId: 's2', status: 'FAIL', error: 'oops' },
];
const analysis = analyzeTestResults(results);
expect(analysis.cumulativeTotal).toBeUndefined();
expect(analysis.cumulativePassed).toBeUndefined();
expect(analysis.cumulativePassedButEmptyRender).toBeUndefined();
expect(analysis.cumulativeSuccessRate).toBeUndefined();
expect(analysis.cumulativeSuccessRateWithoutEmptyRender).toBeUndefined();
expect(analysis.cumulativeUniqueErrorCount).toBeUndefined();
expect(analysis.cumulativeCategorizedErrors).toBeUndefined();
expect(analysis.cumulativeCssCheck).toBeUndefined();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/core/src/shared/utils/analyze-test-results.test.ts` around lines 129 -
140, The test for analyzeTestResults that "omits all cumulative fields when no
cumulative results are provided" is missing assertions for
cumulativePassedButEmptyRender and cumulativeSuccessRateWithoutEmptyRender;
update the test that calls analyzeTestResults(results) to also assert that
analysis.cumulativePassedButEmptyRender and
analysis.cumulativeSuccessRateWithoutEmptyRender are undefined so all cumulative
properties returned by analyzeTestResults are covered.

@storybook-app-bot
Copy link
Copy Markdown

Package Benchmarks

Commit: 1df1a39, ran on 5 May 2026 at 09:07:31 UTC

The following packages have significant changes to their size or dependencies:

@storybook/nextjs-vite

Before After Difference
Dependency count 93 93 0
Self size 1.37 MB 1.12 MB 🎉 -252 KB 🎉
Dependency size 24.67 MB 24.67 MB 🎉 -30 B 🎉
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 184 184 0
Self size 881 KB 880 KB 🎉 -2 KB 🎉
Dependency size 68.30 MB 68.29 MB 🎉 -19 KB 🎉
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 51 51 0
Self size 1.07 MB 1.05 MB 🎉 -19 KB 🎉
Dependency size 37.15 MB 37.15 MB 🎉 -347 B 🎉
Bundle Size Analyzer node node

@yannbf yannbf merged commit 071eca7 into next May 5, 2026
123 checks passed
@yannbf yannbf deleted the yann/fix-observability branch May 5, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal maintenance User-facing maintenance tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants