v0.11.4 020512d

provider_test.go RawHistoryFolder

1package provider
2
3import (
4	"context"
5	"math"
6	"net/http"
7	"net/http/httptest"
8	"strings"
9	"testing"
10)
11
12func TestSSEParse(t *testing.T) {
13	r := strings.NewReader("event: foo\ndata: {\"a\":1}\n\ndata: hello\ndata: world\n\n")
14	ch := make(chan sseEvent, 4)
15	go readSSE(r, ch)
16
17	e := <-ch
18	if e.Event != "foo" || e.Data != `{"a":1}` {
19		t.Fatalf("event 1: %+v", e)
20	}
21	e = <-ch
22	if e.Event != "" || e.Data != "hello\nworld" {
23		t.Fatalf("event 2: %+v", e)
24	}
25	if _, ok := <-ch; ok {
26		t.Fatalf("channel not closed")
27	}
28}
29
30func TestModelCatalog(t *testing.T) {
31	if len(Catalog) == 0 {
32		t.Fatal("empty catalog")
33	}
34	if _, err := FindModel("anthropic", "claude-sonnet-4-5"); err != nil {
35		t.Fatal(err)
36	}
37	if _, err := FindModel("openai", "gpt-5"); err != nil {
38		t.Fatal(err)
39	}
40	if _, err := FindModel("", "nope"); err == nil {
41		t.Fatal("expected error")
42	}
43}
44
45func TestVertexGeminiFlashCatalogLimits(t *testing.T) {
46	for _, id := range []string{"gemini-3.1-flash-lite", "gemini-3.5-flash"} {
47		m, err := FindModel("google-vertex", id)
48		if err != nil {
49			t.Fatal(err)
50		}
51		if m.ContextWindow != 1048576 || m.MaxOutput != 65535 || !m.Reasoning {
52			t.Errorf("%s metadata = %+v", id, m)
53		}
54	}
55}
56
57func TestComputeCost(t *testing.T) {
58	m, _ := FindModel("anthropic", "claude-sonnet-4-5")
59	cost := ComputeCost(m, Usage{InputTokens: 1_000_000, OutputTokens: 1_000_000})
60	want := m.PriceInput + m.PriceOutput
61	if cost != want {
62		t.Fatalf("cost=%v want=%v", cost, want)
63	}
64}
65
66func TestComputeCostInputTier(t *testing.T) {
67	m := Model{
68		PriceInput: 1, PriceOutput: 2, PriceCacheRead: 0.1,
69		PriceTierInputTokens: 100,
70		PriceInputAbove:      3, PriceOutputAbove: 4, PriceCacheReadAbove: 0.2,
71	}
72	below := ComputeCost(m, Usage{InputTokens: 50, OutputTokens: 10, CacheReadTokens: 50})
73	wantBelow := (50.0*1 + 10*2 + 50*0.1) / 1_000_000
74	if math.Abs(below-wantBelow) > 1e-12 {
75		t.Fatalf("below-tier cost=%v want=%v", below, wantBelow)
76	}
77
78	above := ComputeCost(m, Usage{InputTokens: 51, OutputTokens: 10, CacheReadTokens: 50})
79	wantAbove := (51.0*3 + 10*4 + 50*0.2) / 1_000_000
80	if math.Abs(above-wantAbove) > 1e-12 {
81		t.Fatalf("above-tier cost=%v want=%v", above, wantAbove)
82	}
83}
84
85func TestAnthropicErrorStatus(t *testing.T) {
86	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
87		w.WriteHeader(http.StatusUnauthorized)
88		_, _ = w.Write([]byte(`{"error":{"type":"auth","message":"bad key"}}`))
89	}))
90	defer srv.Close()
91
92	c := NewAnthropic("x", srv.URL)
93	_, err := c.Stream(context.Background(), Request{Model: "claude-sonnet-4-5"})
94	if err == nil || !strings.Contains(err.Error(), "401") {
95		t.Fatalf("want 401 err, got %v", err)
96	}
97}
98
99func TestOpenAIErrorStatus(t *testing.T) {
100	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
101		w.WriteHeader(http.StatusBadRequest)
102		_, _ = w.Write([]byte(`{"error":{"message":"nope"}}`))
103	}))
104	defer srv.Close()
105
106	c := NewOpenAI("x", srv.URL)
107	_, err := c.Stream(context.Background(), Request{Model: "gpt-5"})
108	if err == nil || !strings.Contains(err.Error(), "400") {
109		t.Fatalf("want 400 err, got %v", err)
110	}
111}
112
113func TestMiniMaxM3CatalogAndRequest(t *testing.T) {
114	for _, provider := range []string{"minimax", "minimax-cn"} {
115		m, err := FindModel(provider, "MiniMax-M3")
116		if err != nil {
117			t.Fatal(err)
118		}
119		if m.ContextWindow != 1000000 || m.MaxOutput != 131072 || !m.Reasoning || !m.AdaptiveThinkingCompat {
120			t.Errorf("%s metadata = %+v", provider, m)
121		}
122		if m.PriceInput != 0.3 || m.PriceOutput != 1.2 || m.PriceCacheRead != 0.06 || m.PriceTierInputTokens != 512000 || m.PriceInputAbove != 0.6 || m.PriceOutputAbove != 2.4 || m.PriceCacheReadAbove != 0.12 {
123			t.Errorf("%s pricing = %+v", provider, m)
124		}
125	}
126
127	c := NewAnthropicCompat("minimax", "x", "https://api.minimax.io/anthropic").(*anthropicClient)
128	temp := float32(0.7)
129	wire, err := c.buildRequest(Request{
130		Model:       "MiniMax-M3",
131		Reasoning:   "high",
132		Temperature: &temp,
133		Messages:    []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
134	})
135	if err != nil {
136		t.Fatal(err)
137	}
138	if wire.Thinking == nil || wire.Thinking.Type != "adaptive" || wire.Thinking.BudgetTokens != 0 {
139		t.Fatalf("want adaptive thinking without a budget, got %+v", wire.Thinking)
140	}
141	if wire.OutputConfig != nil {
142		t.Fatalf("MiniMax-M3 must not send output_config, got %+v", wire.OutputConfig)
143	}
144	if wire.Temperature == nil || *wire.Temperature != temp {
145		t.Fatalf("MiniMax-M3 should keep temperature, got %v", wire.Temperature)
146	}
147}
148
149func TestAnthropicAdaptiveThinking(t *testing.T) {
150	c := NewAnthropic("x", "").(*anthropicClient)
151	temp := float32(0.7)
152
153	// Opus 5 -> adaptive thinking, effort set, no budget, no temperature.
154	wire, err := c.buildRequest(Request{
155		Model:       "claude-opus-5",
156		Reasoning:   "high",
157		Temperature: &temp,
158		Messages:    []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
159	})
160	if err != nil {
161		t.Fatal(err)
162	}
163	if wire.Thinking == nil || wire.Thinking.Type != "adaptive" {
164		t.Fatalf("want adaptive thinking, got %+v", wire.Thinking)
165	}
166	if wire.Thinking.BudgetTokens != 0 {
167		t.Fatalf("adaptive must not send budget_tokens, got %d", wire.Thinking.BudgetTokens)
168	}
169	if wire.OutputConfig == nil || wire.OutputConfig.Effort != "high" {
170		t.Fatalf("want effort=high, got %+v", wire.OutputConfig)
171	}
172	if wire.Temperature != nil {
173		t.Fatalf("adaptive must drop temperature, got %v", *wire.Temperature)
174	}
175
176	// maximum -> xhigh effort.
177	wire, err = c.buildRequest(Request{
178		Model:     "claude-opus-5",
179		Reasoning: "maximum",
180		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
181	})
182	if err != nil {
183		t.Fatal(err)
184	}
185	if wire.OutputConfig == nil || wire.OutputConfig.Effort != "xhigh" {
186		t.Fatalf("want effort=xhigh, got %+v", wire.OutputConfig)
187	}
188
189	// max is a separate native tier above xhigh on adaptive models.
190	wire, err = c.buildRequest(Request{
191		Model:     "claude-opus-5",
192		Reasoning: "max",
193		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
194	})
195	if err != nil {
196		t.Fatal(err)
197	}
198	if wire.OutputConfig == nil || wire.OutputConfig.Effort != "max" {
199		t.Fatalf("want effort=max, got %+v", wire.OutputConfig)
200	}
201
202	// Sonnet 5 -> adaptive thinking, effort set, no budget, no temperature.
203	wire, err = c.buildRequest(Request{
204		Model:       "claude-sonnet-5",
205		Reasoning:   "high",
206		Temperature: &temp,
207		Messages:    []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
208	})
209	if err != nil {
210		t.Fatal(err)
211	}
212	if wire.Thinking == nil || wire.Thinking.Type != "adaptive" {
213		t.Fatalf("want adaptive thinking for Sonnet 5, got %+v", wire.Thinking)
214	}
215	if wire.Thinking.BudgetTokens != 0 {
216		t.Fatalf("Sonnet 5 adaptive must not send budget_tokens, got %d", wire.Thinking.BudgetTokens)
217	}
218	if wire.OutputConfig == nil || wire.OutputConfig.Effort != "high" {
219		t.Fatalf("want Sonnet 5 effort=high, got %+v", wire.OutputConfig)
220	}
221	if wire.Temperature != nil {
222		t.Fatalf("Sonnet 5 adaptive must drop temperature, got %v", *wire.Temperature)
223	}
224
225	// Opus 4.5 -> budget-based thinking, no output_config, temperature kept.
226	wire, err = c.buildRequest(Request{
227		Model:       "claude-opus-4-5",
228		Reasoning:   "high",
229		Temperature: &temp,
230		Messages:    []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
231	})
232	if err != nil {
233		t.Fatal(err)
234	}
235	if wire.Thinking == nil || wire.Thinking.Type != "enabled" || wire.Thinking.BudgetTokens <= 0 {
236		t.Fatalf("want budget thinking, got %+v", wire.Thinking)
237	}
238	if wire.OutputConfig != nil {
239		t.Fatalf("budget models must not send output_config, got %+v", wire.OutputConfig)
240	}
241	if wire.Temperature == nil || *wire.Temperature != temp {
242		t.Fatalf("budget model should keep temperature, got %v", wire.Temperature)
243	}
244}
245
246func TestAnthropicBuildRequestStripsAssistantImages(t *testing.T) {
247	c := NewAnthropic("x", "").(*anthropicClient)
248	wire, err := c.buildRequest(Request{
249		Model: "claude-sonnet-4-5",
250		Messages: []Message{
251			{Role: RoleUser, Content: []Content{TextBlock{Text: "make an image"}}},
252			{Role: RoleAssistant, Content: []Content{
253				TextBlock{Text: "done"},
254				ImageBlock{MimeType: "image/png", Data: []byte("png")},
255				TextBlock{Text: "Saved image: `zut-gemini-image-x.png`"},
256			}},
257			{Role: RoleUser, Content: []Content{TextBlock{Text: "hello"}}},
258		},
259	})
260	if err != nil {
261		t.Fatal(err)
262	}
263	if len(wire.Messages) != 3 {
264		t.Fatalf("messages=%d", len(wire.Messages))
265	}
266	assistant := wire.Messages[1]
267	if assistant.Role != "assistant" {
268		t.Fatalf("role=%q", assistant.Role)
269	}
270	if len(assistant.Content) != 2 {
271		t.Fatalf("assistant content=%+v", assistant.Content)
272	}
273	for _, b := range assistant.Content {
274		if _, ok := b.(anthImageBlock); ok {
275			t.Fatalf("assistant image block was not stripped: %+v", assistant.Content)
276		}
277	}
278}
279
280func TestAnthropicStreamHappyPath(t *testing.T) {
281	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
282		w.Header().Set("content-type", "text/event-stream")
283		w.WriteHeader(http.StatusOK)
284		fl, _ := w.(http.Flusher)
285		write := func(s string) {
286			_, _ = w.Write([]byte(s))
287			if fl != nil {
288				fl.Flush()
289			}
290		}
291		write("event: message_start\ndata: {\"message\":{\"usage\":{\"input_tokens\":10,\"output_tokens\":0}}}\n\n")
292		write("event: content_block_start\ndata: {\"index\":0,\"content_block\":{\"type\":\"text\",\"text\":\"\"}}\n\n")
293		write("event: content_block_delta\ndata: {\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"hi\"}}\n\n")
294		write("event: content_block_stop\ndata: {\"index\":0}\n\n")
295		write("event: message_delta\ndata: {\"delta\":{\"stop_reason\":\"end_turn\"},\"usage\":{\"output_tokens\":5}}\n\n")
296		write("event: message_stop\ndata: {}\n\n")
297	}))
298	defer srv.Close()
299
300	c := NewAnthropic("x", srv.URL)
301	evs, err := c.Stream(context.Background(), Request{Model: "claude-sonnet-4-5"})
302	if err != nil {
303		t.Fatal(err)
304	}
305	var gotText string
306	var done EventDone
307	for ev := range evs {
308		switch e := ev.(type) {
309		case EventTextDelta:
310			gotText += e.Delta
311		case EventDone:
312			done = e
313		}
314	}
315	if gotText != "hi" {
316		t.Fatalf("text=%q", gotText)
317	}
318	if done.Stop != StopEnd {
319		t.Fatalf("stop=%v", done.Stop)
320	}
321}
322
323func TestClaudeOpus5Catalog(t *testing.T) {
324	m, err := FindModel("anthropic", "claude-opus-5")
325	if err != nil {
326		t.Fatal(err)
327	}
328	if m.DisplayName != "Claude Opus 5" || m.ContextWindow != 1000000 || m.MaxOutput != 128000 || !m.Reasoning || !m.AdaptiveThinking || m.Speculative {
329		t.Fatalf("unexpected Opus 5 model: %+v", m)
330	}
331	if m.PriceInput != 5 || m.PriceOutput != 25 || m.PriceCacheRead != 0.5 || m.PriceCacheWrite != 6.25 {
332		t.Fatalf("unexpected Opus 5 pricing: %+v", m)
333	}
334}
335
336func TestClaudeSonnet5Catalog(t *testing.T) {
337	m, err := FindModel("anthropic", "claude-sonnet-5")
338	if err != nil {
339		t.Fatal(err)
340	}
341	if m.DisplayName != "Claude Sonnet 5" || m.ContextWindow != 1000000 || m.MaxOutput != 128000 || !m.Reasoning || !m.AdaptiveThinking {
342		t.Fatalf("unexpected Sonnet 5 model: %+v", m)
343	}
344	if m.PriceInput != 2 || m.PriceOutput != 10 || m.PriceCacheRead != 0.2 || m.PriceCacheWrite != 2.5 {
345		t.Fatalf("unexpected Sonnet 5 pricing: %+v", m)
346	}
347}
348
349func TestOpenAICompatAnthropicReasoningEffort(t *testing.T) {
350	c := NewOpenRouter("token", "").(*openaiClient)
351	wire, err := c.buildRequest(Request{
352		Model:     "anthropic/claude-opus-4.8",
353		Reasoning: "maximum",
354		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
355	})
356	if err != nil {
357		t.Fatal(err)
358	}
359	if wire.ReasoningEffort != "xhigh" {
360		t.Fatalf("want xhigh for adaptive Anthropic model over OpenAI-compatible wire, got %q", wire.ReasoningEffort)
361	}
362
363	wire, err = c.buildRequest(Request{
364		Model:     "anthropic/claude-sonnet-5",
365		Reasoning: "maximum",
366		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
367	})
368	if err != nil {
369		t.Fatal(err)
370	}
371	if wire.ReasoningEffort != "xhigh" {
372		t.Fatalf("want xhigh for Claude Sonnet 5 over OpenAI-compatible wire, got %q", wire.ReasoningEffort)
373	}
374
375	wire, err = c.buildRequest(Request{
376		Model:     "gpt-5.1",
377		Reasoning: "maximum",
378		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
379	})
380	if err != nil {
381		t.Fatal(err)
382	}
383	if wire.ReasoningEffort != "high" {
384		t.Fatalf("want generic OpenAI-compatible maximum clamped to high, got %q", wire.ReasoningEffort)
385	}
386}
387
388func TestOpenAIBuildRequestSkipsReasoningOnlyAssistantMessages(t *testing.T) {
389	c := NewKimi("token", "").(*openaiClient)
390	wire, err := c.buildRequest(Request{
391		Model: "kimi-for-coding",
392		Messages: []Message{
393			{Role: RoleUser, Content: []Content{TextBlock{Text: "first"}}},
394			{Role: RoleAssistant, Content: []Content{ReasoningBlock{Summary: "thinking only"}}},
395			{Role: RoleUser, Content: []Content{TextBlock{Text: "second"}}},
396		},
397	})
398	if err != nil {
399		t.Fatal(err)
400	}
401	for i, msg := range wire.Messages {
402		if msg.Role == "assistant" && msg.Content == nil && len(msg.ToolCalls) == 0 {
403			t.Fatalf("message %d is empty assistant: %+v", i, msg)
404		}
405	}
406	if got := len(wire.Messages); got != 2 {
407		t.Fatalf("messages=%d want 2 after skipping reasoning-only assistant", got)
408	}
409}
410
411func TestOpenAIStreamHappyPath(t *testing.T) {
412	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
413		w.Header().Set("content-type", "text/event-stream")
414		w.WriteHeader(http.StatusOK)
415		fl, _ := w.(http.Flusher)
416		write := func(s string) {
417			_, _ = w.Write([]byte(s))
418			if fl != nil {
419				fl.Flush()
420			}
421		}
422		write("data: {\"choices\":[{\"index\":0,\"delta\":{\"content\":\"hel\"},\"finish_reason\":null}]}\n\n")
423		write("data: {\"choices\":[{\"index\":0,\"delta\":{\"content\":\"lo\"},\"finish_reason\":\"stop\"}]}\n\n")
424		write("data: {\"choices\":[],\"usage\":{\"prompt_tokens\":8,\"completion_tokens\":2}}\n\n")
425		write("data: [DONE]\n\n")
426	}))
427	defer srv.Close()
428
429	c := NewOpenAI("x", srv.URL)
430	evs, err := c.Stream(context.Background(), Request{Model: "gpt-5"})
431	if err != nil {
432		t.Fatal(err)
433	}
434	var gotText string
435	var done EventDone
436	for ev := range evs {
437		switch e := ev.(type) {
438		case EventTextDelta:
439			gotText += e.Delta
440		case EventDone:
441			done = e
442		}
443	}
444	if gotText != "hello" {
445		t.Fatalf("text=%q", gotText)
446	}
447	if done.Stop != StopEnd {
448		t.Fatalf("stop=%v", done.Stop)
449	}
450}
451
452func TestDiscoverOpenRouter(t *testing.T) {
453	const body = `{"data":[
454		{"id":"x/full","pricing":{"prompt":"0.000003","completion":"0.000015"},
455		 "context_length":200000,"top_provider":{"max_completion_tokens":64000},
456		 "supported_parameters":["reasoning"]},
457		{"id":"x/fallback","top_provider":{"context_length":128000}},
458		{"id":""}]}`
459	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
460		_, _ = w.Write([]byte(body))
461	}))
462	defer srv.Close()
463
464	models, err := DiscoverOpenRouter(context.Background(), srv.URL)
465	if err != nil {
466		t.Fatal(err)
467	}
468	if len(models) != 2 { // empty id dropped
469		t.Fatalf("want 2 models, got %d", len(models))
470	}
471	// per-token USD -> per-1M; reasoning from supported_parameters.
472	if m := models[0]; m.Provider != "openrouter" || m.ContextWindow != 200000 ||
473		m.MaxOutput != 64000 || !m.Reasoning || m.PriceInput != 3 || m.PriceOutput != 15 {
474		t.Errorf("model[0]: %+v", m)
475	}
476	// context falls back to top_provider; no reasoning.
477	if m := models[1]; m.ContextWindow != 128000 || m.MaxOutput != 0 || m.Reasoning {
478		t.Errorf("model[1]: %+v", m)
479	}
480}
481
482func TestGPT56CatalogEntries(t *testing.T) {
483	cases := []struct {
484		provider   string
485		id         string
486		context    int
487		priceInput float64
488		priceOut   float64
489		cacheRead  float64
490		cacheWrite float64
491	}{
492		{"openai", "gpt-5.6-luna", 272000, 1, 6, 0.1, 1.25},
493		{"openai", "gpt-5.6-sol", 272000, 5, 30, 0.5, 6.25},
494		{"openai", "gpt-5.6-terra", 272000, 2.5, 15, 0.25, 3.125},
495		{"openai-codex", "gpt-5.6-luna", 272000, 1, 6, 0.1, 1.25},
496		{"openai-codex", "gpt-5.6-sol", 272000, 5, 30, 0.5, 6.25},
497		{"openai-codex", "gpt-5.6-terra", 272000, 2.5, 15, 0.25, 3.125},
498		{"azure-openai-responses", "gpt-5.6-luna", 1050000, 1, 6, 0.1, 1.25},
499		{"azure-openai-responses", "gpt-5.6-sol", 1050000, 5, 30, 0.5, 6.25},
500		{"azure-openai-responses", "gpt-5.6-terra", 1050000, 2.5, 15, 0.25, 3.125},
501		{"vercel-ai-gateway", "openai/gpt-5.6-luna", 1050000, 1, 6, 0.1, 1.25},
502		{"vercel-ai-gateway", "openai/gpt-5.6-sol", 1050000, 5, 30, 0.5, 6.25},
503		{"vercel-ai-gateway", "openai/gpt-5.6-terra", 1050000, 2.5, 15, 0.25, 3.125},
504	}
505	for _, tc := range cases {
506		m, err := FindModel(tc.provider, tc.id)
507		if err != nil {
508			t.Fatal(err)
509		}
510		if m.ContextWindow != tc.context || m.MaxOutput != 128000 || !m.Reasoning {
511			t.Fatalf("%s/%s limits: %+v", tc.provider, tc.id, m)
512		}
513		if m.PriceInput != tc.priceInput || m.PriceOutput != tc.priceOut || m.PriceCacheRead != tc.cacheRead || m.PriceCacheWrite != tc.cacheWrite {
514			t.Fatalf("%s/%s prices: %+v", tc.provider, tc.id, m)
515		}
516	}
517}
518
519// TestOpenCodeGoCatalog pins the Grok 4.5 and Kimi K3 entries added to
520// the OpenCode Go provider. Both are listed in the vendor's current Go
521// model lineup (https://opencode.ai/docs/go) and were missing from the
522// baked-in catalog.
523func TestOpenCodeGoCatalog(t *testing.T) {
524	cases := []struct {
525		id        string
526		context   int
527		maxOut    int
528		priceIn   float64
529		priceOut  float64
530		cacheRead float64
531	}{
532		{"grok-4.5", 500000, 500000, 2, 6, 0.3},
533		{"kimi-k3", 1048576, 131072, 3, 15, 0.3},
534	}
535	for _, tc := range cases {
536		m, err := FindModel("opencode-go", tc.id)
537		if err != nil {
538			t.Fatal(err)
539		}
540		if m.ContextWindow != tc.context || m.MaxOutput != tc.maxOut || !m.Reasoning {
541			t.Fatalf("opencode-go/%s limits: %+v", tc.id, m)
542		}
543		if m.PriceInput != tc.priceIn || m.PriceOutput != tc.priceOut || m.PriceCacheRead != tc.cacheRead {
544			t.Fatalf("opencode-go/%s prices: %+v", tc.id, m)
545		}
546		if m.BaseURL != "https://opencode.ai/zen/go/v1" {
547			t.Fatalf("opencode-go/%s baseURL: %s", tc.id, m.BaseURL)
548		}
549	}
550}
551
552// TestOpenAIOmitsZeroMaxTokens guards against sending max_tokens: 0 for
553// discovered models that don't advertise an output cap (MaxOutput == 0).
554func TestOpenAIOmitsZeroMaxTokens(t *testing.T) {
555	SetLiveModels([]Model{
556		{Provider: "openrouter", ID: "vendor/no-cap", DisplayName: "No Cap"},
557		{Provider: "openrouter", ID: "vendor/reason-no-cap", DisplayName: "Reason No Cap", Reasoning: true},
558		{Provider: "openrouter", ID: "vendor/capped", DisplayName: "Capped", MaxOutput: 4096},
559	})
560	defer SetLiveModels(nil)
561
562	c := NewOpenAI("x", "").(*openaiClient)
563
564	got, err := c.buildRequest(Request{Model: "vendor/no-cap"})
565	if err != nil {
566		t.Fatal(err)
567	}
568	if got.MaxTokens != nil {
569		t.Errorf("expected max_tokens omitted, got %d", *got.MaxTokens)
570	}
571
572	got, err = c.buildRequest(Request{Model: "vendor/reason-no-cap"})
573	if err != nil {
574		t.Fatal(err)
575	}
576	if got.MaxCompletionTok != nil {
577		t.Errorf("expected max_completion_tokens omitted, got %d", *got.MaxCompletionTok)
578	}
579
580	got, err = c.buildRequest(Request{Model: "vendor/capped"})
581	if err != nil {
582		t.Fatal(err)
583	}
584	if got.MaxTokens == nil || *got.MaxTokens != 4096 {
585		t.Errorf("expected max_tokens 4096, got %v", got.MaxTokens)
586	}
587}

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