@@ -1608,5 +1608,76 @@ describe("importExport", () => {
16081608 "https://custom-api.example.com/v1" ,
16091609 )
16101610 } )
1611+
1612+ it ( "should exclude undefined modelMaxTokens and modelMaxThinkingTokens from export" , async ( ) => {
1613+ // This test verifies that undefined max token fields are not included in the export
1614+ // to prevent them from appearing for models that don't support reasoning budgets
1615+
1616+ ; ( vscode . window . showSaveDialog as Mock ) . mockResolvedValue ( {
1617+ fsPath : "/mock/path/roo-code-settings.json" ,
1618+ } )
1619+
1620+ const mockProviderProfiles = {
1621+ currentApiConfigName : "test-provider" ,
1622+ apiConfigs : {
1623+ "test-provider" : {
1624+ apiProvider : "openai" as ProviderName ,
1625+ id : "test-id" ,
1626+ // modelMaxTokens and modelMaxThinkingTokens are undefined
1627+ apiKey : "test-key" ,
1628+ openAiBaseUrl : "https://api.openai.com/v1" ,
1629+ } ,
1630+ "anthropic-provider" : {
1631+ apiProvider : "anthropic" as ProviderName ,
1632+ id : "anthropic-id" ,
1633+ apiKey : "anthropic-key" ,
1634+ modelMaxTokens : 4096 , // This one has a value set
1635+ // modelMaxThinkingTokens is undefined
1636+ } ,
1637+ "reasoning-provider" : {
1638+ apiProvider : "openrouter" as ProviderName ,
1639+ id : "reasoning-id" ,
1640+ openRouterApiKey : "reasoning-key" ,
1641+ modelMaxTokens : 8192 ,
1642+ modelMaxThinkingTokens : 4096 , // Both values set for reasoning model
1643+ } ,
1644+ } ,
1645+ modeApiConfigs : { } ,
1646+ }
1647+
1648+ const mockGlobalSettings = {
1649+ mode : "code" ,
1650+ autoApprovalEnabled : true ,
1651+ }
1652+
1653+ mockProviderSettingsManager . export . mockResolvedValue ( mockProviderProfiles )
1654+ mockContextProxy . export . mockResolvedValue ( mockGlobalSettings )
1655+ ; ( fs . mkdir as Mock ) . mockResolvedValue ( undefined )
1656+
1657+ await exportSettings ( {
1658+ providerSettingsManager : mockProviderSettingsManager ,
1659+ contextProxy : mockContextProxy ,
1660+ } )
1661+
1662+ // Get the exported data
1663+ const exportedData = ( safeWriteJson as Mock ) . mock . calls [ 0 ] [ 1 ]
1664+
1665+ // Verify that undefined fields are not included in the export
1666+ const testProvider = exportedData . providerProfiles . apiConfigs [ "test-provider" ]
1667+ expect ( testProvider . apiKey ) . toBe ( "test-key" )
1668+ expect ( testProvider . openAiBaseUrl ) . toBe ( "https://api.openai.com/v1" )
1669+ expect ( "modelMaxTokens" in testProvider ) . toBe ( false ) // Should not be present
1670+ expect ( "modelMaxThinkingTokens" in testProvider ) . toBe ( false ) // Should not be present
1671+
1672+ // Verify that defined modelMaxTokens is included but undefined modelMaxThinkingTokens is not
1673+ const anthropicProvider = exportedData . providerProfiles . apiConfigs [ "anthropic-provider" ]
1674+ expect ( anthropicProvider . modelMaxTokens ) . toBe ( 4096 ) // Should be present with value
1675+ expect ( "modelMaxThinkingTokens" in anthropicProvider ) . toBe ( false ) // Should not be present
1676+
1677+ // Verify that both fields are included when they have values
1678+ const reasoningProvider = exportedData . providerProfiles . apiConfigs [ "reasoning-provider" ]
1679+ expect ( reasoningProvider . modelMaxTokens ) . toBe ( 8192 ) // Should be present with value
1680+ expect ( reasoningProvider . modelMaxThinkingTokens ) . toBe ( 4096 ) // Should be present with value
1681+ } )
16111682 } )
16121683} )
0 commit comments