summaryrefslogtreecommitdiff
path: root/internal/llm
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-04 16:10:01 +0300
committerPaul Buetow <paul@buetow.org>2025-09-04 16:10:01 +0300
commit09b33e65d92f5fb5b907e49c3d27584615cf2b83 (patch)
tree60f3acd4880dd2a3c0abed7e895a5f13acafcca7 /internal/llm
parentbf53cf2a673af254d7a08bc3b2ab815a08f66117 (diff)
tests: add negative SSE test, table-driven refactors, and use shared fixtures across tests; update REPORT.md progress
Diffstat (limited to 'internal/llm')
-rw-r--r--internal/llm/openai_sse_negative_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/internal/llm/openai_sse_negative_test.go b/internal/llm/openai_sse_negative_test.go
new file mode 100644
index 0000000..22b938c
--- /dev/null
+++ b/internal/llm/openai_sse_negative_test.go
@@ -0,0 +1,27 @@
+package llm
+
+import (
+ "context"
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+)
+
+func TestOpenAI_ChatStream_SSE_MalformedChunk(t *testing.T) {
+ // Malformed JSON chunk should be skipped; no onDelta calls; no error.
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/event-stream")
+ io.WriteString(w, "data: {not json}\n\n")
+ io.WriteString(w, "data: [DONE]\n")
+ }))
+ defer srv.Close()
+ c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient)
+ c.httpClient = srv.Client()
+ var got string
+ if err := c.ChatStream(context.Background(), []Message{{Role: "user", Content: "hi"}}, func(s string){ got += s }); err != nil {
+ t.Fatalf("unexpected error for malformed chunk: %v", err)
+ }
+ if got != "" { t.Fatalf("expected no deltas for malformed chunk, got %q", got) }
+}
+