Files
magpie/internal/agent/modelprefs_test.go
T
yetone f1ac93aa54 codex: Ultra on every other vendor's model that reasons (pingqipai3 on X)
pingqipai3 asked for Codex's Ultra effort on every model, so Codex uses
subagents more. Codex offers a level only where the model's catalog entry
lists it, and magpie listed Ultra only on OpenAI's own models.

What Codex does with it (openai/codex 553c764): Ultra is never sent.
ModelInfo::resolve_reasoning_effort sends the entry's
multi_agent_reasoning_effort, else max, else its highest other level; and
under MultiAgent V2, Ultra is what makes subagents proactive
(effective_multi_agent_mode). So Ultra on another vendor's model asks it
its own top level, which is honest, and turns on V2's proactive subagents.

codexcat.entriesAt now ends the levels of a model that lists some, from a
vendor other than OpenAI, with "ultra" and says multi_agent_version v2
(ultraHere). Left alone: GPT, o-series and Codex models (their Ultra is
provider.OffersUltra's), a model with no levels, Fast and Seals entries
(V1 stays theirs), a vendor's own Codex entry (listedEntry). The default
level is never Ultra. catalogFormat goes to v3, so Codex fetches the list
again. Only Codex's catalog changes; other agents' level lists don't.
docs/subsystems/agent-wiring.md has a row for it.

Run: at origin/main 54b6d4d39 + these three commits (c63a6d674, mica):
gofmt -l clean; go vet ./internal/{codexcat,gui,agent,gateway,provider,
catalog,usage} on darwin, GOOS=linux -tags nogui and GOOS=windows ok;
go test -count=1 of those seven packages: all ok.
Rebased onto origin/main 21ed46106 after that run (main's gateway,
provider and i18n.js changes): provider, gui, codexcat and
gateway-model-info, i18n-keys, gui-zh-tw run again there (mica): Go all ok, GUI 8 of 9; i18n-keys is red on
"No folder" from 72facf72e on main (#6423), not this change.
The full suite runs after the tag.
The provider tests that read Codex's list (TestCPAVariantModelsBorrowLevels,
TestGroupQuietMemberKeepsCodexEffortControl,
TestCodexOffersLevelsForUnknownModels) now expect ultra at the end.
Broken by hand: ultraHere returning false turns TestUltraOnOtherVendorsModels
red (claude-opus-4-8, glm-5.3, deepseek-v4-pro, group/mixed: no ultra, no v2).
Not tried: a real Codex session picking Ultra on a non-GPT model and
watching it spawn subagents; magpie's own Codex effort control
(codexEfforts) still doesn't list Ultra for these models; a Codex app
[desktop] enabled-reasoning-efforts the user set without "ultra" is left
as they set it.
2026-11-13 12:53:04 +08:00

103 lines
3.9 KiB
Go

package agent
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
)
// A model the user names, or keeps some reasoning levels of, is named so
// and offered only those in the lists magpie wrote into the agents' files,
// rewritten as soon as it is changed; a reset gives the model's own back.
func TestModelNameAndLevelsReachAgentFiles(t *testing.T) {
home := syncHome(t)
os.WriteFile(catalog.CachePath(), []byte(`{"zai":{"models":{"glm-4.6":{"id":"glm-4.6","name":"GLM-4.6","limit":{"context":204800},
"reasoning_options":[{"type":"effort","values":["low","medium","high"]}]}}}}`), 0o644)
catalog.Reset()
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Catalog: "zai", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"glm-4.6"}}); err != nil {
t.Fatal(err)
}
piModels := filepath.Join(home, ".pi", "agent", "models.json")
writeFile(t, piModels, `{"providers":{"magpie":{"name":"magpie","models":[]}}}`)
// Pi runs a model of magpie's: connected, so its list follows
writeFile(t, filepath.Join(home, ".pi", "agent", "settings.json"), `{"defaultProvider":"magpie","defaultModel":"relay/glm-4.6"}`)
setUpInMagpie("pi")
codexDir := filepath.Join(home, ".codex")
codexCat := filepath.Join(codexDir, "magpie-models.json")
writeFile(t, filepath.Join(codexDir, "config.toml"), "model = \"relay/glm-4.6\"\nmodel_provider = \"magpie\"\nmodel_catalog_json = '"+codexCat+"'\n")
writeFile(t, codexCat, `{"models":[]}`)
catalog.Changed = SyncCatalog
t.Cleanup(func() { catalog.Changed = nil })
if err := provider.SetModelName("relay/glm-4.6", "GLM"); err != nil {
t.Fatal(err)
}
if err := provider.SetModelEfforts("relay/glm-4.6", []string{"low", "high"}); err != nil {
t.Fatal(err)
}
var pi struct {
Providers map[string]struct {
Models []map[string]any `json:"models"`
} `json:"providers"`
}
if err := json.Unmarshal([]byte(readFile(piModels)), &pi); err != nil {
t.Fatal(err)
}
ms := pi.Providers["magpie"].Models
// a custom name still carries its provider, the same as GLM-4.6's own
// name would, so a picker full of renamed models can still be told
// apart by vendor
if len(ms) != 1 || ms[0]["id"] != "relay/glm-4.6" || ms[0]["name"] != "GLM · Relay" {
t.Fatalf("pi models.json: %v", ms)
}
var cx struct {
Models []struct {
Slug string `json:"slug"`
Name string `json:"display_name"`
Efforts []struct {
Effort string `json:"effort"`
} `json:"supported_reasoning_levels"`
} `json:"models"`
}
if err := json.Unmarshal([]byte(readFile(codexCat)), &cx); err != nil {
t.Fatal(err)
}
if len(cx.Models) != 1 || cx.Models[0].Slug != "relay/glm-4.6" || cx.Models[0].Name != "GLM · Relay" {
t.Fatalf("codex catalog: %+v", cx.Models)
}
var levels []string
for _, e := range cx.Models[0].Efforts {
levels = append(levels, e.Effort)
}
// and Ultra after them, which Codex sends as high (pingqipai3 on X)
if strings.Join(levels, ",") != "low,high,ultra" {
t.Fatalf("codex levels: %v", levels)
}
// unless the custom name already says the provider: it isn't repeated
if err := provider.SetModelName("relay/glm-4.6", "GLM via Relay"); err != nil {
t.Fatal(err)
}
if got := readFile(codexCat); !strings.Contains(got, `"GLM via Relay"`) || strings.Contains(got, `"GLM via Relay · Relay"`) {
t.Fatalf("codex catalog, provider repeated:\n%s", got)
}
if err := provider.SetModelName("relay/glm-4.6", ""); err != nil {
t.Fatal(err)
}
if err := provider.SetModelEfforts("relay/glm-4.6", nil); err != nil {
t.Fatal(err)
}
if got := readFile(codexCat); !strings.Contains(got, `"GLM-4.6 · Relay"`) || !strings.Contains(got, `"medium"`) {
t.Fatalf("codex catalog after reset:\n%s", got)
}
if got := readFile(piModels); !strings.Contains(got, `"GLM-4.6 · Relay"`) {
t.Fatalf("pi models.json after reset:\n%s", got)
}
}