Files
magpie/internal/codexcat/autoreview_test.go
T
yetone ede0efb054 codexcat, gateway, gui: Settings › Codex auto-review model picks the model Codex's auto-review decides approvals on (#938, guitaoliu)
Codex's auto-review (approvals_reviewer = "auto_review") runs on the
auto_review_model_override of the conversation model's entry in its list,
else on codex-auto-review, else on the conversation's model at low effort,
so a conversation on an expensive model reviewed every approval on it.
settings.CodexAutoReview, picked from the app's menu (magpie's models and
groups, or Codex's own pick), is now put as auto_review_model_override in
every entry magpie hands Codex: magpie-models.json and a signed-in Codex's
/models, the ChatGPT backend's entries included. Unset, the list is as it
was (an override magpie left in Codex's cache is taken out, one OpenAI gives
kept). POST /api/settings/codex-auto-review refuses an id magpie doesn't
serve; settings refuse a value that is no model's id; the list's ETag
carries it so Codex asks again; another Settings save keeps it.

Tested end to end in a sandbox HOME with a real DeepSeek account and Codex
0.160.0 (codex exec, approval_policy on-request, approvals_reviewer
auto_review, read-only sandbox, a command asking for escalation): with the
setting deepseek/deepseek-flash the guardian request (kind guardian) went
to deepseek-flash while the conversation stayed on deepseek-v4-pro; unset,
magpie-models.json had no override and the review ran on deepseek-v4-pro.
Picking DeepSeek V4.1 Flash in the real web UI's Settings row wrote the
setting and rewrote magpie-models.json (4 entries with the override), and
the next codex exec reviewed on deepseek-flash. TestCodexAutoReviewEntries,
TestCodexAutoReviewChecked, TestCodexModelsAutoReview,
TestCodexAutoReviewSetting and codex-auto-review.test.cjs (Chromium and
WebKit, en and zh) are new and fail without the change; gateway-mode and
settings_keep cover the new row and field. go vet, go build (GOOS=linux
nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass.
2026-10-06 01:58:42 +08:00

83 lines
2.5 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)
}
}