YujunT46308 on X: "antigravity 接入 magpie 会导致模型的 effort 不可选".
Antigravity's picker (main.js served by its 2.29.0 language server)
offers effort only by grouping catalog entries named "<name> (Low)",
"(Medium)", "(High)", "(XHigh)", "(Max)" under one row with an effort
submenu, two levels or more. magpie's listSource catalog listed each
model once, so no model of magpie's had an effort control.
Now /v1/models?format=antigravity lists a model with two or more of
those levels once a level, "<id>:<level>" named "<name> (<Level>)".
The app sends the chosen entry's id, and the gateway's existing
":level" suffix handling sends that level upstream, ahead of the row's
pick and of the app's own reasoning_effort (low whatever was chosen,
in a 2.29.0 run). models.defaultModelId names one of those entries
(gateway.AntigravityModel: the row's effort fitted, else medium, else
the lowest), since an id the catalog doesn't list starts the app on
its first model; Sync moves a file written before onto a level. The
row's effort sets the start level and still applies to models with
fewer than two levels. The model field shows the id without the level.
Run:
- Real Antigravity 2.29.0 language server + its UI in Playwright
Chromium on mote, sandbox HOME, magpie built from this tree serving
a fake upstream listing g3 with low/medium/high: `magpie provider
add`, `magpie antigravity magpie/up/g3` wrote defaultModelId
"up/g3:medium"; the picker shows one "g3 · up" row with Low, Medium,
High (starts on Medium); picking High and sending "ping" reached the
upstream as model g3 with reasoning_effort "high" (the app's title
call went at medium, the start level). `magpie antigravity default`
left {} as before.
- go test -tags nogui ./internal/agent ./internal/gateway -run
Antigravity on mote; gofmt -l; go vet of both packages;
GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...
- Full suite on mote, go test -tags nogui -timeout 45m ./... at this
commit on origin/main 53b2773d7 (load ~500): 92 packages ok,
internal/agent and internal/gateway among them; internal/plugin red
at TestHostEndedEndsWhatItsPluginStarted/own_end ("the plugin never
started its child", #5515, already filed, commented), ok alone after.
- Rebased on origin/main 8d9254729 (dsh, Fable 5.2, site): go build,
go vet of agent and gateway, and their Antigravity tests again, ok.
Broken by hand: listing every model once (antigravityLevels(nil))
turns TestAntigravityCatalog red; not writing the level into
defaultModelId (Set, Sync and the effort Set) turns
TestAntigravityEffort red at all four checks. TestAntigravityAgentEffort's
new ":low over the row's high" case guards the suffix order, which
was already so.
Not tried: a real Antigravity account against a real vendor, the
packaged desktop app itself (the UI was its bundled main.js served by
its own language server), and the Windows and Linux apps.
Reported-by: YujunT46308 (X)
133 lines
5.0 KiB
Go
133 lines
5.0 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Antigravity's app lists the gateway's models by id and has no level of
|
|
// its own to pick (MDX-Tom, #4838): with an effort picked for it in
|
|
// magpie, its requests for one of Antigravity's families of levels go out
|
|
// as the variant at that level, told that level; with none picked they go
|
|
// as before, and another agent's requests never take its pick.
|
|
func TestAntigravityAgentEffort(t *testing.T) {
|
|
fresh(t)
|
|
logins := []map[string]any{{
|
|
"agent": "antigravity", "user": "a@example.com", "on": true,
|
|
"auth": map[string]any{"access_token": "a@example.com", "refresh_token": "ref-a", "project": "p1",
|
|
"expiry_date": time.Now().Add(time.Hour).UnixMilli()},
|
|
}}
|
|
dir := filepath.Dir(provider.Path())
|
|
if err := os.MkdirAll(dir, 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "logins.json"), mustJSON(logins), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// the family as Antigravity lists it: High first, then Low
|
|
list := `{"models":{
|
|
"gemini-3.8-flash-high":{"displayName":"Gemini 3.8 Flash (High)","maxTokens":1048576,"quotaInfo":{"remainingFraction":1}},
|
|
"gemini-3.8-flash-low":{"displayName":"Gemini 3.8 Flash (Low)","maxTokens":1048576,"quotaInfo":{"remainingFraction":1}}},
|
|
"agentModelSorts":[{"displayName":"Recommended","groups":[{"modelIds":["gemini-3.8-flash-high","gemini-3.8-flash-low"]}]}]}`
|
|
old := http.DefaultClient
|
|
http.DefaultClient = &http.Client{Transport: countTransport(func(r *http.Request) (*http.Response, error) {
|
|
var body string
|
|
switch {
|
|
case strings.HasSuffix(r.URL.Path, "latest-arm64-mac.yml"):
|
|
body = "version: 2.9.1\n"
|
|
case strings.Contains(r.URL.Path, ":loadCodeAssist"):
|
|
body = `{"currentTier":{"id":"standard-tier"},"cloudaicompanionProject":"p1"}`
|
|
case strings.Contains(r.URL.Path, ":fetchAvailableModels"):
|
|
body = list
|
|
default:
|
|
return nil, fmt.Errorf("unexpected request to %s", r.URL)
|
|
}
|
|
return &http.Response{StatusCode: 200, Header: make(http.Header), Body: io.NopCloser(strings.NewReader(body))}, nil
|
|
})}
|
|
t.Cleanup(func() { http.DefaultClient = old })
|
|
p, _ := provider.Find("antigravity")
|
|
if _, err := p.Fetch(t.Context()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var mu sync.Mutex
|
|
var sent []byte
|
|
s := New()
|
|
s.client = &http.Client{Transport: countTransport(func(r *http.Request) (*http.Response, error) {
|
|
b, _ := io.ReadAll(r.Body)
|
|
mu.Lock()
|
|
sent = b
|
|
mu.Unlock()
|
|
rec := httptest.NewRecorder()
|
|
rec.Header().Set("Content-Type", "text/event-stream")
|
|
io.WriteString(rec, sse(`data: {"response":{"candidates":[{"content":{"role":"model","parts":[{"text":"ok"}]},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":10,"candidatesTokenCount":3}}}`))
|
|
return rec.Result(), nil
|
|
})}
|
|
// the id the envelope went out under and the level it was told
|
|
askedFor := func(agent, model string) (string, string) {
|
|
t.Helper()
|
|
postFrom(t, s, agent, "/v1/chat/completions", `{"model":"`+model+`","stream":false,"messages":[{"role":"user","content":"hi"}]}`)
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
var env struct {
|
|
Model string `json:"model"`
|
|
Request struct {
|
|
GenerationConfig struct {
|
|
ThinkingConfig struct {
|
|
ThinkingLevel string `json:"thinkingLevel"`
|
|
} `json:"thinkingConfig"`
|
|
} `json:"generationConfig"`
|
|
} `json:"request"`
|
|
}
|
|
if err := json.Unmarshal(sent, &env); err != nil {
|
|
t.Fatalf("%v: %s", err, sent)
|
|
}
|
|
return env.Model, env.Request.GenerationConfig.ThinkingConfig.ThinkingLevel
|
|
}
|
|
asked := func(agent string) (string, string) {
|
|
t.Helper()
|
|
return askedFor(agent, "antigravity/gemini-3.8-flash")
|
|
}
|
|
|
|
base, baseLevel := asked("antigravity")
|
|
if base == "" {
|
|
t.Fatal("no request went out")
|
|
}
|
|
for _, c := range []struct{ pick, model, level string }{
|
|
{"high", "gemini-3.8-flash-high", "high"},
|
|
{"low", "gemini-3.8-flash-low", "low"},
|
|
} {
|
|
if err := provider.SetAgentEffort("antigravity", c.pick); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if m, l := asked("antigravity"); m != c.model || l != c.level {
|
|
t.Errorf("picked %s: went as %s at %q, want %s at %q", c.pick, m, l, c.model, c.level)
|
|
}
|
|
// another agent's request goes as it asks
|
|
if m, l := asked("opencode"); m != base || l != baseLevel {
|
|
t.Errorf("picked %s for Antigravity, opencode's went as %s at %q, want %s at %q", c.pick, m, l, base, baseLevel)
|
|
}
|
|
}
|
|
// the level the app's own picker sent, as the model's ":low" suffix
|
|
// (its catalog lists one model a level), outranks the row's pick
|
|
if m, l := askedFor("antigravity", "antigravity/gemini-3.8-flash:low"); m != "gemini-3.8-flash-low" || l != "low" {
|
|
t.Errorf("picked high, asked :low in the app: went as %s at %q, want gemini-3.8-flash-low at \"low\"", m, l)
|
|
}
|
|
if err := provider.SetAgentEffort("antigravity", ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if m, l := asked("antigravity"); m != base || l != baseLevel {
|
|
t.Errorf("taken off: went as %s at %q, want %s at %q", m, l, base, baseLevel)
|
|
}
|
|
}
|