Roo-Code/src/api/providers/__tests__
Hannes Rudolph d1baa6e849
fix: add cache reporting support for OpenAI-Native provider (#7602)
* fix: add cache reporting support for OpenAI-Native provider

- Add normalizeUsage method to properly extract cache tokens from Responses API
- Support both detailed token shapes (input_tokens_details) and legacy fields
- Calculate cache read/write tokens with proper fallbacks
- Include reasoning tokens when available in output_tokens_details
- Ensure accurate cost calculation using uncached input tokens

This fixes the issue where caching information was not being reported
when using the OpenAI-Native provider with the Responses API.

* fix: improve cache token normalization and add comprehensive tests

- Add fallback to derive total input tokens from details when totals are missing
- Remove unused convertToOpenAiMessages import
- Add comment explaining cost calculation alignment with Gemini provider
- Add comprehensive test coverage for normalizeUsage method covering:
  - Detailed token shapes with cached/miss tokens
  - Legacy field names and SSE-only events
  - Edge cases including missing totals with details-only
  - Cost calculation with uncached input tokens

* fix: address PR review comments

- Remove incorrect fallback to missFromDetails for cache write tokens
- Fix cost calculation to pass total input tokens (calculateApiCostOpenAI handles subtraction)
- Improve readability by extracting cache detail checks to intermediate variables
- Remove redundant ?? undefined
- Update tests to reflect correct behavior (miss tokens are not cache writes)
- Add clarifying comments about cache miss vs cache write tokens
2025-09-02 19:59:16 -04:00
..
anthropic-vertex.spec.ts Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
anthropic.spec.ts Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
bedrock-custom-arn.spec.ts Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
bedrock-error-handling.spec.ts Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
bedrock-inference-profiles.spec.ts Add support for bedrock api keys (#6132) 2025-07-25 01:04:49 -04:00
bedrock-invokedModelId.spec.ts Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
bedrock-reasoning.spec.ts Add support for bedrock api keys (#6132) 2025-07-25 01:04:49 -04:00
bedrock-vpc-endpoint.spec.ts Add support for bedrock api keys (#6132) 2025-07-25 01:04:49 -04:00
bedrock.spec.ts Fix: AWS Bedrock 1M context - Move anthropic_beta to additionalModelRequestFields (#7056) 2025-08-13 15:26:50 -04:00
cerebras.spec.ts Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
chutes.spec.ts feat: add DeepSeek V3.1 model to Chutes AI provider (#7295) 2025-08-22 12:18:55 -07:00
claude-code-caching.spec.ts Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
claude-code.spec.ts Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
constants.spec.ts Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
deepseek.spec.ts fix: update DeepSeek models context window to 128k (#7269) 2025-08-21 15:03:35 -07:00
featherless.spec.ts feat: Featherless provider (#7235) 2025-08-20 10:42:57 -07:00
fireworks.spec.ts feat: add Deepseek v3.1 to Fireworks AI provider (#7375) 2025-08-24 18:43:06 -04:00
gemini-handler.spec.ts Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
gemini.spec.ts Feat: Adding Gemini tools - URL Context and Grounding with Google Search (#5959) 2025-07-27 14:34:55 -04:00
glama.spec.ts Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
groq.spec.ts feat: add prompt caching support for Kimi K2 on Groq (#7324) 2025-08-22 09:40:21 -07:00
io-intelligence.spec.ts Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
lite-llm.spec.ts Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
lm-studio-timeout.spec.ts feat: add configurable API request timeout for local providers (#6531) 2025-08-12 11:48:45 -04:00
lmstudio.spec.ts Revert fix: resolve LM Studio context length detection (#5075) (#5083) 2025-06-24 15:56:22 -04:00
mistral.spec.ts fix: handle Mistral thinking content as reasoning chunks (#7106) 2025-08-23 06:33:43 -07:00
moonshot.spec.ts feat: add moonshot provider (#6046) 2025-07-22 00:37:24 -04:00
native-ollama.spec.ts fix: use native Ollama API instead of OpenAI compatibility layer (#7137) 2025-08-15 23:31:58 -04:00
ollama-timeout.spec.ts feat: add configurable API request timeout for local providers (#6531) 2025-08-12 11:48:45 -04:00
ollama.spec.ts feat: add Ollama API key support for Turbo mode (#7425) 2025-08-30 19:20:31 -04:00
openai-native-usage.spec.ts fix: add cache reporting support for OpenAI-Native provider (#7602) 2025-09-02 19:59:16 -04:00
openai-native.spec.ts Fix GPT-5 Responses API issues with condensing and image support (#7067) 2025-08-27 23:30:43 -04:00
openai-timeout.spec.ts feat: add configurable API request timeout for local providers (#6531) 2025-08-12 11:48:45 -04:00
openai-usage-tracking.spec.ts Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
openai.spec.ts fix: omit temperature parameter when not explicitly set for OpenAI Compatible providers (#7188) 2025-08-21 02:14:03 -07:00
openrouter.spec.ts Clamp default model max tokens to 20% of context window (#6761) 2025-08-06 13:51:10 -07:00
requesty.spec.ts feat: add custom base URL support for Requesty provider (#7337) 2025-08-22 13:43:08 -07:00
roo.spec.ts Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
sambanova.spec.ts Pass task ID in the Roo provider request headers (#7303) 2025-08-21 20:27:21 -07:00
unbound.spec.ts Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
vercel-ai-gateway.spec.ts feat: Add Vercel AI Gateway provider integration (#7396) 2025-08-26 13:41:02 -07:00
vertex.spec.ts Feat: Adding Gemini tools - URL Context and Grounding with Google Search (#5959) 2025-07-27 14:34:55 -04:00
vscode-lm.spec.ts Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
xai.spec.ts Farewell jest (#4607) 2025-06-16 21:39:45 -07:00
zai.spec.ts Pass task ID in the Roo provider request headers (#7303) 2025-08-21 20:27:21 -07:00