Files
plugins/packages/antigravity/fake.mjs
T
yetone e35aa928ad antigravity 0.1.0: Antigravity with a Google account, ported from magpie's built-in
Signs in with Google (Antigravity's client, PKCE, loopback) or imports a
refresh token / account-manager export, sets up the Code Assist project
(loadCodeAssist, onboardUser on the default tier), lists the account's
models with level variants, and sends every request through
v1internal:streamGenerateContent in the app's envelope, with the
built-in's request shaping (system-prompt cloak, tool ids and results,
schema flattening, Claude and Gemini rules), its error mapping (turned-away
429 -> 400 unapproved channel, 404 model, refused refresh -> 401 expired)
and its usage windows and pools.

A stream's last chunk is an empty text part; sent back in the next turn,
Claude refuses it ("text: Field required"). Both the whole-reply reader and
the request shaper drop it.

Run:
- bun test packages/antigravity on mote: 78 pass, 0 fail.
- bun scripts/check.mjs antigravity: registry.json ok, antigravity ok.
- Real account (the built-in's saved Google account, read only, sandbox
  HOME): model list; stream and generateContent on gemini-3.8-flash; the
  effort header picking -low; claude-sonnet-4-6, claude-opus-4-6-thinking,
  gpt-oss-120b-medium all answer; a Claude Code system prompt to Gemini
  answers 200 (cloak); an unknown model 404; usage gives plan, model
  windows and the Gemini and Claude & GPT 7-day pools; a tool call round
  trip on Claude Sonnet, Opus thinking, Gemini and GPT-OSS.
- Broken by hand: without the empty-text drop the new shape test and the
  generateContent test go red, and the real Claude round trip answered 400.

Not carried over (README): the 6h rest of a turned-away account, Google
Search grounding and image models, countTokens (404, magpie estimates),
sending the system prompt uncloaked, multi-account import, models.dev
names. Not tried: the browser sign-in end to end (the import path was).
2026-11-10 17:30:21 +08:00

45 lines
1.9 KiB
JavaScript

// A fake Google for the tests: OAuth's token endpoint, the update
// manifest and Code Assist's methods, each answered from `replies`.
import { _internal } from "./index.mjs"
export const real = globalThis.fetch
export function reset() {
for (const m of [_internal.tokens, _internal.projects, _internal.lists, _internal.refused]) m.clear()
_internal.ver.v = "3.1.4"
_internal.ver.at = Date.now()
_internal.onboardPoll = 1
}
export function fake(replies = {}) {
const seen = []
globalThis.fetch = async (input, init = {}) => {
const url = String(input)
const body = typeof init.body === "string" ? init.body : ""
const headers = Object.fromEntries(Object.entries(init.headers ?? {}).map(([k, v]) => [k.toLowerCase(), v]))
const m = /\/v1internal:([a-zA-Z]+)/.exec(url)
const name = m ? m[1] : url.startsWith("https://oauth2.googleapis.com/token") ? "token" : url.includes("userinfo") ? "who" : url
seen.push({ name, url, body, headers, json: (() => { try { return JSON.parse(body) } catch { return undefined } })() })
let r = replies[name]
if (typeof r === "function") r = r(seen[seen.length - 1], seen)
if (r === undefined) {
if (name === "token") r = { access_token: "tok-new", expires_in: 3600 }
else if (name === "loadCodeAssist") r = { cloudaicompanionProject: "ag-proj", currentTier: { id: "free-tier", name: "Antigravity" } }
else if (name === "fetchAvailableModels") r = { models: {} }
else if (name === "retrieveUserQuotaSummary") r = { groups: [] }
else return new Response("not found", { status: 404 })
}
if (r instanceof Response) return r
return new Response(typeof r === "string" ? r : JSON.stringify(r), { status: 200, headers: { "content-type": "application/json" } })
}
return seen
}
export const auth = (project = "ag-proj") => ({
type: "oauth",
access: "tok",
refresh: "rt-ag|" + project,
expires: Date.now() + 3600_000,
accountId: "ag@example.com",
})