mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-10-06 15:50:49 +08:00
test(executor): allow non-negative TTFT in xAI usage record assertions
- Accept zero TTFT duration to accommodate sub-tick loopback responses - Add unit test verifying zero TTFT validation in usage records Closes: #5996
This commit is contained in:
@@ -3471,9 +3471,7 @@ func TestXAIExecutorExecuteImagesUsesImagesEndpointAndPublishesUsage(t *testing.
|
||||
if record.Detail != (usage.Detail{}) {
|
||||
t.Fatalf("detail = %+v, want zero token usage", record.Detail)
|
||||
}
|
||||
if record.TTFT <= 0 {
|
||||
t.Fatalf("ttft = %v, want positive duration", record.TTFT)
|
||||
}
|
||||
assertXAIUsageRecordTTFT(t, record.TTFT)
|
||||
assertNoAdditionalXAIUsageRecord(t, plugin.records)
|
||||
}
|
||||
|
||||
@@ -3599,6 +3597,23 @@ func assertNoAdditionalXAIUsageRecord(t *testing.T, records <-chan usage.Record)
|
||||
}
|
||||
}
|
||||
|
||||
func assertXAIUsageRecordTTFT(t *testing.T, ttft time.Duration) {
|
||||
t.Helper()
|
||||
if ttft < 0 {
|
||||
t.Fatalf("ttft = %v, want non-negative duration", ttft)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXAIUsageRecord_ZeroTTFTValidation(t *testing.T) {
|
||||
// A sub-tick loopback response can yield TTFT == 0s.
|
||||
// The test assertion must accept non-negative TTFT (>= 0).
|
||||
record := usage.Record{
|
||||
Model: "grok-imagine-image-quality",
|
||||
TTFT: 0,
|
||||
}
|
||||
assertXAIUsageRecordTTFT(t, record.TTFT)
|
||||
}
|
||||
|
||||
func TestXAIExecutorExecuteImagesUsesEditsEndpoint(t *testing.T) {
|
||||
var gotPath string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -3839,9 +3854,7 @@ func TestXAIExecutorExecuteVideosCreate(t *testing.T) {
|
||||
if record.Detail != (usage.Detail{}) {
|
||||
t.Fatalf("detail = %+v, want zero token usage", record.Detail)
|
||||
}
|
||||
if record.TTFT <= 0 {
|
||||
t.Fatalf("ttft = %v, want positive duration", record.TTFT)
|
||||
}
|
||||
assertXAIUsageRecordTTFT(t, record.TTFT)
|
||||
assertNoAdditionalXAIUsageRecord(t, plugin.records)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user