@@ -1102,7 +1102,12 @@ describe('ACP server test', { timeout: 40_000 }, () => {
11021102
11031103 it ( 'handles goal slash commands through Codex app server' , async ( ) => {
11041104 const { mockFixture, turnStartSpy } = setupPromptFixture ( ) ;
1105- const goalSetSpy = vi . spyOn ( mockFixture . getCodexAppServerClient ( ) , "threadGoalSet" )
1105+ const goalRunSpy = vi . spyOn ( mockFixture . getCodexAppServerClient ( ) , "runGoalSet" )
1106+ . mockResolvedValue ( {
1107+ threadId : "session-id" ,
1108+ turn : createTurn ( "goal-turn-id" , "completed" ) ,
1109+ } ) ;
1110+ const goalStatusSpy = vi . spyOn ( mockFixture . getCodexAppServerClient ( ) , "threadGoalSet" )
11061111 . mockResolvedValue ( { goal : createThreadGoal ( ) } ) ;
11071112 const goalClearSpy = vi . spyOn ( mockFixture . getCodexAppServerClient ( ) , "threadGoalClear" )
11081113 . mockResolvedValue ( { cleared : true } ) ;
@@ -1124,36 +1129,27 @@ describe('ACP server test', { timeout: 40_000 }, () => {
11241129 prompt : [ { type : "text" , text : "/goal clear" } ] ,
11251130 } ) ;
11261131
1127- expect ( goalSetSpy ) . toHaveBeenNthCalledWith ( 1 , {
1132+ expect ( goalRunSpy ) . toHaveBeenNthCalledWith ( 1 , {
11281133 threadId : "session-id" ,
11291134 objective : "Ship the migration and keep tests green" ,
11301135 status : "active" ,
1131- } ) ;
1132- expect ( goalSetSpy ) . toHaveBeenNthCalledWith ( 2 , {
1136+ } , expect . any ( Function ) ) ;
1137+ expect ( goalStatusSpy ) . toHaveBeenCalledWith ( {
11331138 threadId : "session-id" ,
11341139 status : "paused" ,
11351140 } ) ;
1136- expect ( goalSetSpy ) . toHaveBeenNthCalledWith ( 3 , {
1141+ expect ( goalRunSpy ) . toHaveBeenNthCalledWith ( 2 , {
11371142 threadId : "session-id" ,
11381143 status : "active" ,
1139- } ) ;
1144+ } , expect . any ( Function ) ) ;
11401145 expect ( goalClearSpy ) . toHaveBeenCalledWith ( { threadId : "session-id" } ) ;
11411146 expect ( turnStartSpy ) . not . toHaveBeenCalled ( ) ;
11421147 } ) ;
11431148
11441149 it ( 'waits for goal slash command turn completion' , async ( ) => {
11451150 const { mockFixture } = setupPromptFixture ( ) ;
11461151 vi . spyOn ( mockFixture . getCodexAppServerClient ( ) , "threadGoalSet" )
1147- . mockImplementation ( async ( ) => {
1148- mockFixture . sendServerNotification ( {
1149- method : "turn/started" ,
1150- params : {
1151- threadId : "session-id" ,
1152- turn : createTurn ( "goal-turn-id" , "inProgress" ) ,
1153- } ,
1154- } ) ;
1155- return { goal : createThreadGoal ( ) } ;
1156- } ) ;
1152+ . mockResolvedValue ( { goal : createThreadGoal ( ) } ) ;
11571153 let completeGoal : ( value : TurnCompletedNotification ) => void = ( ) => { } ;
11581154 const goalCompletedPromise = new Promise < TurnCompletedNotification > ( ( resolve ) => {
11591155 completeGoal = resolve ;
@@ -1170,6 +1166,48 @@ describe('ACP server test', { timeout: 40_000 }, () => {
11701166 return response ;
11711167 } ) ;
11721168
1169+ await vi . waitFor ( ( ) => {
1170+ expect ( mockFixture . getCodexAppServerClient ( ) . threadGoalSet ) . toHaveBeenCalledWith ( {
1171+ threadId : "session-id" ,
1172+ objective : "Ship the migration and keep tests green" ,
1173+ status : "active" ,
1174+ } ) ;
1175+ } ) ;
1176+ await Promise . resolve ( ) ;
1177+ expect ( promptResolved ) . toBe ( false ) ;
1178+ expect ( mockFixture . getCodexAppServerClient ( ) . awaitTurnCompleted ) . not . toHaveBeenCalled ( ) ;
1179+
1180+ mockFixture . sendServerNotification ( {
1181+ method : "thread/goal/updated" ,
1182+ params : {
1183+ threadId : "session-id" ,
1184+ turnId : null ,
1185+ goal : createThreadGoal ( ) ,
1186+ } ,
1187+ } ) ;
1188+ mockFixture . sendServerNotification ( {
1189+ method : "thread/status/changed" ,
1190+ params : {
1191+ threadId : "session-id" ,
1192+ status : {
1193+ type : "active" ,
1194+ activeFlags : [ ] ,
1195+ } ,
1196+ } ,
1197+ } ) ;
1198+ await Promise . resolve ( ) ;
1199+ expect ( promptResolved ) . toBe ( false ) ;
1200+ expect ( mockFixture . getCodexAppServerClient ( ) . awaitTurnCompleted ) . not . toHaveBeenCalled ( ) ;
1201+
1202+ mockFixture . sendServerNotification ( {
1203+ method : "item/agentMessage/delta" ,
1204+ params : {
1205+ threadId : "session-id" ,
1206+ turnId : "goal-turn-id" ,
1207+ itemId : "goal-message-id" ,
1208+ delta : "I" ,
1209+ } ,
1210+ } ) ;
11731211 await vi . waitFor ( ( ) => {
11741212 expect ( mockFixture . getCodexAppServerClient ( ) . awaitTurnCompleted ) . toHaveBeenCalledWith (
11751213 "session-id" ,
0 commit comments