v0.3.60 bfc7b11

reasoning_usage_test.go RawHistoryFolder

1package provider
2
3import (
4	"context"
5	"fmt"
6	"net/http"
7	"net/http/httptest"
8	"testing"
9)
10
11func TestOpenAIReportsReasoningTokens(t *testing.T) {
12	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
13		w.Header().Set("content-type", "text/event-stream")
14		fmt.Fprintln(w, `data: {"choices":[{"delta":{"content":"ok"},"finish_reason":"stop"}],"usage":{"prompt_tokens":12,"completion_tokens":9,"completion_tokens_details":{"reasoning_tokens":6}}}`)
15		fmt.Fprintln(w)
16		fmt.Fprintln(w, "data: [DONE]")
17		fmt.Fprintln(w)
18	}))
19	defer srv.Close()
20
21	events, err := NewOpenAI("test", srv.URL).Stream(context.Background(), Request{Model: "gpt-test"})
22	if err != nil {
23		t.Fatal(err)
24	}
25	usage := usageFromEvents(events)
26	if usage.OutputTokens != 9 || usage.ReasoningTokens != 6 || !usage.ReasoningTokensKnown {
27		t.Fatalf("usage = %+v", usage)
28	}
29}
30
31func TestOpenAIResponsesReportsReasoningTokens(t *testing.T) {
32	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
33		w.Header().Set("content-type", "text/event-stream")
34		fmt.Fprintln(w, `data: {"type":"response.completed","response":{"status":"completed","usage":{"input_tokens":12,"output_tokens":9,"output_tokens_details":{"reasoning_tokens":6}}}}`)
35		fmt.Fprintln(w)
36	}))
37	defer srv.Close()
38
39	events, err := NewOpenAICodex("test", "account", srv.URL).Stream(context.Background(), Request{Model: "gpt-5.5"})
40	if err != nil {
41		t.Fatal(err)
42	}
43	usage := usageFromEvents(events)
44	if usage.OutputTokens != 9 || usage.ReasoningTokens != 6 || !usage.ReasoningTokensKnown {
45		t.Fatalf("usage = %+v", usage)
46	}
47}
48
49func usageFromEvents(events <-chan Event) Usage {
50	var usage Usage
51	for event := range events {
52		if e, ok := event.(EventUsage); ok {
53			usage = e.Usage
54		}
55	}
56	return usage
57}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close