providers: Antigravity CLI's own Gemini API key is found and imported (shenggxhz on X)

shenggxhz set agy up on an AI Studio key: "modelProvider": "gemini" in
~/.gemini/antigravity-cli/settings.json, GEMINI_API_KEY exported in the
shell. `agy models` then listed Gemini 4 Carbon and Hydrogen. magpie's
model refresh didn't, because the agy-cli subscription runs agy on its
Google sign-in, whose models are the account's in Antigravity, and the
key was used nowhere in magpie.

The Providers page now finds that key on its own. A new import source,
"Antigravity CLI" (readAgySettings), reads agy's settings.json and offers
the key as the Google Gemini preset, which lists the key's models from
the Gemini API. With GOOGLE_GEMINI_BASE_URL set, it uses that endpoint's
Gemini API instead. The variables are taken from magpie's environment,
else from the login shell's: a key exported only in .zshrc is found when
magpie is opened from the Dock. proc.GeminiKeyVars are only read
(LoginEnv), never set in magpie's environment. agy on its sign-in offers
nothing. With no key the entry shows as not importable, and a key that
points at magpie itself is refused.

Not changed: the agy-cli plugin's own `agy models` reads the same
setting and, with no key in magpie's environment, fails and keeps the
old list silently. Filed as magpie-community/plugins#1218.

Run:
- red on the old code: with the appReaders entry removed, all four
  TestAgyGeminiKey* tests fail (no "agy" source); green with it.
- a real login shell on mica, in a sandbox HOME (key exported only in
  .zshrc, MAGPIE env without it): DiscoverSources gives status new,
  preset google, the key read.
- real agy 1.5.9 in a sandbox HOME: API-key mode lists the Gemini 4
  models from a list built into agy; without the key it exits 1 with the
  modelProvider error.
- go vet (darwin, GOOS=linux, GOOS=windows) for proc and provider, plus
  darwin internal/gui; gofmt -l clean.
- full `go test -timeout 45m ./...` on Linux (magpie-desktop): every
  package ok except internal/usage's TestRequestStateKeptAcrossACatalogFetchedAgain
  (#6572, filed, untouched here) and the root, internal/cli and
  internal/gui, which don't build there (no gtk4/webkitgtk-6.0 dev
  packages). Those three, plus provider and proc, ran on mote (darwin): ok.
  A first full run on mica died of a full disk (117G of shared Go build
  cache), so it tested nothing.
- GUI on Linux, Chromium + WebKit: icon-tile, import-collision,
  import-opencode, provider-discovery, import-row and i18n-keys pass,
  92 of 93. The one red is icon-tile's dim-color (#6759, red on main).
- appIcon became a table so the agy icon fits app.js's code budget
  without raising it (TestCoreScriptBudget ok).

Not tried: a real AI Studio key or a real Gemini request; the GUI import
sheet in a browser (the source shows through the existing discovery and
import sheets, with Antigravity's icon); Windows (LoginEnv is "" there,
so only magpie's own environment is read).
This commit is contained in:
yetone
2026-11-16 17:59:26 +08:00
parent b5688404da
commit 1bfc6378c9
7 changed files with 248 additions and 6 deletions
+1
View File
@@ -44,6 +44,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi
| Accounts at once | `MaxAccounts *int` is the user's own count of keys or accounts taking requests at the same time: nil takes the plugin's (`PluginAtOnce`: `maxAccounts` on the plugin's auth hook or package.json `magpie`, host.js `atOnceOf`), 0 is no limit, saved clamped to 0..`MaxLimit`; a subscription's is kept with its picks (`withPicks`). `AtOnce()` answers the one in force, `SetAtOnce` sets it (`magpie provider at-once`, the editor's Accounts at once; GUI save leaves it as it was when the body has none). The gateway's use is in [gateway routing](gateway-routing.md) (`TestAtOnce`, `TestAtOnceSave`, `TestAtOnceCmd`). | [`concurrency.go`](../../internal/provider/concurrency.go) |
| A provider with no key | A provider of the user's own saves, imports and is `Ready` with no key when it is a preset with `NoKey` or its host is on this computer or the user's own network (`keyOptional`, `ownNetwork`): localhost, a loopback, private, link-local or carrier-grade NAT (Tailscale's 100.64/10) address, or a `.local` name, read from the URL alone with no lookup. A company's keyless relay at a LAN address is taken as a local server is (iSnow_999 on X: a Codex relay at http://<LAN IP>:8080 was left out of a CC Switch import as "it has no API key"); a keyless address on the internet still needs its key. With no key it is asked as one on 127.0.0.1 is: a Responses request carries no `Authorization`. | [`provider.go`](../../internal/provider/provider.go), [`importapps.go`](../../internal/provider/importapps.go), [`import_lan_test.go`](../../internal/provider/import_lan_test.go) |
| A key a provider | One vendor's keys saved a provider each — an app that keeps an entry a key, as CC Switch does, imported (yuluo_yx on X: "NVIDIA #001" to "#600" at one address, "Mistral #0001"…) — are folded into one provider with those keys (`FoldCopies` at start-up, `foldAdded` after `ImportFromApps`): hundreds of copies listed every model hundreds of times in every agent's picker and found group, and 3,000 made `/api/state` 86 MB. At start-up only copies by name are folded: a base name and that name with a number after it (`copyBase`: " #12", or `freeName`'s " 2"), one at least numbered; an import folds what it added whatever their names. Either way they must be alike in all but their key (`foldShape`: the provider with its id, name, keys and on/off left out), what the settings say of their models (`modelPrefs`) and where they are named (`foldRefs`: Visible, the agents' picked, hidden and ordered models, the groups, the providers falling back to them), so one key shown to one agent and another to another stays apart. Not folded: a subscription's, a hidden one, one without a key, Vertex, one with a StepFun sign-in of its own. The first on, in the providers' order, takes the rest in; its name becomes the base and its key is named its old name. Each other is a key in order, named its name, off if it was off (all off: the provider is off, its keys on); its id goes in `Was`, so its calls count with the provider by their key (`ProviderKeyID` is the key's fingerprint, unchanged) and a model picked by the old id still reaches it. Group members, rules, weights and fallbacks naming them name the provider once; their per-model settings and fetched lists go; balance and window history kept by their id moves to their key's name (`foldHistories`). A providers.json that doesn't parse is left alone. It runs at every start and writes nothing when there is nothing to fold. `TestFoldCopies`, `TestFoldCopiesIntoOneOn`, `TestFoldCopiesUnreadable`, `TestImportFoldsAKeyAnEntry`. | [`fold.go`](../../internal/provider/fold.go), [`importapps.go`](../../internal/provider/importapps.go), [`main.go`](../../internal/cli/main.go) |
| Antigravity CLI's own key | agy on a Gemini API key of the user's own (`"modelProvider": "gemini"` in `~/.gemini/antigravity-cli/settings.json`, `GEMINI_API_KEY` in its environment) lists the Gemini API's models, Gemini 4 Carbon and Hydrogen among them, while the agy-cli subscription runs agy on its Google sign-in (shenggxhz on X: agy listed Gemini 4, magpie's refresh didn't). The Providers page finds that key as an import source ("Antigravity CLI", `readAgySettings`) and offers it as the Google Gemini preset, or at `GOOGLE_GEMINI_BASE_URL`'s Gemini endpoint when it is set. The variables are magpie's environment's, else the login shell's (`proc.GeminiKeyVars`, read with `LoginEnv` and never set in magpie's environment), as a terminal's agy has them. agy on its sign-in offers nothing; with no key it is listed as not importable; at magpie itself it is refused, as every import is. The plugin's own listing reading that setting is plugins#1218. `TestAgyGeminiKeyIsFound`, `TestAgyGeminiKeyOnlyWhenAgyUsesIt`. | [`import_agy.go`](../../internal/provider/import_agy.go), [`path_other.go`](../../internal/proc/path_other.go) |
| A key's plan | A vendor whose plans take keys of their own (`PresetDef.KeyPlans`: zhipu, zai, stepfun, stepfun-cn, xiaomi, baidu-qianfan, tencent-cloud, huaweicloud, volcengine, siliconflow) lets each key say which of the preset's Regions it is for (`KeyAccount.Plan`, `Provider.KeyPlan` for the first; yckonnnn on X: a Volcengine pay-as-you-go key and an Agent Plan key in one provider). No plan, or the provider's own, is the provider's plan, as every key was before, and is stored as none (`SetKeyPlan`, the GUI's `keys/plan`). `WithKey` moves a key's copy to its plan's endpoints (`atKeyPlan`: chat, Responses, Anthropic, decide, key page, docs and catalog; a provider at a host of its own, a mirror or a test's fake vendor, keeps that host) and marks it a key's view (`keyView`), so nothing judges plans on it again. Only when the keys in use are on more than one plan (`PlansMixed`) does anything differ: the model list is each key's plan's (`fetch` goes to `fetchPerKey`; a plan with no list of its own, `planOnly`, is its preset list without a request, so Ark's Coding and Agent Plans ask nothing while pay as you go asks `/api/v3/models` with its own key); plan media (`planMedia`) are every plan's; each key serves its plan's models alone (`PlanServing`, read by the gateway's `perKeyBarred`; a model set for the key in `AccountModels` it serves); plan windows (`PlanQuotas`), Volcengine's and Tencent Cloud's access-key windows (`planViews`) and balances (`balance.go`) are read at each key's plan. Volcengine's keys carry nothing that says their plan, so none is guessed; Xiaomi's `tp-`, Tencent's `sk-tp-`, MiniMax's `sk-cp-` and Bailian's `sk-sp-` prefixes are documented in code but not used to set a plan. The editor's key row has a plan chip (`planPicker`, the app's own menu) while the provider has several keys or the key has a plan. Not done: a gateway key held to some keys of a mixed provider's video (`videoAsker`) may pick another key's plan; a mixed provider whose own plan has no balance source while a key's plan has is not read (`KeyBalances` reads each key at its own plan, and a key whose plan has none, a GLM Coding Plan's, gets no balance card beside its plan windows; Zhipu/Z.ai pay-as-you-go keys read `/api/biz/account/query-customer-account-report`, undocumented, at their own host, and SiliconFlow's card says its query is gone with the console to open, `siliconFlowRetired`, nam.haid on Discord); StepFun's plan windows are a sign-in per site, unchanged. `TestKeyPlanEndpoints`, `TestKeyPlanServing`, `TestKeyPlanOldConfigsUnchanged`, `TestSetKeyPlan`, `TestKeyPlanModelList`, `TestKeyPlanViews`, `key-plan.test.cjs`. | [`key_plans.go`](../../internal/provider/key_plans.go), [`keys.go`](../../internal/provider/keys.go), [`models.go`](../../internal/provider/models.go) |
| Google Vertex AI | `google-vertex` (`VertexPreset`, `IsVertex`) is a provider of the user's own, signed with Google credentials, or with one API key (express mode, below). `Provider.Vertex` holds `project`, `location` (`global`, `us`, `eu` or a region; `global` when empty), `credentials` (a file; empty for Application Default Credentials) and `impersonate` (a service account's email). Save refuses a list of keys (it takes one), then normalizes them (`Normal`) and checks each (`check`); `normalize` clears the four URLs and any key put in `providers.json` by hand, which stands in for neither a token nor a project and leaves the provider as found savable, so the provider's one address is `vertexBase`, `https://<host>/v1/projects/<project>/locations/<location>`, its host following the location (`vertexHost`). It speaks chat completions, Anthropic's Messages API and Gemini (`Speaks`, `Base`), each model one of them (`ListedAPIs`, which `ModelAPI` can't change for it): a Gemini model on generateContent at that address, a partner model (`VertexPartner`: a `publisher/model` id, as every one models.dev lists for `google-vertex` has, such as `deepseek-ai/deepseek-v4.1-flash-maas`) on Google's OpenAI-compatible chat completions at `<address>/endpoints/openapi`, and Claude (`VertexClaude`: an id starting `claude-` with no publisher, `claude-opus-5-5` or Vertex's dated `claude-sonnet-4-5@20250929`) on the Messages API at that address, each request at its model's own path (`VertexClaudeRequest`: `/publishers/anthropic/models/<model>:streamRawPredict` or `:rawPredict`, `count-tokens:rawPredict` for a count, `anthropic_version` `vertex-2023-10-16` in the body), as Anthropic's Vertex SDK in Claude Code asks it. The preset lists the current Claude models at `global` under the ids Claude Code gives them for Vertex. The provider's test asks Gemini alone, since a partner model or Claude answers only after the project turns it on in Model Garden. Each such model has its own test (`TestModel`, `TestVertexPartnerModels`, `TestVertexClaudeModels`), and a test as Codex is refused as it is for Claude Code. It is `Ready` once that address can be made (a project), or it has a key (express mode), never from an account; until then the app, `magpie providers` and the TUI say it needs a project, and `magpie provider <id>` says how to give it one. `hasEndpoint` counts it as a provider of the user's own, not a subscription's picks. **Express mode** (Langanpaibian on X): a `Key` and no project (`VertexExpress`) is asked at `https://aiplatform.googleapis.com/v1/publishers/google/models/<model>:streamGenerateContent`, the key in `x-goog-api-key` (`Sign`), no Google token read or minted. Google serves Gemini models alone there, so `Base(Chat)` and `Base(Anthropic)` are empty and the list drops partner and Claude models (`vertexExpressModels`). A key with a project is asked at the project's address, signed by the key. `Vertex.BaseURL` (any `/v1` stripped, `vertexRootOf`) replaces Google's host for a keyed provider, such as a proxy; without a key it is refused at Save and dropped on load, so a Google token never goes to an address the user typed. An import link naming it is refused (`ParseImport`): its project and credentials are the user's own, which no link hands over. `Sign` refuses any other address and sets the bearer token before the user's `Headers`; `AuthHeaders` gives it no key header (a key is `x-goog-api-key`, set by `Sign`). Its models are its location's (`vertexModels`, in `planModels`): the preset has `NoList`, because Vertex AI has no list that says what a location serves. The lists are in the [reference](../reference.md#google-vertex-ai). | [`vertex.go`](../../internal/provider/vertex.go), [`provider.go`](../../internal/provider/provider.go), [`account.go`](../../internal/provider/account.go), [`rename.go`](../../internal/provider/rename.go), [`models.go`](../../internal/provider/models.go), [`importurl.go`](../../internal/provider/importurl.go) |
| Vertex AI tokens | `vertexCredentialsFile` finds the credentials as Google's libraries find Application Default Credentials: the provider's `credentials`, else the file `GOOGLE_APPLICATION_CREDENTIALS` names, else `application_default_credentials.json` in gcloud's folder (`CLOUDSDK_CONFIG`, else `~/.config/gcloud`, `%APPDATA%\gcloud` on Windows); a `~/` that starts any of them is the home. `mint` reads three kinds: `authorized_user` (a refresh-token grant), `service_account` (an RS256 JWT, RFC 7523: `signed`) and gcloud's `impersonated_service_account`, whose `source_credentials` are minted and traded at IAM Credentials, along its `delegates`, for the account its `service_account_impersonation_url` names (`impersonationURL`: the token never goes to that URL's host). With `impersonate` set, the token those give is traded at IAM Credentials' `generateAccessToken` for a `cloud-platform` token of that account's, as gcloud's `--impersonate-service-account` does (`impersonateFor`); the credentials' account needs `roles/iam.serviceAccountTokenCreator` on it, which the 403 names. `vertexTokens` keeps one token per file and impersonated account, in memory only; requests made together mint it once, and those that waited through a mint that failed are given its error rather than each minting in turn (`mints`, `failed`). A mint cut short because its own request was given up on fails none of them: the next one mints. It is minted again within `vertexRefreshLead` (5 minutes) of expiry, or when the file's size or modification time has changed (gcloud signed in again). One mint, every exchange included, gets `vertexMintWait` (30 seconds). The file is only read. | [`vertex.go`](../../internal/provider/vertex.go), [`signin.go`](../../internal/provider/signin.go) |
+4 -3
View File
@@ -10740,9 +10740,10 @@ async function openImportApps(discovered) {
renderProviders();
}
// appIcon is an import source's logo; Claude Code, Codex and OpenCode have
// their marks among the vendor icons rather than an app tile of their own.
const appIcon = (id) => id === "claude-code" ? "icons/claudecode-color.svg" : id === "codex" ? "icons/codex-color.svg" : id === "opencode" ? "icons/opencode.svg" : `icons/app-${id}.png`;
// appIcon is an import source's logo; Claude Code, Codex, OpenCode and
// Antigravity's CLI have their marks among the vendor icons rather than an
// app tile of their own.
const appIcon = (id) => "icons/" + ({ "claude-code": "claudecode-color.svg", codex: "codex-color.svg", opencode: "opencode.svg", agy: "antigravity-color.svg" }[id] || `app-${id}.png`);
function renderImportApps(ia) {
const ed = el("div", "editor new importapps");
+13 -3
View File
@@ -119,14 +119,24 @@ var ProxyVars = []string{"HTTP_PROXY", "http_proxy", "HTTPS_PROXY", "https_proxy
// the Dock didn't see (timwangdev on X). Only read (LoginEnvKnown).
var RegistryVars = []string{"BUN_CONFIG_REGISTRY", "NPM_CONFIG_REGISTRY", "npm_config_registry"}
// GeminiKeyVars are the Gemini API variables the login shell is asked for
// beside them: Antigravity's CLI on a key of the user's own
// ("modelProvider": "gemini") reads its key and endpoint from the
// environment a terminal gives it, which magpie opened from the Dock
// doesn't have, and the Providers page offers that key (provider's
// readAgySettings). Only read (LoginEnv), never set in magpie's
// environment: the programs magpie starts don't get them.
var GeminiKeyVars = []string{"GEMINI_API_KEY", "GOOGLE_GEMINI_BASE_URL"}
// shellVars are the variables shellProbe asks for, in its order. Claude
// Code's provider switches (agentenv.ClaudeProviders) are only read, as the
// proxy variables are.
var shellVars = slices.Concat(agentenv.Vars, ProxyVars, agentenv.ClaudeProviders, RegistryVars)
var shellVars = slices.Concat(agentenv.Vars, ProxyVars, agentenv.ClaudeProviders, RegistryVars, GeminiKeyVars)
// LoginEnv is the value a terminal opened now has for k, one of
// agentenv.Vars, ProxyVars or agentenv.ClaudeProviders: the login shell's, asked as LoginPath asks
// and with it; "" when the shell has none for it or doesn't say.
// agentenv.Vars, ProxyVars, agentenv.ClaudeProviders, RegistryVars or
// GeminiKeyVars: the login shell's, asked as LoginPath asks and with it;
// "" when the shell has none for it or doesn't say.
func LoginEnv(k string) string {
LoginPath()
login.Lock()
+4
View File
@@ -89,6 +89,10 @@ func isolate(t testing.TB) {
t.Cleanup(func() { downloadClaudeCode = oldDownload })
// the machine's own devin, if it has one, is no test's
DevinExecutable = func() string { return "" }
// nor the login shell's Gemini key (agy's, import_agy.go)
oldAgyEnv := agyLoginEnv
agyLoginEnv = func(string) string { return "" }
t.Cleanup(func() { agyLoginEnv = oldAgyEnv })
forgetClaudeCredential()
forgetClaudeStatus()
devinStatus.forget()
+84
View File
@@ -0,0 +1,84 @@
package provider
import (
"encoding/json"
"errors"
"os"
"path/filepath"
"strings"
"github.com/tidwall/jsonc"
"github.com/yetone/magpie/internal/edit"
"github.com/yetone/magpie/internal/proc"
)
// Antigravity's CLI, agy, on a Gemini API key of the user's own: with
// "modelProvider": "gemini" in ~/.gemini/antigravity-cli/settings.json it
// skips the Google sign-in and asks the Gemini API with GEMINI_API_KEY
// from its environment (GOOGLE_GEMINI_BASE_URL for another endpoint), and
// `agy models` lists the Gemini API's models, Gemini 4 Carbon and Hydrogen
// among them. magpie's agy-cli subscription runs agy on its Google
// sign-in, whose models are the account's in Antigravity, so that key is
// served nowhere in magpie (shenggxhz on X: agy listed Gemini 4, magpie's
// refresh didn't). The key is a Gemini API key, and the Providers page
// offers it as the Google Gemini provider, which serves those models.
//
// The variables are agy's environment: magpie's own, else the login
// shell's (proc.GeminiKeyVars), as a terminal's agy has them. They are
// only read.
// agyLoginEnv is what a terminal opened now has for a variable (a var for
// tests).
var agyLoginEnv = proc.LoginEnv
func agySettingsPath() string {
home, _ := os.UserHomeDir()
return filepath.Join(home, ".gemini", "antigravity-cli", "settings.json")
}
// agyEnv is a variable as agy started in a terminal has it.
func agyEnv(k string) string {
if v := strings.TrimSpace(os.Getenv(k)); v != "" {
return v
}
return strings.TrimSpace(agyLoginEnv(k))
}
func readAgySettings(path string) ([]AppImport, error) {
raw, err := edit.Read(path)
if err != nil {
return nil, err
}
if len(strings.TrimSpace(string(raw))) == 0 {
return nil, nil
}
var s map[string]any
if err := json.Unmarshal(jsonc.ToJSON(edit.TrimBOM(raw)), &s); err != nil {
return nil, errors.New("agy's settings.json: " + err.Error())
}
// agy on its Google sign-in: the agy-cli subscription's
if mp, _ := s["modelProvider"].(string); !strings.EqualFold(strings.TrimSpace(mp), "gemini") {
return nil, nil
}
it := AppImport{Ref: "gemini-api-key", From: "settings.json"}
var eps endpoints
if base := agyEnv("GOOGLE_GEMINI_BASE_URL"); base != "" {
eps.gemini = geminiCLIBase(base)
} else {
pr := Preset("google")
eps.chat, eps.responses, eps.anthropic = pr.Chat, pr.Responses, pr.Anthropic
}
key := agyEnv("GEMINI_API_KEY")
if key == "" {
// GEMINI_API_KEY isn't set: agy itself refuses to start
it.Provider, it.Skip = Provider{Name: "Google Gemini"}, "it has no API key"
return []AppImport{it}, nil
}
p, skip := imported("Google Gemini", key, eps, nil)
if skip != "" {
it.Provider, it.Skip = Provider{Name: "Google Gemini"}, skip
return []AppImport{it}, nil
}
it.Provider = p
return []AppImport{it}, nil
}
+141
View File
@@ -0,0 +1,141 @@
package provider
import (
"os"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/settings"
)
func agyImportHome(t *testing.T, settings string) {
t.Helper()
isolate(t)
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home) // Windows
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming")) // Windows: never the real Alma
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
t.Setenv("GEMINI_API_KEY", "")
t.Setenv("GOOGLE_GEMINI_BASE_URL", "")
if settings != "" {
dir := filepath.Join(home, ".gemini", "antigravity-cli")
if err := os.MkdirAll(dir, 0o700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "settings.json"), []byte(settings), 0o600); err != nil {
t.Fatal(err)
}
}
}
// loginShell makes the login shell answer vars, as a terminal's agy has
// them while magpie, opened from the Dock, doesn't.
func loginShell(t *testing.T, vars map[string]string) {
t.Helper()
agyLoginEnv = func(k string) string { return vars[k] }
}
func agyDiscovered(t *testing.T) (AppSource, bool) {
t.Helper()
for _, s := range DiscoverSources() {
if s.ID == "agy" {
return s, true
}
}
return AppSource{}, false
}
// shenggxhz on X: agy set up on an AI Studio key ("modelProvider":
// "gemini" in its settings.json, GEMINI_API_KEY exported in the shell)
// lists Gemini 4 Carbon and Hydrogen, and nothing in magpie served that
// key. The Providers page finds it by itself, as the Google Gemini
// provider, and imports it as one.
func TestAgyGeminiKeyIsFound(t *testing.T) {
agyImportHome(t, "{\n // the reporter's\n \"modelProvider\": \"gemini\"\n}\n")
loginShell(t, map[string]string{"GEMINI_API_KEY": "AIzaSy-test-key"})
s, ok := agyDiscovered(t)
if !ok || !s.Found || s.Error != "" || len(s.Items) != 1 {
t.Fatalf("agy's key isn't offered: %+v", s)
}
it := s.Items[0]
if it.Skip != "" || it.Off != "" || it.Status != "new" {
t.Fatalf("offered as %+v, want new", it)
}
if p := it.Provider; p.Preset != "google" || p.Catalog != "google" || p.Key != "AIzaSy-test-key" {
t.Fatalf("provider %+v, want Google Gemini on the key", p)
}
added, err := ImportFromApps([]AppPick{{Source: "agy", Ref: it.Ref}})
if err != nil || len(added) != 1 {
t.Fatalf("import: %v %v", added, err)
}
var got *Provider
for _, p := range load().Providers {
if p.Preset == "google" {
got = &p
}
}
if got == nil || got.Key != "AIzaSy-test-key" {
t.Fatalf("after import: %+v", load().Providers)
}
if s, _ := agyDiscovered(t); len(s.Items) != 1 || s.Items[0].Status != "same" {
t.Fatalf("after import it is still offered: %+v", s.Items)
}
}
// magpie's own environment comes first, as agy started from it has it.
func TestAgyGeminiKeyFromMagpiesEnv(t *testing.T) {
agyImportHome(t, `{"modelProvider": "gemini"}`)
loginShell(t, nil)
t.Setenv("GEMINI_API_KEY", "AIzaSy-env-key")
s, _ := agyDiscovered(t)
if len(s.Items) != 1 || s.Items[0].Provider.Key != "AIzaSy-env-key" {
t.Fatalf("%+v", s.Items)
}
}
// agy on its Google sign-in is the agy-cli subscription's, not a key's:
// nothing is offered, a GEMINI_API_KEY in the shell for another program
// included. Nor is a key with no setting, or one at magpie itself.
func TestAgyGeminiKeyOnlyWhenAgyUsesIt(t *testing.T) {
for name, c := range map[string]struct {
settings string
vars map[string]string
skip bool
}{
"signed in": {`{"model": "gemini-4-argon-high"}`, map[string]string{"GEMINI_API_KEY": "AIzaSy-other"}, false},
"other provider": {`{"modelProvider": "vertex"}`, map[string]string{"GEMINI_API_KEY": "AIzaSy-other"}, false},
"empty": {" ", map[string]string{"GEMINI_API_KEY": "AIzaSy-other"}, false},
"no key": {`{"modelProvider": "gemini"}`, nil, true},
"magpie": {`{"modelProvider": "gemini"}`, map[string]string{"GEMINI_API_KEY": "mp-agy", "GOOGLE_GEMINI_BASE_URL": "magpie"}, true},
} {
t.Run(name, func(t *testing.T) {
agyImportHome(t, c.settings)
if c.vars["GOOGLE_GEMINI_BASE_URL"] == "magpie" {
c.vars["GOOGLE_GEMINI_BASE_URL"] = "http://" + settings.GatewayAddr()
}
loginShell(t, c.vars)
s, _ := agyDiscovered(t)
if c.skip {
if len(s.Items) != 1 || s.Items[0].Skip == "" {
t.Fatalf("want one skipped: %+v", s.Items)
}
return
}
if len(s.Items) != 0 {
t.Fatalf("offered: %+v", s.Items)
}
})
}
}
// A relay agy is pointed at is imported at its Gemini endpoint.
func TestAgyGeminiKeyAtRelay(t *testing.T) {
agyImportHome(t, `{"modelProvider": "gemini"}`)
loginShell(t, map[string]string{"GEMINI_API_KEY": "sk-relay", "GOOGLE_GEMINI_BASE_URL": "https://relay.example.com/gemini"})
s, _ := agyDiscovered(t)
if len(s.Items) != 1 || s.Items[0].Skip != "" || s.Items[0].Provider.Gemini != "https://relay.example.com/gemini/v1beta" {
t.Fatalf("%+v", s.Items)
}
}
+1
View File
@@ -83,6 +83,7 @@ var appReaders = []struct {
asked bool
}{
{"alma", "Alma", almaPath, readAlma, false},
{"agy", "Antigravity CLI", agySettingsPath, readAgySettings, false},
{"cc-switch", "CC Switch", ccSwitchPath, readCCSwitch, false},
{"claude-code", "Claude Code", claudeSettingsPath, readClaudeSettings, false},
{"codex", "Codex", codexConfigPath, readCodexConfig, false},