agy dials --ide-mcp-port by running `nc` from PATH, and on Windows the
bridge's nc was nc.cmd: cmd.exe running mcp-server.mjs, two console
programs. When agy starts a console program with a console of its own
(CREATE_NEW_CONSOLE, or CREATE_NO_WINDOW), each dial gets a window or a
conhost.exe. Each session also made its own bin dir, and a host that
exited left its parked agy's cmd/bun children and its workspace dirs
behind.
- Under Bun (magpie's runtime), nc is now a GUI-subsystem nc.exe that
Bun builds from mcp-server.mjs on the user's own machine (`bun build
--compile --windows-hide-console`, ~0.3s on the test box). A GUI exe
gets no console under any creation flags, and it still talks over the
stdio pipes agy hands it. Nothing prebuilt ships. It lives in
%TEMP%\magpie-agy-bridge-nc-<hash of runtime, Bun version and server
source>, so every session and every later host reuses one build. A dir
no host has used for a week, or a half-done build dir older than an
hour, is swept. If the build fails, or the runtime isn't Bun (e.g.
opencode.exe), nc.cmd is used as before.
- At exit on Windows one `taskkill /T /F` ends every live agy with its
tree (cmd, nc). The workspace rm retries while the just-killed
processes let go of their cwd. Only a shim dir this host made is
removed; the shared nc.exe dir stays.
Run on Windows 11 (build 26200, xiaomi-gpu), Bun 1.4.2. A fake agy (Go)
answers ACP and dials `nc 127.0.0.1 <port>` 3 times per session, with
CreationFlags none, CREATE_NO_WINDOW or CREATE_NEW_CONSOLE. 4 sessions
per run, all 12 dials answered in every run below. conhost counts are
those under the host after 4 sessions, while agy is parked:
old, none: 5 conhost; agy 4, cmd 4, bun 4; 4 workspace dirs leaked
old, nowindow: 9 conhost (+2 per session); same leak
old, newconsole: 9 conhost (+2 per session); same leak
new, none / nowindow / newconsole: 5 conhost (the parked agy's own);
agy 4, nc.exe 4, no cmd, no bun; one magpie-agy-bridge-nc-<hash>
dir, nothing else left in TEMP after exit
new, idle eviction (3s): back to 1 conhost, no agy/nc left
new, host hard-killed: no agy/nc left; the 4 workspace dirs stay (no
code runs after a hard kill; the same on old, which also leaks its
bin dir)
old, DETACHED_PROCESS: the dial never answers (agy start times out),
so that isn't what the reported agy does.
The system-wide conhost count was 1 before and after every run.
Tests: test/windows-nc.mjs (6 tests, on any OS through the kit's
platform, execPath and versions overrides): the build command, the
shared dir built once and reused by a later host, no nc.cmd, the
nc.cmd fallback, the one-run tree kill at exit and which dirs it
removes.
Run at this tree on mica (Bun 1.4.2, temp HOME): bun test
packages/agy-cli 15 pass 0 fail; bun scripts/check.mjs exit 0.
On the Windows box: 14 pass, 1 fail. The red is smoke.mjs's "no call to
the loaded tool reaches agy's validator in the old prompt". It fails the
same way at origin/main 8768126 on the same box, and is filed as #973.
Broken by hand, each red in windows-nc.mjs: never using nc.exe (2
red), a build without --windows-hide-console (2), a rebuild per host (1),
SIGKILL per child instead of the taskkill tree (1), removing the shared
dir at exit (1).
Not tried: a real agy on Windows (it isn't installed on the box, and was
not downloaded); whether a window is visible (ssh runs in session 0,
where none is, so conhosts were counted instead); the reporter's build
26300. A host killed hard can still leave an agy that ignores stdin EOF:
only a job object around the plugin host (magpie's
internal/plugin/host.go starts it with a plain cmd.Start) would end it.
Reported-by: Tericerice <Tericerice@users.noreply.github.com>
56 lines
2.0 KiB
JavaScript
56 lines
2.0 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 }, 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],
|
|
["catalog.mjs", false],
|
|
["step-usage.mjs", false],
|
|
["usage-settlement.mjs", false],
|
|
["repeat-batch.mjs", false],
|
|
["conversation-key.mjs", false],
|
|
["windows-nc.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)
|