Files
plugins/packages/antigravity/schema.test.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

124 lines
7.9 KiB
JavaScript

// plainSchema, held to magpie's built-in (internal/gateway/codeassist.go)
// by its tests: codeassist_test.go, antigravity_array_items_test.go,
// antigravity_enum_blank_test.go and antigravity_root_union_test.go.
import { expect, test } from "bun:test"
import { _internal } from "./index.mjs"
const { plainSchema } = _internal
const ps = (s) => plainSchema(JSON.parse(s))
test("a tool's schema as the built-in sends it", () => {
const s = `{"$schema":"http://json-schema.org/draft-07/schema#","type":"object",
"properties":{"path":{"type":["string","null"],"format":"uri"},"mode":{"const":"r"},"opts":{"$ref":"#/$defs/Opts"},
"n":{"anyOf":[{"type":"integer"},{"type":"null"}]}},"required":["path","gone"],"additionalProperties":false,
"$defs":{"Opts":{"type":"object","properties":{"deep":{"type":"boolean","default":false}}}}}`
expect(ps(s)).toEqual(
JSON.parse(`{"properties":{"mode":{"enum":["r"]},"n":{"nullable":true,"type":"integer"},"opts":{"properties":{"deep":{"type":"boolean"}},"type":"object"},"path":{"nullable":true,"type":"string"}},"required":["path"],"type":"object"}`),
)
})
test("every array has items, however deep", () => {
const got = ps(`{"type":"object","$defs":{"Tags":{"type":"array","description":"tags"}},
"properties":{
"grid":{"type":"array","items":{"type":"array"}},
"maybe":{"anyOf":[{"type":"null"},{"type":"array"}]},
"one":{"oneOf":[{"type":"array","minItems":1},{"type":"string"}]},
"both":{"allOf":[{"type":"object","properties":{"list":{"type":"array"}}}]},
"tags":{"$ref":"#/$defs/Tags"},
"opt":{"type":["array","null"]},
"kept":{"type":"array","items":{"type":"string"}},
"deep":{"type":"object","properties":{"rows":{"type":"array","items":{"type":"object","properties":{"cells":{"type":"array"}}}}}}
}}`)
expect(got).toEqual(
JSON.parse(`{"type":"object","properties":{
"grid":{"type":"array","items":{"type":"array","items":{}}},
"maybe":{"type":"array","items":{},"nullable":true},
"one":{"type":"array","items":{},"minItems":1},
"both":{"type":"object","properties":{"list":{"type":"array","items":{}}}},
"tags":{"type":"array","items":{},"description":"tags"},
"opt":{"type":"array","items":{},"nullable":true},
"kept":{"type":"array","items":{"type":"string"}},
"deep":{"type":"object","properties":{"rows":{"type":"array","items":{"type":"object","properties":{"cells":{"type":"array","items":{}}}}}}}
}}`),
)
expect(JSON.stringify(ps(`{"type":"object","properties":{"s":{"type":"string"}}}`))).not.toContain("items")
})
test("blank enum values are dropped (#5235)", () => {
const out = ps(
`{"type":"object","properties":{"StatusMessage":{"type":"object","properties":{"operationStatus":{"allOf":[{"enum":["processing","warning","error",""],"type":"string","x-enum-varnames":["A","B","C","D"]}],"description":"'', 'error', 'processing'","example":"error"}}},` +
`"blank":{"type":"string","enum":[""," "]},"c":{"type":"string","const":""},"n":{"enum":["a",1,""]}}}`,
)
const op = out.properties.StatusMessage.properties.operationStatus
expect(op.type).toBe("string")
expect(op.enum).toEqual(["processing", "warning", "error"])
for (const k of ["blank", "c", "n"]) expect(out.properties[k].enum).toBeUndefined()
expect(JSON.stringify(out)).not.toContain('""')
})
const rg = `{"type":"object","properties":{"pattern":{"type":"string"},"cursor":{"type":"string"}},"oneOf":[{"required":["pattern"],"not":{"required":["cursor"]}},{"required":["cursor"],"not":{"required":["pattern"]}}]}`
test.each([
["root oneOf", rg, `{"type":"object","properties":{"pattern":{"type":"string"},"cursor":{"type":"string"}}}`],
["root anyOf", `{"type":"object","properties":{"a":{"type":"string"}},"anyOf":[{"required":["a"]},{"not":{"required":["a"]}}]}`, `{"type":"object","properties":{"a":{"type":"string"}}}`],
["properties only, no type", `{"properties":{"a":{"type":"string"}},"oneOf":[{"required":["a"]}]}`, `{"type":"object","properties":{"a":{"type":"string"}},"required":["a"]}`],
[
"nested oneOf",
`{"type":"object","properties":{"q":{"type":"object","description":"query","properties":{"pattern":{"type":"string"},"cursor":{"type":"string"}},"oneOf":[{"required":["pattern"],"not":{"required":["cursor"]}},{"required":["cursor"],"not":{"required":["pattern"]}}]}},"required":["q"]}`,
`{"type":"object","properties":{"q":{"type":"object","description":"query","properties":{"pattern":{"type":"string"},"cursor":{"type":"string"}}}},"required":["q"]}`,
],
[
"nested anyOf",
`{"type":"object","properties":{"q":{"type":"object","properties":{"a":{"type":"integer"}},"anyOf":[{"required":["a"]},{"type":"null"}]}}}`,
`{"type":"object","properties":{"q":{"type":"object","properties":{"a":{"type":"integer"}},"required":["a"],"nullable":true}}}`,
],
[
"branches add fields",
`{"type":"object","properties":{"kind":{"type":"string"}},"required":["kind"],"oneOf":[{"properties":{"kind":{"const":"a"},"x":{"type":"string"}},"required":["kind","x"]},{"properties":{"kind":{"const":"b"},"y":{"type":"number"}},"required":["kind","y"]}]}`,
`{"type":"object","properties":{"kind":{"type":"string"},"x":{"type":"string"},"y":{"type":"number"}},"required":["kind"]}`,
],
[
"every branch requires it",
`{"type":"object","properties":{"a":{"type":"string"},"b":{"type":"string"}},"anyOf":[{"required":["a","b"]},{"required":["a"]}]}`,
`{"type":"object","properties":{"a":{"type":"string"},"b":{"type":"string"}},"required":["a"]}`,
],
[
"root allOf",
`{"type":"object","properties":{"a":{"type":"string"}},"required":["a"],"allOf":[{"properties":{"b":{"type":"string"}},"required":["b"]},{"not":{"required":["c"]}}]}`,
`{"type":"object","properties":{"a":{"type":"string"},"b":{"type":"string"}},"required":["a","b"]}`,
],
[
"nested allOf",
`{"type":"object","properties":{"q":{"type":"object","properties":{"a":{"type":"string"}},"allOf":[{"required":["a"]}]}}}`,
`{"type":"object","properties":{"q":{"type":"object","properties":{"a":{"type":"string"}},"required":["a"]}}}`,
],
[
"allOf beside oneOf",
`{"type":"object","properties":{"a":{"type":"string"}},"allOf":[{"properties":{"b":{"type":"string"}}}],"oneOf":[{"required":["a"]},{"required":["b"]}]}`,
`{"type":"object","properties":{"a":{"type":"string"},"b":{"type":"string"}}}`,
],
["typed scalar", `{"type":"string","description":"d","anyOf":[{"format":"date"},{"format":"uuid"}]}`, `{"type":"string","description":"d"}`],
[
"bare union still its first branch",
`{"type":"object","properties":{"v":{"description":"value","anyOf":[{"type":"null"},{"type":"integer"},{"type":"string"}]}}}`,
`{"type":"object","properties":{"v":{"type":"integer","description":"value","nullable":true}}}`,
],
])("a union keeps its own shape: %s", (_, input, want) => {
expect(ps(input)).toEqual(JSON.parse(want))
})
test("a reference to itself, or deeper than 32, ends", () => {
const out = ps(`{"type":"object","properties":{"node":{"$ref":"#/$defs/Node"}},"$defs":{"Node":{"type":"object","properties":{"next":{"$ref":"#/$defs/Node"},"v":{"type":"string"}}}}}`)
expect(out.properties.node.properties.next).toEqual({ type: "object" })
expect(out.properties.node.properties.v).toEqual({ type: "string" })
expect(ps(`{"type":"object","properties":{"me":{"$ref":"#"}}}`).properties.me).toEqual({ type: "object" })
expect(ps(`{"type":"object","properties":{"x":{"$ref":"#/$defs/Gone"}}}`).properties.x).toEqual({ type: "object" })
})
test("exclusive bounds and tuples", () => {
expect(ps(`{"type":"number","exclusiveMinimum":1,"exclusiveMaximum":9,"maximum":5}`)).toEqual({ type: "number", minimum: 1, maximum: 5 })
expect(ps(`{"type":"array","prefixItems":[{"type":"string"},{"type":"string"}]}`)).toEqual({ type: "array", items: { type: "string" } })
expect(ps(`{"type":"array","prefixItems":[{"type":"string"},{"type":"number"}]}`)).toEqual({ type: "array", items: {} })
expect(ps(`{"type":"array","items":false}`)).toEqual({ type: "array", items: {}, maxItems: 0 })
})