Files
yetone 4b3af4a565 agy-cli 0.1.89: a session whose agy never loads the client's tools fails and says why (#1239)
pi declared read, bash, edit and write through the gateway on Windows and
the model saw only agy's own manage_task; `read` came back
`unknown tool: "read"`. agy reads a client's tools from the bridge's
ide-tools MCP server, which it starts by running `nc` from PATH. When
that never answers, #waitForToolList gave up after 5s without a word and
the turn ran with no client tool at all, for every client.

On Windows agy 1.5 runs only nc.exe, never the nc.cmd the bridge falls
back to. A failed nc.exe build was swallowed and cached for the whole
host process, so every session after it had no tools until magpie
restarted.

- A session that declares tools and whose agy hasn't listed them after
  AGY_BRIDGE_TOOL_LIST_WAIT_MS (now 20s) fails with 502
  tools_not_loaded, naming the cause: on Windows, the nc.exe build's own
  failure (not Bun, non-ASCII folder, bun build's exit code or "wrote no
  nc.exe" plus its last stderr lines); elsewhere, the `nc` MCP server
  that never answered. No session/prompt is sent.
- A live agy that never listed the tools a follow-up declares (started
  with none) is replaced (session_new reason tools_unlisted), not reused.
- On Windows a failed nc.exe build is tried again after 5 minutes,
  rather than never.

Tests: test/tools-listed.mjs (new, in agy-cli.test.mjs). The testkit's
fake agy can now not list tools (listTools), or not keep a watch
(watchTools), and records each listing.

Run at this tree:
- mica-run, HOME=$(mktemp -d): cd packages/agy-cli && bun test:
  41 pass 0 fail; bun scripts/check.mjs agy-cli: ok. (mote was at load
  130.) An earlier run of the same suite had test/usage.mjs red twice on
  its 3s usage-query deadline at mica load 23; it passed 41/41 twice
  alone. That is #1191.
- win-run on xiaomi-gpu (real Windows, Bun 1.4.2): tools-listed.mjs and
  windows-nc.mjs, 13 pass 0 fail. The first Windows run caught that the
  platform-neutral cases took the real win32 path; they now pin linux.

Broken by hand: tools-listed.mjs against the old index.mjs
(AGY_BRIDGE_TEST_INDEX = HEAD's copy): 3 of 5 red. The unlisted session
ran its turn (200, end_turn after 5s), the follow-up ran on the agy that
never listed Read, and the failed Windows build was never retried. The
two cases that should hold either way pass.

Earlier, on xiaomi-gpu: a real nc.exe built in ~335ms, and the shim
answered tools/list in 137ms first and ~28ms after.

Not tried: a real agy turn or a real Windows agy session. There is no
usable account: the Mac one is banned, and Windows agy answers
session/new with "Authentication required". So the reporter's exact
trigger (which nc.exe build failure, or none) isn't confirmed. The error
now names it on their machine.
2026-11-17 19:25:36 +08:00

69 lines
2.4 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],
["dropped-call.mjs", false],
["repeat-batch.mjs", false],
["conversation-key.mjs", false],
["windows-nc.mjs", false],
["spare.mjs", false],
["tools-listed.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)
test("test/documents-unit.mjs", () => {
const { code, output } = run([path.join(dir, "documents-unit.mjs")], 60_000)
expect(output).toMatch(/ALL OK/)
expect(code).toBe(0)
}, 70_000)