@@ -184,7 +184,15 @@ describe( 'CLI: studio ai sessions command', () => {
184184 return parser ;
185185 }
186186
187- it ( 'records sessions by default when running studio ai' , async ( ) => {
187+ it ( 'does not record an empty session when running studio ai and exiting immediately' , async ( ) => {
188+ await buildParser ( ) . parseAsync ( [ 'ai' ] ) ;
189+
190+ expect ( ( AiSessionRecorder as typeof AiSessionRecorder ) . create ) . not . toHaveBeenCalled ( ) ;
191+ } ) ;
192+
193+ it ( 'records sessions by default once a prompt is submitted' , async ( ) => {
194+ waitForInputMock . mockResolvedValueOnce ( 'Hello' ) . mockResolvedValueOnce ( '/exit' ) ;
195+
188196 await buildParser ( ) . parseAsync ( [ 'ai' ] ) ;
189197
190198 expect ( ( AiSessionRecorder as typeof AiSessionRecorder ) . create ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -231,12 +239,7 @@ describe( 'CLI: studio ai sessions command', () => {
231239 await buildParser ( ) . parseAsync ( [ 'ai' , 'sessions' , 'resume' , 'latest' ] ) ;
232240
233241 expect ( loadAiSession ) . toHaveBeenCalledWith ( 'session-latest' ) ;
234- expect ( ( AiSessionRecorder as typeof AiSessionRecorder ) . open ) . toHaveBeenCalledWith (
235- expect . objectContaining ( {
236- sessionId : 'session-latest' ,
237- filePath : '/tmp/session-latest.jsonl' ,
238- } )
239- ) ;
242+ expect ( ( AiSessionRecorder as typeof AiSessionRecorder ) . open ) . not . toHaveBeenCalled ( ) ;
240243 expect ( process . exit ) . toHaveBeenCalledWith ( 0 ) ;
241244 } ) ;
242245
@@ -376,6 +379,12 @@ describe( 'CLI: studio ai sessions command', () => {
376379 await buildParser ( ) . parseAsync ( [ 'ai' , 'sessions' , 'resume' , 'latest' ] ) ;
377380
378381 expect ( resolveAiEnvironment ) . toHaveBeenCalledWith ( 'anthropic-api-key' ) ;
382+ expect ( ( AiSessionRecorder as typeof AiSessionRecorder ) . open ) . toHaveBeenCalledWith (
383+ expect . objectContaining ( {
384+ sessionId : 'session-latest' ,
385+ filePath : '/tmp/session-latest.jsonl' ,
386+ } )
387+ ) ;
379388 expect ( startAiAgent ) . toHaveBeenCalledWith (
380389 expect . objectContaining ( {
381390 model : 'claude-opus-4-6' ,
0 commit comments