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.
70 lines
2.4 KiB
Go
70 lines
2.4 KiB
Go
package agent
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Lumens on Discord (v0.1.1233): connecting WorkBuddy said it was
|
|
// connected, then its switch went back off and WorkBuddy had none of
|
|
// magpie's models. WorkBuddy's one field puts magpie in its own picker, so
|
|
// Connect set it without asking whether any model was left for it: with
|
|
// every model taken out of WorkBuddy's list, models.json got none, and the
|
|
// row read as not connected. Connect now says why, as it does for an agent
|
|
// that picks among the catalog (#1989).
|
|
func TestConnectMagpieAsProviderWithNoModelLeft(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", "")
|
|
path := filepath.Join(home, ".workbuddy", "models.json")
|
|
os.MkdirAll(filepath.Dir(path), 0o755)
|
|
os.WriteFile(path, []byte(`[{"id":"qwen-local","local":true,"url":"http://127.0.0.1:8080/v1/chat/completions"}]`), 0o600)
|
|
|
|
// nothing added in magpie yet
|
|
_, err := workbuddy(home).ConnectHow()
|
|
var nm *NoModelsError
|
|
if !errors.As(err, &nm) || nm.Agent != "WorkBuddy" {
|
|
t.Fatalf("no providers: %v", err)
|
|
}
|
|
|
|
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.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"pro"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// shown only a model picked for it whose provider is off
|
|
if _, err := provider.SetModelLists(map[string]provider.ModelList{"workbuddy": {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)
|
|
}
|
|
_, err = workbuddy(home).ConnectHow()
|
|
var ah *AllHiddenError
|
|
if !errors.As(err, &ah) || ah.Agent != "WorkBuddy" {
|
|
t.Fatalf("every model taken out: %v", err)
|
|
}
|
|
if workbuddyWired(path) {
|
|
t.Fatal("wired with no model")
|
|
}
|
|
|
|
if err := provider.SetOff("gem", false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c, err := workbuddy(home).ConnectHow()
|
|
if err != nil || c.How != "magpie" {
|
|
t.Fatalf("with a model: %+v %v", c, err)
|
|
}
|
|
if !workbuddyWired(path) {
|
|
t.Fatal("not wired")
|
|
}
|
|
}
|