Files
magpie/internal/agent/standin_test.go
T
yetone 6ab31fbaeb gateway: every full id of a Claude family Claude Code names goes to its tier's model, served by a provider of the user's or not (KevinXC on Discord, v0.1.665, T3 Code 0.0.45 over Claude Code 2.1.287: claude-haiku-4-5, claude-opus-5, claude-fable-5 and claude-sonnet-4-6 went to the haiku/opus/fable/sonnet tiers, but claude-fable-5-1, claude-sonnet-5 and claude-sonnet-5-5 went to the Claude account, 429 "requires usage credits" / "weekly limit") — the stand-in (4cbd96a3) was only asked for a model magpie shows no entry for, so a full id a provider of the user's serves bare (the Claude account lists claude-sonnet-5, claude-fable-5-1, …; a found auto-<model> group has it too) went there, while one none listed went to the tier: which tier a model reached depended on what the user's providers happen to list, not on the model. T3 Code names every model by its full id rather than Claude Code's alias, so it hit both. Now an id of the opus, sonnet, haiku or fable family (claudeFamily: claude-<family>-<any version>[-date][1m], and claude-3-5-sonnet-… alike, so a release magpie has never heard of is one too) from Claude Code routed through magpie goes to the model its tier is set to before groups or providers are looked at, count_tokens counting it there too. Kept as asked: a provider's "anth/claude-…", another agent's request, Claude Code not routed through magpie (StandIn says nothing), a routing group of the user's own named by the id (one magpie found, auto-…, was never picked for it), and the main model when Claude Code's ANTHROPIC_MODEL is that very id. A tier at an effort of its own (#536, "fake/sol:high[1m]") now reaches its model at that level through a stand-in too, where it was looked up whole and refused. TestClaudeTierStandInByFamily (claude-haiku-4-5, -20251001, claude-haiku-5, claude-opus-5, -5-5, -5-5[1m], claude-opus-6, claude-fable-5, -5-1, -5-1[1m], claude-sonnet-4-6, -5, -5-5, -5-5-20261001, claude-3-5-sonnet-20241022 through /v1/messages, beside a provider serving seven of them bare) fails without the change for the nine served ones; TestClaudeStandIn gains the families and the main model. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass (TestDevinSignedInOnlyInMagpie, a known flake, aside).
2026-10-02 23:50:42 +08:00

89 lines
3.3 KiB
Go

package agent
import (
"os"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/gateway"
"github.com/yetone/magpie/internal/usage"
)
func TestClaudeStandIn(t *testing.T) {
path := filepath.Join(t.TempDir(), "settings.json")
write := func(s string) {
if err := os.WriteFile(path, []byte(s), 0o644); err != nil {
t.Fatal(err)
}
}
write(`{"env":{"ANTHROPIC_BASE_URL":"` + gateway.URL() + `","ANTHROPIC_MODEL":"a/main","ANTHROPIC_DEFAULT_HAIKU_MODEL":"a/small","ANTHROPIC_DEFAULT_OPUS_MODEL":"a/big"}}`)
for asked, want := range map[string]string{
"claude-haiku-4-5-20251001": "a/small",
"claude-opus-5-5": "a/big",
"claude-sonnet-5": "a/main", // a tier without a model follows the main one
"gpt-5": "a/main",
} {
if got := claudeStandIn(path, asked); got != want {
t.Errorf("%s: %q, want %q", asked, got, want)
}
}
// every version of a family is its tier's; the main model, named by
// its own id, is the main model's
write(`{"env":{"ANTHROPIC_BASE_URL":"` + gateway.URL() + `","ANTHROPIC_MODEL":"claude-opus-5[1m]","ANTHROPIC_DEFAULT_OPUS_MODEL":"a/big:high[1m]","ANTHROPIC_DEFAULT_SONNET_MODEL":"a/mid","ANTHROPIC_DEFAULT_FABLE_MODEL":"a/fab[1m]"}}`)
for asked, want := range map[string]string{
"claude-opus-5": "claude-opus-5[1m]",
"claude-opus-5-5": "a/big:high[1m]",
"claude-sonnet-5-5-20261001": "a/mid",
"claude-fable-5-1[1m]": "a/fab[1m]",
} {
if got := claudeStandIn(path, asked); got != want {
t.Errorf("%s: %q, want %q", asked, got, want)
}
}
// Claude Code on Anthropic's own endpoint: nothing stands in
write(`{"env":{"ANTHROPIC_MODEL":"a/main"}}`)
if got := claudeStandIn(path, "claude-haiku-4-5"); got != "" {
t.Errorf("not routed: %q", got)
}
if got := StandIn("gemini", "claude-haiku-4-5"); got != "" {
t.Errorf("another agent: %q", got)
}
}
// Codex on magpie as its provider asks for its auto-review by OpenAI's
// name, codex-auto-review (shihao H on X: 404 magpie knows no model
// "codex-auto-review"); it goes to the model Codex is set to. Signed in
// (routed by openai_base_url) or not routed, nothing stands in.
func TestCodexStandIn(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
dir := filepath.Join(home, ".codex")
if err := os.MkdirAll(dir, 0o755); err != nil {
t.Fatal(err)
}
write := func(s string) {
if err := os.WriteFile(filepath.Join(dir, "config.toml"), []byte(s), 0o644); err != nil {
t.Fatal(err)
}
}
write("model = \"deepseek/deepseek-v4\"\nmodel_provider = \"magpie\"\n\n[model_providers.magpie]\nname = \"magpie\"\n")
if got := StandIn("codex", "codex-auto-review"); got != "deepseek/deepseek-v4" {
t.Errorf("magpie as provider: %q", got)
}
// the gateway knows the request as Codex's by its User-Agent
for _, ua := range []string{"codex_cli_rs/0.160.0 (Mac OS 26.6.0; arm64) Apple_Terminal/455", "Codex Desktop/0.160.0"} {
if got := usage.AgentOf(ua); got != "codex" {
t.Errorf("%s: agent %q", ua, got)
}
}
write("model = \"gpt-5.5\"\nopenai_base_url = \"" + gateway.URL() + gateway.CodexPath + "\"\n")
if got := StandIn("codex", "codex-auto-review"); got != "" {
t.Errorf("signed in: %q", got)
}
write("model = \"gpt-5.5\"\n")
if got := StandIn("codex", "codex-auto-review"); got != "" {
t.Errorf("not routed: %q", got)
}
}