Files
plugins/packages/agy-cli/test
yetone c00c4b9f6c agy-cli: usage timeout tests wait on the children, not a duration (#950)
Cause: "simulated Windows timeouts kill the whole tree" ran fetchUsage
with a 600ms timeout that covers both children. On a loaded machine the
fake agy's start (bun startup plus its browser-guard spawnSync) can use
most of it, so the timeout fired before the report child had logged, or
before it was even spawned, and logs[1] was undefined
("undefined is not an object (evaluating 'logs[1].pid')"). The same
budget made its sibling "version/report hangs time out" read a log the
killed version child never wrote (ENOENT). After the kill, a fixed 20ms
(and 50ms in both descendant tests) stood in for the kernel and event
loop reaping a SIGKILLed child.

Fix, test-only:
- timedOut() records each spawned child's pid itself and doubles the
  timeout (600ms up to 38.4s) until the timeout lands while the child
  under test runs; the taskkill assertions use the spawned report pid.
- The "gone" checks poll: waitForPidExit with a 15s bound over the
  spawned pids and every pid the fixture logged (the agy under cmd.exe
  on Windows); waitForNotRunning polls ps for the two descendant tests.
- agy-cli.test.mjs runs each suite with bun's --timeout 120000: bun's
  5s per-test default was the next fixed wait these tests hit under the
  injected delay.
- The fake agy takes TEST_START_DELAY_MS to reproduce a slow start.

Injected: TEST_START_DELAY_MS=400 on the old test (WSL magpie-desktop)
-> the #950 test red with the logs[1].pid TypeError; =900 -> it and the
hang test red with ENOENT. With this change: 20/20 at 0, 400 and 900 on
WSL, 20/20 at 0 and 900 on mote (macOS), 17/17 (3 skipped) at 0 and 900
on xiaomi-gpu (Windows).

Ran: wsl-run 'export HOME=$(mktemp -d); bun test packages/agy-cli;
bun scripts/check.mjs' -> 13 pass, 0 fail; check.mjs all ok.

Not tried: the reaping race by itself (a SIGKILLed child still listed
after 20ms) wasn't injected; it is covered by polling, not reproduced.
No source change, so no version bump.
2026-11-11 18:41:02 +08:00
..