Files
magpie/internal/agent/connect_all_hidden_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

46 lines
1.5 KiB
Go

package agent
import (
"errors"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// znuaibot's case (#1989): OpenCode is shown only the one model picked for
// it, and that model's provider is switched off. magpie has models, but
// none is left in OpenCode's lists: Connect says so, with a code the GUI
// says it by in the reader's language, not that OpenCode can't be
// connected.
func TestConnectWithEveryModelTakenOut(t *testing.T) {
home, _ := codexHome(t, "", "")
if err := provider.Save(provider.Provider{ID: "gem", Name: "Gem", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"gemini-3.8-flash"}}); err != nil {
t.Fatal(err)
}
if _, err := provider.SetModelLists(map[string]provider.ModelList{"opencode": {Only: true, Picked: []string{"gem/gemini-3.8-flash"}}}); err != nil {
t.Fatal(err)
}
if err := provider.SetOff("gem", true); err != nil {
t.Fatal(err)
}
cfg := filepath.Join(home, ".config")
_, err := opencode(home, cfg).ConnectHow()
var ah *AllHiddenError
if !errors.As(err, &ah) || ah.Agent != "OpenCode" || !strings.Contains(err.Error(), "Model list → Pick") {
t.Fatalf("%v", err)
}
var nm *NoModelsError
if errors.As(err, &nm) {
t.Fatalf("said there are no models: %v", err)
}
// the provider on again, its picked model is there to connect to
if err := provider.SetOff("gem", false); err != nil {
t.Fatal(err)
}
if _, err := opencode(home, cfg).ConnectHow(); err != nil {
t.Fatalf("with the picked model's provider on: %v", err)
}
}