@@ -274,7 +274,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
274274 } ) ;
275275 } ) ;
276276
277- it ( 'should cancel ChatGPT device code login when URL elicitation is declined ' , async ( ) => {
277+ it . each ( [ "decline" , "cancel" ] as const ) ( 'should cancel ChatGPT device code login when URL elicitation is answered with %s ' , async ( action ) => {
278278 const { deviceFixture, codexAppServerClient } = createDeviceCodeFixture ( ) ;
279279 const codexAcpAgent = deviceFixture . getCodexAcpAgent ( ) ;
280280 await codexAcpAgent . initialize ( {
@@ -283,16 +283,39 @@ describe('ACP server test', { timeout: 40_000 }, () => {
283283 } ) ;
284284 const cancelSpy = vi . spyOn ( codexAppServerClient , "accountLoginCancel" )
285285 . mockResolvedValue ( { status : "canceled" } ) ;
286- deviceFixture . setElicitationResponse ( { action : "decline" } ) ;
286+ deviceFixture . setElicitationResponse ( { action } ) ;
287287
288288 await expect ( codexAcpAgent . authenticate ( { methodId : "chat-gpt-device-code" } , 42 ) )
289- . rejects . toThrow ( ) ;
289+ . rejects . toMatchObject ( {
290+ code : - 32800 ,
291+ message : "Request cancelled: ChatGPT device code sign-in was cancelled" ,
292+ data : { methodId : "chat-gpt-device-code" , action } ,
293+ } ) ;
290294 expect ( cancelSpy ) . toHaveBeenCalledWith ( { loginId : "login-1" } ) ;
291295 expect ( deviceFixture . getAcpConnectionEvents ( [ ] )
292296 . some ( event => event . method === "completeElicitation" ) )
293297 . toBe ( false ) ;
294298 } ) ;
295299
300+ it ( 'should report an incomplete sign-in when ChatGPT device code login fails' , async ( ) => {
301+ const { deviceFixture, completeLogin, loginCompletedSubscribed } = createDeviceCodeFixture ( ) ;
302+ const codexAcpAgent = deviceFixture . getCodexAcpAgent ( ) ;
303+ await codexAcpAgent . initialize ( {
304+ protocolVersion : 1 ,
305+ clientCapabilities : { elicitation : { url : { } } } ,
306+ } ) ;
307+ deviceFixture . setElicitationResponse ( { action : "accept" } ) ;
308+
309+ const authPromise = codexAcpAgent . authenticate ( { methodId : "chat-gpt-device-code" } , 42 ) ;
310+ await vi . waitFor ( ( ) => expect ( loginCompletedSubscribed ( ) ) . toBe ( true ) ) ;
311+ completeLogin ( false ) ;
312+ await expect ( authPromise ) . rejects . toMatchObject ( {
313+ code : - 32000 ,
314+ message : "Authentication required: Sign-in did not complete" ,
315+ data : { methodId : "chat-gpt-device-code" } ,
316+ } ) ;
317+ } ) ;
318+
296319 it ( 'should complete URL elicitation when login finishes before the elicitation response' , async ( ) => {
297320 const { deviceFixture, completeLogin, loginCompletedSubscribed } = createDeviceCodeFixture ( ) ;
298321 const codexAcpAgent = deviceFixture . getCodexAcpAgent ( ) ;
0 commit comments