test(frontend): unit tests exercise named SSE events (fidelity) + cleanup

FakeEventSource.addEventListener was a no-op, so emit() only drove onmessage.
Production relies on addEventListener for the backend's NAMED events
(event: ui_request), so the unit tests could pass while prod silently broke.

- fakeEventSource: store named handlers in a Map<string,Set>; add emitNamed()
  that dispatches to them; keep emit() for the unnamed/default onmessage path
- useSessionStream.test: ui_request now driven via emitNamed (production path);
  add a separate test for the unnamed text_delta path via plain emit
- f1-loop.test: widget emission switched to emitNamed("ui_request", ...)
- verified: tests FAIL if addEventListener wiring is removed from
  useSessionStream (then restored)
- cleanup: fake-pi.mjs drops unused execFileSync import, uses static spawnSync

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-28 13:33:50 +02:00
co-authored by Claude Opus 4.8
parent 1171181f9a
commit ddbbe4d1ac
4 changed files with 31 additions and 11 deletions
+3 -4
View File
@@ -4,15 +4,14 @@
// exec()s the scripted fake-pi-rpc.mjs with the F1 disambiguation scenario.
import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";
import { execFileSync } from "node:child_process";
import { spawnSync } from "node:child_process";
const __dir = dirname(fileURLToPath(import.meta.url));
const fakePiRpc = resolve(__dir, "../../..", "harness/tests/fake_pi/fake_pi_rpc.mjs");
const scenario = resolve(__dir, "../../..", "harness/tests/fake_pi/scripts/f1_disambiguation.json");
// exec replaces the current process so the backend's child handle stays valid.
// On Node.js we use spawnSync with stdio inherit to approximate exec().
const { spawnSync } = await import("node:child_process");
// Run the scripted fake-pi-rpc on this process's stdio so the backend's child
// handle (stdin/stdout) drives the JSONL protocol directly.
const result = spawnSync(process.execPath, [fakePiRpc, scenario], {
stdio: "inherit",
env: { ...process.env },