providers: a switched-off provider says how to turn it on, after a sign-in too
Atlas (Discord) signed in to WorkBuddy AI with `magpie plugin login
workbuddy-ai`, and `magpie providers` then showed "○ switched off" with
nothing saying why or how to undo it. magpie never sets Provider.Off by
itself; only the user's own switch does, and a sign-in rightly keeps it.
So the setting stays as the user left it, and magpie now says how to
change it:
- `magpie plugin login <id>` and `magpie accounts add <id>` (plugin and
built-in paths), finishing for a provider that is switched off, print
"! <Name> is switched off in magpie, so agents aren't given its models
· turn it on: magpie provider on <id>". One that can't be found says
nothing (not known to be off).
- `magpie providers` puts "magpie provider on <id>" in the switched-off
row's last, unpadded column, so the key column keeps its width.
- The TUI's Providers row notes "o switches it on" (its `o` key).
- The GUI row already shows a "Switched off" badge and its own switch,
and the editor says how to switch it on: left alone.
Run, at this tree (base c9c28aa58):
- TestPluginLoginSaysItIsSwitchedOff (new), TestProvidersShowVertexCredentials
and TestTUIAddsVertexWithItsProject (extended): red with the source
changes reverted (no hint in the login output, providers row or TUI
row), green with them.
- go test -timeout 45m ./internal/cli/... ./internal/provider/... ./internal/tui/...: ok (cli 45.8s, provider 120.1s, tui 21.8s)
- gofmt -l: clean. GOOS=linux go vet -tags nogui ./...: ok.
GOOS=windows go vet of the three packages: ok. go build: ok.
- Real run in a sandbox HOME with the fake test plugin and real Bun:
plugin login (on: no line), provider off, plugin login again (the
line, still off), magpie providers (row shows the command), provider
on (row back to "signed in", no hint).
Not tried: a real WorkBuddy AI account; the built-in (non-plugin)
`magpie accounts add` path's line has no test of its own (its sign-in
needs a vendor's OAuth); the TUI was checked through its test, not a
real terminal; the full ./... suite was not run.
This commit is contained in:
@@ -505,6 +505,7 @@ func addAccount(agentID string) error {
|
||||
}
|
||||
switch st.State {
|
||||
case "done":
|
||||
defer sayStillOff(agentID)
|
||||
if st.Again {
|
||||
fmt.Println(green.Render("✓"), st.User, "is already listed — its sign-in was renewed")
|
||||
} else if st.Using {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -184,3 +185,46 @@ func TestPluginLoginInstallsItsCLIFirst(t *testing.T) {
|
||||
t.Fatalf("installed for a key: %v", installed)
|
||||
}
|
||||
}
|
||||
|
||||
// A sign-in to a provider the user switched off keeps it off, and says so
|
||||
// with the command that turns it on (Atlas: WorkBuddy AI signed in, then
|
||||
// "○ switched off" with nothing saying why or how). One that is on says
|
||||
// nothing of it. magpie providers says the same command beside the row.
|
||||
func TestPluginLoginSaysItIsSwitchedOff(t *testing.T) {
|
||||
fakeCoHome(t)
|
||||
noBrowser(t)
|
||||
login := func() string {
|
||||
t.Helper()
|
||||
piped(t, "1", "sk-one-key-1111")
|
||||
out, err := said(t, func() error { return pluginCmd([]string{"plugin", "login", "fakeco"}) })
|
||||
if err != nil {
|
||||
t.Fatalf("%v: %s", err, out)
|
||||
}
|
||||
return out
|
||||
}
|
||||
if out := login(); strings.Contains(out, "switched off") {
|
||||
t.Fatalf("a provider that is on said switched off:\n%s", out)
|
||||
}
|
||||
if err := provider.SetOff("fakeco", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out := login()
|
||||
if !strings.Contains(out, "switched off") || !strings.Contains(out, "magpie provider on fakeco") {
|
||||
t.Fatalf("signed in to a switched-off provider, and nothing said how to turn it on:\n%s", out)
|
||||
}
|
||||
if p, err := provider.Find("fakeco"); err != nil || !p.Off {
|
||||
t.Fatalf("the sign-in turned the user's switch over: %+v %v", p, err)
|
||||
}
|
||||
// magpie accounts add, the same sign-in, says it too
|
||||
piped(t, "1", "sk-two-key-2222")
|
||||
if out, err := said(t, func() error { return accountsCmd([]string{"accounts", "add", "fakeco"}) }); err != nil || !strings.Contains(out, "magpie provider on fakeco") {
|
||||
t.Fatalf("accounts add: %v\n%s", err, out)
|
||||
}
|
||||
out, err := printed(t, providers)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if row := lineWith(out, "fakeco"); !strings.Contains(row, "switched off") || !strings.Contains(row, "magpie provider on fakeco") {
|
||||
t.Errorf("magpie providers, off: %q", row)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,9 +535,21 @@ func pluginLogin(ctx context.Context, name, method string) error {
|
||||
// magpie, it comes back
|
||||
id := provider.PluginSignedIn(saved)
|
||||
fmt.Println(green.Render("✓"), "signed in to", pp.Name, muted.Render("· its models are "+id+"/<model>"))
|
||||
sayStillOff(id)
|
||||
return nil
|
||||
}
|
||||
|
||||
// sayStillOff tells, after a sign-in, that the provider it went to is
|
||||
// switched off. A sign-in keeps the user's own switch as it was, but
|
||||
// "signed in" and then "○ switched off" in magpie providers read as a bug
|
||||
// with nothing saying how to turn it on (Atlas, WorkBuddy AI). A provider
|
||||
// that can't be found says nothing: not known to be off.
|
||||
func sayStillOff(id string) {
|
||||
if p, err := provider.Find(id); err == nil && p.Off {
|
||||
fmt.Println(amber.Render("!"), p.Name, "is switched off in magpie, so agents aren't given its models · turn it on: magpie provider on "+p.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// keyPrompt asks an "api" method's key: its title, then the hint the
|
||||
// plugin gives (its placeholder), as a question's is.
|
||||
func keyPrompt(name string, m plugin.Method) string {
|
||||
|
||||
@@ -207,6 +207,11 @@ func providers() error {
|
||||
if u := uses[p.ID]; len(u) > 0 {
|
||||
r.uses = green.Render("← " + strings.Join(u, ", "))
|
||||
}
|
||||
if p.Off {
|
||||
// the user's own switch, kept as they set it: how to undo it
|
||||
// is said beside it, never done for them
|
||||
r.uses = strings.TrimSpace(muted.Render("magpie provider on "+p.ID) + " " + r.uses)
|
||||
}
|
||||
if e := p.ListError(); e != "" {
|
||||
r.uses += amber.Render(" ! couldn't list its models: " + e)
|
||||
}
|
||||
|
||||
@@ -225,9 +225,12 @@ func TestProvidersShowVertexCredentials(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out, _ = printed(t, providers)
|
||||
if row := lineWith(out, "google-vertex"); !strings.Contains(row, "switched off") || strings.Contains(row, "Google credentials") {
|
||||
if row := lineWith(out, "google-vertex"); !strings.Contains(row, "switched off") || strings.Contains(row, "Google credentials") || !strings.Contains(row, "magpie provider on google-vertex") {
|
||||
t.Errorf("list, off: %q", row)
|
||||
}
|
||||
if row := lineWith(out, "vertex-sa"); strings.Contains(row, "magpie provider on") {
|
||||
t.Errorf("list, on, says how to turn it on: %q", row)
|
||||
}
|
||||
}
|
||||
|
||||
// A Vertex AI provider with no project an address can be made of
|
||||
|
||||
@@ -777,6 +777,10 @@ func (m model) viewProviders() string {
|
||||
}
|
||||
r.models = fmt.Sprintf("%d models", len(p.Exposed()))
|
||||
var notes []string
|
||||
if p.Off {
|
||||
// how to switch it on again, as magpie providers says it
|
||||
notes = append(notes, "o switches it on")
|
||||
}
|
||||
if v, ok := m.bal[p.ID]; ok {
|
||||
notes = append(notes, v)
|
||||
}
|
||||
|
||||
@@ -80,10 +80,10 @@ func TestTUIAddsVertexWithItsProject(t *testing.T) {
|
||||
if r := row("google-vertex"); !strings.Contains(r, "● Google credentials") || strings.Contains(r, " as ") || strings.Contains(r, "no key") {
|
||||
t.Errorf("its row: %q", r)
|
||||
}
|
||||
if r := row("vertex-sa"); !strings.Contains(r, "● Google credentials as vertex@my-project.iam.gserviceaccount.com") {
|
||||
if r := row("vertex-sa"); !strings.Contains(r, "● Google credentials as vertex@my-project.iam.gserviceaccount.com") || strings.Contains(r, "switches it on") {
|
||||
t.Errorf("a service account's row: %q", r)
|
||||
}
|
||||
if r := row("vertex-off"); !strings.Contains(r, "○ switched off") || strings.Contains(r, "Google credentials") {
|
||||
if r := row("vertex-off"); !strings.Contains(r, "○ switched off") || strings.Contains(r, "Google credentials") || !strings.Contains(r, "o switches it on") {
|
||||
t.Errorf("a switched-off one's row: %q", r)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user