Files
magpie/internal/gateway/restricted_held_test.go
T
yetone 9cd5f36521 antigravity: retired, the built-in and its plugin both ask Google nothing; Antigravity is served by your own agy (agy-cli)
Google bans accounts it sees on Code Assist through Antigravity's own
client. magpie offered that route twice, the built-in and
@magpie-community/opencode-antigravity-auth, and anyone who picked
Antigravity in magpie took it by default (the owner, 11-15: 全部下线,改推
agy-cli).

- retiredBuiltins has antigravity. googleLogins lists no account of a
  subscription its plugin serves, so no list, usage read, quota read or
  request goes to Google with a built-in Antigravity account (the usage
  loop in subscription_usage.go had no gate of its own). The mover reads
  googleSavedLogins, so saved accounts still move.
- The mover's min is 0.2.0 (on the plugins dist index, b8bf5a57): that
  version sends nothing, answers every request 410 ModelDeprecated
  ("model has been retired", which modelRetired reads, so a group asks its
  next member) naming Antigravity (local agy CLI) and
  `magpie plugin add @magpie-community/opencode-agy-cli-auth`, and turns
  sign-in away. It left the plugins registry (003a38ff).
- Gemini CLI's route, on the same code, is unchanged.
- The built-in's code stays for now (shared with Gemini CLI); taking it
  out is #6723. Its 123 tests serve it again for their run through
  provider.AntigravityBuiltinForTest(), a counter BuiltinRetired reads.
- README (en, zh) and site docs subscriptions (en, zh, ja) point to
  Antigravity through the user's own agy CLI. AGENTS.md and
  provider-plugins.md say why and that neither route comes back.

What users lose: Antigravity with Google accounts signed in to magpie, and
rotating several of them. agy-cli serves the one account the user's agy is
signed in to, and needs agy installed.

Tests: TestRetiredAntigravityAsksGoogleNothing saves an Antigravity
account and checks googleLogins/googleAccountOf give nothing, the mover
still carries it, usage has no Antigravity card and the fake Google was
asked nothing, and Gemini's account still lists. Broken by hand (the
PluginServes gate removed from googleLogins): red,
"googleLogins(antigravity) = 1 accounts".

Run (mote/mica, at this change on origin/main 5bd41301b): gofmt -l clean;
go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./... and go build ./... ok; go test ./internal/gateway/ (1245s),
./internal/agent/ (419s), ./internal/provider/ (253s) ok on mica;
after rebasing on origin/main f362d3b9a: go test ./internal/provider/
(160s) and ./internal/plugin/ (184s) ok on mica.
Earlier at this change minus the test opt-ins: sessions, usage, library,
gui ok (mica). internal/cli's TestEveryRouteHasACommandOrIsNamed is red at
5bd41301b itself (/api/warm-all, #6724), not from this change.
Not run: the full ./... suite (mote and mica each had another session's
full or GUI suite); the GUI suite (no app.js change); a real move of a
built-in Antigravity account onto 0.2.0.

Plugins side: magpie-community/plugins 003a38ff (antigravity 0.2.0) and
f9155256 (agy-cli 0.1.56, comments only).
2026-11-15 12:14:48 +08:00

165 lines
6.9 KiB
Go

package gateway
import (
"io"
"net/http"
"net/http/httptest"
"slices"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// agyTurn sends one chat turn for an Antigravity model to s.
func agyTurn(s *Server) (int, string) {
rec := httptest.NewRecorder()
s.Handler().ServeHTTP(rec, httptest.NewRequest("POST", "/v1/chat/completions", strings.NewReader(`{"model":"antigravity/gemini-3.8-flash","stream":false,"messages":[{"role":"user","content":"hi"}]}`)))
return rec.Code, rec.Body.String()
}
// Every account Google suspended, resting as restricted, is not asked
// again while it rests: the agent is given Google's refusal at once, and
// the rest isn't taken anew, so it ends when it would. Before, restLast
// and probeOne kept one resting account for each request, and every
// request was sent to one of them and refused (leowang on Discord: two
// suspended Antigravity accounts, 23 and 22 tries, none answered). Lifted
// on the Routing page, the account is asked again.
func TestSuspendedAccountsNotAskedWhileTheyRest(t *testing.T) {
t.Cleanup(provider.AntigravityBuiltinForTest()) // the retired built-in route
var asked []string
s, _ := antigravityGroupFor(t, []string{"u1@example.com", "u2@example.com"}, "gemini-3.8-flash", func(w http.ResponseWriter, r *http.Request) {
asked = append(asked, strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer "))
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusForbidden)
io.WriteString(w, antigravitySuspended)
})
if code, out := agyTurn(s); code != 403 || !strings.Contains(out, "violation of Terms of Service") || !slices.Equal(asked, []string{"u1@example.com", "u2@example.com"}) {
t.Fatalf("first turn: %d %s, asked %v", code, out, asked)
}
r1, ok1 := restOf("antigravity@u1@example.com")
r2, ok2 := restOf("antigravity@u2@example.com")
if !ok1 || !ok2 || r1.Why != failRestricted || r2.Why != failRestricted {
t.Fatalf("rests %+v %v, %+v %v", r1, ok1, r2, ok2)
}
for n := 2; n <= 6; n++ {
asked = nil
code, out := agyTurn(s)
if code != 403 || !strings.Contains(out, "violation of Terms of Service") || len(asked) != 0 {
t.Fatalf("turn %d: %d %s, asked %v", n, code, out, asked)
}
if tr := lastRoute(s).Tries; len(tr) == 0 || tr[len(tr)-1].Fail != failRestricted {
t.Fatalf("turn %d's tries %+v", n, tr)
}
}
if r, _ := restOf("antigravity@u1@example.com"); !r.Until.Equal(r1.Until) {
t.Fatalf("u1's rest moved from %v to %v", r1.Until, r.Until)
}
if r, _ := restOf("antigravity@u2@example.com"); !r.Until.Equal(r2.Until) {
t.Fatalf("u2's rest moved from %v to %v", r2.Until, r.Until)
}
// an appeal went through for u1: it is asked again, and u2 still not
if !s.Unrest("antigravity@u1@example.com") {
t.Fatal("u1's rest not lifted")
}
asked = nil
if code, _ := agyTurn(s); code != 403 || !slices.Equal(asked, []string{"u1@example.com"}) {
t.Fatalf("after the lift: %d, asked %v", code, asked)
}
}
// The same for any vendor's account restriction (here magpie's words for
// ZCode's risk control, on a ChatGPT account): the lone account resting
// as restricted is not asked by the next requests.
func TestRestrictedLoneAccountNotAskedWhileItRests(t *testing.T) {
codexSignedIn(t)
var tried []string
chatgptRefusing(t, &tried, riskBlocked)
s := New()
for n := 1; n <= 3; n++ {
code, body := postAs(t, s, "", `{"model":"codex/gpt-5.5","messages":[{"role":"user","content":"hi"}]}`)
if code != http.StatusForbidden || !strings.Contains(body, provider.ZCodeRestrictedHint) || strings.Join(tried, ",") != "acct-1" {
t.Fatalf("request %d: %d %s; asked %v", n, code, body, tried)
}
}
}
// A refusal of the request's content is not the account's: it rests
// nobody, and the next request asks the same account again.
func TestContentRefusalStillAsksTheAccount(t *testing.T) {
t.Cleanup(provider.AntigravityBuiltinForTest()) // the retired built-in route
n := 0
s, _ := antigravityGroupFor(t, []string{"u1@example.com"}, "gemini-3.8-flash", func(w http.ResponseWriter, r *http.Request) {
n++
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
io.WriteString(w, `{"error":{"code":400,"message":"`+highRiskRefusal+`","status":"INVALID_ARGUMENT"}}`)
})
for want := 1; want <= 3; want++ {
if code, out := agyTurn(s); code < 400 || n != want {
t.Fatalf("turn %d: %d %s, asked %d times", want, code, out, n)
}
}
if r, ok := restOf("antigravity@u1@example.com"); ok {
t.Fatalf("a content refusal rests the account: %+v", r)
}
}
// A conversation kept strictly on its account (Stays: Strict) whose
// account Google suspended is given the refusal again without asking, and
// the account's rest isn't taken anew by each such turn: it ends when it
// would, rather than never while the conversation goes on.
func TestSuspendedStrictConversationKeepsItsRest(t *testing.T) {
t.Cleanup(provider.AntigravityBuiltinForTest()) // the retired built-in route
var asked []string
suspended := false
s, _ := antigravityGroupFor(t, []string{"u1@example.com", "u2@example.com"}, "gemini-3.8-flash", func(w http.ResponseWriter, r *http.Request) {
asked = append(asked, strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer "))
if suspended {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusForbidden)
io.WriteString(w, antigravitySuspended)
return
}
w.Header().Set("Content-Type", "text/event-stream")
io.WriteString(w, sse(`data: {"response":{"candidates":[{"content":{"role":"model","parts":[{"text":"answered"}]},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":10,"candidatesTokenCount":3}}}`))
})
p, err := provider.Find("antigravity")
if err != nil {
t.Fatal(err)
}
p.Affinity = provider.AffinityStrict
if err := provider.Save(*p); err != nil {
t.Fatal(err)
}
turn := func() (int, string) {
rec := httptest.NewRecorder()
req := httptest.NewRequest("POST", "/v1/chat/completions", strings.NewReader(`{"model":"antigravity/gemini-3.8-flash","stream":false,"messages":[{"role":"user","content":"hi"}]}`))
req.Header.Set("x-session-id", "s1")
s.Handler().ServeHTTP(rec, req)
return rec.Code, rec.Body.String()
}
if code, out := turn(); code != 200 || len(asked) != 1 {
t.Fatalf("first turn: %d %s, asked %v", code, out, asked)
}
kept := asked[0]
suspended, asked = true, nil
if code, out := turn(); code != 403 || !slices.Equal(asked, []string{kept}) {
t.Fatalf("suspended turn: %d %s, asked %v", code, out, asked)
}
first, ok := restOf("antigravity@" + kept)
if !ok || first.Why != failRestricted {
t.Fatalf("%s rests %+v %v", kept, first, ok)
}
for n := 3; n <= 5; n++ {
asked = nil
code, out := turn()
if code != 403 || !strings.Contains(out, "violation of Terms of Service") || len(asked) != 0 {
t.Fatalf("turn %d: %d %s, asked %v", n, code, out, asked)
}
if r, _ := restOf("antigravity@" + kept); !r.Until.Equal(first.Until) {
t.Fatalf("turn %d moved the rest from %v to %v", n, first.Until, r.Until)
}
}
}