MCPcopy Create free account
hub / github.com/codehamr/codehamr / TestChatStructuredErrorPrefersProviderHint

Function TestChatStructuredErrorPrefersProviderHint

internal/llm/llm_test.go:547–567  ·  view source on GitHub ↗

TestChatStructuredErrorPrefersProviderHint: the hamrpass proxy wraps upstream errors as `{"error":{"message":...,"provider_hint":...}}`. The client must surface provider_hint over message, so users see the useful "retry shortly" text, not "upstream rate limited".

(t *testing.T)

Source from the content-addressed store, hash-verified

545 }
546}
547
548// TestChatStructuredErrorPrefersProviderHint: the hamrpass proxy wraps upstream
549// errors as `{"error":{"message":...,"provider_hint":...}}`. The client must
550// surface provider_hint over message, so users see the useful "retry shortly"
551// text, not "upstream rate limited".
552func TestChatStructuredErrorPrefersProviderHint(t *testing.T) {
553 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
554 w.Header().Set("Content-Type", "application/json")
555 w.WriteHeader(http.StatusTooManyRequests)
556 fmt.Fprint(w, `{"error":{"message":"upstream rate limited","type":"rate_limited","upstream_status":429,"provider_hint":"the upstream model is temporarily rate-limited, retry shortly"}}`)
557 }))
558 defer srv.Close()
559 c := New(srv.URL, "m", "")
560 c.RetryBackoff = nil // pin the terminal error surface, not the retry path
561 evs := collect(c.Chat(context.Background(), nil, nil))
562 if len(evs) != 1 || evs[0].Kind != EventError {
563 t.Fatalf("want single error event, got %+v", evs)
564 }
565 if !strings.Contains(evs[0].Err.Error(), "429") {
566 t.Fatalf("error should include upstream status: %v", evs[0].Err)
567 }
568 if !strings.Contains(evs[0].Err.Error(), "retry shortly") {
569 t.Fatalf("error should surface provider_hint: %v", evs[0].Err)
570 }

Callers

nothing calls this directly

Calls 4

collectFunction · 0.85
ChatMethod · 0.80
ErrorMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected