Files
paseo/scripts/daemon-launch-contract.test.mjs
f4b5f32862 test(e2e): boot the Playwright harness on Windows (#3804)
* 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>
2026-08-24 18:20:19 +02:00

83 lines
3.1 KiB
JavaScript

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import test from "node:test";
const repoRoot = join(import.meta.dirname, "..");
function assertNoDirectWorkerLaunch(label, command) {
for (const workerEntrypoint of [
"src/server/index.ts",
"dist/server/server/index.js",
"src/server/daemon-worker.ts",
"dist/server/server/daemon-worker.js",
]) {
assert.ok(
!command.includes(workerEntrypoint),
`${label} must not launch ${workerEntrypoint} directly: ${command}`,
);
}
}
function assertNoSpawnedWorkerEntrypoint(label, source) {
assertNoDirectWorkerLaunch(label, source);
assert.doesNotMatch(
source,
/spawn\([^)]*["'`][^"'`]*\.\.\/index\.ts["'`]/s,
`${label} must not spawn ../index.ts directly`,
);
}
test("every executable daemon entrypoint enters the supervisor", async () => {
const [
serverPackageSource,
appIsolatedHostDaemon,
serverConnectionOfferE2e,
desktopRuntimePaths,
nixPackage,
nixModule,
] = await Promise.all([
readFile(join(repoRoot, "packages/server/package.json"), "utf8"),
readFile(join(repoRoot, "packages/app/e2e/support/helpers/isolated-host-daemon.ts"), "utf8"),
readFile(
join(repoRoot, "packages/server/src/server/daemon-e2e/connection-offer.e2e.test.ts"),
"utf8",
),
readFile(join(repoRoot, "packages/desktop/src/daemon/runtime-paths.ts"), "utf8"),
readFile(join(repoRoot, "nix/package.nix"), "utf8"),
readFile(join(repoRoot, "nix/module.nix"), "utf8"),
]);
const serverPackage = JSON.parse(serverPackageSource);
const startScript = serverPackage.scripts?.start ?? "";
const devScript = serverPackage.scripts?.dev ?? "";
const devTsxScript = serverPackage.scripts?.["dev:tsx"] ?? "";
assert.match(startScript, /dist\/scripts\/supervisor-entrypoint\.js/);
assertNoDirectWorkerLaunch("server start script", startScript);
assert.match(devScript, /scripts\/dev-runner\.ts/);
assertNoDirectWorkerLaunch("server dev script", devScript);
assert.match(devTsxScript, /scripts\/dev-runner\.ts/);
assertNoDirectWorkerLaunch("server dev:tsx script", devTsxScript);
assert.match(
appIsolatedHostDaemon,
/spawnTsx\("scripts\/supervisor-entrypoint\.ts", \["--dev"\]/,
);
assertNoSpawnedWorkerEntrypoint("app e2e isolated host daemon", appIsolatedHostDaemon);
assert.match(serverConnectionOfferE2e, /scripts\/supervisor-entrypoint\.ts/);
assertNoSpawnedWorkerEntrypoint("server daemon e2e process launch", serverConnectionOfferE2e);
assert.match(desktopRuntimePaths, /"dist", "scripts", "supervisor-entrypoint\.js"/);
assert.match(desktopRuntimePaths, /"scripts", "supervisor-entrypoint\.ts"/);
assertNoDirectWorkerLaunch("desktop runtime paths", desktopRuntimePaths);
assert.match(nixPackage, /dist\/scripts\/supervisor-entrypoint\.js/);
assertNoDirectWorkerLaunch("Nix package wrapper", nixPackage);
assert.match(nixPackage, /--set PASEO_NODE_ENV production/);
assert.doesNotMatch(nixPackage, /--set(-default)?\s+NODE_ENV\b/);
assert.doesNotMatch(nixModule, /\bNODE_ENV\b\s*=/);
assert.doesNotMatch(nixModule, /\bPASEO_NODE_ENV\b/);
});