@@ -244,6 +244,8 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
244244 plugins . push ( mdxStubPlugin ) ;
245245 }
246246
247+ let withinAgenticSetupSession = false ;
248+
247249 const storybookTestPlugin : Plugin = {
248250 name : 'vite-plugin-storybook-test' ,
249251 async transformIndexHtml ( html ) {
@@ -384,16 +386,7 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
384386 manual : ! shouldRunA11yTests ,
385387 } ;
386388
387- if ( process . env . STORYBOOK_COMPONENT_PATHS ) {
388- globals . ghostStories = {
389- enabled : true ,
390- } ;
391- globals . renderAnalysis = {
392- enabled : true ,
393- } ;
394- }
395-
396- if ( detectAgent ( ) ) {
389+ if ( process . env . STORYBOOK_COMPONENT_PATHS || withinAgenticSetupSession ) {
397390 globals . renderAnalysis = {
398391 enabled : true ,
399392 } ;
@@ -475,7 +468,9 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
475468 // When an agent is running vitest via CLI, inject a reporter that sends
476469 // detailed test result telemetry (pass/fail, error analysis, empty renders)
477470 const agent = detectAgent ( ) ;
478- if ( agent && ( await isWithinInitialSession ( [ 'init' , 'ai-prepare' ] ) ) ) {
471+ withinAgenticSetupSession =
472+ ! ! agent && ( await isWithinInitialSession ( [ 'init' , 'ai-prepare' ] ) ) ;
473+ if ( agent && withinAgenticSetupSession ) {
479474 context . vitest . config . reporters . push (
480475 new AgentTelemetryReporter ( {
481476 configDir : finalOptions . configDir ,
0 commit comments