The Codex app's home-page prompt suggestions (thread_source ambient_suggestions, and their safety check, ambient_suggestion_safety; the Routing page's 提示词建议) are a background agentic turn that reads the project and connected apps. The app asks for the model its server config names (codex-app-model-routing's codex_ambient_suggestions_model_slug, gpt-6-luna) with provider model fallback on, so with magpie as Codex's provider they ran on the provider's default model, often auto: @0xcb198609 saw 76.9k tokens in 113s on deepseek-v4-pro. Codex has no config.toml key for that model, only an on/off switch in the app (store key ambient-suggestions-enabled, Settings › Configuration › Homepage suggestions; read from the 26.1106 bundle). magpie now has a setting for it, "Codex prompt suggestions" in Codex's row on the Agents page (Settings, beside Codex composer predictions): - Empty, the default, is Codex's own pick: nothing moves. A value the user set is never overridden. - A model or group of magpie's puts both calls there: in serve as the codex-suggestions move (the Routing page says why), and on the ChatGPT backend's route before the split, carrying the asked model to serve so the trace and ledger keep it. codexOwnOffMagpie leaves a bare gpt-6-luna to magpie while the setting is on (codexSideSet). - A target that is disabled, unserved or not allowed to the gateway key leaves the call as asked, with a log line (compactRefused). - To fit app.js's script budget without raising it, the suggestions and auto-review pickers share codexPick with codexSidePick, and every Codex row's button comes from condButton. The new route is named for the CLI (settings_parity_test.go). agent-prefs and settings-general list the new row. - The row's tooltip and the Routing page's Suggestions story say where Codex turns them off. magpie's old story said "Suggested prompts", which the current app no longer shows; corrected in all five languages from the app's own locale files. Run (mote, at this head rebased one25210b6e): - go test -timeout 45m ./...: ok, every package (101). A first run ate97271f02had cli and gui red on the CLI-parity guard and TestCoreScriptBudget; both fixed here, without raising the budget. - go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean. gofmt -l: clean. - TestCodexSuggestionsMoved/Left/MovedOffChatGPT/ModelRefusesBareName, TestCodexSuggestionsSetting: ok. - GUI: codex-suggestions (new), codex-predictions, codex-auto-review, routing-kind, i18n-keys: 58/58 ok before the rebase; at this head codex-suggestions, i18n-keys, agent-prefs, routing-kind 84/84 ok. Every GUI file that opens Codex's row or the Routing kind stories (26) ran too: red only in codex-async-compact (zh, zh-TW) and codex-memories-settings (chromium scroll), both red the same on origin/maine25210b6eand filed as #6658 and #6372. - Rebased last onto90d54a267(internal/sessions and internal/usage only): internal/sessions, internal/usage, TestCoreScriptBudget, the route guards and the CodexSuggestions tests ok again there. Broken by hand: codexSuggestionsTo returning "" and codexSideSet's new case off: TestCodexSuggestionsMoved red (m1 sent, and a 404 "magpie knows no model gpt-6-luna"), TestCodexSuggestionsMovedOffChatGPT red. Not tried: a real Codex app's prompt suggestions against magpie (no Codex.app here or on mote); the whole GUI suite (only the files that open Codex's row, its settings or the Routing kind stories).
196 lines
8.7 KiB
Go
196 lines
8.7 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/agentenv"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// Settings' Codex thread titles (#705) is set on its own: off, a model
|
|
// magpie serves (one it doesn't is refused), or back to Codex's own; the
|
|
// Settings page's other saves, which never send it, keep it; and the page
|
|
// is told the models it may name.
|
|
func TestCodexTitlesSetting(t *testing.T) {
|
|
h := t.TempDir()
|
|
t.Setenv("HOME", h)
|
|
t.Setenv("USERPROFILE", h)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
|
t.Setenv("APPDATA", filepath.Join(h, "AppData", "Roaming"))
|
|
t.Setenv("LOCALAPPDATA", filepath.Join(h, "AppData", "Local"))
|
|
for _, v := range agentenv.Vars {
|
|
t.Setenv(v, "")
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Models: []string{"m1"}, Chat: "http://127.0.0.1:9/v1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
call := func(path, body string) (int, map[string]any) {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
|
var out map[string]any
|
|
json.Unmarshal(rec.Body.Bytes(), &out)
|
|
return rec.Code, out
|
|
}
|
|
|
|
code, out := call("/api/settings/codex-titles", `{"model":"off"}`)
|
|
if code != 200 || out["codexTitles"] != "off" || settings.Load().CodexTitles != "off" {
|
|
t.Fatalf("off: %d %v", code, out["codexTitles"])
|
|
}
|
|
found := false
|
|
for _, m := range out["titleModels"].([]any) {
|
|
if m.(map[string]any)["id"] == "fake/m1" {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Errorf("titleModels %v has no fake/m1", out["titleModels"])
|
|
}
|
|
if code, _ := call("/api/settings", `{"theme":"dark"}`); code != 200 || settings.Load().CodexTitles != "off" {
|
|
t.Errorf("another save (%d) lost the setting: %q", code, settings.Load().CodexTitles)
|
|
}
|
|
if code, _ := call("/api/settings/codex-titles", `{"model":"nope/x"}`); code < 400 || settings.Load().CodexTitles != "off" {
|
|
t.Errorf("a model magpie doesn't serve: %d, %q", code, settings.Load().CodexTitles)
|
|
}
|
|
if code, out := call("/api/settings/codex-titles", `{"model":"fake/m1"}`); code != 200 || out["codexTitles"] != "fake/m1" {
|
|
t.Errorf("a model: %d %v", code, out["codexTitles"])
|
|
}
|
|
if code, _ := call("/api/settings/codex-titles", `{"model":""}`); code != 200 || settings.Load().CodexTitles != "" {
|
|
t.Errorf("Codex's own: %d %q", code, settings.Load().CodexTitles)
|
|
}
|
|
}
|
|
|
|
func TestCodexDescriptionsSetting(t *testing.T) {
|
|
h := t.TempDir()
|
|
t.Setenv("HOME", h)
|
|
t.Setenv("USERPROFILE", h)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
|
t.Setenv("APPDATA", filepath.Join(h, "AppData", "Roaming"))
|
|
t.Setenv("LOCALAPPDATA", filepath.Join(h, "AppData", "Local"))
|
|
for _, v := range agentenv.Vars {
|
|
t.Setenv(v, "")
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Models: []string{"m1"}, Chat: "http://127.0.0.1:9/v1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
call := func(path, body string) (int, map[string]any) {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
|
var out map[string]any
|
|
json.Unmarshal(rec.Body.Bytes(), &out)
|
|
return rec.Code, out
|
|
}
|
|
code, out := call("/api/settings/codex-descriptions", `{"model":"fake/m1"}`)
|
|
if code != 200 || out["codexDescriptions"] != "fake/m1" || settings.Load().CodexDescriptions != "fake/m1" {
|
|
t.Fatalf("model: %d %v", code, out["codexDescriptions"])
|
|
}
|
|
if code, _ := call("/api/settings", `{"theme":"dark"}`); code != 200 || settings.Load().CodexDescriptions != "fake/m1" {
|
|
t.Errorf("another save lost the setting: %q", settings.Load().CodexDescriptions)
|
|
}
|
|
if code, _ := call("/api/settings/codex-descriptions", `{"model":"nope/x"}`); code < 400 || settings.Load().CodexDescriptions != "fake/m1" {
|
|
t.Errorf("unknown model: %d %q", code, settings.Load().CodexDescriptions)
|
|
}
|
|
// off, as titles' (cybercaius on Discord), kept by another save
|
|
if code, out := call("/api/settings/codex-descriptions", `{"model":"off"}`); code != 200 || out["codexDescriptions"] != "off" || settings.Load().CodexDescriptions != "off" {
|
|
t.Errorf("off: %d %v %q", code, out["codexDescriptions"], settings.Load().CodexDescriptions)
|
|
}
|
|
if code, _ := call("/api/settings", `{"theme":"light"}`); code != 200 || settings.Load().CodexDescriptions != "off" {
|
|
t.Errorf("another save (%d) lost off: %q", code, settings.Load().CodexDescriptions)
|
|
}
|
|
if code, _ := call("/api/settings/codex-descriptions", `{"model":""}`); code != 200 || settings.Load().CodexDescriptions != "" {
|
|
t.Errorf("Codex's own: %d %q", code, settings.Load().CodexDescriptions)
|
|
}
|
|
}
|
|
|
|
// Codex's composer predictions (#1970): a model, off, or Codex's own,
|
|
// kept by a save of the rest of Settings.
|
|
func TestCodexPredictionsSetting(t *testing.T) {
|
|
h := t.TempDir()
|
|
t.Setenv("HOME", h)
|
|
t.Setenv("USERPROFILE", h)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
|
t.Setenv("APPDATA", filepath.Join(h, "AppData", "Roaming"))
|
|
t.Setenv("LOCALAPPDATA", filepath.Join(h, "AppData", "Local"))
|
|
for _, v := range agentenv.Vars {
|
|
t.Setenv(v, "")
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Models: []string{"m1"}, Chat: "http://127.0.0.1:9/v1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
call := func(path, body string) (int, map[string]any) {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
|
var out map[string]any
|
|
json.Unmarshal(rec.Body.Bytes(), &out)
|
|
return rec.Code, out
|
|
}
|
|
code, out := call("/api/settings/codex-predictions", `{"model":"fake/m1"}`)
|
|
if code != 200 || out["codexPredictions"] != "fake/m1" || settings.Load().CodexPredictions != "fake/m1" {
|
|
t.Fatalf("model: %d %v", code, out["codexPredictions"])
|
|
}
|
|
if code, _ := call("/api/settings", `{"theme":"dark"}`); code != 200 || settings.Load().CodexPredictions != "fake/m1" {
|
|
t.Errorf("another save lost the setting: %q", settings.Load().CodexPredictions)
|
|
}
|
|
if code, _ := call("/api/settings/codex-predictions", `{"model":"nope/x"}`); code < 400 || settings.Load().CodexPredictions != "fake/m1" {
|
|
t.Errorf("unknown model: %d %q", code, settings.Load().CodexPredictions)
|
|
}
|
|
if code, _ := call("/api/settings/codex-predictions", `{"model":"off"}`); code != 200 || settings.Load().CodexPredictions != "off" {
|
|
t.Errorf("off: %d %q", code, settings.Load().CodexPredictions)
|
|
}
|
|
if code, _ := call("/api/settings/codex-predictions", `{"model":""}`); code != 200 || settings.Load().CodexPredictions != "" {
|
|
t.Errorf("Codex's own: %d %q", code, settings.Load().CodexPredictions)
|
|
}
|
|
}
|
|
|
|
// The model for the Codex app's prompt suggestions (@0xcb198609 on X) is
|
|
// set on its own route and kept by every other save; a model magpie
|
|
// doesn't serve is refused, and "" goes back to Codex's own pick.
|
|
func TestCodexSuggestionsSetting(t *testing.T) {
|
|
h := t.TempDir()
|
|
t.Setenv("HOME", h)
|
|
t.Setenv("USERPROFILE", h)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
|
t.Setenv("APPDATA", filepath.Join(h, "AppData", "Roaming"))
|
|
t.Setenv("LOCALAPPDATA", filepath.Join(h, "AppData", "Local"))
|
|
for _, v := range agentenv.Vars {
|
|
t.Setenv(v, "")
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Models: []string{"m1"}, Chat: "http://127.0.0.1:9/v1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
call := func(path, body string) (int, map[string]any) {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
|
var out map[string]any
|
|
json.Unmarshal(rec.Body.Bytes(), &out)
|
|
return rec.Code, out
|
|
}
|
|
code, out := call("/api/settings/codex-suggestions", `{"model":"fake/m1"}`)
|
|
if code != 200 || out["codexSuggestions"] != "fake/m1" || settings.Load().CodexSuggestions != "fake/m1" {
|
|
t.Fatalf("model: %d %v", code, out["codexSuggestions"])
|
|
}
|
|
if code, _ := call("/api/settings", `{"theme":"dark"}`); code != 200 || settings.Load().CodexSuggestions != "fake/m1" {
|
|
t.Errorf("another save lost the setting: %q", settings.Load().CodexSuggestions)
|
|
}
|
|
for _, bad := range []string{"nope/x", "off", "gpt-6-luna"} {
|
|
if code, _ := call("/api/settings/codex-suggestions", `{"model":"`+bad+`"}`); code < 400 || settings.Load().CodexSuggestions != "fake/m1" {
|
|
t.Errorf("%s: %d %q", bad, code, settings.Load().CodexSuggestions)
|
|
}
|
|
}
|
|
if code, _ := call("/api/settings/codex-suggestions", `{"model":""}`); code != 200 || settings.Load().CodexSuggestions != "" {
|
|
t.Errorf("Codex's own: %d %q", code, settings.Load().CodexSuggestions)
|
|
}
|
|
}
|