@@ -12,7 +12,12 @@ import fs from "node:fs";
1212import os from "node:os" ;
1313import { AgentMode } from "../AgentMode" ;
1414import { expect , vi } from "vitest" ;
15- import type { Model , ReasoningEffortOption } from "../app-server/v2" ;
15+ import type {
16+ AccountLoginCompletedNotification ,
17+ LoginAccountResponse ,
18+ Model ,
19+ ReasoningEffortOption
20+ } from "../app-server/v2" ;
1621
1722export type MethodCallEvent = { method : string ; args : any [ ] } ;
1823
@@ -42,6 +47,9 @@ function normalizeAcpConnectionEvent(event: MethodCallEvent): MethodCallEvent {
4247 if ( event . method === "request" && event . args [ 0 ] === acp . methods . client . session . requestPermission ) {
4348 return { method : "requestPermission" , args : [ event . args [ 1 ] ] } ;
4449 }
50+ if ( event . method === "request" && event . args [ 0 ] === acp . methods . client . elicitation . create ) {
51+ return { method : "elicitationCreate" , args : [ event . args [ 1 ] ] } ;
52+ }
4553 if ( event . method === "notify" && event . args [ 0 ] === acp . methods . client . session . update ) {
4654 return { method : "sessionUpdate" , args : [ event . args [ 1 ] ] } ;
4755 }
@@ -238,6 +246,9 @@ export interface CodexMockTestFixture extends TestFixture {
238246 sendServerNotification ( notification : ServerNotification | Record < string , unknown > ) : void ,
239247 sendServerRequest < T > ( method : string , params : unknown ) : Promise < T > ,
240248 setPermissionResponse ( response : RequestPermissionResponse ) : void ,
249+ setElicitationResponse ( response : acp . CreateElicitationResponse ) : void ,
250+ setAccountLoginResponse ( response : LoginAccountResponse ) : void ,
251+ sendAccountLoginCompleted ( notification : AccountLoginCompletedNotification ) : void ,
241252}
242253
243254/**
@@ -250,18 +261,30 @@ export interface CodexMockTestFixture extends TestFixture {
250261export function createCodexMockTestFixture ( ) : CodexMockTestFixture {
251262 let unhandledNotificationHandler : ( ( notification : any ) => void ) | null = null ;
252263 const requestHandlers = new Map < string , ( params : unknown ) => Promise < unknown > > ( ) ;
264+ const loginCompletedHandlers = new Set < ( notification : AccountLoginCompletedNotification ) => void > ( ) ;
253265
254266 // State for controlling permission responses
255267 const permissionState : { response : RequestPermissionResponse } = {
256268 response : { outcome : { outcome : 'cancelled' } }
257269 } ;
270+ const elicitationState : { response : acp . CreateElicitationResponse } = {
271+ response : { action : 'cancel' }
272+ } ;
258273
259274 const mockCodexConnection = {
260275 sendRequest : ( ) => Promise . resolve ( undefined ) ,
261276 onUnhandledNotification : ( handler : ( notification : any ) => void ) => {
262277 unhandledNotificationHandler = handler ;
263278 } ,
264- onNotification : ( ) => { } ,
279+ onNotification : ( method : string , handler : ( notification : AccountLoginCompletedNotification ) => void ) => {
280+ if ( method === "account/login/completed" ) {
281+ loginCompletedHandlers . add ( handler ) ;
282+ return {
283+ dispose : ( ) => loginCompletedHandlers . delete ( handler ) ,
284+ } ;
285+ }
286+ return { dispose : ( ) => { } } ;
287+ } ,
265288 onRequest : ( type : { method : string } , handler : ( params : unknown ) => Promise < unknown > ) => {
266289 requestHandlers . set ( type . method , handler ) ;
267290 } ,
@@ -276,9 +299,13 @@ export function createCodexMockTestFixture(): CodexMockTestFixture {
276299 if ( args [ 0 ] === acp . methods . client . session . requestPermission ) {
277300 return permissionState . response ;
278301 }
302+ if ( args [ 0 ] === acp . methods . client . elicitation . create ) {
303+ return elicitationState . response ;
304+ }
279305 return { mock : "Mocked return" } ;
280306 } ) ;
281307 returnValues . set ( 'requestPermission' , ( ) => permissionState . response ) ;
308+ returnValues . set ( 'elicitationCreate' , ( ) => elicitationState . response ) ;
282309
283310 const acpConnection = createSmartMock < AcpClientConnection > ( ( event ) => {
284311 const normalizedEvent = normalizeAcpConnectionEvent ( event ) ;
@@ -313,6 +340,17 @@ export function createCodexMockTestFixture(): CodexMockTestFixture {
313340 setPermissionResponse ( response : RequestPermissionResponse ) : void {
314341 permissionState . response = response ;
315342 } ,
343+ setElicitationResponse ( response : acp . CreateElicitationResponse ) : void {
344+ elicitationState . response = response ;
345+ } ,
346+ setAccountLoginResponse ( response : LoginAccountResponse ) : void {
347+ vi . spyOn ( baseFixture . getCodexAppServerClient ( ) , "accountLogin" ) . mockResolvedValue ( response ) ;
348+ } ,
349+ sendAccountLoginCompleted ( notification : AccountLoginCompletedNotification ) : void {
350+ for ( const handler of loginCompletedHandlers ) {
351+ handler ( notification ) ;
352+ }
353+ } ,
316354 } ;
317355}
318356
0 commit comments