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/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({ 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" }