Files
magpie/internal/agent/codex_desktop_efforts_test.go
T
yetone ddb1701fe0 codex: a model magpie has no word on is offered low, medium and high
ccdcn on X: in the Codex app, the models of a provider they added
(XJAI's model-code, model-work, model-test) had no reasoning effort to
pick, though the chip said 中. Nothing magpie reads knows those ids, so
their entries in magpie-models.json (and /v1/codex/models) had
supported_reasoning_levels [] and default_reasoning_level null. Codex
then hides the choice but still sends an effort (medium, or
model_reasoning_effort), and the gateway's fitEffort passes an effort on
as asked when a model's levels are unknown, so the effort went out and
couldn't be changed.

provider.CodexEfforts offers low, medium and high for a model whose
levels are wholly unknown. It is used by codexListed (GET
/v1/codex/models, the backend list, spawn models) and by
agent.magpieModels("codex") (the file Codex reads, and magpie's own
Codex effort control). A model known to have no levels keeps none: one
the vendor's catalog or models.dev lists (any provider, any spelling),
one the user marked as taking no reasoning ask, a vendor entry in
Codex's shape, and a routing group.

TestCodexDesktopEfforts' "user's own" now expects medium added to the
user's enabled-reasoning-efforts: its fixture's fake/m1 is such a model.

Run (on mote):
- go test -timeout 45m -count=1 ./internal/provider ./internal/agent
  ./internal/codexcat: ok
- go test -timeout 45m -count=1 ./internal/gateway ./internal/gui:
  gateway ok (615s); gui red only in 10 real-window AppKit tests
  (dock, panel, tray, main window), each killed at its deadline. Four of
  them run alone on origin/main 024393fbb fail the same way on mote:
  #4125 (mote's AppKit/launchd hang). Not run on another Mac.
- GOOS=linux / GOOS=windows go vet ./internal/provider ./internal/agent
  ./internal/gateway: ok; gofmt -l clean
The runs above were at base d99e213f5. Rebased on 024393fbb, which
changed internal/gateway only; at this head the new tests and every
TestCodex.*Effort test in provider, agent and gateway pass again.
Broken by hand: with codex_models.go and route.go stashed, the new
TestCodexOffersLevelsForUnknownModels and
TestCodexCatalogOffersUnknownModelsLevels fail (offered []).
TestCodexPickedEffortReachesUnknownModel checks each offered level
reaches the vendor as reasoning_effort.
Real Codex: codex-cli 0.165.0 app-server (sandbox CODEX_HOME), model/list
on the catalog codexcat writes for xjai/model-test: before,
supportedReasoningEfforts [] / default none; after, low, medium, high /
default medium.

Not tried: the Codex desktop app with a real XJAI vendor. Not changed:
other agents (OpenCode variants etc.), which send no effort for such a
model today, and groups whose members are all unknown.
2026-10-30 21:47:07 +08:00

143 lines
5.9 KiB
Go

package agent
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/edit"
"github.com/yetone/magpie/internal/provider"
)
// #310: the Codex app's model picker offers only the efforts in its
// [desktop] enabled-reasoning-efforts (unset: low … xhigh, ultra,
// persistent), so a magpie model's "max" was never offered. Routed to one,
// magpie adds what its models take and the app knows; the user's entries,
// order and comments stay, and nothing is written when nothing is missing.
func TestCodexDesktopEfforts(t *testing.T) {
setup := func(t *testing.T, config string) (string, func() string) {
home, read := codexHome(t, "", config)
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
os.WriteFile(catalog.CachePath(), []byte(`{
"zai":{"models":{"glm-5.3-flash":{"id":"glm-5.3-flash","reasoning_options":[{"type":"effort","values":["low","high","max","turbo"]}]}}}}`), 0o644)
catalog.Reset()
t.Cleanup(catalog.Reset)
if err := provider.Save(provider.Provider{ID: "volc", Name: "Volc", Key: "k", Chat: "http://127.0.0.1:1/api/v3",
Models: []string{"glm-5.3-flash"}}); err != nil {
t.Fatal(err)
}
return home, read
}
t.Run("unset", func(t *testing.T) {
home, read := setup(t, "# mine\n")
if err := codex(home).Fields[0].Set("volc/glm-5.3-flash"); err != nil {
t.Fatal(err)
}
cfg := read()
if !strings.Contains(cfg, "[desktop]\nenabled-reasoning-efforts = [\"low\", \"medium\", \"high\", \"xhigh\", \"ultra\", \"persistent\", \"max\"]\n") ||
!strings.Contains(cfg, "# mine") || strings.Contains(cfg, "turbo") {
t.Fatalf("config:\n%s", cfg)
}
})
t.Run("user's own", func(t *testing.T) {
home, read := setup(t, "[desktop]\n# the ones I use\nenabled-reasoning-efforts = [\"high\", \"low\"] # mine\nother = 1\n")
if err := codex(home).Fields[0].Set("volc/glm-5.3-flash"); err != nil {
t.Fatal(err)
}
cfg := read()
// medium: codexHome's fake/m1, a model nothing knows, is offered
// low, medium and high (provider.CodexEfforts)
if !strings.Contains(cfg, "# the ones I use\nenabled-reasoning-efforts = [\"high\", \"low\", \"medium\", \"max\"] # mine\nother = 1\n") {
t.Fatalf("config:\n%s", cfg)
}
// again: nothing missing, nothing written
before, _ := os.Stat(filepath.Join(home, ".codex", "config.toml"))
if err := codexEnableEfforts(filepath.Join(home, ".codex", "config.toml"), magpieModels("codex")); err != nil {
t.Fatal(err)
}
if after, _ := os.Stat(filepath.Join(home, ".codex", "config.toml")); !after.ModTime().Equal(before.ModTime()) || read() != cfg {
t.Fatalf("rewritten:\n%s", read())
}
})
t.Run("not routed", func(t *testing.T) {
home, read := setup(t, "")
if err := codex(home).Fields[0].Set("gpt-5.5"); err != nil {
t.Fatal(err)
}
if cfg := read(); strings.Contains(cfg, "desktop") {
t.Fatalf("config:\n%s", cfg)
}
})
t.Run("inline desktop", func(t *testing.T) {
home, read := setup(t, "desktop = { theme = \"dark\" }\n")
if err := codex(home).Fields[0].Set("volc/glm-5.3-flash"); err != nil {
t.Fatal(err)
}
if cfg := read(); strings.Contains(cfg, "[desktop]") || !strings.Contains(cfg, "desktop = { theme = \"dark\" }") {
t.Fatalf("config:\n%s", cfg)
}
})
}
// #2127 (cnlove7777777-art): a routing group Dash could run at High or Max
// showed in the Codex app at High with no effort control. Its entry lists
// high and max, but the app offers a model only the efforts in [desktop]
// enabled-reasoning-efforts, whose default leaves max out, and magpie
// added max only when Codex's config.toml was on one of magpie's models:
// the group got its levels later (8c5190a20, a catalog change) while the
// config was on Codex's own model, the app's last pick, so the catalog was
// rewritten with high and max and the app still offered high alone.
func TestCodexDesktopEffortsFollowTheCatalog(t *testing.T) {
home, read := codexHome(t, "", "")
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
os.WriteFile(catalog.CachePath(), []byte(`{
"zai":{"models":{"glm-5.3":{"id":"glm-5.3","reasoning_options":[{"type":"effort","values":["low","high","max"]}]},
"glm-4.5-air":{"id":"glm-4.5-air"}}},
"deepseek":{"models":{"deepseek-v4":{"id":"deepseek-v4","reasoning_options":[{"type":"effort","values":["high","max"]}]}}}}`), 0o644)
catalog.Reset()
t.Cleanup(catalog.Reset)
if err := provider.Save(provider.Provider{ID: "volc", Name: "Volc", Key: "k", Chat: "http://127.0.0.1:1/api/v3",
Models: []string{"glm-4.5-air"}}); err != nil {
t.Fatal(err)
}
cx := codex(home)
if err := cx.Fields[0].Set("volc/glm-4.5-air"); err != nil {
t.Fatal(err)
}
if cfg := read(); strings.Contains(cfg, `"max"`) {
t.Fatalf("max enabled with no model taking it:\n%s", cfg)
}
// the app's own pick, written to config.toml as Codex writes it
path := filepath.Join(home, ".codex", "config.toml")
if err := edit.SetTOMLTop(path, edit.KV{Path: "model", Value: "gpt-5.5"}); err != nil {
t.Fatal(err)
}
// the group comes to take high and max: its members are added
if err := provider.Save(provider.Provider{ID: "volc", Name: "Volc", Key: "k", Chat: "http://127.0.0.1:1/api/v3",
Models: []string{"glm-4.5-air", "glm-5.3", "deepseek-v4"}}); err != nil {
t.Fatal(err)
}
if err := provider.SaveGroup(provider.Group{ID: "normal", Name: "普通性能", Members: []string{"volc/glm-5.3", "volc/deepseek-v4"}}); err != nil {
t.Fatal(err)
}
if e := catalog.Efforts(magpieModels("codex"), "group/normal"); strings.Join(e, ",") != "high,max" {
t.Fatalf("group levels %v", e)
}
if err := cx.Sync(); err != nil {
t.Fatal(err)
}
cfg := read()
if !strings.Contains(cfg, "[desktop]\nenabled-reasoning-efforts = [\"low\", \"medium\", \"high\", \"xhigh\", \"ultra\", \"persistent\", \"max\"]\n") {
t.Fatalf("the app isn't offered max for the group:\n%s", cfg)
}
if !strings.Contains(cfg, `model = "gpt-5.5"`) {
t.Fatalf("the app's pick changed:\n%s", cfg)
}
}