@@ -273,6 +273,92 @@ describe("session command compatibility checks", () => {
273273 }
274274 } ) ;
275275
276+ test ( "refreshes a stale daemon before running comment-add" , async ( ) => {
277+ const selector : SessionSelectorInput = { sessionId : "session-1" } ;
278+ const restartCalls : Array < { action : string ; selector ?: SessionSelectorInput } > = [ ] ;
279+ const createdClients : string [ ] = [ ] ;
280+ const notices : string [ ] = [ ] ;
281+ const originalConsoleError = console . error ;
282+ console . error = ( ...args : unknown [ ] ) => {
283+ notices . push ( args . map ( ( value ) => String ( value ) ) . join ( " " ) ) ;
284+ } ;
285+
286+ const clients = [
287+ createClient ( {
288+ getCapabilities : async ( ) => {
289+ createdClients . push ( "stale-capabilities" ) ;
290+ return null ;
291+ } ,
292+ } ) ,
293+ createClient ( {
294+ addComment : async ( input ) => {
295+ createdClients . push ( "fresh-comment-add" ) ;
296+ expect ( input . selector ) . toEqual ( selector ) ;
297+ expect ( input . filePath ) . toBe ( "README.md" ) ;
298+ expect ( input . side ) . toBe ( "new" ) ;
299+ expect ( input . line ) . toBe ( 2 ) ;
300+ expect ( input . summary ) . toBe ( "Review note" ) ;
301+ return {
302+ commentId : "comment-1" ,
303+ fileId : "file-1" ,
304+ filePath : "README.md" ,
305+ hunkIndex : 0 ,
306+ side : "new" ,
307+ line : 2 ,
308+ } ;
309+ } ,
310+ } ) ,
311+ ] ;
312+
313+ try {
314+ setSessionCommandTestHooks ( {
315+ createClient : ( ) => {
316+ const client = clients . shift ( ) ;
317+ if ( ! client ) {
318+ throw new Error ( "No fake session client remaining." ) ;
319+ }
320+
321+ return client ;
322+ } ,
323+ resolveDaemonAvailability : async ( ) => true ,
324+ restartDaemonForMissingAction : async ( action , receivedSelector ) => {
325+ restartCalls . push ( { action, selector : receivedSelector } ) ;
326+ } ,
327+ } ) ;
328+
329+ const output = await runSessionCommand ( {
330+ kind : "session" ,
331+ action : "comment-add" ,
332+ selector,
333+ filePath : "README.md" ,
334+ side : "new" ,
335+ line : 2 ,
336+ summary : "Review note" ,
337+ reveal : false ,
338+ output : "json" ,
339+ } satisfies SessionCommandInput ) ;
340+
341+ expect ( JSON . parse ( output ) ) . toMatchObject ( {
342+ result : {
343+ commentId : "comment-1" ,
344+ filePath : "README.md" ,
345+ side : "new" ,
346+ line : 2 ,
347+ } ,
348+ } ) ;
349+ expect ( restartCalls ) . toEqual ( [
350+ {
351+ action : "comment-add" ,
352+ selector,
353+ } ,
354+ ] ) ;
355+ expect ( createdClients ) . toEqual ( [ "stale-capabilities" , "fresh-comment-add" ] ) ;
356+ expect ( notices ) . toContain ( HUNK_DAEMON_UPGRADE_RESTART_NOTICE ) ;
357+ } finally {
358+ console . error = originalConsoleError ;
359+ }
360+ } ) ;
361+
276362 test ( "runs review commands through the daemon without raw patch text by default" , async ( ) => {
277363 setSessionCommandTestHooks ( {
278364 createClient : ( ) =>
0 commit comments