MCPcopy Index your code
hub / github.com/codehamr/codehamr / TestChatSendsStreamIncludeUsage

Function TestChatSendsStreamIncludeUsage

internal/llm/llm_test.go:346–358  ·  view source on GitHub ↗

TestChatSendsStreamIncludeUsage: servers emit the usage block only when `stream_options.include_usage:true` is in the request; without it the per-turn token counter sits at 0. Every Chat call must ship the flag.

(t *testing.T)

Source from the content-addressed store, hash-verified

344// `stream_options.include_usage:true` is in the request; without it the per-turn
345// token counter sits at 0. Every Chat call must ship the flag.
346func TestChatSendsStreamIncludeUsage(t *testing.T) {
347 var gotBody string
348 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
349 b, _ := io.ReadAll(r.Body)
350 gotBody = string(b)
351 sseOK(w, []string{`{"choices":[{"delta":{"content":"ok"}}]}`})
352 }))
353 defer srv.Close()
354 collect(New(srv.URL, "m", "").Chat(context.Background(), nil, nil))
355 if !strings.Contains(gotBody, `"stream_options":{"include_usage":true}`) {
356 t.Fatalf("stream_options.include_usage missing from body: %s", gotBody)
357 }
358}
359
360// TestChatMidStreamErrorFrameSurfacesAsError: OpenAI-compatible backends (and
361// OpenRouter-style proxies like the hosted endpoint) report a post-200

Callers

nothing calls this directly

Calls 4

sseOKFunction · 0.85
collectFunction · 0.85
ChatMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected