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

Function TestChatStructuredErrorFallsBackToMessage

internal/llm/llm_test.go:571–589  ·  view source on GitHub ↗

TestChatStructuredErrorFallsBackToMessage: with only `error.message` (no provider_hint), surface that, not the raw JSON envelope.

(t *testing.T)

Source from the content-addressed store, hash-verified

569 t.Fatalf("error should surface provider_hint: %v", evs[0].Err)
570 }
571 if strings.Contains(evs[0].Err.Error(), "upstream rate limited") {
572 t.Fatalf("provider_hint should win over message: %v", evs[0].Err)
573 }
574}
575
576// TestChatStructuredErrorFallsBackToMessage: with only `error.message` (no
577// provider_hint), surface that, not the raw JSON envelope.
578func TestChatStructuredErrorFallsBackToMessage(t *testing.T) {
579 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
580 w.Header().Set("Content-Type", "application/json")
581 w.WriteHeader(http.StatusServiceUnavailable)
582 fmt.Fprint(w, `{"error":{"message":"upstream unavailable","type":"upstream_unavailable","upstream_status":503}}`)
583 }))
584 defer srv.Close()
585 c := New(srv.URL, "m", "")
586 c.RetryBackoff = nil // pin the terminal error surface, not the retry path
587 evs := collect(c.Chat(context.Background(), nil, nil))
588 if len(evs) != 1 || evs[0].Kind != EventError {
589 t.Fatalf("want single error event, got %+v", evs)
590 }
591 if !strings.Contains(evs[0].Err.Error(), "503") ||
592 !strings.Contains(evs[0].Err.Error(), "upstream unavailable") {

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