Files
magpie/internal/provider/models_test.go
T
yetone 084480beec provider: OpenCode Go and Zen presets, with the session header OpenCode requires (#2)
OpenCode's gateway turns away requests that do not name their conversation
in x-opencode-session ('Request is missing x-opencode-session and cannot be
routed efficiently'), and magpie never sent it. Requests to opencode.ai now
carry the agent's own session id (OpenCode's x-session-affinity, Pi's,
Codex's session_id, Claude Code's) or, when the agent sends none, an id
derived from the conversation's first user message, stable across turns;
the provider test sends one too. OpenCode's docs ask exactly this of
third-party clients, along with their own User-Agent, which magpie already
sends.
2026-09-24 11:49:06 +08:00

42 lines
1.1 KiB
Go

package provider
import (
"testing"
"github.com/yetone/magpie/internal/catalog"
)
func TestRejectsTemperatureFromFetchedList(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("XDG_CACHE_HOME", home)
no, yes := false, true
if err := catalog.SaveLive("p", "http://x", []catalog.Model{
{ID: "strict", Name: "Strict", Temperature: &no},
{ID: "plain", Name: "Plain", Temperature: &yes},
{ID: "silent", Name: "Silent"},
}); err != nil {
t.Fatal(err)
}
p := Provider{ID: "p"}
for model, want := range map[string]bool{"strict": true, "plain": false, "silent": false, "unknown": false} {
if got := p.RejectsTemperature(model); got != want {
t.Errorf("RejectsTemperature(%q) = %v, want %v", model, got, want)
}
}
}
func TestIsOpenCode(t *testing.T) {
for base, want := range map[string]bool{
"https://opencode.ai/zen/go/v1": true,
"https://api.opencode.ai/v1": true,
"https://notopencode.ai/v1": false,
"https://api.deepseek.com/v1": false,
} {
if got := (Provider{Chat: base}).IsOpenCode(); got != want {
t.Errorf("%s: %v", base, got)
}
}
}