mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-20 14:13:23 +00:00
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]>
43 lines
1.3 KiB
Go
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
|
|
}
|