Files
ai/controllers/anthropic_flusher_test.go
zeekayandHanzo Dev 0c08bd1d94 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers; omitzero is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 01:01:10 -07:00

43 lines
1.3 KiB
Go

package controllers
import (
"bufio"
"bytes"
"net/http"
"testing"
)
// EVERY STREAMING MODEL ADAPTER ASSERTS http.Flusher BEFORE IT EMITS A FRAME
// (model/claude.go, model/local.go, model/gemini.go and the rest all open with
// `writer.(http.Flusher)`). AnthropicWriter is the writer /v1/messages hands
// them, so if it does not satisfy that interface the endpoint cannot answer at
// all — which is what it did: "writer does not implement http.Flusher", 500,
// for every request.
//
// The trap is that it EMBEDS *bufio.Writer, which promotes a Flush that returns
// an error. That is not http.Flusher, but it reads like it at a glance and it
// compiles, so nothing caught it.
func TestAnthropicWriter_SatisfiesHTTPFlusher(t *testing.T) {
var buf bytes.Buffer
w := &AnthropicWriter{Writer: bufio.NewWriter(&buf)}
f, ok := any(w).(http.Flusher)
if !ok {
t.Fatal("AnthropicWriter does not implement http.Flusher — /v1/messages will 500 on every request")
}
if _, err := w.Writer.WriteString("frame"); err != nil {
t.Fatal(err)
}
f.Flush()
if buf.String() != "frame" {
t.Fatalf("Flush did not reach the underlying writer: %q", buf.String())
}
}
// A writer with no sink must not panic when a provider flushes it.
func TestAnthropicWriter_FlushWithNoSink(t *testing.T) {
w := &AnthropicWriter{}
w.Flush() // must be a no-op, not a nil dereference
}