@@ -232,6 +232,74 @@ describe("CopilotClient", () => {
232232 spy . mockRestore ( ) ;
233233 } ) ;
234234
235+ it ( "defaults mcpOAuthTokenStorage to 'in-memory' in session.create when not specified" , async ( ) => {
236+ const client = new CopilotClient ( ) ;
237+ await client . start ( ) ;
238+ onTestFinished ( ( ) => client . forceStop ( ) ) ;
239+
240+ const spy = vi . spyOn ( ( client as any ) . connection ! , "sendRequest" ) ;
241+ await client . createSession ( { onPermissionRequest : approveAll } ) ;
242+
243+ const payload = spy . mock . calls . find ( ( c ) => c [ 0 ] === "session.create" ) ! [ 1 ] as any ;
244+ expect ( payload . mcpOAuthTokenStorage ) . toBe ( "in-memory" ) ;
245+ } ) ;
246+
247+ it ( "forwards explicit 'persistent' for mcpOAuthTokenStorage in session.create" , async ( ) => {
248+ const client = new CopilotClient ( ) ;
249+ await client . start ( ) ;
250+ onTestFinished ( ( ) => client . forceStop ( ) ) ;
251+
252+ const spy = vi . spyOn ( ( client as any ) . connection ! , "sendRequest" ) ;
253+ await client . createSession ( {
254+ onPermissionRequest : approveAll ,
255+ mcpOAuthTokenStorage : "persistent" ,
256+ } ) ;
257+
258+ const payload = spy . mock . calls . find ( ( c ) => c [ 0 ] === "session.create" ) ! [ 1 ] as any ;
259+ expect ( payload . mcpOAuthTokenStorage ) . toBe ( "persistent" ) ;
260+ } ) ;
261+
262+ it ( "defaults mcpOAuthTokenStorage to 'in-memory' in session.resume when not specified" , async ( ) => {
263+ const client = new CopilotClient ( ) ;
264+ await client . start ( ) ;
265+ onTestFinished ( ( ) => client . forceStop ( ) ) ;
266+
267+ const session = await client . createSession ( { onPermissionRequest : approveAll } ) ;
268+ const spy = vi
269+ . spyOn ( ( client as any ) . connection ! , "sendRequest" )
270+ . mockImplementation ( async ( method : string , params : any ) => {
271+ if ( method === "session.resume" ) return { sessionId : params . sessionId } ;
272+ throw new Error ( `Unexpected method: ${ method } ` ) ;
273+ } ) ;
274+ await client . resumeSession ( session . sessionId , { onPermissionRequest : approveAll } ) ;
275+
276+ const payload = spy . mock . calls . find ( ( c ) => c [ 0 ] === "session.resume" ) ! [ 1 ] as any ;
277+ expect ( payload . mcpOAuthTokenStorage ) . toBe ( "in-memory" ) ;
278+ spy . mockRestore ( ) ;
279+ } ) ;
280+
281+ it ( "forwards explicit 'persistent' for mcpOAuthTokenStorage in session.resume" , async ( ) => {
282+ const client = new CopilotClient ( ) ;
283+ await client . start ( ) ;
284+ onTestFinished ( ( ) => client . forceStop ( ) ) ;
285+
286+ const session = await client . createSession ( { onPermissionRequest : approveAll } ) ;
287+ const spy = vi
288+ . spyOn ( ( client as any ) . connection ! , "sendRequest" )
289+ . mockImplementation ( async ( method : string , params : any ) => {
290+ if ( method === "session.resume" ) return { sessionId : params . sessionId } ;
291+ throw new Error ( `Unexpected method: ${ method } ` ) ;
292+ } ) ;
293+ await client . resumeSession ( session . sessionId , {
294+ onPermissionRequest : approveAll ,
295+ mcpOAuthTokenStorage : "persistent" ,
296+ } ) ;
297+
298+ const payload = spy . mock . calls . find ( ( c ) => c [ 0 ] === "session.resume" ) ! [ 1 ] as any ;
299+ expect ( payload . mcpOAuthTokenStorage ) . toBe ( "persistent" ) ;
300+ spy . mockRestore ( ) ;
301+ } ) ;
302+
235303 it ( "forwards continuePendingWork in session.resume request" , async ( ) => {
236304 const client = new CopilotClient ( ) ;
237305 await client . start ( ) ;
0 commit comments