nb5p's screenshot of the Agents page: Codex's model picker drew each of
Codex's own models by its slug (gpt-6-astra · 经 magpie · GPT-6-Astra in
grey). Every other list in magpie, magpie's catalog included, draws the
model's name. options() gives a model its name only as the grey note;
Codex's own were the one list built straight from it, and on magpie API or
with magpie Codex's provider the label was set to the slug outright.
codexNamed gives each of Codex's own models its name (the display_name
Codex lists it by) as the label, for the picker of this machine's Codex
and of a WSL distro's (wsl.go, both of its lists), and the magpie-API
branch no longer writes the slug over it. The value is the slug, as
before: what Codex is set to and sends is unchanged (codex/gpt-… on
magpie API, gpt-… otherwise). The Codex app's own picker was not the
cause: magpie's catalog file already gives it the names.
Test: TestCodexOwnModelsNamedInPicker (beside the ChatGPT sign-in, and
magpie the provider) checks each own model is labelled by its name and
valued by its slug. TestCodexAPIKeepsMagpieOnOwnModel and
TestCodexProviderOwnModelSaysItsPath now check the name too.
Run on mote at this tree: go test ./internal/agent ok (176s); go vet for
darwin, linux -tags nogui and windows on internal/agent; go build ./...;
gofmt -l clean.
Broken by hand: codexNamed left without the label, all three tests red
("gpt-6-astra is offered as "" ... want it named "GPT-6-Astra"").
Not tried: the GUI suite (no GUI file changed; the picker already draws
a label when there is one), a real Codex in WSL.
69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// With magpie Codex's provider, a model of Codex's own on the Agents page
|
|
// says what picking it does (#1269, shenghsi: "gpt-5.5 经 magpie", and
|
|
// Codex was taken off magpie the moment it was picked). With no ChatGPT
|
|
// account in magpie to serve it, it goes straight to OpenAI and says so;
|
|
// with one, it is picked as magpie serves it and Codex stays on magpie.
|
|
func TestCodexProviderOwnModelSaysItsPath(t *testing.T) {
|
|
ownOf := func(a *Agent) []Option {
|
|
var out []Option
|
|
for _, o := range a.Fields[0].Options(nil) {
|
|
if o.Group == "OpenAI" && (o.Value == "gpt-a" || o.Value == "codex/gpt-a") {
|
|
out = append(out, o)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
cache := []byte(`{"models":[{"slug":"gpt-a","display_name":"A","priority":1}]}`)
|
|
|
|
t.Run("no ChatGPT account", func(t *testing.T) {
|
|
home, read := codexHome(t, `{"OPENAI_API_KEY":"sk-x"}`, "")
|
|
os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"), cache, 0o644)
|
|
cx := codex(home)
|
|
if err := cx.Fields[0].Set("fake/m1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg := read(); !strings.Contains(cfg, `model_provider = "magpie"`) {
|
|
t.Fatalf("magpie isn't Codex's provider:\n%s", cfg)
|
|
}
|
|
own := ownOf(codex(home))
|
|
if len(own) != 1 {
|
|
t.Fatalf("Codex's own gpt-a: %+v", own)
|
|
}
|
|
if o := own[0]; o.Via || o.Direct != "OpenAI" || o.Value != "gpt-a" {
|
|
t.Fatalf("picking gpt-a takes Codex off magpie, yet it reads %+v", o)
|
|
}
|
|
})
|
|
|
|
t.Run("ChatGPT account out of allowance", func(t *testing.T) {
|
|
home, read := codexHome(t, `{"tokens":{"access_token":"x","id_token":"x.e30.x"}}`, "")
|
|
os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"), cache, 0o644)
|
|
codexUsedUp = func() bool { return true }
|
|
cx := codex(home)
|
|
if err := cx.Fields[0].Set("fake/m1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg := read(); !strings.Contains(cfg, `model_provider = "magpie"`) {
|
|
t.Fatalf("magpie isn't Codex's provider:\n%s", cfg)
|
|
}
|
|
own := ownOf(codex(home))
|
|
if len(own) != 1 || own[0].Value != "codex/gpt-a" || own[0].Label != "A" || !own[0].Via {
|
|
t.Fatalf("Codex's own gpt-a, served by magpie: %+v", own)
|
|
}
|
|
if err := codex(home).Fields[0].Set(own[0].Value); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg := read(); !strings.Contains(cfg, `model_provider = "magpie"`) || !strings.Contains(cfg, `model = "codex/gpt-a"`) {
|
|
t.Fatalf("picking it took Codex off magpie:\n%s", cfg)
|
|
}
|
|
})
|
|
}
|