Files
ThothII/frontend/e2e/fixtures/fake-pi.mjs
marcopanandClaude Opus 4.8 ddbbe4d1ac 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>
2026-06-28 13:33:50 +02:00

20 lines
892 B
JavaScript
Executable File

#!/usr/bin/env node
// fake-pi.mjs — hermetic PI_BIN stub for e2e tests.
// Ignores all argv (the backend passes --mode rpc --approve) and
// 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 { 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");
// 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 },
});
process.exit(result.status ?? 0);