Files

97 lines
2.3 KiB
Go

package channels
import (
"strings"
"testing"
)
func TestFormatAgentError_ContextOverflow(t *testing.T) {
t.Parallel()
testCases := []string{
"context length exceeded",
"Prompt exceeds max length",
"request_too_large: payload too big",
"Input is too long for this model",
"token limit exceeded",
"请求输入过长",
}
for _, tc := range testCases {
result := FormatAgentError(tc)
if !strings.Contains(result, "conversation has grown too long") {
t.Errorf("expected context overflow message for %q, got %q", tc, result)
}
}
}
func TestFormatAgentError_RateLimit(t *testing.T) {
t.Parallel()
result := FormatAgentError("rate limit exceeded")
if !strings.Contains(result, "Too many requests") {
t.Errorf("unexpected rate limit message: %s", result)
}
}
func TestFormatAgentError_Auth(t *testing.T) {
t.Parallel()
result := FormatAgentError("unauthorized access")
if !strings.Contains(result, "Authentication error") {
t.Errorf("unexpected auth message: %s", result)
}
}
func TestFormatAgentError_Timeout(t *testing.T) {
t.Parallel()
result := FormatAgentError("request timeout")
if !strings.Contains(result, "timed out") {
t.Errorf("unexpected timeout message: %s", result)
}
}
func TestFormatAgentError_Generic(t *testing.T) {
t.Parallel()
result := FormatAgentError("some unknown error")
if !strings.Contains(result, "Something went wrong") {
t.Errorf("unexpected generic message: %s", result)
}
}
func TestFormatAgentError_Empty(t *testing.T) {
t.Parallel()
result := FormatAgentError("")
if result != "" {
t.Errorf("expected empty string for empty error, got %q", result)
}
}
func TestIsTransientFailureMessage(t *testing.T) {
t.Parallel()
transient := []string{
"llm call: HTTP 429: rate limited",
"request timeout",
"deadline exceeded",
"service overloaded",
"connection reset by peer",
"llm call: HTTP 503: service unavailable",
"too many requests",
}
for _, tc := range transient {
if !isTransientFailureMessage(tc) {
t.Errorf("expected %q to be transient", tc)
}
}
permanent := []string{
"unauthorized access",
"invalid api key",
"context length exceeded",
"request context budget exceeded",
"",
}
for _, tc := range permanent {
if isTransientFailureMessage(tc) {
t.Errorf("expected %q to be permanent", tc)
}
}
}