#!/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 { execFileSync } 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"); const result = spawnSync(process.execPath, [fakePiRpc, scenario], { stdio: "inherit", env: { ...process.env }, }); process.exit(result.status ?? 0);