MCPcopy Create free account
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 {Role: chmctx.RoleSystem, Content: "be terse"},
345 {Role: chmctx.RoleUser, Content: "run it"},
346 {Role: chmctx.RoleAssistant, Content: "Running.", Reasoning: []json.RawMessage{json.RawMessage(`{"type":"reasoning","id":"rs_1"}`)},
347 ToolCalls: []chmctx.ToolCall{{ID: "c1", Name: "bash", Arguments: map[string]any{"cmd": "true"}}}},
348 {Role: chmctx.RoleTool, Content: "", ToolCallID: "c1", ToolName: "bash"},
349 }
350 buf, err := json.Marshal(toInput(msgs))
351 if err != nil {
352 t.Fatalf("marshal: %v", err)
353 }
354 want := `[{"type":"message","role":"system","content":"be terse"},` +
355 `{"type":"message","role":"user","content":"run it"},` +
356 `{"type":"reasoning","id":"rs_1"},` +
357 `{"type":"message","role":"assistant","content":"Running."},` +
358 `{"type":"function_call","call_id":"c1","name":"bash","arguments":"{\"cmd\":\"true\"}"},` +
359 `{"type":"function_call_output","call_id":"c1","output":""}]`
360 if string(buf) != want {
361 t.Fatalf("toInput =\n%s\nwant\n%s", buf, want)

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