@@ -19,6 +19,16 @@ import { setDefaultSuiteTimeout } from "../test-utils"
1919type ZAiFixture = { match : string ; result : string }
2020type ZAiRequestCapture = { maxTokens ?: number }
2121
22+ function getBaseZAiConfiguration ( ) {
23+ return {
24+ apiProvider : "zai" as const ,
25+ zaiApiKey : ZAI_API_KEY ?? "mock-key" ,
26+ zaiApiLine : "international_api" as const ,
27+ modelMaxTokens : undefined ,
28+ modelMaxThinkingTokens : undefined ,
29+ }
30+ }
31+
2232function installZAiFetchInterceptor (
2333 fixtures : ZAiFixture [ ] ,
2434 capture ?: ZAiRequestCapture ,
@@ -151,6 +161,10 @@ suite("Z.ai GLM provider", function () {
151161 let restoreFetch : ( ( ) => void ) | undefined
152162 const requestCapture : ZAiRequestCapture = { }
153163
164+ setup ( ( ) => {
165+ requestCapture . maxTokens = undefined
166+ } )
167+
154168 suiteSetup ( async ( ) => {
155169 restoreFetch = installZAiFetchInterceptor (
156170 [
@@ -161,12 +175,14 @@ suite("Z.ai GLM provider", function () {
161175 ! ! ZAI_API_KEY ,
162176 )
163177
164- await globalThis . api . setConfiguration ( {
165- apiProvider : "zai" as const ,
166- zaiApiKey : ZAI_API_KEY ?? "mock-key" ,
167- zaiApiLine : "international_api" as const ,
168- apiModelId : "glm-5.1" ,
169- } )
178+ await globalThis . api . upsertProfile (
179+ "default" ,
180+ {
181+ ...getBaseZAiConfiguration ( ) ,
182+ apiModelId : "glm-5.1" ,
183+ } ,
184+ true ,
185+ )
170186 } )
171187
172188 suiteTeardown ( async ( ) => {
@@ -175,12 +191,16 @@ suite("Z.ai GLM provider", function () {
175191
176192 const aimockUrl = process . env . AIMOCK_URL
177193 const isRecord = process . env . AIMOCK_RECORD === "true"
178- await globalThis . api . setConfiguration ( {
179- apiProvider : "openrouter" as const ,
180- openRouterApiKey : aimockUrl && ! isRecord ? "mock-key" : process . env . OPENROUTER_API_KEY ! ,
181- openRouterModelId : "openai/gpt-4.1" ,
182- ...( aimockUrl && { openRouterBaseUrl : `${ aimockUrl } /v1` } ) ,
183- } )
194+ await globalThis . api . upsertProfile (
195+ "default" ,
196+ {
197+ apiProvider : "openrouter" as const ,
198+ openRouterApiKey : aimockUrl && ! isRecord ? "mock-key" : process . env . OPENROUTER_API_KEY ! ,
199+ openRouterModelId : "openai/gpt-4.1" ,
200+ ...( aimockUrl && { openRouterBaseUrl : `${ aimockUrl } /v1` } ) ,
201+ } ,
202+ true ,
203+ )
184204 } )
185205
186206 test ( "Should complete a task end-to-end using glm-5.1 via Z.ai provider" , async ( ) => {
@@ -216,12 +236,14 @@ suite("Z.ai GLM provider", function () {
216236 } )
217237
218238 test ( "Should complete a task end-to-end using glm-5-turbo via Z.ai provider" , async ( ) => {
219- await globalThis . api . setConfiguration ( {
220- apiProvider : "zai" as const ,
221- zaiApiKey : ZAI_API_KEY ?? "mock-key" ,
222- zaiApiLine : "international_api" as const ,
223- apiModelId : "glm-5-turbo" ,
224- } )
239+ await globalThis . api . upsertProfile (
240+ "default" ,
241+ {
242+ ...getBaseZAiConfiguration ( ) ,
243+ apiModelId : "glm-5-turbo" ,
244+ } ,
245+ true ,
246+ )
225247
226248 const api = globalThis . api
227249 const messages : ClineMessage [ ] = [ ]
0 commit comments