agy-cli signs in and serves requests through Google's agy CLI. In magpie's
Docker image there is none, so its sign-in failed with "agy CLI not found"
and the user had to get a shell in the container and install it by hand,
where it lived outside the volume. Claude's sign-in already installs
claude when it is missing ("Installing Claude Code…"); a plugin had no way
to say it needs a CLI.
A plugin now declares its CLI as auth.cli = {name, manual, installed(),
install({signal})}. The host lists it as Provider.CLI and answers two new
calls, cliInstalled and installCli (run through the provider's proxy, and
given up when magpie gives up). pluginCLI returns that CLI when it isn't
installed, so the plugin's sign-in goes through the same "installing"
state as Claude's: the Providers sheet shows "Installing Antigravity CLI…",
then the sign-in link; a failed install names its cause and the plugin's
manual command. `magpie plugin login` does the same in a terminal. An
answer magpie can't get (host down, a timeout) counts as installed, so a
plugin is never reinstalled for a failed read.
The agy-cli side (installing agy into the data folder, which is on the
container's volume, and keeping that copy current) is in
magpie-community/plugins.
Run, at this head (rebased on 60ebaea03), on mica:
- go test ./internal/cli ./internal/plugin ./internal/provider ./internal/gui: ok
- GOOS=linux (-tags nogui) and GOOS=windows go vet of plugin, provider, cli: ok; gofmt clean
- TestPluginSignInInstallsItsCLI red on the old pluginSignIn (no CLI found,
straight to waiting), green now. TestPluginInstallsItsCLI covers the host
calls: listing, a refused install, an install given up, a good one.
Real use, magpie's Dockerfile built on xiaomi-gpu (Docker Desktop, linux
amd64), volume on /config, agy-cli loaded from its working tree:
- `magpie plugin login agy-cli 1`: "Installing it…", agy 1.5.9 downloaded
to /config/data/magpie-agy-cli/agy, then agy's Google sign-in link.
- restart: agy still there and runs.
- `magpie web` in the container, agy removed, POST /api/plugin-signin:
state installing ("Antigravity CLI"), then waiting with the link.
- agy.version set back to 1.5.0 and restarted: the plugin updated its copy
a minute later.
Not tried: finishing a Google sign-in in the container (no keyring there;
agy-cli's file sign-in is the path), a real install on macOS, Windows or a
musl Linux, and the full suite.
80 lines
2.6 KiB
Go
80 lines
2.6 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/plugin"
|
|
"github.com/yetone/magpie/internal/testenv"
|
|
)
|
|
|
|
// A plugin whose vendor CLI isn't on this machine had its sign-in fail
|
|
// with "install it first", which a magpie in a container can't do
|
|
// (niuniu_8964 on X: agy-cli in Docker). A plugin that says how to install
|
|
// it (auth.cli) has its sign-in install it first, "Installing {name}…" as
|
|
// a moved built-in's, then open the page; one whose install fails says
|
|
// why and how to do it by hand; with the CLI there, nothing is installed.
|
|
func TestPluginSignInInstallsItsCLI(t *testing.T) {
|
|
bun := testenv.Bun(t)
|
|
home := claudeHome(t)
|
|
t.Setenv("MAGPIE_BUN", bun)
|
|
t.Cleanup(plugin.Settle)
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
abs, _ := filepath.Abs("../plugin/testdata/cliinstall/index.js")
|
|
if _, err := plugin.Add(ctx, abs); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := plugin.Providers(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
settled := func(id string) SignInState {
|
|
t.Helper()
|
|
for range 500 {
|
|
if st, _ := SignInStatus(id); st.State != "installing" {
|
|
return st
|
|
}
|
|
time.Sleep(20 * time.Millisecond)
|
|
}
|
|
t.Fatal("the sign-in is still installing")
|
|
return SignInState{}
|
|
}
|
|
|
|
if got := PluginCLIMissing("cliinstall"); got != "Fake CLI" {
|
|
t.Fatalf("PluginCLIMissing = %q", got)
|
|
}
|
|
os.WriteFile(filepath.Join(home, "cli-mode"), []byte("fail"), 0o600)
|
|
st, err := StartPluginSignIn("cliinstall", 0, nil)
|
|
if err != nil || st.State != "installing" || st.Installing != "Fake CLI" {
|
|
t.Fatalf("StartPluginSignIn = %+v, %v", st, err)
|
|
}
|
|
if got := settled(st.ID); got.State != "failed" || !strings.Contains(got.Error, "the download was refused") || !strings.Contains(got.Error, "fake.invalid/install.sh") {
|
|
t.Fatalf("a failed install: %+v", got)
|
|
}
|
|
|
|
os.Remove(filepath.Join(home, "cli-mode"))
|
|
st, err = StartPluginSignIn("cliinstall", 0, nil)
|
|
if err != nil || st.State != "installing" {
|
|
t.Fatalf("StartPluginSignIn = %+v, %v", st, err)
|
|
}
|
|
if got := settled(st.ID); got.State != "waiting" || got.URL != "https://cliinstall.invalid/login" {
|
|
t.Fatalf("after the install: %+v", got)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(home, "fake-cli")); err != nil {
|
|
t.Fatal("the plugin's CLI wasn't installed")
|
|
}
|
|
|
|
if got := PluginCLIMissing("cliinstall"); got != "" {
|
|
t.Fatalf("installed, PluginCLIMissing = %q", got)
|
|
}
|
|
st, err = StartPluginSignIn("cliinstall", 0, nil)
|
|
if err != nil || st.State != "waiting" || st.URL != "https://cliinstall.invalid/login" {
|
|
t.Fatalf("with the CLI there: %+v, %v", st, err)
|
|
}
|
|
CancelSignIn(st.ID)
|
|
}
|