chore: import Local-Cursor v1.1.8 source snapshot
Includes the current working directory changes. Historical commits and release binaries are excluded to limit Gitea storage. Source base: d7515973fbfd6dd2001fa156c483455b8081c7cb
This commit is contained in:
70
internal/backend/agent/model/provider_limits_test.go
Normal file
70
internal/backend/agent/model/provider_limits_test.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package modeladapter
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAnthropicOutputLimitFromError(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
err error
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "one-api 风格超限错误提取上限",
|
||||
err: errors.New(`anthropic adapter status=400 body={"error":{"type":"<nil>","message":"Requested token count exceeds the configured maximum output length of 131072 tokens. (request id: 202611021331431481912008268d9d6mRcDNnYN)"},"type":"error"}`),
|
||||
want: 131072,
|
||||
},
|
||||
{
|
||||
name: "其他 400 文本不匹配",
|
||||
err: errors.New("anthropic adapter status=400 body={\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"max temperature allowed is 1.0\"}}"),
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
name: "nil 错误",
|
||||
err: nil,
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
name: "无数字的变体不匹配",
|
||||
err: errors.New("exceeds the configured maximum output length of abc tokens"),
|
||||
want: 0,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := anthropicOutputLimitFromError(tc.err); got != tc.want {
|
||||
t.Fatalf("anthropicOutputLimitFromError() = %d, 期望 %d", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnthropicBodyMaxTokens(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
body map[string]any
|
||||
want int
|
||||
}{
|
||||
{"常规构造为 int", map[string]any{"max_tokens": 278000}, 278000},
|
||||
{"RequestBodyOverride 反序列化为 float64", map[string]any{"max_tokens": float64(278000)}, 278000},
|
||||
{"int64 兼容", map[string]any{"max_tokens": int64(278000)}, 278000},
|
||||
{"字段缺失", map[string]any{}, 0},
|
||||
{"非数值类型", map[string]any{"max_tokens": "278000"}, 0},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := anthropicBodyMaxTokens(tc.body); got != tc.want {
|
||||
t.Fatalf("anthropicBodyMaxTokens() = %d, 期望 %d", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
if got := anthropicBodyMaxTokens(nil); got != 0 {
|
||||
t.Fatalf("nil body 应返回 0, got %d", got)
|
||||
}
|
||||
if got := fmt.Sprint(anthropicOutputLimitPattern.String()); got == "" {
|
||||
t.Fatal("onAnthropic pattern 不应为空")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user