AnxForever's Google AI Pro account (loadCodeAssist: current tier
free-tier, paid tier g1-pro-tier, project aicode-consumers) gets
"Request contains an invalid argument." for fetchAvailableModels with
entitlement.userTier g1-pro-tier, and ends up with the catalog's
models. magpie already asks once more with {project} alone after that
refusal, but the log didn't say so, and when that second request also
failed nothing was logged at all: antigravityPoolModels kept the
account's last list silently whenever another account (here the
reporter's free one) succeeded.
What changed (logging only; the requests are unchanged):
- a refused tier's line now ends "; asking with <next> next" or
"; asking with none next";
- a failure of the request with no entitlement is logged with the
endpoint and project;
- the pool logs each enabled account whose refresh failed, with the
error and how many models it keeps from before.
Why the request is not changed: no authoritative source for the value
the official client puts in entitlement.user_tier for a paid account
was found. The Antigravity app is not installed on this Mac. The
extracted language-server schema (jkfujinami/antigravity-grpc-schemas,
model_configs.proto / entitlement.proto) confirms the field shape magpie
sends: FetchAvailableModelsRequest{project=1, request_id=2,
entitlement=9 {user_tier string}, location=3}; the LS also has
License{userTier, tierDisplayName, projectId, location} and
SelectLicense, so the tier it names may come with its own project or
location, but nothing public shows the values. Every open-source client
that serves Pro accounts sends {"project": ...} only, on
daily-cloudcode-pa: CLIProxyAPI (sdk/cliproxy/antigravity_models.go),
sub2api (backend/internal/pkg/antigravity/client.go),
Antigravity-Manager (src-tauri/src/modules/quota.rs, which notes the
list is the same for free and Pro accounts), syrtis. magpie's fallback
already sends exactly that, so a guessed tier value is not added.
TestAntigravityProInvalidTierAsksWithoutOne is built from the
reporter's log lines: the first fetch is
{entitlement:{userTier:g1-pro-tier}, project:aicode-consumers} and gets
400 INVALID_ARGUMENT, the second is {project:aicode-consumers} and its
list is used; then, with the second refused too, the account keeps its
3 models and both failures are in the log. Removing the pool's log
line turns it red.
Run: gofmt -l; go vet -tags nogui ./internal/provider (darwin,
GOOS=linux, GOOS=windows); go test -tags nogui -count=1 ./internal/provider;
go test -tags nogui -timeout 40m ./... under a temp HOME: every
package ok but internal/provider, where only
TestAccountDiscoveryOffReadsNoSignIn failed ("the watch didn't answer a
read: {}{}"). It fails the same way at every run from this agent's
checkout under .claude/worktrees, and passes at this same commit and at
origin/main from a checkout under the scratchpad, where the whole
internal/provider package passes too; it touches no Antigravity code.
Not verified: no Google AI Pro account was available. Whether the
reporter's second request ({project} only) succeeds or fails, and why,
is not known; this commit makes the next release's log say which.
242 lines
10 KiB
Go
242 lines
10 KiB
Go
package provider
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// A Google AI Pro account as loadCodeAssist answers it (CLIProxyAPI
|
|
// #6186): on standard-tier, paying for g1-pro-tier, in aicode-consumers.
|
|
const proLoad = `{
|
|
"currentTier":{"id":"standard-tier","name":"Antigravity","userDefinedCloudaicompanionProject":true,"usesGcpTos":true},
|
|
"paidTier":{"id":"g1-pro-tier","name":"Google AI Pro","availableCredits":[{"creditType":"GOOGLE_ONE_AI","minimumCreditAmountForUsage":"50"}]},
|
|
"cloudaicompanionProject":"aicode-consumers",
|
|
"ineligibleTiers":[{"tierId":"free-tier","reasonCode":"VALIDATION_REQUIRED","validationErrorMessage":"Verify your account to continue."}]}`
|
|
|
|
const (
|
|
geminiOnly = `{"models":{
|
|
"gemini-3.8-flash-high":{"displayName":"Gemini 3.8 Flash (High)","maxTokens":1048576,"quotaInfo":{"remainingFraction":1}},
|
|
"gemini-2.5-pro":{"displayName":"Gemini 2.5 Pro"},
|
|
"tab_flash_lite_preview":{},
|
|
"chat_20706":{}}}`
|
|
withClaude = `{"models":{
|
|
"gemini-3.8-flash-high":{"displayName":"Gemini 3.8 Flash (High)","maxTokens":1048576,"quotaInfo":{"remainingFraction":1}},
|
|
"claude-opus-5-5":{"displayName":"Claude Opus 5.5","maxTokens":250000,"quotaInfo":{"remainingFraction":1}},
|
|
"claude-sonnet-5-5":{"displayName":"Claude Sonnet 5.5","maxTokens":250000,"disabled":true,"quotaInfo":{"remainingFraction":1}},
|
|
"tab_flash_lite_preview":{}}}`
|
|
tierRefused = `{"error":{"code":400,"message":"Precondition check failed.","status":"FAILED_PRECONDITION"}}`
|
|
)
|
|
|
|
// Code Assist as it serves an account on tier has: the plan's models when
|
|
// asked with that tier named, Code Assist Standard's without one, and a
|
|
// 400 for a tier the account hasn't.
|
|
func tierModels(has string) func(map[string]any) (int, string) {
|
|
return func(body map[string]any) (int, string) {
|
|
e, _ := body["entitlement"].(map[string]any)
|
|
switch tier, _ := e["userTier"].(string); tier {
|
|
case "":
|
|
return 200, geminiOnly
|
|
case has:
|
|
return 200, withClaude
|
|
default:
|
|
return 400, tierRefused
|
|
}
|
|
}
|
|
}
|
|
|
|
func captureLog(t *testing.T) *bytes.Buffer {
|
|
t.Helper()
|
|
var buf bytes.Buffer
|
|
old := log.Writer()
|
|
log.SetOutput(&buf)
|
|
t.Cleanup(func() { log.SetOutput(old) })
|
|
return &buf
|
|
}
|
|
|
|
func antigravityModelIDs(t *testing.T, agent string) []string {
|
|
t.Helper()
|
|
ms, err := googleLogins(agent)[0].acct.models(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var ids []string
|
|
for _, m := range ms {
|
|
ids = append(ids, m.ID)
|
|
}
|
|
slices.Sort(ids)
|
|
return ids
|
|
}
|
|
|
|
// A Google AI Pro account's Antigravity has Claude (Discord: magpie 0.1.770
|
|
// listed a Pro account's models without any, while Antigravity's picker
|
|
// had Claude 5.5): fetchAvailableModels names the plan the account pays for
|
|
// in entitlement.userTier, as Antigravity's language server does, and the
|
|
// log says what Google answered and what magpie left out.
|
|
func TestAntigravityProAccountNamesItsTier(t *testing.T) {
|
|
f := &fakeGoogle{load: proLoad, modelsFor: tierModels("g1-pro-tier")}
|
|
googleSandbox(t, f)
|
|
buf := captureLog(t)
|
|
auth := googleAuth{AccessToken: "tok", RefreshToken: "rt-pro", Expiry: time.Now().Add(time.Hour).UnixMilli()}
|
|
if err := addGoogleLogin("antigravity", "pro@example.com", "", auth); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, want := antigravityModelIDs(t, "antigravity"), []string{"claude-opus-5-5", "claude-sonnet-5-5", "gemini-3.8-flash-high"}; !slices.Equal(got, want) {
|
|
t.Fatalf("models %v, want %v", got, want)
|
|
}
|
|
if len(f.fetches) != 1 || fmt.Sprint(f.fetches[0]["entitlement"]) != "map[userTier:g1-pro-tier]" || f.fetches[0]["project"] != "aicode-consumers" {
|
|
t.Errorf("asked %v", f.fetches)
|
|
}
|
|
out := buf.String()
|
|
for _, w := range []string{
|
|
`loadCodeAssist at ` + codeAssistProd + `: current tier standard-tier (Antigravity) gcp-tos, paid tier g1-pro-tier (Google AI Pro), project "aicode-consumers", ineligible free-tier (VALIDATION_REQUIRED: Verify your account to continue.)`,
|
|
`fetchAvailableModels at ` + codeAssistDaily + ` (antigravity/hub/3.1.4 `,
|
|
`project "aicode-consumers", current tier "standard-tier", paid tier "g1-pro-tier", entitlement "g1-pro-tier"): 4 models, 3 kept; left out 1 not for chat [tab_flash_lite_preview], 0 completion-only []; disabled [claude-sonnet-5-5]; Claude [claude-opus-5-5 claude-sonnet-5-5]`,
|
|
} {
|
|
if !strings.Contains(out, w) {
|
|
t.Errorf("log lacks %q:\n%s", w, out)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A tier Google won't take from the account is left out: the next is
|
|
// tried, then none, and the refusal is logged.
|
|
func TestAntigravityTierRefusedFallsBack(t *testing.T) {
|
|
f := &fakeGoogle{load: proLoad, modelsFor: tierModels("standard-tier")}
|
|
googleSandbox(t, f)
|
|
buf := captureLog(t)
|
|
auth := googleAuth{AccessToken: "tok", RefreshToken: "rt-pro2", Expiry: time.Now().Add(time.Hour).UnixMilli()}
|
|
addGoogleLogin("antigravity", "pro@example.com", "", auth)
|
|
if got := antigravityModelIDs(t, "antigravity"); !slices.Contains(got, "claude-opus-5-5") {
|
|
t.Fatalf("models %v", got)
|
|
}
|
|
var sent []string
|
|
for _, b := range f.fetches {
|
|
sent = append(sent, fmt.Sprint(b["entitlement"]))
|
|
}
|
|
if w := "map[userTier:g1-pro-tier] map[userTier:standard-tier]"; strings.Join(sent, " ") != w {
|
|
t.Errorf("sent %v, want %s", sent, w)
|
|
}
|
|
if !strings.Contains(buf.String(), "with entitlement g1-pro-tier: ") || !strings.Contains(buf.String(), "Precondition check failed.") {
|
|
t.Errorf("log:\n%s", buf.String())
|
|
}
|
|
|
|
// none taken: asked without one, as before
|
|
f.modelsFor = tierModels("g1-ultra-tier")
|
|
resetGoogleState()
|
|
if got := antigravityModelIDs(t, "antigravity"); !slices.Equal(got, []string{"gemini-3.8-flash-high"}) {
|
|
t.Fatalf("models %v", got)
|
|
}
|
|
if n := len(f.fetches); n != 5 || f.fetches[n-1]["entitlement"] != nil {
|
|
t.Errorf("asked %v", f.fetches)
|
|
}
|
|
}
|
|
|
|
// A free account names no tier (Google refuses "free-tier" there), as
|
|
// before; one whose project was kept with its sign-in still has its tiers
|
|
// asked for, so a Pro account imported with its project names its plan.
|
|
func TestAntigravityTierFreeAndKeptProject(t *testing.T) {
|
|
f := &fakeGoogle{
|
|
load: `{"currentTier":{"id":"free-tier","name":"Antigravity"},"paidTier":{"id":"free-tier","name":"Antigravity Starter Quota"},"cloudaicompanionProject":"aicode-consumers"}`,
|
|
modelsFor: tierModels("g1-pro-tier"),
|
|
}
|
|
googleSandbox(t, f)
|
|
captureLog(t)
|
|
auth := googleAuth{AccessToken: "tok", RefreshToken: "rt-free", Expiry: time.Now().Add(time.Hour).UnixMilli()}
|
|
addGoogleLogin("antigravity", "free@example.com", "", auth)
|
|
antigravityModelIDs(t, "antigravity")
|
|
if len(f.fetches) != 1 || f.fetches[0]["entitlement"] != nil {
|
|
t.Errorf("a free account asked %v", f.fetches)
|
|
}
|
|
|
|
f.load, f.fetches = proLoad, nil
|
|
resetGoogleState()
|
|
if err := SetGoogleProject("antigravity", "free@example.com", "kept-proj"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := antigravityModelIDs(t, "antigravity"); !slices.Contains(got, "claude-opus-5-5") {
|
|
t.Fatalf("models %v", got)
|
|
}
|
|
if len(f.fetches) != 1 || f.fetches[0]["project"] != "kept-proj" || fmt.Sprint(f.fetches[0]["entitlement"]) != "map[userTier:g1-pro-tier]" {
|
|
t.Errorf("asked %v", f.fetches)
|
|
}
|
|
}
|
|
|
|
// #1553 (AnxForever): a Google AI Pro account that loadCodeAssist has on
|
|
// free-tier, paying for g1-pro-tier, in aicode-consumers. Google answered
|
|
// its fetchAvailableModels with g1-pro-tier named "Request contains an
|
|
// invalid argument." magpie then asks again with {project} alone, which is
|
|
// all the open-source clients that serve Pro accounts send (CLIProxyAPI,
|
|
// sub2api, Antigravity-Manager), and lists what that gives. Should that
|
|
// fail too, the log says so and the account keeps the list it had.
|
|
func TestAntigravityProInvalidTierAsksWithoutOne(t *testing.T) {
|
|
const load = `{"currentTier":{"id":"free-tier","name":"Antigravity"},
|
|
"paidTier":{"id":"g1-pro-tier","name":"Google AI Pro"},
|
|
"cloudaicompanionProject":"aicode-consumers"}`
|
|
const invalid = `{"error":{"code":400,"message":"Request contains an invalid argument.","status":"INVALID_ARGUMENT"}}`
|
|
plain := 200
|
|
f := &fakeGoogle{load: load, modelsFor: func(body map[string]any) (int, string) {
|
|
if body["entitlement"] != nil {
|
|
return 400, invalid
|
|
}
|
|
if plain != 200 {
|
|
return plain, `{"error":{"code":503,"message":"The service is currently unavailable.","status":"UNAVAILABLE"}}`
|
|
}
|
|
return 200, withClaude
|
|
}}
|
|
googleSandbox(t, f)
|
|
buf := captureLog(t)
|
|
auth := googleAuth{AccessToken: "tok", RefreshToken: "rt-1553", Expiry: time.Now().Add(time.Hour).UnixMilli()}
|
|
if err := addGoogleLogin("antigravity", "paid@gmail.com", "", auth); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, _ := googleAccountOf("antigravity")
|
|
ms, err := p.Fetch(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(ms) != 3 || !slices.ContainsFunc(ms, func(m catalog.Model) bool { return m.ID == "claude-opus-5-5" }) {
|
|
t.Fatalf("models %v", ms)
|
|
}
|
|
f.mu.Lock()
|
|
asked := fmt.Sprint(f.fetches)
|
|
f.mu.Unlock()
|
|
if asked != "[map[entitlement:map[userTier:g1-pro-tier] project:aicode-consumers] map[project:aicode-consumers]]" {
|
|
t.Errorf("asked %s", asked)
|
|
}
|
|
for _, w := range []string{
|
|
`antigravity paid@gmail.com: loadCodeAssist at ` + codeAssistProd + `: current tier free-tier (Antigravity), paid tier g1-pro-tier (Google AI Pro), project "aicode-consumers"`,
|
|
`antigravity paid@gmail.com: fetchAvailableModels with entitlement g1-pro-tier: Antigravity: Request contains an invalid argument.; asking with none next`,
|
|
`project "aicode-consumers", current tier "free-tier", paid tier "g1-pro-tier", entitlement ""): 4 models, 3 kept`,
|
|
} {
|
|
if !strings.Contains(buf.String(), w) {
|
|
t.Errorf("log lacks %q:\n%s", w, buf.String())
|
|
}
|
|
}
|
|
|
|
// asked without one and refused too: logged, the list it had is kept
|
|
f.mu.Lock()
|
|
plain = 503
|
|
f.mu.Unlock()
|
|
buf.Reset()
|
|
ms, err = p.Fetch(context.Background())
|
|
if err != nil || len(ms) != 3 {
|
|
t.Fatalf("kept: %v, %v", ms, err)
|
|
}
|
|
for _, w := range []string{
|
|
`antigravity paid@gmail.com: fetchAvailableModels at ` + codeAssistDaily + ` (project "aicode-consumers", no entitlement): Antigravity: The service is currently unavailable.`,
|
|
`antigravity paid@gmail.com: models not refreshed: Antigravity: The service is currently unavailable.; keeping the 3 it listed before`,
|
|
} {
|
|
if !strings.Contains(buf.String(), w) {
|
|
t.Errorf("log lacks %q:\n%s", w, buf.String())
|
|
}
|
|
}
|
|
}
|