Files
magpie/internal/codexcat/autoreview_test.go
T
yetone a1174674da codex: subagents and memories follow the session's magpie model; auto-review can too (cybercaius on Discord)
Codex's side calls ask for one of Codex's own models by its bare name
whatever the conversation is on: a subagent goes on the model the lead
names in spawn_agent, memories on gpt-5.6-luna/terra, auto-review on
codex-auto-review. With Codex signed in to ChatGPT and the conversation
routed onto one of magpie's models, each of those went to the ChatGPT
account instead (cybercaius: "can't pick follow the main model").

- gateway (codexFollowTo, codexLeads): a collab_spawn or memory call
  that asks for a bare model, with nothing set for it (no magpie
  subagent model, no [agents] default_subagent_model, no [memories]
  extract/consolidation_model in Codex's config), goes on the model its
  conversation's own turns go on (parent thread, own thread, else the
  key's last turn), when that is a magpie model the key may use. A task
  the ChatGPT backend sealed stays on ChatGPT. The trace shows a
  subagent's pick as {asked -> to}.
- agent.CodexSideSet reads Codex's config.toml for those keys; an
  unreadable config counts as set (leave as sent).
- Auto-review gets "Same as the session" (settings value "session"):
  codexcat writes each magpie entry's own id as its
  auto_review_model_override. Not the default: codex-auto-review runs
  free on a ChatGPT sign-in (#1593).
- GUI: the option in all languages; Memories' default text says it
  follows the session. app.js stays under its budget by folding five
  identical writingPrefs then/catch chains into prefWrite.

Ran (sandbox HOME, -tags nogui -count=1 -timeout 45m):
- go test ./internal/gateway ./internal/agent ./internal/codexcat
  ./internal/settings ./internal/cli ./internal/gui: ok.
  ./internal/provider: FAIL with "close of synctest channel from outside
  bubble" in filememo.Forget (TestUnreadLoginsWriteErrorsKeepCredentials),
  which is #3632 on main; this change touches nothing there.
- TestCodexSubagentFollowsTheSession and TestCodexMemoriesFollowTheSession
  go red with codexFollowTo returning "" (broken by hand).
  TestCodexSideCallsKeepTheConfigsModel, TestCodexSideCallsStayOnChatGPT,
  TestCodexSideSet, TestCodexAutoReviewFollowsTheSession pass.
- GUI (playwright 1.62.0, chromium + webkit): codex-auto-review (en, zh,
  zh-TW, ja, de), codex-memories, codex-memories-settings, codex-titles,
  codex-predictions, codex-descriptions, settings-general, agent-prefs,
  i18n-keys: 120/120 pass. TestCoreScriptBudget passes, budget unchanged.
- gofmt -l clean; go vet -tags nogui for linux, windows and darwin ok.

Again after rebasing on origin/main 49f15d124 (25341b4ca on top touches
only internal/redact; rebuilt): nogui builds (darwin, linux,
windows), TestCoreScriptBudget, the tests above, and the GUI files 120/120.

Not tried: a real Codex with a real ChatGPT account and a relay model.
2026-10-26 15:35:12 +08:00

112 lines
3.8 KiB
Go

package codexcat
import (
"encoding/json"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/settings"
)
func overrides(t *testing.T, ms []catalog.Model) map[string]any {
t.Helper()
var got struct {
Models []map[string]any `json:"models"`
}
if err := json.Unmarshal(Catalog(ms), &got); err != nil {
t.Fatal(err)
}
out := map[string]any{}
for _, m := range got.Models {
v, ok := m["auto_review_model_override"]
if !ok {
v = "none"
}
out[m["slug"].(string)] = v
}
return out
}
// With settings.CodexAutoReview every entry magpie hands Codex — the ChatGPT
// account's own and magpie's — names that model as
// auto_review_model_override, which Codex's auto-review runs on (#938); with
// none set no entry has the field, and one magpie left in Codex's cache is
// taken out.
func TestCodexAutoReviewEntries(t *testing.T) {
v1Home(t, `{"etag":"W/\"a\"","models":[{"slug":"gpt-6","base_instructions":"x"},{"slug":"gpt-7","base_instructions":"x","auto_review_model_override":"deepseek/old"},{"slug":"gpt-8","base_instructions":"x","auto_review_model_override":"codex-auto-review"}]}`)
ms := []catalog.Model{
{ID: "codex/gpt-6", Name: "GPT-6 · Codex"},
{ID: "codex/gpt-7", Name: "GPT-7 · Codex"},
{ID: "codex/gpt-8", Name: "GPT-8 · Codex"},
{ID: "codex/gpt-9", Name: "GPT-9 · Codex"},
{ID: "group/smart", Name: "smart"},
{ID: "anthropic/claude-opus", Name: "Opus"},
}
off := overrides(t, ms)
want := map[string]any{"codex/gpt-6": "none", "codex/gpt-7": "none", "codex/gpt-8": "codex-auto-review",
"codex/gpt-9": "none", "group/smart": "none", "anthropic/claude-opus": "none"}
for k, v := range want {
if off[k] != v {
t.Fatalf("unset: %s = %v, want %v (%v)", k, off[k], v, off)
}
}
s := settings.Load()
s.CodexAutoReview = "deepseek/deepseek-flash"
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
on := overrides(t, ms)
for k := range want {
if on[k] != "deepseek/deepseek-flash" {
t.Fatalf("set: %s = %v (%v)", k, on[k], on)
}
}
}
// The setting must be a model's id.
func TestCodexAutoReviewChecked(t *testing.T) {
v1Home(t, `{"models":[]}`)
s := settings.Load()
s.CodexAutoReview = "flash"
if err := settings.Save(s); err == nil {
t.Fatal("a value that is no model's id was saved")
}
s.CodexAutoReview = " group/smart "
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
if got := settings.Load().CodexAutoReview; got != "group/smart" {
t.Fatalf("saved %q", got)
}
}
// Set to "session" (cybercaius on Discord: left to Codex, a conversation
// on magpie's model had its auto-review on codex-auto-review through the
// ChatGPT sign-in), each of magpie's entries names itself, so the review
// runs on the session's model; Codex's own entries are left as OpenAI
// gave them, and one magpie put there before is taken out.
func TestCodexAutoReviewFollowsTheSession(t *testing.T) {
v1Home(t, `{"etag":"W/\"a\"","models":[{"slug":"gpt-6","base_instructions":"x"},{"slug":"gpt-7","base_instructions":"x","auto_review_model_override":"deepseek/old"},{"slug":"gpt-8","base_instructions":"x","auto_review_model_override":"codex-auto-review"}]}`)
s := settings.Load()
s.CodexAutoReview = settings.CodexAutoReviewSession
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
ms := []catalog.Model{
{ID: "codex/gpt-6", Name: "GPT-6 · Codex"},
{ID: "codex/gpt-7", Name: "GPT-7 · Codex"},
{ID: "codex/gpt-8", Name: "GPT-8 · Codex"},
{ID: "group/smart", Name: "smart"},
{ID: "token/gpt-6.1-sol", Name: "GPT-6.1 Sol"},
}
got := overrides(t, ms)
want := map[string]any{"codex/gpt-6": "none", "codex/gpt-7": "none", "codex/gpt-8": "codex-auto-review",
"group/smart": "group/smart", "token/gpt-6.1-sol": "token/gpt-6.1-sol"}
for k, v := range want {
if got[k] != v {
t.Fatalf("%s = %v, want %v (%v)", k, got[k], v, got)
}
}
}