fix
This commit is contained in:
@@ -49,6 +49,65 @@ func TestTruncateError_redactsSecrets(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTruncateError_mapsInternalProviderLeaks(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
in: `openai length-capped at max_tokens=16000 for model "gpt-5.4" (prefer a faster non-reasoning product-enhance model): unexpected EOF`,
|
||||
want: "processing_failed",
|
||||
},
|
||||
{
|
||||
in: "ai_enhance: skipped (platform OpenAI unset; configure admin settings or company BYOK)",
|
||||
want: "provider_unavailable",
|
||||
},
|
||||
{
|
||||
in: "openai retries exhausted: green-chat unavailable",
|
||||
want: "provider_unavailable",
|
||||
},
|
||||
{
|
||||
in: "upstream 503: model overloaded",
|
||||
want: "provider_unavailable",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got := TruncateError(errString(tc.in))
|
||||
if got != tc.want {
|
||||
t.Fatalf("TruncateError(%q)=%q want %q", tc.in, got, tc.want)
|
||||
}
|
||||
if strings.Contains(strings.ToLower(got), "openai") ||
|
||||
strings.Contains(strings.ToLower(got), "max_tokens") ||
|
||||
strings.Contains(got, "gpt-") {
|
||||
t.Fatalf("internal leak in TruncateError: %q → %q", tc.in, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicV1Error_stripsProviderInternals(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{in: `openai length-capped at max_tokens=8000 for model "gpt-4o"`, want: "processing_failed"},
|
||||
{in: "ai_enhance: skipped (platform OpenAI unset; configure admin settings or company BYOK)", want: "provider_unavailable"},
|
||||
{in: "processing_failed", want: "processing_failed"},
|
||||
{in: "Product data not available", want: "Product data not available"},
|
||||
{in: "processing.job.error.all_failed|count=3", want: "processing.job.error.all_failed|count=3"},
|
||||
{in: "insufficient credits", want: "insufficient credits"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got := PublicV1Error(tc.in)
|
||||
if got != tc.want {
|
||||
t.Fatalf("PublicV1Error(%q)=%q want %q", tc.in, got, tc.want)
|
||||
}
|
||||
lower := strings.ToLower(got)
|
||||
if strings.Contains(lower, "openai") || strings.Contains(lower, "max_tokens") {
|
||||
t.Fatalf("public v1 leak: %q → %q", tc.in, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTruncateError_classifiesProviderFailures(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
@@ -68,10 +127,8 @@ in: "unauthorized", want: "AI provider rejected the API key"},
|
||||
in: "openai http 401", want: "AI provider rejected the API key"},
|
||||
{in: "rate limited or server error", want: "AI provider temporarily unavailable"},
|
||||
{in: "too many requests", want: "AI provider rate limited"},
|
||||
{
|
||||
in: "upstream 503: model overloaded", want: "upstream 503: model overloaded"},
|
||||
{
|
||||
in: "openai retries exhausted: green-chat unavailable", want: "green-chat unavailable"},
|
||||
{in: "upstream 503: model overloaded", want: "provider_unavailable"},
|
||||
{in: "openai retries exhausted: green-chat unavailable", want: "provider_unavailable"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got := TruncateError(errString(tc.in))
|
||||
|
||||
Reference in New Issue
Block a user