@@ -1536,6 +1536,52 @@ describe('ACP server test', { timeout: 40_000 }, () => {
15361536 } ) ;
15371537 } ) ;
15381538
1539+ it ( 'suppresses the first routed goal notification after cancellation marks the turn stale' , async ( ) => {
1540+ const { mockFixture } = setupPromptFixture ( ) ;
1541+ const codexAppServerClient = mockFixture . getCodexAppServerClient ( ) ;
1542+ const threadGoalSetSpy = vi . spyOn ( codexAppServerClient , "threadGoalSet" )
1543+ . mockResolvedValue ( { goal : createThreadGoal ( ) } ) ;
1544+ const turnInterruptSpy = vi . spyOn ( mockFixture . getCodexAcpClient ( ) , "turnInterrupt" )
1545+ . mockResolvedValue ( undefined ) ;
1546+ const controller = new AbortController ( ) ;
1547+
1548+ const promptPromise = mockFixture . getCodexAcpAgent ( ) . prompt ( {
1549+ sessionId : "session-id" ,
1550+ prompt : [ { type : "text" , text : "/goal Ship the migration and keep tests green" } ] ,
1551+ } , controller . signal ) ;
1552+
1553+ await vi . waitFor ( ( ) => {
1554+ expect ( threadGoalSetSpy ) . toHaveBeenCalledWith ( {
1555+ threadId : "session-id" ,
1556+ objective : "Ship the migration and keep tests green" ,
1557+ status : "active" ,
1558+ } ) ;
1559+ } ) ;
1560+
1561+ controller . abort ( ) ;
1562+ await expect ( promptPromise ) . resolves . toMatchObject ( { stopReason : "cancelled" } ) ;
1563+ mockFixture . clearAcpConnectionDump ( ) ;
1564+
1565+ mockFixture . sendServerNotification ( {
1566+ method : "item/agentMessage/delta" ,
1567+ params : {
1568+ threadId : "session-id" ,
1569+ turnId : "goal-turn-id" ,
1570+ itemId : "goal-message-id" ,
1571+ delta : "leaked goal output" ,
1572+ } ,
1573+ } ) ;
1574+
1575+ await vi . waitFor ( ( ) => {
1576+ expect ( turnInterruptSpy ) . toHaveBeenCalledWith ( {
1577+ threadId : "session-id" ,
1578+ turnId : "goal-turn-id" ,
1579+ } ) ;
1580+ } ) ;
1581+ await flushAsyncWork ( ) ;
1582+ expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . not . toContain ( "leaked goal output" ) ;
1583+ } ) ;
1584+
15391585 it ( 'does not hang when goal set starts no continuation turn' , async ( ) => {
15401586 const mockFixture = createCodexMockTestFixture ( ) ;
15411587 const codexAppServerClient = mockFixture . getCodexAppServerClient ( ) ;
0 commit comments