11import { describe , it , expect , vi , beforeEach } from 'vitest' ;
22import type { SessionState } from '../../CodexAcpServer' ;
33import type { ServerNotification } from '../../app-server' ;
4- import { createCodexMockTestFixture , createTestSessionState , type CodexMockTestFixture } from '../acp-test-utils' ;
4+ import { createCodexMockTestFixture , createTestSessionState , setupPromptAndSendNotifications , type CodexMockTestFixture } from '../acp-test-utils' ;
55import { AgentMode } from "../../AgentMode" ;
66
77describe ( 'CodexEventHandler - command action events' , ( ) => {
@@ -19,36 +19,6 @@ describe('CodexEventHandler - command action events', () => {
1919 agentMode : AgentMode . DEFAULT_AGENT_MODE
2020 } ) ;
2121
22- async function setupAndSendNotifications ( notifications : ServerNotification [ ] ) {
23- const codexAcpAgent = mockFixture . getCodexAcpAgent ( ) ;
24-
25- mockFixture . getCodexAppServerClient ( ) . turnStart = vi . fn ( ) . mockResolvedValue ( {
26- turn : { id : "turn-id" , items : [ ] , status : "inProgress" , error : null }
27- } ) ;
28- mockFixture . getCodexAppServerClient ( ) . awaitTurnCompleted = vi . fn ( ) . mockResolvedValue ( {
29- threadId : sessionId ,
30- turn : { id : "turn-id" , items : [ ] , status : "completed" , error : null }
31- } ) ;
32-
33- vi . spyOn ( codexAcpAgent , 'getSessionState' ) . mockReturnValue ( sessionState ) ;
34-
35- await codexAcpAgent . prompt ( {
36- sessionId,
37- prompt : [ { type : 'text' , text : 'test prompt' } ] ,
38- } ) ;
39-
40- mockFixture . clearAcpConnectionDump ( ) ;
41-
42- for ( const notification of notifications ) {
43- mockFixture . sendServerNotification ( notification ) ;
44- }
45-
46- await vi . waitFor ( ( ) => {
47- const dump = mockFixture . getAcpConnectionDump ( [ ] ) ;
48- expect ( dump . length ) . toBeGreaterThan ( 0 ) ;
49- } ) ;
50- }
51-
5222 it ( 'should handle list files command with explicit path' , async ( ) => {
5323 const listFilesNotification : ServerNotification = {
5424 method : 'item/started' ,
@@ -76,7 +46,7 @@ describe('CodexEventHandler - command action events', () => {
7646 } ,
7747 } ;
7848
79- await setupAndSendNotifications ( [ listFilesNotification ] ) ;
49+ await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ listFilesNotification ] ) ;
8050
8151 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
8252 'data/command-list-files-with-path.json'
@@ -110,7 +80,7 @@ describe('CodexEventHandler - command action events', () => {
11080 } ,
11181 } ;
11282
113- await setupAndSendNotifications ( [ listFilesNotification ] ) ;
83+ await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ listFilesNotification ] ) ;
11484
11585 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
11686 'data/command-list-files-without-path.json'
@@ -145,7 +115,7 @@ describe('CodexEventHandler - command action events', () => {
145115 } ,
146116 } ;
147117
148- await setupAndSendNotifications ( [ searchNotification ] ) ;
118+ await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ searchNotification ] ) ;
149119
150120 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
151121 'data/command-search-with-query-and-path.json'
@@ -180,7 +150,7 @@ describe('CodexEventHandler - command action events', () => {
180150 } ,
181151 } ;
182152
183- await setupAndSendNotifications ( [ searchNotification ] ) ;
153+ await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ searchNotification ] ) ;
184154
185155 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
186156 'data/command-search-with-query-only.json'
@@ -215,7 +185,7 @@ describe('CodexEventHandler - command action events', () => {
215185 } ,
216186 } ;
217187
218- await setupAndSendNotifications ( [ searchNotification ] ) ;
188+ await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ searchNotification ] ) ;
219189
220190 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
221191 'data/command-search-with-path-only.json'
@@ -250,7 +220,7 @@ describe('CodexEventHandler - command action events', () => {
250220 } ,
251221 } ;
252222
253- await setupAndSendNotifications ( [ searchNotification ] ) ;
223+ await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ searchNotification ] ) ;
254224
255225 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
256226 'data/command-search-no-query-no-path.json'
@@ -277,7 +247,7 @@ describe('CodexEventHandler - command action events', () => {
277247 } ,
278248 } ;
279249
280- await setupAndSendNotifications ( [ searchNotification ] ) ;
250+ await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ searchNotification ] ) ;
281251
282252 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
283253 'data/mcp-tool-in-progress.json'
@@ -303,7 +273,7 @@ describe('CodexEventHandler - command action events', () => {
303273 } ,
304274 } ;
305275
306- await setupAndSendNotifications ( [ dynamicToolNotification ] ) ;
276+ await setupPromptAndSendNotifications ( mockFixture , sessionId , sessionState , [ dynamicToolNotification ] ) ;
307277
308278 await expect ( mockFixture . getAcpConnectionDump ( [ ] ) ) . toMatchFileSnapshot (
309279 'data/dynamic-tool-in-progress.json'
0 commit comments