11import { describe , test , expect } from "vitest"
2- import { getModelMaxOutputTokens , shouldUseReasoningBudget , shouldUseReasoningEffort } from "../api"
2+ import {
3+ getModelMaxOutputTokens ,
4+ shouldUseReasoningBudget ,
5+ shouldUseReasoningEffort ,
6+ GPT5_MAX_OUTPUT_TOKENS ,
7+ } from "../api"
38import type { ModelInfo , ProviderSettings } from "@roo-code/types"
49import { CLAUDE_CODE_DEFAULT_MAX_OUTPUT_TOKENS , ANTHROPIC_DEFAULT_MAX_TOKENS } from "@roo-code/types"
510
@@ -233,7 +238,7 @@ describe("getModelMaxOutputTokens", () => {
233238 format : "openai" ,
234239 } )
235240
236- expect ( result ) . toBe ( 10_000 )
241+ expect ( result ) . toBe ( GPT5_MAX_OUTPUT_TOKENS )
237242 } )
238243
239244 test ( "should limit GPT-5-mini models to 10k max output tokens" , ( ) => {
@@ -250,7 +255,7 @@ describe("getModelMaxOutputTokens", () => {
250255 format : "openai" ,
251256 } )
252257
253- expect ( result ) . toBe ( 10_000 )
258+ expect ( result ) . toBe ( GPT5_MAX_OUTPUT_TOKENS )
254259 } )
255260
256261 test ( "should limit GPT-5-nano models to 10k max output tokens" , ( ) => {
@@ -267,17 +272,17 @@ describe("getModelMaxOutputTokens", () => {
267272 format : "openai" ,
268273 } )
269274
270- expect ( result ) . toBe ( 10_000 )
275+ expect ( result ) . toBe ( GPT5_MAX_OUTPUT_TOKENS )
271276 } )
272277
273- test ( "should respect user override for GPT-5 models but cap at 10k " , ( ) => {
278+ test ( "should respect user override for GPT-5 models but cap at GPT5_MAX_OUTPUT_TOKENS " , ( ) => {
274279 const gpt5Model : ModelInfo = {
275280 contextWindow : 400_000 ,
276281 maxTokens : 128_000 ,
277282 supportsPromptCache : true ,
278283 }
279284
280- // User tries to set 15k, should be capped at 10k
285+ // User tries to set 15k, should be capped at GPT5_MAX_OUTPUT_TOKENS
281286 const settings : ProviderSettings = {
282287 modelMaxTokens : 15_000 ,
283288 }
@@ -289,10 +294,10 @@ describe("getModelMaxOutputTokens", () => {
289294 format : "openai" ,
290295 } )
291296
292- expect ( result ) . toBe ( 10_000 )
297+ expect ( result ) . toBe ( GPT5_MAX_OUTPUT_TOKENS )
293298 } )
294299
295- test ( "should allow user to set lower than 10k for GPT-5 models" , ( ) => {
300+ test ( "should allow user to set lower than GPT5_MAX_OUTPUT_TOKENS for GPT-5 models" , ( ) => {
296301 const gpt5Model : ModelInfo = {
297302 contextWindow : 400_000 ,
298303 maxTokens : 128_000 ,
@@ -331,6 +336,54 @@ describe("getModelMaxOutputTokens", () => {
331336 // Should use model's maxTokens since it's within 20% of context window
332337 expect ( result ) . toBe ( 16_384 )
333338 } )
339+
340+ test ( "should handle GPT-5 models with date suffixes" , ( ) => {
341+ const gpt5Model : ModelInfo = {
342+ contextWindow : 400_000 ,
343+ maxTokens : 128_000 ,
344+ supportsPromptCache : true ,
345+ }
346+
347+ // Test various date-suffixed GPT-5 models
348+ const modelIds = [ "gpt-5-2025-08-07" , "gpt-5-mini-2025-08-07" , "gpt-5-nano-2025-08-07" ]
349+
350+ modelIds . forEach ( ( modelId ) => {
351+ const result = getModelMaxOutputTokens ( {
352+ modelId,
353+ model : gpt5Model ,
354+ settings : { } ,
355+ format : "openai" ,
356+ } )
357+ expect ( result ) . toBe ( GPT5_MAX_OUTPUT_TOKENS )
358+ } )
359+ } )
360+
361+ test ( "should not match invalid GPT-5 model names" , ( ) => {
362+ const model : ModelInfo = {
363+ contextWindow : 128_000 ,
364+ maxTokens : 16_384 ,
365+ supportsPromptCache : true ,
366+ }
367+
368+ // These should NOT be treated as GPT-5 models
369+ const invalidModelIds = [
370+ "gpt-5-turbo" , // Invalid variant
371+ "gpt-50" , // Different number
372+ "gpt-5-" , // Incomplete
373+ "gpt-5-mini-turbo" , // Invalid variant combination
374+ ]
375+
376+ invalidModelIds . forEach ( ( modelId ) => {
377+ const result = getModelMaxOutputTokens ( {
378+ modelId,
379+ model,
380+ settings : { } ,
381+ format : "openai" ,
382+ } )
383+ // Should use model's maxTokens since it's within 20% of context window
384+ expect ( result ) . toBe ( 16_384 )
385+ } )
386+ } )
334387 } )
335388} )
336389
0 commit comments