Lumens (v0.1.1233) connected WorkBuddy from the Agents page. The toast said it was connected, but the toggle flipped straight back and WorkBuddy had no magpie models. For agents that take magpie itself as the provider (WorkBuddy, WorkBuddy AI, ZCode, Pencil, T3 Code, Copilot JetBrains), Agent.connect() went down the "magpie" branch and called Apply without checking whether any model was listed for the agent. With none listed (no provider or subscription yet, or "only picked" with every pick gone), Apply wrote nothing, connect still answered 200, and the next read found nothing wired. The fix applies, then, if the agent still doesn't read as wired, returns the same NoModelsError or AllHiddenError the field-less path already used. The GUI already maps both to no_models and all_hidden, in all five languages. The check comes after Apply because Cursor Private Inference is wired through its environment with no models at all, and TestCursorLocalConnects keeps that connecting. The noModelLeft helper is shared with the existing field-less path. Tests: - TestConnectMagpieAsProviderWithNoModelLeft (agent): WorkBuddy with no provider gives NoModelsError. With its only picked provider switched off it gives AllHiddenError and stays unwired. Switched back on, it connects and is wired. - TestAgentConnectNoModelsMagpieAsProvider (gui): POST /api/agents/connect/workbuddy with nothing in magpie gives 400 no_models. The old code gave 200. Both fail on the old code. Run: - gofmt -l is clean. - go vet passes on darwin, on GOOS=linux -tags nogui and on GOOS=windows, for internal/agent and internal/gui. - go test -tags nogui passes for ./internal/agent and ./internal/gui under a sandbox HOME (load ~250 from sibling sessions). - An earlier full ./... run: gateway, library and provider passed on a rerun with a longer -timeout. Their first run hit the 10m timeout under load, with no assertion failures. Not tried: the real WorkBuddy app, and Lumens' own settings, which haven't been seen. Left for its own change: workbuddyWired counts only vendor "magpie" entries, while buddyWrite also treats an entry under magpie's key that WorkBuddy re-saved as vendor "Custom" as magpie's.
71 lines
2.9 KiB
Go
71 lines
2.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)
|
|
}
|
|
}
|
|
|
|
// Lumens on Discord: connecting WorkBuddy, whose one field puts magpie in
|
|
// its own picker, answered 200 with nothing added in magpie, so the page
|
|
// said it was connected and its switch went back off. It answers
|
|
// no_models now, as Codex does.
|
|
func TestAgentConnectNoModelsMagpieAsProvider(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("WORKBUDDY_CONFIG_DIR", "")
|
|
os.MkdirAll(filepath.Join(home, ".workbuddy"), 0o755)
|
|
os.WriteFile(filepath.Join(home, ".workbuddy", "models.json"), []byte("[]\n"), 0o600)
|
|
rec := httptest.NewRecorder()
|
|
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", "/api/agents/connect/workbuddy", strings.NewReader("{}")))
|
|
var out map[string]any
|
|
json.Unmarshal(rec.Body.Bytes(), &out)
|
|
if rec.Code != 400 || out["code"] != "no_models" || out["agent"] != "WorkBuddy" {
|
|
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)
|
|
}
|
|
}
|