Files
magpie/internal/gui/agent_nomodels_test.go
T
ChampionTina c1e354245d agent, gui: connecting an agent whose model list holds none of magpie's models says so, in the reader's language (#1989, znuaibot)
znuaibot's case: OpenCode shown only its one picked model, whose provider
was switched off. connect() found no field to set, and since the catalog
still held models (shown 0, hidden 7) it said only "OpenCode can't be
connected to magpie", which sent the user looking at the agent rather
than at the model list that emptied it.

znuaibot's patch (74160e1f) told the case apart in connect(). Changed on
review: the plain English error would have reached the GUI untranslated
(NoModelsError beside it is said by code), so the case is a typed
AllHiddenError, fail() answers it with code all_hidden, and the GUI says
it in en/zh/zh-TW/ja/de, pointing at the agent's Model list → Pick (the
names the Agents page uses).

Run: TestConnectWithEveryModelTakenOut (agent) reproduces the case with
a provider switched off under OpenCode's picked list: on the old connect
it FAILs with "OpenCode can't be connected to magpie"; passes now, and
connects once the provider is on again. TestAgentConnectAllHidden (gui)
checks the code. agent-connect-no-models.test.cjs now runs both codes in
Chromium and WebKit, en/zh/ja/de: 16/16 pass, and with app.js's
all_hidden line removed the 8 all_hidden cases FAIL. gui-de, gui-ja,
gui-zh-tw, i18n-keys: pass. Full internal/agent and internal/gui: see
the push record on #1989.
2026-10-14 05:43:48 +08:00

49 lines
1.9 KiB
Go

package gui
import (
"encoding/json"
"fmt"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/agent"
)
// Tystem on Discord: connecting Codex with no provider or subscription in
// magpie answered "Codex can't be connected to magpie", untranslated. The
// answer carries code no_models and the agent's name, which the GUI says
// in the reader's language.
func TestAgentConnectNoModels(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
t.Setenv("CODEX_HOME", filepath.Join(home, ".codex"))
os.MkdirAll(filepath.Join(home, ".codex"), 0o755)
os.WriteFile(filepath.Join(home, ".codex", "config.toml"), []byte("model = \"gpt-5.5\"\n"), 0o600)
rec := httptest.NewRecorder()
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", "/api/agents/connect/codex", strings.NewReader("{}")))
var out map[string]string
json.Unmarshal(rec.Body.Bytes(), &out)
if rec.Code != 400 || out["code"] != "no_models" || out["agent"] != "Codex" || !strings.Contains(out["error"], "Add a provider or subscription") {
t.Fatalf("%d %s", rec.Code, rec.Body)
}
}
// znuaibot (#1989): magpie has models, none left in the agent's lists. The
// answer carries code all_hidden and the agent's name, which the GUI says
// in the reader's language, pointing at the agent's Model list.
func TestAgentConnectAllHidden(t *testing.T) {
rec := httptest.NewRecorder()
fail(rec, fmt.Errorf("connect: %w", &agent.AllHiddenError{Agent: "OpenCode"}))
var out map[string]string
json.Unmarshal(rec.Body.Bytes(), &out)
if rec.Code != 400 || out["code"] != "all_hidden" || out["agent"] != "OpenCode" || !strings.Contains(out["error"], "Model list → Pick") {
t.Fatalf("%d %s", rec.Code, rec.Body)
}
}