(t *testing.T)
| 399 | } |
| 400 | |
| 401 | func TestContextOverflowError(t *testing.T) { |
| 402 | t.Parallel() |
| 403 | |
| 404 | t.Run("wraps underlying error", func(t *testing.T) { |
| 405 | t.Parallel() |
| 406 | underlying := errors.New("prompt is too long: 226360 tokens > 200000 maximum") |
| 407 | ctxErr := NewContextOverflowError(underlying) |
| 408 | |
| 409 | assert.Contains(t, ctxErr.Error(), "context window overflow") |
| 410 | assert.Contains(t, ctxErr.Error(), "prompt is too long") |
| 411 | assert.ErrorIs(t, ctxErr, underlying) |
| 412 | }) |
| 413 | |
| 414 | t.Run("nil underlying returns fallback message", func(t *testing.T) { |
| 415 | t.Parallel() |
| 416 | ctxErr := NewContextOverflowError(nil) |
| 417 | assert.Equal(t, "context window overflow", ctxErr.Error()) |
| 418 | assert.NoError(t, ctxErr.Unwrap()) |
| 419 | }) |
| 420 | |
| 421 | t.Run("errors.As works through wrapping", func(t *testing.T) { |
| 422 | t.Parallel() |
| 423 | underlying := errors.New("test error") |
| 424 | wrapped := fmt.Errorf("all models failed: %w", NewContextOverflowError(underlying)) |
| 425 | |
| 426 | var ctxErr *ContextOverflowError |
| 427 | require.ErrorAs(t, wrapped, &ctxErr) |
| 428 | assert.Equal(t, underlying, ctxErr.Underlying) |
| 429 | }) |
| 430 | } |
| 431 | |
| 432 | func TestIsRetryableModelError_ContextOverflow(t *testing.T) { |
| 433 | t.Parallel() |
nothing calls this directly
no test coverage detected