From 1d5ea9581a6ac7bc069eb9694863dda4f09cd9a1 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Fri, 1 May 2026 12:55:09 +0200 Subject: [PATCH 1/2] move agent detection to config hook instead of configureVitest Co-authored-by: Copilot --- code/addons/vitest/src/vitest-plugin/index.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/code/addons/vitest/src/vitest-plugin/index.ts b/code/addons/vitest/src/vitest-plugin/index.ts index 82cd351a54af..ebd17dbe2a53 100644 --- a/code/addons/vitest/src/vitest-plugin/index.ts +++ b/code/addons/vitest/src/vitest-plugin/index.ts @@ -252,6 +252,7 @@ export const storybookTest = async (options?: UserOptions): Promise => plugins.push(mdxStubPlugin); } + let agent: ReturnType | undefined; let withinAgenticSetupSession = false; const storybookTestPlugin: Plugin = { @@ -267,6 +268,11 @@ export const storybookTest = async (options?: UserOptions): Promise => .replace('', `${bodyHtmlSnippet ?? ''}`); }, async config(nonMutableInputConfig, { mode }) { + if (isTelemetryModuleEnabled()) { + agent = detectAgent(); + withinAgenticSetupSession = !!agent && (await isWithinInitialSession('ai-setup')); + } + if (mode) { // Needed for `preset.apply('env')` to work correctly process.env.BUILD_TARGET = mode; @@ -367,7 +373,8 @@ export const storybookTest = async (options?: UserOptions): Promise => provide: { [STORYBOOK_CORE_GHOST_STORIES_PROVIDE_KEY]: !!process.env.STORYBOOK_COMPONENT_PATHS, - [STORYBOOK_CORE_RENDER_ANALYSIS_PROVIDE_KEY]: !!process.env.STORYBOOK_COMPONENT_PATHS, + [STORYBOOK_CORE_RENDER_ANALYSIS_PROVIDE_KEY]: + !!process.env.STORYBOOK_COMPONENT_PATHS || withinAgenticSetupSession, }, include: [...includeStories, ...getComponentTestPaths()], @@ -458,11 +465,6 @@ export const storybookTest = async (options?: UserOptions): Promise => if (isTelemetryModuleEnabled()) { // When an agent is running vitest via CLI, inject a reporter that sends // detailed test result telemetry (pass/fail, error analysis, empty renders) - const agent = detectAgent(); - withinAgenticSetupSession = !!agent && (await isWithinInitialSession('ai-setup')); - if (withinAgenticSetupSession) { - await context.vitest.provide(STORYBOOK_CORE_RENDER_ANALYSIS_PROVIDE_KEY, true); - } if (agent && withinAgenticSetupSession) { context.vitest.config.reporters.push( new AgentTelemetryReporter({ From 9681b6aff615f932aa1397c13719438919c1b1e0 Mon Sep 17 00:00:00 2001 From: storybook-bot <32066757+storybook-bot@users.noreply.github.com> Date: Fri, 1 May 2026 11:33:48 +0000 Subject: [PATCH 2/2] Write changelog for 10.4.0-alpha.15 [skip ci] --- CHANGELOG.prerelease.md | 4 ++++ code/package.json | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.prerelease.md b/CHANGELOG.prerelease.md index bb750beb09b8..f485befe12fd 100644 --- a/CHANGELOG.prerelease.md +++ b/CHANGELOG.prerelease.md @@ -1,3 +1,7 @@ +## 10.4.0-alpha.15 + +- Vitest: Fix agent detection breaking runs - [#34681](https://github.com/storybookjs/storybook/pull/34681), thanks @JReinhold! + ## 10.4.0-alpha.14 - CLI: Fix agentic check - [#34678](https://github.com/storybookjs/storybook/pull/34678), thanks @yannbf! diff --git a/code/package.json b/code/package.json index 2f6f0837e366..4a0a0dd02664 100644 --- a/code/package.json +++ b/code/package.json @@ -196,5 +196,6 @@ "Dependency Upgrades" ] ] - } + }, + "deferredNextVersion": "10.4.0-alpha.15" }