43 lines
1.8 KiB
Go
43 lines
1.8 KiB
Go
package ledger
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"textmachine/backend/internal/llm"
|
|
)
|
|
|
|
// TestTheThinkingShareOfACompletionPricesNothing keeps the diagnostic off the money path.
|
|
//
|
|
// llm.Usage carries two thinking counts and only one is money: ReasoningTokens is added to the
|
|
// completion here, ReasoningInCompletion is a SUBSET of a completion already priced. On the measured
|
|
// DeepSeek shape thinking is ~60% of a call, so pricing the subset field would inflate every bill on
|
|
// the only provider the shipping configs call.
|
|
//
|
|
// The assertion is built so the money is UNAVOIDABLE rather than likely: the completion is large, the
|
|
// output price is non-zero, and the baseline cost is required to be positive — a formula change that
|
|
// zeroed the output term would otherwise make this pass by comparing nothing with nothing.
|
|
func TestTheThinkingShareOfACompletionPricesNothing(t *testing.T) {
|
|
price := ModelPrice{InputPerM: 1.32, CachedPerM: 0.044, OutputPerM: 3.96}
|
|
base := llm.Usage{PromptTokens: 6908, CachedTokens: 1152, CompletionTokens: 16000}
|
|
|
|
want := CostUSD(price, base)
|
|
if want <= 0 {
|
|
t.Fatalf("the fixture must actually cost money, else this test compares two zeros: %v", want)
|
|
}
|
|
|
|
for _, share := range []int{0, 1, 8000, 16000} {
|
|
n := share
|
|
withThinking := base
|
|
withThinking.ReasoningInCompletion = &n
|
|
if got := CostUSD(price, withThinking); got != want {
|
|
t.Fatalf("a thinking share of %d moved the bill %v -> %v; the subset field is a diagnostic and must price nothing", share, want, got)
|
|
}
|
|
}
|
|
|
|
// The other field still IS money, so a pin that passed for both would be measuring nothing.
|
|
onTop := base
|
|
onTop.ReasoningTokens = 16000
|
|
if got := CostUSD(price, onTop); got <= want {
|
|
t.Fatalf("reasoning billed ON TOP must raise the bill above %v, got %v — the control that proves this test can see a price move at all", want, got)
|
|
}
|
|
}
|