Files
magpie/internal/codexcat/summaries_test.go
T
yetone c65d9fb473 codex: magpie-models.json keeps the keys the user added by hand to a model, and says supports_reasoning_summaries itself, so Codex before 0.145 sends the effort and shows thinking (heng91, #1450)
What was wrong: every write of ~/.codex/magpie-models.json rendered the
catalog from magpie's models alone, so a key the user had put into an
entry was gone after the next model switch, catalog sync (Refresh, a
provider added, a gateway start) or a switch to Codex's own default,
which also deleted the file outright. The key heng91 added,
supports_reasoning_summaries, is one Codex before 0.145 needs: its
client.rs build_reasoning sends no `reasoning` (no effort, no summary,
so no thinking shown) for a model whose entry doesn't say true, until
openai/codex#32206 (first in 0.145). 0.144 also refuses to load a
catalog an entry of which lacks the key at all.

What changed:
- codexcat: every entry says supports_reasoning_summaries, true for a
  model with effort levels, false otherwise. Later Codex ignore it.
- codexcat.Keep: before a write, the keys of an entry on disk magpie
  doesn't write are carried over to the entry of the same slug, and a
  true of supports_reasoning_summaries stays over magpie's false. A key
  magpie writes keeps magpie's value; a model magpie no longer serves
  drops out; an unreadable file keeps nothing.
- agent/codex.go: the write when magpie becomes the provider and the
  catalog sync go through Keep; the three places that removed the file
  remove it only when nothing of the user's is in it.

Run:
- New tests TestCodexCatalogKeepsWhatTheUserAdded,
  TestCodexCatalogRemovedWhenNothingAdded (agent, from the file magpie
  writes, edited by hand) and TestCodexCatalogReasoningSummaries,
  TestKeepUserKeys (codexcat). Each fails on origin/main's code.
- Real Codex in a sandbox CODEX_HOME against a capture server:
  0.144.0 fails to load the old catalog ("missing field
  supports_reasoning_summaries"), loads the new one and sends
  reasoning {effort: high, summary: auto}; with the user's keys kept
  it sends summary "detailed". 0.162.0 loads both and sends the same.
- gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet of
  ./internal/agent ./internal/codexcat; linux and windows builds;
  go test -tags nogui ./... under a temp HOME, all ok.
2026-10-10 09:07:44 +08:00

100 lines
3.6 KiB
Go

package codexcat
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/catalog"
)
// Codex before 0.145 loads no catalog an entry of which lacks
// supports_reasoning_summaries, and sends the effort and asks for the
// thinking summary only for a model whose entry says true (#1450): every
// entry says it, true for a model with effort levels.
func TestCodexCatalogReasoningSummaries(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", os.Getenv("HOME"))
var got struct {
Models []map[string]any `json:"models"`
}
json.Unmarshal(Catalog([]catalog.Model{
{ID: "deepseek/deepseek-v4", Name: "v4", Efforts: []string{"high", "max"}},
{ID: "fake/m1", Name: "m1"},
}), &got)
if len(got.Models) != 2 {
t.Fatalf("%v", got)
}
if got.Models[0]["supports_reasoning_summaries"] != true {
t.Errorf("a model with efforts: %v", got.Models[0]["supports_reasoning_summaries"])
}
if v, ok := got.Models[1]["supports_reasoning_summaries"]; !ok || v != false {
t.Errorf("a model without efforts: %v %v", v, ok)
}
}
// Keep carries over what the user put in by hand, Codex's own entries too,
// and a true of supports_reasoning_summaries where magpie says false; of
// the rest magpie owns, nothing.
func TestKeepUserKeys(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
os.MkdirAll(filepath.Join(home, ".codex"), 0o755)
os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"), []byte(`{"models":[
{"slug":"gpt-5.5","display_name":"GPT-5.5","priority":3,"visibility":"list","context_window":272000,"supports_reasoning_summaries":true}]}`), 0o644)
ms := []catalog.Model{
{ID: "fake/m1", Name: "m1"},
{ID: "codex/gpt-5.5", Name: "GPT-5.5 · Codex", Efforts: []string{"low", "high"}},
}
b := Catalog(ms)
if got := Keep(nil, b); string(got) != string(b) {
t.Error("no file: changed")
}
if got := Keep([]byte("{not json"), b); string(got) != string(b) {
t.Error("a file that doesn't parse: changed")
}
if got := Keep(b, b); string(got) != string(b) {
t.Error("magpie's own file: changed")
}
cur := `{"models":[
{"slug":"fake/m1","supports_reasoning_summaries":true,"x_note":{"by":"me"},"max_output_tokens":128000,
"context_window":1,"auto_review_model_override":"old/one","shell_type":"local"},
{"slug":"codex/gpt-5.5","supports_reasoning_summaries":false,"upgrade":{"model":"gpt-6"},"x_mine":1},
{"slug":"gone/model","x_note":"left"}]}`
var got struct {
Models []map[string]any `json:"models"`
}
d := json.NewDecoder(strings.NewReader(string(Keep([]byte(cur), b))))
d.UseNumber()
if err := d.Decode(&got); err != nil || len(got.Models) != 2 {
t.Fatalf("%v %v", err, got)
}
m1, own := got.Models[0], got.Models[1]
if m1["supports_reasoning_summaries"] != true || m1["max_output_tokens"] != json.Number("128000") {
t.Errorf("user's keys: %v %v", m1["supports_reasoning_summaries"], m1["max_output_tokens"])
}
if n, _ := m1["x_note"].(map[string]any); n["by"] != "me" {
t.Errorf("user's object: %v", m1["x_note"])
}
if _, ok := m1["context_window"]; ok {
t.Error("a window magpie left out came back")
}
if _, ok := m1["auto_review_model_override"]; ok {
t.Error("an auto-review model magpie took out came back")
}
if m1["shell_type"] != "unified_exec" {
t.Errorf("a key magpie writes: %v", m1["shell_type"])
}
// Codex's own entry: its cache's value is magpie's; a key of the user's stays
if own["supports_reasoning_summaries"] != true || own["x_mine"] != json.Number("1") {
t.Errorf("own entry: %v %v", own["supports_reasoning_summaries"], own["x_mine"])
}
if _, ok := own["upgrade"]; ok {
t.Error("upgrade prompt came back")
}
}