(t *testing.T)
| 320 | } |
| 321 | |
| 322 | func TestOverflowKindOf(t *testing.T) { |
| 323 | t.Parallel() |
| 324 | |
| 325 | t.Run("returns stored Kind on wrapped error", func(t *testing.T) { |
| 326 | t.Parallel() |
| 327 | err := &ContextOverflowError{Underlying: errors.New("anything"), Kind: OverflowKindWire} |
| 328 | assert.Equal(t, OverflowKindWire, OverflowKindOf(err)) |
| 329 | }) |
| 330 | |
| 331 | t.Run("classifies underlying when wrap has no Kind", func(t *testing.T) { |
| 332 | t.Parallel() |
| 333 | // Legacy wrap: Kind left empty, Underlying carries the signal. |
| 334 | err := &ContextOverflowError{Underlying: errors.New("prompt is too long")} |
| 335 | assert.Equal(t, OverflowKindTokens, OverflowKindOf(err)) |
| 336 | }) |
| 337 | |
| 338 | t.Run("falls back to tokens on legacy wrap with no signal", func(t *testing.T) { |
| 339 | t.Parallel() |
| 340 | err := &ContextOverflowError{Underlying: errors.New("opaque")} |
| 341 | assert.Equal(t, OverflowKindTokens, OverflowKindOf(err)) |
| 342 | }) |
| 343 | |
| 344 | t.Run("returns empty on non-overflow error", func(t *testing.T) { |
| 345 | t.Parallel() |
| 346 | assert.Equal(t, OverflowKind(""), OverflowKindOf(errors.New("rate limited"))) |
| 347 | assert.Equal(t, OverflowKind(""), OverflowKindOf(nil)) |
| 348 | }) |
| 349 | |
| 350 | t.Run("NewContextOverflowError sets Kind from underlying", func(t *testing.T) { |
| 351 | t.Parallel() |
| 352 | // Anthropic 413 with structured body → wire |
| 353 | under := &StatusError{StatusCode: 413, Err: errors.New( |
| 354 | `413 Payload Too Large {"type":"error","error":{"type":"request_too_large","message":"too big"}}`)} |
| 355 | wrapped := NewContextOverflowError(under) |
| 356 | assert.Equal(t, OverflowKindWire, wrapped.Kind) |
| 357 | |
| 358 | // Token-overflow prose → tokens |
| 359 | wrapped = NewContextOverflowError(errors.New("prompt is too long")) |
| 360 | assert.Equal(t, OverflowKindTokens, wrapped.Kind) |
| 361 | |
| 362 | // Image rejection → media |
| 363 | wrapped = NewContextOverflowError(errors.New("image exceeds 5 MB maximum")) |
| 364 | assert.Equal(t, OverflowKindMedia, wrapped.Kind) |
| 365 | |
| 366 | // Unclassifiable underlying → tokens (safe historical default) |
| 367 | wrapped = NewContextOverflowError(errors.New("opaque")) |
| 368 | assert.Equal(t, OverflowKindTokens, wrapped.Kind) |
| 369 | }) |
| 370 | } |
| 371 | |
| 372 | func TestFormatError_OverflowKinds(t *testing.T) { |
| 373 | t.Parallel() |
nothing calls this directly
no test coverage detected