In the GUI, an agent magpie is in has "Disconnect from magpie" (断开 magpie(还原配置)) in its row's menu (its logo, or a right-click; beside Apply again), with a tooltip saying what it does, and in its model picker right under Default, so the two aren't taken for each other; the logo's title says the menu has it. It asks first in the app's own dialog (askDisconnect, as askReset and askForgetSaved do; no native confirm), and the row is then drawn from the answer: the model the agent had, no longer wired, and the status line says so. Every new string has its Chinese. The drag grip stays hover-only; no click moves the page. What it leaves: Codex keeps magpie's [model_providers.magpie] table, as its own-model pick does, for threads started on it; with several ChatGPT accounts in magpie, Codex failover may write openai_base_url again on a later sync. A relay's own ANTHROPIC_MODEL in Claude Code's env was never stashed, so it doesn't come back; modelSettings effort entries for magpie models may stay in settings.json. Tests: TestCodexDisconnect (own provider, own provider signed in, nothing set: the top keys as before, the user's provider table untouched, no subagent model, no catalog file, no stash, not wired, no drift), TestClaudeDisconnect (own relay and nothing set: settings.json as before), TestGeminiDisconnect, TestDisconnectUnwiredLeavesConfig, TestAgentDisconnectAPI; internal/gui/tests/agent-disconnect.test.cjs (WebKit, English and Chinese: only a wired agent has it in the menu and the picker, the in-app dialog, Cancel posts nothing, Disconnect posts and the row shows the old model, no native dialog, the page doesn't move). click-scroll, agent-grip, agent-layout, agent-models, agent-model-groups, model-pick, favorite-star, claude-picker-fold and panel-effort pass under WebKit; menu-scroll fails on /api/plugins/updates unmocked, as it does on main. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. Not run against a live agent config.
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// The Agents page's Disconnect: an agent magpie is in says so (wired), and
|
|
// disconnecting it puts back the model the user had and answers with the
|
|
// agent no longer wired.
|
|
func TestAgentDisconnectAPI(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)
|
|
cfg := filepath.Join(home, ".codex", "config.toml")
|
|
os.WriteFile(cfg, []byte("model = \"gpt-5.4\"\n"), 0o600)
|
|
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
h := Handler(nil, nil)
|
|
call := func(path, body string) stateJSON {
|
|
t.Helper()
|
|
method := "POST"
|
|
if body == "" {
|
|
method = "GET"
|
|
}
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, httptest.NewRequest(method, path, strings.NewReader(body)))
|
|
if rec.Code != 200 {
|
|
t.Fatalf("%s %d %s", path, rec.Code, rec.Body)
|
|
}
|
|
var s stateJSON
|
|
json.Unmarshal(rec.Body.Bytes(), &s)
|
|
return s
|
|
}
|
|
codex := func(s stateJSON) agentJSON {
|
|
for _, a := range s.Agents {
|
|
if a.ID == "codex" {
|
|
return a
|
|
}
|
|
}
|
|
t.Fatalf("no codex in %+v", s.Agents)
|
|
return agentJSON{}
|
|
}
|
|
if codex(call("/api/state", "")).Wired {
|
|
t.Fatal("wired before magpie set anything")
|
|
}
|
|
if !codex(call("/api/set", `{"agent":"codex","field":"model","value":"relay/m1"}`)).Wired {
|
|
t.Fatal("not wired on a magpie model")
|
|
}
|
|
a := codex(call("/api/agents/disconnect/codex", "{}"))
|
|
if a.Wired || a.Fields[0].Value != "gpt-5.4" {
|
|
t.Fatalf("after disconnect: wired %v, model %q", a.Wired, a.Fields[0].Value)
|
|
}
|
|
}
|