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:
Luis Pater
2026-09-21 10:15:52 +08:00
parent a5ab69521f
commit fd5cd228a8

View File

@@ -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)
}