@@ -219,6 +219,7 @@ suite("Z.ai GLM provider", function () {
219219 } )
220220
221221 await waitUntilCompleted ( { api, taskId } )
222+ const capturedMaxTokens = requestCapture . maxTokens
222223
223224 const completionMessage = messages . find (
224225 ( { say, text } ) => ( say === "completion_result" || say === "text" ) && text ?. trim ( ) === "4" ,
@@ -228,10 +229,12 @@ suite("Z.ai GLM provider", function () {
228229
229230 // Verify max_tokens uses the restored default clamp (20% of context window)
230231 // unless the user explicitly overrides it via modelMaxTokens.
232+ // Snapshot immediately after waitUntilCompleted to avoid straggling async calls
233+ // from this task overwriting requestCapture before the assertion runs.
231234 assert . strictEqual (
232- requestCapture . maxTokens ,
235+ capturedMaxTokens ,
233236 40_000 ,
234- `max_tokens should default to the glm-5.1 clamp (40_000) but was ${ requestCapture . maxTokens } ` ,
237+ `max_tokens should default to the glm-5.1 clamp (40_000) but was ${ capturedMaxTokens } ` ,
235238 )
236239 } )
237240
@@ -260,6 +263,7 @@ suite("Z.ai GLM provider", function () {
260263 } )
261264
262265 await waitUntilCompleted ( { api, taskId } )
266+ const capturedMaxTokens = requestCapture . maxTokens
263267
264268 const completionMessage = messages . find (
265269 ( { say, text } ) => ( say === "completion_result" || say === "text" ) && text ?. trim ( ) === "4" ,
@@ -269,10 +273,12 @@ suite("Z.ai GLM provider", function () {
269273
270274 // Verify max_tokens uses the restored default clamp (20% of context window)
271275 // unless the user explicitly overrides it via modelMaxTokens.
276+ // Snapshot immediately after waitUntilCompleted to avoid straggling async calls
277+ // from the prior test overwriting requestCapture before this assertion runs.
272278 assert . strictEqual (
273- requestCapture . maxTokens ,
279+ capturedMaxTokens ,
274280 40_551 ,
275- `max_tokens should default to the glm-5-turbo clamp (40_551) but was ${ requestCapture . maxTokens } ` ,
281+ `max_tokens should default to the glm-5-turbo clamp (40_551) but was ${ capturedMaxTokens } ` ,
276282 )
277283 } )
278284} )
0 commit comments