diff --git a/internal/runtime/executor/xai_executor_test.go b/internal/runtime/executor/xai_executor_test.go index 1d348e3f3..037802976 100644 --- a/internal/runtime/executor/xai_executor_test.go +++ b/internal/runtime/executor/xai_executor_test.go @@ -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) }