@@ -18,12 +18,6 @@ describe("CodexEventHandler - thread goal events", () => {
1818 vi . clearAllMocks ( ) ;
1919 } ) ;
2020
21- const sessionState : SessionState = createTestSessionState ( {
22- sessionId,
23- currentModelId : "model-id[effort]" ,
24- agentMode : AgentMode . DEFAULT_AGENT_MODE ,
25- } ) ;
26-
2721 it ( "should send thread goal updates as agent messages" , async ( ) => {
2822 const goalUpdatedNotification : ServerNotification = {
2923 method : "thread/goal/updated" ,
@@ -43,7 +37,7 @@ describe("CodexEventHandler - thread goal events", () => {
4337 } ,
4438 } ;
4539
46- await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ goalUpdatedNotification ] ) ;
40+ await setupPromptAndSendNotifications ( mockFixture , sessionId , createSessionState ( ) , [ goalUpdatedNotification ] ) ;
4741
4842 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
4943 "data/thread-goal-updated.json"
@@ -69,7 +63,7 @@ describe("CodexEventHandler - thread goal events", () => {
6963 } ,
7064 } ;
7165
72- await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ goalUpdatedNotification ] ) ;
66+ await setupPromptAndSendNotifications ( mockFixture , sessionId , createSessionState ( ) , [ goalUpdatedNotification ] ) ;
7367
7468 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
7569 "data/thread-goal-updated-multiline.json"
@@ -84,10 +78,77 @@ describe("CodexEventHandler - thread goal events", () => {
8478 } ,
8579 } ;
8680
87- await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ goalClearedNotification ] ) ;
81+ await setupPromptAndSendNotifications ( mockFixture , sessionId , createSessionState ( ) , [ goalClearedNotification ] ) ;
8882
8983 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
9084 "data/thread-goal-cleared.json"
9185 ) ;
9286 } ) ;
87+
88+ it ( "should suppress duplicate thread goal updates" , async ( ) => {
89+ const goalUpdatedNotification : ServerNotification = {
90+ method : "thread/goal/updated" ,
91+ params : {
92+ threadId : sessionId ,
93+ turnId : "turn-1" ,
94+ goal : {
95+ threadId : sessionId ,
96+ objective : "Ship the goal update" ,
97+ status : "active" ,
98+ tokenBudget : null ,
99+ tokensUsed : 42 ,
100+ timeUsedSeconds : 12 ,
101+ createdAt : 1710000000 ,
102+ updatedAt : 1710000012 ,
103+ } ,
104+ } ,
105+ } ;
106+ const duplicateGoalUpdatedNotification : ServerNotification = {
107+ method : "thread/goal/updated" ,
108+ params : {
109+ ...goalUpdatedNotification . params ,
110+ goal : {
111+ ...goalUpdatedNotification . params . goal ,
112+ tokensUsed : 84 ,
113+ timeUsedSeconds : 24 ,
114+ updatedAt : 1710000024 ,
115+ } ,
116+ } ,
117+ } ;
118+
119+ await setupPromptAndSendNotifications ( mockFixture , sessionId , createSessionState ( ) , [
120+ goalUpdatedNotification ,
121+ duplicateGoalUpdatedNotification ,
122+ ] ) ;
123+
124+ const events = mockFixture . getAcpConnectionEvents ( [ ] ) ;
125+ expect ( events ) . toHaveLength ( 1 ) ;
126+ expect ( events [ 0 ] ! . args [ 0 ] . update . content . text ) . toBe ( "Goal updated (active): Ship the goal update" ) ;
127+ } ) ;
128+
129+ it ( "should suppress duplicate thread goal cleared notifications" , async ( ) => {
130+ const goalClearedNotification : ServerNotification = {
131+ method : "thread/goal/cleared" ,
132+ params : {
133+ threadId : sessionId ,
134+ } ,
135+ } ;
136+
137+ await setupPromptAndSendNotifications ( mockFixture , sessionId , createSessionState ( ) , [
138+ goalClearedNotification ,
139+ goalClearedNotification ,
140+ ] ) ;
141+
142+ const events = mockFixture . getAcpConnectionEvents ( [ ] ) ;
143+ expect ( events ) . toHaveLength ( 1 ) ;
144+ expect ( events [ 0 ] ! . args [ 0 ] . update . content . text ) . toBe ( "Goal cleared." ) ;
145+ } ) ;
146+
147+ function createSessionState ( ) : SessionState {
148+ return createTestSessionState ( {
149+ sessionId,
150+ currentModelId : "model-id[effort]" ,
151+ agentMode : AgentMode . DEFAULT_AGENT_MODE ,
152+ } ) ;
153+ }
93154} ) ;
0 commit comments