provider: moving Antigravity onto agy goes through Antigravity's proxy (huiqiang6 on X)

huiqiang6 on X: in the Docker image, moving Antigravity's accounts onto
"Antigravity (local agy CLI)" always fails at installing agy.

Reproduced with ghcr.io/yetone/magpie:latest (v0.1.4377) on
xiaomi-gpu's Docker, with the owner's real Antigravity account in
plugin-auth.json:
- plain network, amd64 and emulated arm64: the move works (26s, 39s);
  agy 1.5.10 installs into /config/data/magpie-agy-cli.
- Google unreachable directly, reachable only through a squid proxy set
  on Antigravity alone (providers.json proxy, as a user in China sets
  it): the move fails in 7s, every time, with "installing Antigravity
  CLI failed (couldn't reach Antigravity's release server: Unable to
  connect…); install it yourself with `curl … | bash`".

Cause: MoveToAgy ran agy's install and the accounts' import under
agy-cli's proxy, which a new agy-cli doesn't have, so both went direct
and never through the proxy Antigravity's requests used.

Now MoveToAgy first carries Antigravity's proxy onto agy-cli (its
provider proxy while agy-cli has no account and no proxy of its own;
each moving account's own, or Antigravity's, as an account proxy where
agy-cli would take another), then installs agy and imports through
agy-cli's. A proxy the user set on agy-cli is kept.

Run:
- go test ./internal/provider -run Agy on mote: ok. The two new proxy
  tests are red with the carry and Via lines taken out (installed
  through "", imported through "").
- A linux/amd64 nogui build of this tree in the same blocked container
  (fresh volume, same account, same proxy): the move gives
  kumw95ya25@gmail.com "added" in 26s, agy 1.5.10 installed,
  providers.json has agy-cli's proxy, and a chat request to
  agy-cli/gemini-3.8-flash answers "OK", squid logging the CONNECTs.
- gofmt -l; go vet GOOS=linux -tags nogui ./..., GOOS=windows ./...
- Full suite: not run before the push. mote and mica were each running
  another session's suite; it runs after, one per machine, and a red
  gets its own issue.

Not tried: native arm64 hardware with the proxy; the reporter's own
config (the tweet has no screenshot, so their proxy setup is inferred);
an agy-cli that already has accounts and no proxy (the move's import
then goes through agy-cli's, direct; the moving accounts still keep
their proxy afterwards). Moves that already failed simply work on retry;
none half-moved anything.
This commit is contained in:
yetone
2026-11-17 21:43:12 +08:00
parent fefe3f658c
commit a922e3864e
2 changed files with 154 additions and 9 deletions
+75 -5
View File
@@ -5,6 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"slices"
"sort"
"strings"
@@ -132,7 +134,16 @@ func MoveToAgy(ctx context.Context) ([]ImportedAccount, error) {
return nil, fmt.Errorf("%s takes no Antigravity accounts", agyCLIPackage)
}
forgetAccountCaches()
if PluginCLIMissing(agyCLIID) != "" {
// agy is downloaded from Google and checks each account with Google,
// so it goes the way Antigravity's requests went: where Google is
// reached only through Antigravity's own proxy (magpie in a container
// in China), going direct failed the install every time (huiqiang6 on
// X). agy-cli keeps that proxy for its requests after the move too.
if err := carryAgyProxy(accts); err != nil {
return nil, err
}
ctx = Via(ctx, PluginID(agyCLIID))
if agyCLIMissing(agyCLIID) != "" {
if err := installAgy(ctx, agyCLIID); err != nil {
return nil, err
}
@@ -144,9 +155,68 @@ func MoveToAgy(ctx context.Context) ([]ImportedAccount, error) {
return importPlugin(ctx, PluginID(agyCLIID), []string{string(text)})
}
// installAgy and importPlugin are InstallPluginCLI and ImportPluginFiles,
// for tests to stand in for.
// carryAgyProxy gives agy-cli the proxy Antigravity's requests went
// through: Antigravity's own, when agy-cli has no account yet and no proxy
// of its own; and each moving account's, where agy-cli would take another
// for it and has none of the account's own. A proxy the user chose in
// agy-cli is kept.
func carryAgyProxy(accts []map[string]any) error {
from, ok := agyProxyFrom()
if !ok {
return nil
}
id := PluginID(agyCLIID)
f, err := read()
if err != nil {
return err
}
i := slices.IndexFunc(f.Providers, func(p Provider) bool { return p.ID == id })
if i < 0 {
f.Providers = append(f.Providers, Provider{ID: id})
i = len(f.Providers) - 1
}
p := &f.Providers[i]
changed := false
if p.Proxy == "" && from.Proxy != "" && len(plugin.Auths(agyCLIID)) == 0 {
p.Proxy, changed = from.Proxy, true
}
own := maps.Clone(p.AccountProxies)
if own == nil {
own = map[string]string{}
}
for _, a := range accts {
k := accountKey(agyWho(a))
want := from.AccountProxies[k]
if want == "" {
want = from.Proxy
}
if k != "" && want != "" && want != p.Proxy && own[k] == "" {
own[k], changed = want, true
}
}
if !changed {
return nil
}
p.AccountProxies = normalAccountProxies(own)
return store(f)
}
// agyProxyFrom is where Antigravity's proxy is kept: under the id its
// accounts were served by (the plugin's own, "antigravity-plugin", while
// the built-in was beside it), the first of them that has one.
func agyProxyFrom() (Provider, bool) {
for _, id := range []string{PluginID("antigravity"), "antigravity", "antigravity-plugin"} {
if p, ok := storedPicks(id); ok && (p.Proxy != "" || len(p.AccountProxies) > 0) {
return p, true
}
}
return Provider{}, false
}
// agyCLIMissing, installAgy and importPlugin are PluginCLIMissing,
// InstallPluginCLI and ImportPluginFiles, for tests to stand in for.
var (
installAgy = InstallPluginCLI
importPlugin = ImportPluginFiles
agyCLIMissing = PluginCLIMissing
installAgy = InstallPluginCLI
importPlugin = ImportPluginFiles
)
+79 -4
View File
@@ -8,6 +8,7 @@ import (
"strings"
"testing"
"github.com/yetone/magpie/internal/netproxy"
"github.com/yetone/magpie/internal/plugin"
)
@@ -17,12 +18,16 @@ import (
type agyStandIn struct {
installed []string
texts []string
// the proxy agy was installed and the accounts imported through, as
// their ctx chose it
cliVia, importVia string
cliInstalled bool
}
func standInAgy(t *testing.T, importable bool) *agyStandIn {
t.Helper()
s := &agyStandIn{}
oldInstall, oldProviders, oldCLI, oldImport := installPlugin, pluginProviders, installAgy, importPlugin
oldInstall, oldProviders, oldCLI, oldImport, oldMissing := installPlugin, pluginProviders, installAgy, importPlugin, agyCLIMissing
installPlugin = func(_ context.Context, pkg, min string) error {
s.installed = append(s.installed, pkg+"@"+min)
return nil
@@ -30,16 +35,21 @@ func standInAgy(t *testing.T, importable bool) *agyStandIn {
pluginProviders = func(context.Context) ([]plugin.Provider, error) {
return []plugin.Provider{{ID: agyCLIID, Spec: agyCLIPackage, Importable: importable}}, nil
}
installAgy = func(context.Context, string) error { return errors.New("agy is installed here") }
importPlugin = func(_ context.Context, id string, texts []string) ([]ImportedAccount, error) {
agyCLIMissing = func(string) string { return "" }
installAgy = func(ctx context.Context, _ string) error {
s.cliInstalled, s.cliVia = true, netproxy.Choice(ctx)
return nil
}
importPlugin = func(ctx context.Context, id string, texts []string) ([]ImportedAccount, error) {
if id != agyCLIID {
return nil, errors.New("imported into " + id)
}
s.importVia = netproxy.Choice(ctx)
s.texts = append(s.texts, texts...)
return []ImportedAccount{{User: "a@x.com", Status: "added"}}, nil
}
t.Cleanup(func() {
installPlugin, pluginProviders, installAgy, importPlugin = oldInstall, oldProviders, oldCLI, oldImport
installPlugin, pluginProviders, installAgy, importPlugin, agyCLIMissing = oldInstall, oldProviders, oldCLI, oldImport, oldMissing
})
return s
}
@@ -112,3 +122,68 @@ func TestMoveToAgyNeedsAccountsAndAnImport(t *testing.T) {
t.Fatalf("no import: %v, imported %v", err, s.texts)
}
}
// Where Google is reached only through Antigravity's own proxy (magpie in
// a container, with that proxy set on Antigravity alone), agy is
// installed and the accounts checked through it, and agy-cli keeps it for
// its requests: going direct, the install failed every time (huiqiang6 on
// X). Each account with a proxy of its own keeps that one.
func TestMoveToAgyGoesThroughAntigravitysProxy(t *testing.T) {
signIn(t)
writePluginAuth(t, map[string]any{
"antigravity": map[string]any{"type": "oauth", "refresh": "1//a|p", "accountId": "a@x.com"},
"antigravity#b": map[string]any{"type": "oauth", "refresh": "1//b|p", "accountId": "B@x.com"},
})
if err := store(file{Providers: []Provider{{ID: "antigravity", Proxy: "http://10.0.0.7:3128", AccountProxies: map[string]string{"b@x.com": "socks5://10.0.0.8:1080"}}}}); err != nil {
t.Fatal(err)
}
s := standInAgy(t, true)
agyCLIMissing = func(string) string { return "Antigravity CLI" }
if _, err := MoveToAgy(context.Background()); err != nil {
t.Fatal(err)
}
if !s.cliInstalled || s.cliVia != "http://10.0.0.7:3128" || s.importVia != "http://10.0.0.7:3128" {
t.Fatalf("agy installed (%v) through %q, imported through %q", s.cliInstalled, s.cliVia, s.importVia)
}
if got := ProxyOfLogin(agyCLIID, "a@x.com"); got != "http://10.0.0.7:3128" {
t.Fatalf("a@x.com goes through %q", got)
}
if got := ProxyOfLogin(agyCLIID, "b@x.com"); got != "socks5://10.0.0.8:1080" {
t.Fatalf("b@x.com goes through %q", got)
}
}
// A proxy the user chose in agy-cli stays its own; a moving account keeps
// Antigravity's as its own, as its requests went.
func TestMoveToAgyKeepsAgyCLIsOwnProxy(t *testing.T) {
signIn(t)
writePluginAuth(t, map[string]any{"antigravity": map[string]any{"type": "oauth", "refresh": "1//a|p", "accountId": "a@x.com"}})
if err := store(file{Providers: []Provider{{ID: "antigravity", Proxy: "http://10.0.0.7:3128"}, {ID: agyCLIID, Proxy: "direct"}}}); err != nil {
t.Fatal(err)
}
s := standInAgy(t, true)
agyCLIMissing = func(string) string { return "Antigravity CLI" }
if _, err := MoveToAgy(context.Background()); err != nil {
t.Fatal(err)
}
if ProxyOf(agyCLIID) != "direct" || s.cliVia != "direct" {
t.Fatalf("agy-cli's proxy %q, installed through %q", ProxyOf(agyCLIID), s.cliVia)
}
if got := ProxyOfLogin(agyCLIID, "a@x.com"); got != "http://10.0.0.7:3128" {
t.Fatalf("a@x.com goes through %q", got)
}
}
// With no proxy on Antigravity, agy-cli is left following the global one.
func TestMoveToAgyWithoutAProxyWritesNone(t *testing.T) {
signIn(t)
writePluginAuth(t, map[string]any{"antigravity": map[string]any{"type": "oauth", "refresh": "1//a|p", "accountId": "a@x.com"}})
s := standInAgy(t, true)
agyCLIMissing = func(string) string { return "Antigravity CLI" }
if _, err := MoveToAgy(context.Background()); err != nil {
t.Fatal(err)
}
if _, ok := storedPicks(agyCLIID); ok || s.cliVia != "" {
t.Fatalf("agy-cli written (%v), installed through %q", ok, s.cliVia)
}
}