@@ -123,7 +123,44 @@ describe("CodexEventHandler - thread goal events", () => {
123123
124124 const events = mockFixture . getAcpConnectionEvents ( [ ] ) ;
125125 expect ( events ) . toHaveLength ( 1 ) ;
126- expect ( events [ 0 ] ! . args [ 0 ] . update . content . text ) . toBe ( "Goal updated (active): Ship the goal update\n\n" ) ;
126+ expect ( events [ 0 ] ! . args [ 0 ] . update . content . text ) . toBe ( "\n\nGoal updated (active): Ship the goal update\n\n" ) ;
127+ } ) ;
128+
129+ it ( "should separate completed goal updates from preceding agent text" , async ( ) => {
130+ const goalCompletedNotification : ServerNotification = {
131+ method : "thread/goal/updated" ,
132+ params : {
133+ threadId : sessionId ,
134+ turnId : "turn-1" ,
135+ goal : {
136+ threadId : sessionId ,
137+ objective : "tell me a joke" ,
138+ status : "complete" ,
139+ tokenBudget : null ,
140+ tokensUsed : 42 ,
141+ timeUsedSeconds : 12 ,
142+ createdAt : 1710000000 ,
143+ updatedAt : 1710000012 ,
144+ } ,
145+ } ,
146+ } ;
147+
148+ await setupPromptAndSendNotifications ( mockFixture , sessionId , createSessionState ( ) , [
149+ {
150+ method : "item/agentMessage/delta" ,
151+ params : {
152+ threadId : sessionId ,
153+ turnId : "turn-1" ,
154+ itemId : "message-1" ,
155+ delta : "Because they kept losing interest in `any`." ,
156+ } ,
157+ } ,
158+ goalCompletedNotification ,
159+ ] ) ;
160+
161+ const events = mockFixture . getAcpConnectionEvents ( [ ] ) ;
162+ expect ( events ) . toHaveLength ( 2 ) ;
163+ expect ( events [ 1 ] ! . args [ 0 ] . update . content . text ) . toBe ( "\n\nGoal updated (complete): tell me a joke\n\n" ) ;
127164 } ) ;
128165
129166 it ( "should suppress duplicate thread goal cleared notifications" , async ( ) => {
@@ -141,7 +178,7 @@ describe("CodexEventHandler - thread goal events", () => {
141178
142179 const events = mockFixture . getAcpConnectionEvents ( [ ] ) ;
143180 expect ( events ) . toHaveLength ( 1 ) ;
144- expect ( events [ 0 ] ! . args [ 0 ] . update . content . text ) . toBe ( "Goal cleared.\n\n" ) ;
181+ expect ( events [ 0 ] ! . args [ 0 ] . update . content . text ) . toBe ( "\n\nGoal cleared.\n\n" ) ;
145182 } ) ;
146183
147184 function createSessionState ( ) : SessionState {
0 commit comments