fix(usage): 移动端缓存 token 拆分为读/写两列展示

cache_read 与 cache_creation 原本被合并为单值,现分别显示并补充测试
This commit is contained in:
fawney19
2026-04-25 09:53:32 +08:00
parent e5bbc797e0
commit 1761921670
3 changed files with 28 additions and 6 deletions
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { getCacheCreationTokens, getEffectiveInputTokens } from '../token-normalization'
import { getCacheCreationTokens, getCacheReadTokens, getEffectiveInputTokens } from '../token-normalization'
describe('usage token normalization', () => {
it('prefers explicit cache creation totals when present', () => {
@@ -19,6 +19,20 @@ describe('usage token normalization', () => {
})).toBe(20)
})
it('keeps cache read and cache creation as separate display values', () => {
const usage = {
input_tokens: 1,
cache_creation_input_tokens: 1530,
cache_read_input_tokens: 104026,
output_tokens: 591,
api_format: 'claude:chat',
}
expect(getEffectiveInputTokens(usage)).toBe(1)
expect(getCacheReadTokens(usage)).toBe(104026)
expect(getCacheCreationTokens(usage)).toBe(1530)
})
it('keeps effective input token normalization unchanged', () => {
expect(getEffectiveInputTokens({
input_tokens: 100,