mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-30 05:02:58 +00:00
* test(e2e): boot the Playwright harness on Windows
The harness could not start on Windows. Metro was launched with
spawn("npx", ...) and the isolated daemon resolved its runner with
execSync("which tsx") — npx is a .cmd shim that Node's bare spawn
cannot launch, and `which` does not exist there.
Route both through process.execPath instead of the node_modules/.bin
shims. Node refuses to spawn .cmd or .bat without shell: true, and
shell: true is the wrong escape hatch: it concatenates argv unescaped
(DEP0190), splits paths containing spaces, and sends kill signals to
cmd.exe rather than the real child. Spawning Node directly has none of
those properties and is identical on POSIX, so no platform branch is
needed. The same reasoning fixes the published-server npm install,
which passed "npm.cmd" to execFileSync and had been failing with
EINVAL on Windows since Node's CVE-2024-27980 mitigation landed.
Teardown now kills the process tree. A Windows signal reaches only the
direct child, so Metro's and the supervisor's forked workers kept the
listening port and the next run failed to bind.
The daemon startup deadline goes from 20s to 90s. A cold tsx start was
measured at 25s on Windows and exceeded 60s under load; the loop still
fails immediately on a crashed child, so the ceiling only costs time
that a genuinely slow start needs.
The fake editor and gh binaries the harness puts on PATH gain .cmd
wrappers, because Windows resolves PATH entries by PATHEXT and cannot
execute an extension-less shebang file. The wrappers point at the same
payload file so the recorded command name stays "cursor", "code", or
"gh" on every platform.
The asdf-backed local Elixir relay stays POSIX-only and now says so
before spawning.
* test(ci): follow shared e2e daemon launcher
---------
Co-authored-by: ABorakati <ABorakati@users.noreply.github.com>
Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
123 lines
3.6 KiB
TypeScript
123 lines
3.6 KiB
TypeScript
import { spawn, type ChildProcess } from "node:child_process";
|
|
import { existsSync } from "node:fs";
|
|
import net from "node:net";
|
|
import path from "node:path";
|
|
import { killProcessTree } from "./spawn-node";
|
|
|
|
export interface LocalElixirRelay {
|
|
endpoint: string;
|
|
port: number;
|
|
start(): Promise<void>;
|
|
stop(): Promise<void>;
|
|
close(): Promise<void>;
|
|
}
|
|
|
|
async function availablePort(): Promise<number> {
|
|
return await new Promise((resolve, reject) => {
|
|
const server = net.createServer();
|
|
server.once("error", reject);
|
|
server.listen(0, "127.0.0.1", () => {
|
|
const address = server.address();
|
|
if (!address || typeof address === "string") {
|
|
server.close(() => reject(new Error("Could not allocate a relay port")));
|
|
return;
|
|
}
|
|
server.close(() => resolve(address.port));
|
|
});
|
|
});
|
|
}
|
|
|
|
async function waitUntilReady(
|
|
port: number,
|
|
child: ChildProcess,
|
|
recentOutput: () => string,
|
|
): Promise<void> {
|
|
const deadline = Date.now() + 60_000;
|
|
let lastError: unknown;
|
|
while (Date.now() < deadline) {
|
|
if (child.exitCode !== null || child.signalCode !== null) {
|
|
throw new Error(
|
|
`Elixir relay exited before becoming ready (code ${String(child.exitCode)}, signal ${String(child.signalCode)}).\n${recentOutput()}`,
|
|
);
|
|
}
|
|
try {
|
|
const response = await fetch(`http://127.0.0.1:${port}/ready`, {
|
|
signal: AbortSignal.timeout(1_000),
|
|
});
|
|
if (response.ok) return;
|
|
lastError = new Error(`Relay readiness returned HTTP ${response.status}`);
|
|
} catch (error) {
|
|
lastError = error;
|
|
}
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
}
|
|
throw new Error(
|
|
`Elixir relay did not become ready on port ${port}: ${lastError instanceof Error ? lastError.message : String(lastError)}\n${recentOutput()}`,
|
|
);
|
|
}
|
|
|
|
export async function startLocalElixirRelay(): Promise<LocalElixirRelay> {
|
|
if (process.platform === "win32") {
|
|
throw new Error(
|
|
"The local Elixir relay requires asdf, which is not available on Windows; the relay-deployment Playwright project is POSIX-only.",
|
|
);
|
|
}
|
|
|
|
const relayRoot =
|
|
process.env.PASEO_RELAY_CHECKOUT ?? path.resolve(__dirname, "../../../../../..", "paseo-relay");
|
|
if (!existsSync(path.join(relayRoot, "mix.exs"))) {
|
|
throw new Error(
|
|
`Expected the Elixir relay checkout at ${relayRoot}. Set PASEO_RELAY_CHECKOUT to override it.`,
|
|
);
|
|
}
|
|
|
|
const port = await availablePort();
|
|
let child: ChildProcess | null = null;
|
|
let output: string[] = [];
|
|
|
|
const start = async () => {
|
|
if (child && child.exitCode === null && child.signalCode === null) {
|
|
throw new Error("Elixir relay is already running");
|
|
}
|
|
output = [];
|
|
child = spawn("asdf", ["exec", "mix", "run", "--no-halt"], {
|
|
cwd: relayRoot,
|
|
env: {
|
|
...process.env,
|
|
MIX_ENV: "prod",
|
|
PASEO_RELAY_HOST: "127.0.0.1",
|
|
PASEO_RELAY_PORT: String(port),
|
|
PASEO_RELAY_MIN_CLUSTER_SIZE: "1",
|
|
},
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
const capture = (chunk: Buffer) => {
|
|
output.push(chunk.toString("utf8"));
|
|
output = output.join("").split("\n").slice(-80);
|
|
};
|
|
child.stdout?.on("data", capture);
|
|
child.stderr?.on("data", capture);
|
|
try {
|
|
await waitUntilReady(port, child, () => output.join("\n"));
|
|
} catch (error) {
|
|
await killProcessTree(child);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
const stop = async () => {
|
|
if (!child) return;
|
|
await killProcessTree(child);
|
|
child = null;
|
|
};
|
|
|
|
await start();
|
|
return {
|
|
endpoint: `127.0.0.1:${port}`,
|
|
port,
|
|
start,
|
|
stop,
|
|
close: stop,
|
|
};
|
|
}
|