From fd5cd228a80462c74f005603da66b494d4e1c45a Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Mon, 21 Sep 2026 10:15:52 +0800 Subject: [PATCH] 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 --- .../runtime/executor/xai_executor_test.go | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/runtime/executor/xai_executor_test.go b/internal/runtime/executor/xai_executor_test.go index 1d348e3f35..0378029765 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) }