TestChat402: budget exhaustion surfaces as a typed error with the snapshot reporting zero remaining, so the UI paints the depleted state immediately.
(t *testing.T)
| 492 | // TestChat402: budget exhaustion surfaces as a typed error with the snapshot |
| 493 | // reporting zero remaining, so the UI paints the depleted state immediately. |
| 494 | func TestChat402(t *testing.T) { |
| 495 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 496 | w.WriteHeader(http.StatusPaymentRequired) |
| 497 | })) |
| 498 | defer srv.Close() |
| 499 | evs := collect(New(srv.URL, "m", "k").Chat(context.Background(), nil, nil)) |
| 500 | if len(evs) != 1 || !errors.Is(evs[0].Err, cloud.ErrBudgetExhausted) { |
| 501 | t.Fatalf("want ErrBudgetExhausted, got %+v", evs) |
| 502 | } |
| 503 | if !evs[0].Budget.Set || evs[0].Budget.Remaining != 0 { |
| 504 | t.Fatalf("budget snapshot should report zero remaining: %+v", evs[0].Budget) |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | // TestChatUnreachable: transport failure surfaces as ErrUnreachable. Retries |
| 509 | // off: this test pins the terminal error surface, not the retry path. |