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.
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// With an auto-review model picked (#938), every entry of the list a
|
|
// signed-in Codex is handed — the ChatGPT backend's and magpie's — names it
|
|
// as auto_review_model_override, under another ETag; unset, the backend's
|
|
// entries are as it gave them, an override of its own kept, and magpie's
|
|
// have none.
|
|
func TestCodexModelsAutoReview(t *testing.T) {
|
|
setup(t, provider.Chat, &fake{t: t})
|
|
chatgpt(t, func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("ETag", `W/"up"`)
|
|
w.Write([]byte(`{"models":[{"slug":"gpt-6","priority":1,"auto_review_model_override":"codex-auto-review"},{"slug":"gpt-5.5","priority":2}]}`))
|
|
})
|
|
t.Setenv("XDG_CONFIG_HOME", "")
|
|
list := func() (string, map[string]map[string]any) {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
req := httptest.NewRequest("GET", CodexPath+"/models?client_version=0.159.2", nil)
|
|
req.Header.Set("Authorization", "Bearer chatgpt-token")
|
|
New().Handler().ServeHTTP(rec, req)
|
|
var l struct {
|
|
Models []map[string]any `json:"models"`
|
|
}
|
|
if rec.Code != 200 || json.Unmarshal(rec.Body.Bytes(), &l) != nil {
|
|
t.Fatalf("%d %s", rec.Code, rec.Body.String())
|
|
}
|
|
by := map[string]map[string]any{}
|
|
for _, m := range l.Models {
|
|
by[m["slug"].(string)] = m
|
|
}
|
|
return rec.Header().Get("ETag"), by
|
|
}
|
|
has := func(m map[string]any) any {
|
|
v, ok := m["auto_review_model_override"]
|
|
if !ok {
|
|
return "none"
|
|
}
|
|
return v
|
|
}
|
|
|
|
tagOff, off := list()
|
|
if has(off["gpt-6"]) != "codex-auto-review" || has(off["gpt-5.5"]) != "none" || has(off["fake/m1"]) != "none" {
|
|
t.Fatalf("unset: %v", off)
|
|
}
|
|
if err := provider.SetCodexAutoReview("fake/m1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tagOn, on := list()
|
|
if len(on) != len(off) {
|
|
t.Fatalf("the list changed: %v", on)
|
|
}
|
|
for slug, m := range on {
|
|
if has(m) != "fake/m1" {
|
|
t.Fatalf("set: %s says %v", slug, has(m))
|
|
}
|
|
}
|
|
if tagOn == tagOff {
|
|
t.Fatalf("ETag %q unchanged", tagOn)
|
|
}
|
|
if err := provider.SetCodexAutoReview(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tagBack, back := list()
|
|
if tagBack != tagOff || has(back["gpt-6"]) != "codex-auto-review" || has(back["gpt-5.5"]) != "none" || has(back["fake/m1"]) != "none" {
|
|
t.Fatalf("unset again %q: %v", tagBack, back)
|
|
}
|
|
}
|