Files
new-api-custom/controller/relay_client_error_test.go
T
cneicy a5f7b8e586
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 1m40s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 42m16s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
feat: sync deployed v1.0.0-rc.38-custom.42
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
2026-09-26 04:49:11 +08:00

64 lines
2.4 KiB
Go

package controller
import (
"errors"
"fmt"
"net/http"
"strings"
"testing"
"github.com/QuantumNous/new-api/relaykit/types"
)
func TestClientFacingOpenAIErrorHidesUpstreamDetails(t *testing.T) {
err := types.NewOpenAIError(errors.New("provider.example.invalid provider secret failure"), types.ErrorCodeBadResponseStatusCode, http.StatusBadGateway)
got := clientFacingOpenAIError(err, true, "local-request-id")
if strings.Contains(got.Message, "example-provider") || strings.Contains(got.Message, "provider secret") {
t.Fatalf("upstream details leaked: %q", got.Message)
}
if !strings.Contains(got.Message, "local-request-id") {
t.Fatalf("local request id missing: %q", got.Message)
}
if got.Code != "model_service_error" {
t.Fatalf("unexpected public code: %v", got.Code)
}
}
func TestClientFacingClaudeErrorHidesUpstreamDetails(t *testing.T) {
err := types.NewOpenAIError(errors.New("provider.example.invalid provider secret failure"), types.ErrorCodeBadResponseStatusCode, http.StatusBadGateway)
got := clientFacingClaudeError(err, true, "local-request-id")
if strings.Contains(got.Message, "example-provider") || strings.Contains(got.Message, "provider secret") {
t.Fatalf("upstream details leaked: %q", got.Message)
}
if !strings.Contains(got.Message, "local-request-id") {
t.Fatalf("local request id missing: %q", got.Message)
}
}
func TestClientFacingErrorKeepsLocalValidationMessage(t *testing.T) {
err := types.NewErrorWithStatusCode(errors.New("model is required"), types.ErrorCodeInvalidRequest, http.StatusBadRequest)
got := clientFacingOpenAIError(err, false, "local-request-id")
if !strings.Contains(got.Message, "model is required") {
t.Fatalf("local validation message was hidden: %q", got.Message)
}
}
func TestClientFacingResponseGuardErrorNamesDeclaredModel(t *testing.T) {
err := types.NewErrorWithStatusCode(
errors.New("Requested model gpt-6-astra, but the upstream response declared gpt-5.6-luna."),
"response_model_rejected",
http.StatusConflict,
)
got := clientFacingOpenAIError(err, true, "local-request-id")
if fmt.Sprint(got.Code) != "response_model_rejected" {
t.Fatalf("unexpected public code: %v", got.Code)
}
for _, expected := range []string{"gpt-6-astra", "gpt-5.6-luna", "local-request-id"} {
if !strings.Contains(got.Message, expected) {
t.Fatalf("public mismatch message %q does not contain %q", got.Message, expected)
}
}
}