diff --git a/backend/internal/service/openai_gateway_count_tokens_test.go b/backend/internal/service/openai_gateway_count_tokens_test.go index 6aa8825c9e..37bfa91e00 100644 --- a/backend/internal/service/openai_gateway_count_tokens_test.go +++ b/backend/internal/service/openai_gateway_count_tokens_test.go @@ -4,8 +4,10 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io" + "net" "net/http" "net/http/httptest" "os" @@ -350,9 +352,13 @@ func TestEstimateOpenAIInputTokens_CompareWithOpenAIAPI(t *testing.T) { actual, err := callOpenAIInputTokensAPIForTest(client, apiKey, prepared.Request) if err != nil { - // Live-API comparison only; invalid/expired local keys should skip, not fail CI. - if strings.Contains(err.Error(), "status=401") || strings.Contains(err.Error(), "invalid_api_key") { - t.Skipf("OPENAI_API_KEY rejected by OpenAI: %v", err) + // This is an optional live-API comparison. Credential and transient + // network failures must not make the deterministic unit suite fail. + var netErr net.Error + if strings.Contains(err.Error(), "status=401") || + strings.Contains(err.Error(), "invalid_api_key") || + errors.As(err, &netErr) { + t.Skipf("OpenAI live comparison unavailable: %v", err) } require.NoError(t, err) }