77import { describe , it , expect , vi , beforeEach } from 'vitest' ;
88import { Session } from './Session.js' ;
99import type { Config , GeminiChat } from '@qwen-code/qwen-code-core' ;
10- import { ApprovalMode } from '@qwen-code/qwen-code-core' ;
10+ import { ApprovalMode , AuthType } from '@qwen-code/qwen-code-core' ;
1111import type * as acp from '../acp.js' ;
1212import type { LoadedSettings } from '../../config/settings.js' ;
1313import * as nonInteractiveCliCommands from '../../nonInteractiveCliCommands.js' ;
@@ -24,14 +24,19 @@ describe('Session', () => {
2424 let mockSettings : LoadedSettings ;
2525 let session : Session ;
2626 let currentModel : string ;
27- let setModelSpy : ReturnType < typeof vi . fn > ;
27+ let currentAuthType : AuthType ;
28+ let switchModelSpy : ReturnType < typeof vi . fn > ;
2829 let getAvailableCommandsSpy : ReturnType < typeof vi . fn > ;
2930
3031 beforeEach ( ( ) => {
3132 currentModel = 'qwen3-code-plus' ;
32- setModelSpy = vi . fn ( ) . mockImplementation ( async ( modelId : string ) => {
33- currentModel = modelId ;
34- } ) ;
33+ currentAuthType = AuthType . USE_OPENAI ;
34+ switchModelSpy = vi
35+ . fn ( )
36+ . mockImplementation ( async ( authType : AuthType , modelId : string ) => {
37+ currentAuthType = authType ;
38+ currentModel = modelId ;
39+ } ) ;
3540
3641 mockChat = {
3742 sendMessageStream : vi . fn ( ) ,
@@ -40,8 +45,9 @@ describe('Session', () => {
4045
4146 mockConfig = {
4247 setApprovalMode : vi . fn ( ) ,
43- setModel : setModelSpy ,
48+ switchModel : switchModelSpy ,
4449 getModel : vi . fn ( ) . mockImplementation ( ( ) => currentModel ) ,
50+ getAuthType : vi . fn ( ) . mockImplementation ( ( ) => currentAuthType ) ,
4551 } as unknown as Config ;
4652
4753 mockClient = {
@@ -88,17 +94,25 @@ describe('Session', () => {
8894
8995 describe ( 'setModel' , ( ) => {
9096 it ( 'sets model via config and returns current model' , async ( ) => {
97+ const requested = `qwen3-coder-plus(${ AuthType . USE_OPENAI } )` ;
9198 const result = await session . setModel ( {
9299 sessionId : 'test-session-id' ,
93- modelId : ' qwen3-coder-plus ' ,
100+ modelId : ` ${ requested } ` ,
94101 } ) ;
95102
96- expect ( mockConfig . setModel ) . toHaveBeenCalledWith ( 'qwen3-coder-plus' , {
97- reason : 'user_request_acp' ,
98- context : 'session/set_model' ,
99- } ) ;
103+ expect ( mockConfig . switchModel ) . toHaveBeenCalledWith (
104+ AuthType . USE_OPENAI ,
105+ 'qwen3-coder-plus' ,
106+ undefined ,
107+ {
108+ reason : 'user_request_acp' ,
109+ context : 'session/set_model' ,
110+ } ,
111+ ) ;
100112 expect ( mockConfig . getModel ) . toHaveBeenCalled ( ) ;
101- expect ( result ) . toEqual ( { modelId : 'qwen3-coder-plus' } ) ;
113+ expect ( result ) . toEqual ( {
114+ modelId : `qwen3-coder-plus(${ AuthType . USE_OPENAI } )` ,
115+ } ) ;
102116 } ) ;
103117
104118 it ( 'rejects empty/whitespace model IDs' , async ( ) => {
@@ -109,17 +123,17 @@ describe('Session', () => {
109123 } ) ,
110124 ) . rejects . toThrow ( 'Invalid params' ) ;
111125
112- expect ( mockConfig . setModel ) . not . toHaveBeenCalled ( ) ;
126+ expect ( mockConfig . switchModel ) . not . toHaveBeenCalled ( ) ;
113127 } ) ;
114128
115- it ( 'propagates errors from config.setModel ' , async ( ) => {
129+ it ( 'propagates errors from config.switchModel ' , async ( ) => {
116130 const configError = new Error ( 'Invalid model' ) ;
117- setModelSpy . mockRejectedValueOnce ( configError ) ;
131+ switchModelSpy . mockRejectedValueOnce ( configError ) ;
118132
119133 await expect (
120134 session . setModel ( {
121135 sessionId : 'test-session-id' ,
122- modelId : ' invalid-model' ,
136+ modelId : ` invalid-model( ${ AuthType . USE_OPENAI } )` ,
123137 } ) ,
124138 ) . rejects . toThrow ( 'Invalid model' ) ;
125139 } ) ;
0 commit comments