A new conversation spawned `agy acp` and waited for initialize before session/new. Now, after a conversation starts, the plugin warms one spare agy for the same account, binary, folder, flags and environment: spawned and initialised, with no session. The next new conversation for that key opens its session on the spare and skips agy's start. Then another spare is warmed. Only the process is warmed. On WSL with agy 1.5.9, measured through a logging HTTPS proxy, spawn + initialize + 45s idle made no connection to any host. session/new is where agy sends Code Assist calls (loadCodeAssist, fetchAvailableModels, quota, user info, experiments), plus telemetry. Closing an unused session writes its trajectory ACLs at Google. Sessions also carry the conversation's own instructions. So sessions are never opened ahead. agy reads its sign-in at session/new, so a spare picks up a sign-in that changed after it started. Spares are stopped when idle (IDLE_MS), first when the pool needs room, never warmed when the pool has one slot left, at most 2 at a time, and with the host (reapOnExit). agy also exits when its stdin closes. AGY_BRIDGE_SPARE=0 turns them off. TTFT of a second new conversation (test kit fake agy, initialize 1000ms, session/new 3000ms): first 4026ms, second 3008ms; before, both ~4s. Real agy start, measured on WSL: ~1s cold, ~0.25s warm. That is the saving. The ~3s session open (Google) and model latency remain. Run (mote): - test/spare.mjs on the old index.mjs (AGY_BRIDGE_TEST_INDEX): 6 of 7 red, only the AGY_BRIDGE_SPARE=0 case green. On the new index.mjs: 7 of 7 green. - `HOME=<sandbox> bun test packages/agy-cli/`: 36 pass, 0 fail. - `bun scripts/check.mjs` ok. The test kit defaults AGY_BRIDGE_SPARE=0 so suites that count spawns keep their counts. Not tried: a real signed-in account through the spare path, native Windows agy, macOS agy.
61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
// Runs the suites in test/ (brought over from gitxm/yce-magpie-agy, MIT), each
|
|
// in a bun process of its own: they mock node:child_process, move the clock and
|
|
// set the bridge's environment, and smoke.mjs ends with process.exit.
|
|
import { expect, test } from "bun:test"
|
|
import path from "node:path"
|
|
|
|
const dir = path.join(import.meta.dir, "test")
|
|
const hook = path.join(dir, "cp-hook.mjs")
|
|
|
|
function run(args, timeout) {
|
|
const result = Bun.spawnSync({ cmd: [process.execPath, ...args], cwd: dir, env: { ...process.env, AGY_BRIDGE_STORED_SIGNIN: "skip" }, stdout: "pipe", stderr: "pipe", timeout })
|
|
const output = result.stdout.toString() + result.stderr.toString()
|
|
if (result.exitCode !== 0) console.error(output)
|
|
return { code: result.exitCode, output }
|
|
}
|
|
|
|
for (const [name, mocks] of [
|
|
["platform.mjs", true],
|
|
["compat.mjs", true],
|
|
["prefill.mjs", false],
|
|
["usage.mjs", true],
|
|
["signin.mjs", false],
|
|
["catalog.mjs", false],
|
|
["step-usage.mjs", false],
|
|
["tool-schema.mjs", false],
|
|
["tool-summary.mjs", false],
|
|
["usage-settlement.mjs", false],
|
|
["steer-in-session.mjs", false],
|
|
["repeat-batch.mjs", false],
|
|
["conversation-key.mjs", false],
|
|
["windows-nc.mjs", false],
|
|
["spare.mjs", false],
|
|
]) {
|
|
test(`test/${name}`, () => {
|
|
// bun's 5s default per test is a fixed wait these process-spawning tests
|
|
// overrun on a loaded machine; the 240s run bounds a real hang.
|
|
const { code, output } = run(["test", "--timeout", "120000", ...(mocks ? ["--preload", hook] : []), `./${name}`], 240_000)
|
|
expect(output).toMatch(/\b[1-9]\d* pass\b/)
|
|
expect(code).toBe(0)
|
|
}, 250_000)
|
|
}
|
|
|
|
|
|
test("test/re2-pattern-unit.mjs", () => {
|
|
const { code, output } = run([path.join(dir, "re2-pattern-unit.mjs")], 60_000)
|
|
expect(output).toMatch(/ALL OK/)
|
|
expect(code).toBe(0)
|
|
}, 70_000)
|
|
|
|
test("test/smoke.mjs against a fake agy", () => {
|
|
const { code, output } = run([path.join(dir, "smoke.mjs")], 240_000)
|
|
expect(output).toMatch(/ALL OK \(\d+ checks\)/)
|
|
expect(code).toBe(0)
|
|
}, 250_000)
|
|
|
|
test("test/array-items-unit.mjs", () => {
|
|
const { code, output } = run([path.join(dir, "array-items-unit.mjs")], 60_000)
|
|
expect(output).toMatch(/ALL OK/)
|
|
expect(code).toBe(0)
|
|
}, 70_000)
|