codeburn/tests/providers/session-message.test.ts
Resham Joshi 6dc81f5ce6
Some checks are pending
CI / semgrep (push) Waiting to run
Tests / test-platforms (windows-latest) (push) Waiting to run
Tests / desktop (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (22.13.0) (push) Waiting to run
Tests / test (24) (push) Waiting to run
Tests / test (26) (push) Waiting to run
Tests / test-platforms (macos-latest) (push) Waiting to run
fix: four cost accuracy bugs in export and pricing (#1544)
* fix: four cost accuracy bugs in export and pricing

- export daily rows bucket each call on its own day (same rule as the day
  aggregator) and no longer skip a turn without a timestamp
- cache-write tokens on a non-Anthropic model with no published write rate
  bill at the input rate instead of a fabricated 1.25x (calculateCost and
  audit); daily cache v35 and pricing schema 4 so stored figures re-derive
- OpenCode/Kilo messages with output but no usage, and Copilot transcript
  calls with no token count, are marked estimated
- export records keep unrounded cost and gain estimated/unpriced columns

* fix: plain-decimal CSV costs, re-parse cached copilot transcripts for the estimated flag

* ci(upgrade-path): compare copilot records at cent precision across the export rounding change
2026-09-24 15:55:23 +02:00

30 lines
1,009 B
TypeScript

import { describe, it, expect } from 'vitest'
import { buildAssistantCall } from '../../src/providers/session-message.js'
const base = {
providerName: 'opencode',
dedupKey: 'opencode:s1:m1',
sessionId: 's1',
parts: [{ type: 'text', text: 'answer' }],
timeCreatedMs: 1_776_000_000_000,
userMessage: 'q',
}
describe('buildAssistantCall usage', () => {
it('marks a call with output but no recorded usage as estimated, never a measured $0', () => {
const call = buildAssistantCall({ ...base, data: { role: 'assistant', modelID: 'claude-sonnet-4-6' } })
expect(call).not.toBeNull()
expect(call!.costUSD).toBe(0)
expect(call!.costIsEstimated).toBe(true)
})
it('leaves a call with recorded usage unflagged', () => {
const call = buildAssistantCall({
...base,
data: { role: 'assistant', modelID: 'claude-sonnet-4-6', tokens: { input: 10, output: 5 } },
})
expect(call!.costUSD).toBeGreaterThan(0)
expect(call!.costIsEstimated).toBeUndefined()
})
})