mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-09 07:42:42 +08:00
fix(usage_helpers): skip zero-token usage in additional model records
- Added `buildAdditionalModelRecord` to filter out zero-token usage details. - Introduced `hasNonZeroTokenUsage` helper function for token usage validation. - Updated tests to cover scenarios for zero and non-zero token usage.
This commit is contained in:
@@ -62,3 +62,21 @@ func TestUsageReporterBuildRecordIncludesLatency(t *testing.T) {
|
||||
t.Fatalf("latency = %v, want <= 3s", record.Latency)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUsageReporterBuildAdditionalModelRecordSkipsZeroTokens(t *testing.T) {
|
||||
reporter := &UsageReporter{
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
requestedAt: time.Now(),
|
||||
}
|
||||
|
||||
if _, ok := reporter.buildAdditionalModelRecord("gpt-image-2", usage.Detail{}); ok {
|
||||
t.Fatalf("expected all-zero token usage to be skipped")
|
||||
}
|
||||
if _, ok := reporter.buildAdditionalModelRecord("gpt-image-2", usage.Detail{InputTokens: 2}); !ok {
|
||||
t.Fatalf("expected non-zero input token usage to be recorded")
|
||||
}
|
||||
if _, ok := reporter.buildAdditionalModelRecord("gpt-image-2", usage.Detail{CachedTokens: 2}); !ok {
|
||||
t.Fatalf("expected non-zero cached token usage to be recorded")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user