Files
magpie/internal/provider/migrate_antigravity_test.go
T
yetone 6886da1ca9 provider: Antigravity moves onto @magpie-community/opencode-antigravity-auth
The plugin (plugins e35aa928, 0.1.0 on the dist branch) ports the
built-in's sign-in, project set-up, models and levels, request shaping,
errors and usage pools. This adds its mover, so the hourly MoveRetiring
moves every Antigravity account onto it, with no way back:

- out: each saved antigravity login becomes an oauth sign-in, refresh
  "<refresh token>|<project>", access, expires and the email.
- back: splits the refresh again and writes token, expiry and project
  into the built-in login, clearing Lapsed and Refused.
- antigravity_pool.go says PLUGIN-SERVED. The built-in code stays until
  every account has gone over; Gemini CLI and the agy agent stay built in.
- AGENTS.md lists Antigravity in the moved table.

Run:
- Real move (WSL magpie-desktop, sandbox HOME holding only a copy of the
  owner's live Antigravity login, nogui build of this tree):
  `magpie plugins move antigravity` installed the plugin, wrote state
  "plugin" with the backup; `serve` on 127.0.0.1:3476 listed 11
  antigravity models; gemini-3-flash and claude-sonnet-4-6 answered
  "pong" through the plugin; /v1/magpie/quotas read the plan
  ("Antigravity Starter Quota") and each model's window plus both 7-day
  pools. The copied login was deleted after.
- TestAntigravityMover (out and back, lapsed and own accounts),
  TestMovedBuiltinsSayTheirPlugin: pass on WSL. The test's b-account
  check was red until back cleared Refused.
- go vet -tags nogui ./... and GOOS=windows go vet ./... clean;
  go test -tags nogui -timeout 45m ./... on WSL (no gtk4 there) at this
  head: 92 packages ok, provider/plugin/gateway's own tests included.
  Three reds, none on a path this touches:
  - internal/agent TestGrokInstalled: WSL binfmt interop, red alone at
    0f94acc99 too (#3548).
  - internal/cli timed out in TestGroupMembersFast's PATH lookup (an
    os.Stat stuck ~44m, #5234, commented); passes alone here and on main.
  - internal/gateway TestUnroutedSlowBodyNotCutOff 504 "held 0s" under
    the full run; passes alone here (-count=3) and on main (#5953).
- After rebasing onto 4d95d81ea, at this head: vet (linux nogui and
  windows) clean, internal/provider and internal/plugin ok whole,
  internal/gateway -run 'TestPlugin|TestUnrouted' ok.
- TestPluginToldTheEffort red with host.js's MAGPIE_ONLY entry removed
  by hand (the vendor saw X-Magpie-Effort), green restored.

Not tried: the plugin's browser sign-in end to end (import and the moved
account were); a Mac or Windows run (mote unreachable). The min is 0.1.0
from the dist branch: npm has no version yet, its first publish needs
the owner (no NPM_TOKEN in the plugins repo).
2026-11-10 20:16:44 +08:00

72 lines
3.4 KiB
Go

package provider
import (
"encoding/json"
"testing"
)
// Antigravity's accounts go to its plugin as "<refresh token>|<project>"
// with the access token, its expiry and the email; one with no project yet
// goes with none for the plugin to ask Code Assist. Back, a renewed sign-in
// is written into the account it came from, its project kept when the
// plugin's has none, and one signed in since is added.
func TestAntigravityMover(t *testing.T) {
claudeHome(t)
auth := func(a googleAuth) json.RawMessage {
b, _ := json.Marshal(a)
return b
}
saveLogins(t,
savedLogin{Agent: "antigravity", User: "a@x.com", Auth: auth(googleAuth{RefreshToken: "ra", AccessToken: "aa", Expiry: 1900000000000, Project: "proj-a"}), On: true, First: true, Plan: "Google AI Pro"},
savedLogin{Agent: "antigravity", User: "b@x.com", Auth: auth(googleAuth{RefreshToken: "rb"}), Lapsed: "refused", Refused: revokedPrefix + "rb"},
// Gemini CLI's accounts are no Antigravity's
savedLogin{Agent: "gemini", User: "g@x.com", Auth: auth(googleAuth{RefreshToken: "rg"}), On: true})
ForgetAccounts()
ms := movingOf(t, "antigravity")
if len(ms) != 2 {
t.Fatalf("moving %+v", ms)
}
a := ms["a@x.com"]
if !a.First || !a.On || a.Lapsed || a.Plan != "Google AI Pro" || a.Auth["type"] != "oauth" || a.Auth["refresh"] != "ra|proj-a" ||
a.Auth["access"] != "aa" || a.Auth["expires"] != int64(1900000000000) || a.Auth["accountId"] != "a@x.com" {
t.Fatalf("a: %+v", a)
}
if b := ms["b@x.com"]; b.First || !b.Lapsed || b.Auth["refresh"] != "rb|" || b.Auth["accountId"] != "b@x.com" {
t.Fatalf("b: %+v", b)
}
// a renewed, with the project the plugin found for it
ls, user, err := movers["antigravity"].back(readLogins(), "a@x.com", map[string]any{"type": "oauth", "refresh": "ra2|proj-a2", "access": "aa2", "expires": float64(1950000000000), "accountId": "a@x.com"})
if err != nil || user != "a@x.com" {
t.Fatalf("back a: %q %v", user, err)
}
var got googleAuth
l := loginOf(t, ls, "antigravity", "a@x.com")
if json.Unmarshal(l.Auth, &got) != nil || got.RefreshToken != "ra2" || got.AccessToken != "aa2" || got.Expiry != 1950000000000 || got.Project != "proj-a2" || l.Project != "proj-a2" || l.Plan != "Google AI Pro" {
t.Fatalf("a back: %+v %s", l, l.Auth)
}
// b back with no project: the one it had stays, and it is lapsed no more
ls, _, err = movers["antigravity"].back(ls, "b@x.com", map[string]any{"type": "oauth", "refresh": "rb2|", "access": "ab2", "accountId": "b@x.com"})
if err != nil {
t.Fatal(err)
}
if l := loginOf(t, ls, "antigravity", "b@x.com"); l.Lapsed != "" || l.Refused != "" || func() error { got = googleAuth{}; return json.Unmarshal(l.Auth, &got) }() != nil || got.RefreshToken != "rb2" || got.Project != "" {
t.Fatalf("b back: %+v %s", l, l.Auth)
}
// one signed in through the plugin since, named by its accountId
n := len(ls)
ls, user, err = movers["antigravity"].back(ls, "", map[string]any{"type": "oauth", "refresh": "rc|proj-c", "access": "ac", "accountId": "c@x.com"})
if err != nil || user != "c@x.com" || len(ls) != n+1 {
t.Fatalf("back c: %q %v %d", user, err, len(ls))
}
if l := loginOf(t, ls, "antigravity", "c@x.com"); l.Project != "proj-c" {
t.Fatalf("c back: %+v", l)
}
for _, bad := range []map[string]any{{"type": "oauth", "refresh": "|p", "accountId": "d@x.com"}, {"type": "oauth", "refresh": "rd"}} {
if _, _, err := movers["antigravity"].back(ls, "", bad); err == nil {
t.Fatalf("back took %v", bad)
}
}
}