Add fail-fast on init for missing provider credentials

This commit is contained in:
2026-03-06 21:31:51 +00:00
parent 610b6c3367
commit 89c7e3ac85
14 changed files with 398 additions and 20 deletions

View File

@@ -0,0 +1,53 @@
package server
import (
"io"
"log/slog"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
type nonFlusherRecorder struct {
recorder *httptest.ResponseRecorder
writeHeaderCalls int
}
func newNonFlusherRecorder() *nonFlusherRecorder {
return &nonFlusherRecorder{recorder: httptest.NewRecorder()}
}
func (w *nonFlusherRecorder) Header() http.Header {
return w.recorder.Header()
}
func (w *nonFlusherRecorder) Write(b []byte) (int, error) {
return w.recorder.Write(b)
}
func (w *nonFlusherRecorder) WriteHeader(statusCode int) {
w.writeHeaderCalls++
w.recorder.WriteHeader(statusCode)
}
func (w *nonFlusherRecorder) StatusCode() int {
return w.recorder.Code
}
func (w *nonFlusherRecorder) BodyString() string {
return w.recorder.Body.String()
}
func TestHandleStreamingResponseWithoutFlusherWritesSingleErrorHeader(t *testing.T) {
s := New(nil, nil, slog.New(slog.NewTextHandler(io.Discard, nil)))
req := httptest.NewRequest(http.MethodPost, "/v1/responses", nil)
w := newNonFlusherRecorder()
s.handleStreamingResponse(w, req, nil, nil, nil, nil, nil)
assert.Equal(t, 1, w.writeHeaderCalls)
assert.Equal(t, http.StatusInternalServerError, w.StatusCode())
assert.Contains(t, w.BodyString(), "streaming not supported")
}