MCPcopy Index your code
hub / github.com/docker/docker-agent / TestIsContextOverflowError

Function TestIsContextOverflowError

pkg/modelerrors/modelerrors_test.go:136–168  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

134}
135
136func TestIsContextOverflowError(t *testing.T) {
137 t.Parallel()
138
139 tests := []struct {
140 name string
141 err error
142 expected bool
143 }{
144 {name: "nil error", err: nil, expected: false},
145 {name: "generic error", err: errors.New("something went wrong"), expected: false},
146 {name: "anthropic prompt too long", err: errors.New("prompt is too long: 226360 tokens > 200000 maximum"), expected: true},
147 {name: "openai context length exceeded", err: errors.New("maximum context length is 128000 tokens"), expected: true},
148 {name: "context_length_exceeded code", err: errors.New("error code: context_length_exceeded"), expected: true},
149 {name: "thinking budget error", err: errors.New("max_tokens must be greater than thinking.budget_tokens"), expected: true},
150 {name: "request too large", err: errors.New("request too large for model"), expected: true},
151 {name: "input is too long", err: errors.New("input is too long"), expected: true},
152 {name: "reduce your prompt", err: errors.New("please reduce your prompt"), expected: true},
153 {name: "reduce the length", err: errors.New("please reduce the length of the messages"), expected: true},
154 {name: "token limit", err: errors.New("token limit exceeded"), expected: true},
155 {name: "wrapped ContextOverflowError", err: &ContextOverflowError{Underlying: errors.New("test")}, expected: true},
156 {name: "errors.As wrapped", err: fmt.Errorf("all models failed: %w", &ContextOverflowError{Underlying: errors.New("test")}), expected: true},
157 {name: "500 internal server error", err: errors.New("500 Internal Server Error"), expected: false},
158 {name: "429 rate limit", err: errors.New("429 too many requests"), expected: false},
159 {name: "network timeout", err: errors.New("connection timeout"), expected: false},
160 }
161
162 for _, tt := range tests {
163 t.Run(tt.name, func(t *testing.T) {
164 t.Parallel()
165 assert.Equal(t, tt.expected, IsContextOverflowError(tt.err), "IsContextOverflowError(%v)", tt.err)
166 })
167 }
168}
169
170func TestClassifyOverflow(t *testing.T) {
171 t.Parallel()

Callers

nothing calls this directly

Calls 3

IsContextOverflowErrorFunction · 0.85
RunMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected