Compare commits

...
Author SHA1 Message Date
paseo-bot[bot] 34a7942cb5 test(e2e): authenticate the readiness probe with the daemon's local credential
A password with spaces cannot travel as an HTTP bearer, so the status
probe of a password-protected daemon stayed 401. The daemon writes a
local credential into its home before listening and /api/status accepts
it, as the CLI's local status does.
2026-11-16 12:19:21 +00:00
paseo-bot[bot] d25e44b146 test(e2e): wait for the isolated daemon itself, not any listener on its port
The helper reserves a port, releases it, and starts the daemon on it. If
another process takes the port in between, the daemon exits with
EADDRINUSE, but the readiness probe already succeeded against the other
listener. The worker fixture then reported the daemon as started and its
seed client retried a dead endpoint until the 60s fixture timeout.

Readiness now requires /api/status on the port to report this daemon's
server id, so the probe keeps waiting, sees the EADDRINUSE exit, and the
existing retry moves to a fresh port.
2026-11-16 12:10:01 +00:00
@@ -6,7 +6,7 @@ import {
type ChildProcess,
type SpawnOptions,
} from "node:child_process";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import net from "node:net";
import { tmpdir } from "node:os";
import path from "node:path";
@@ -59,7 +59,17 @@ export async function getAvailableHostDaemonPort(): Promise<number> {
return port;
}
async function waitForServer(port: number, child: ChildProcess): Promise<void> {
/**
* Resolves once this daemon answers on its port. An open TCP port is not
* enough: the port is released before the daemon binds it, and whatever takes
* it in between also accepts connections while the daemon exits with
* EADDRINUSE. Only the daemon's own status reports its server id.
*/
async function waitForServer(
port: number,
child: ChildProcess,
identity: { serverId: string; paseoHome: string },
): Promise<void> {
const deadline = Date.now() + 90_000;
let lastError: unknown = null;
@@ -70,22 +80,13 @@ async function waitForServer(port: number, child: ChildProcess): Promise<void> {
);
}
try {
await new Promise<void>((resolve, reject) => {
const socket = net.connect(port, "127.0.0.1", () => {
socket.end();
resolve();
});
socket.setTimeout(1_000, () => {
socket.destroy();
reject(new Error(`Connection timed out to isolated daemon port ${port}`));
});
socket.on("error", reject);
});
return;
const serverId = await readServerId(port, identity.paseoHome);
if (serverId === identity.serverId) return;
lastError = new Error(`Port ${port} is served by ${serverId}, not ${identity.serverId}`);
} catch (error) {
lastError = error;
await new Promise((resolve) => setTimeout(resolve, 100));
}
await new Promise((resolve) => setTimeout(resolve, 100));
}
throw new Error(
@@ -95,6 +96,25 @@ async function waitForServer(port: number, child: ChildProcess): Promise<void> {
);
}
/**
* Reads the server id from the daemon's status route. The route needs a bearer
* on a password-protected daemon; the daemon accepts the local credential it
* writes into its home before listening, as the CLI does for local status.
*/
async function readServerId(port: number, paseoHome: string): Promise<string> {
const localCredential = await readFile(path.join(paseoHome, "local-credential"), "utf8").then(
(token) => token.trim(),
() => null,
);
const response = await fetch(`http://127.0.0.1:${port}/api/status`, {
headers: localCredential ? { authorization: `Bearer ${localCredential}` } : {},
signal: AbortSignal.timeout(1_000),
});
if (!response.ok) throw new Error(`Status request to port ${port} returned ${response.status}`);
const status = (await response.json()) as { serverId?: unknown };
return String(status.serverId);
}
function withMutableRelay(
config: NonNullable<IsolatedHostDaemonOptions["config"]>,
relay: NonNullable<IsolatedHostDaemonOptions["mutableRelay"]>,
@@ -221,7 +241,7 @@ export async function startIsolatedHostDaemon(
});
try {
await waitForServer(port, spawned);
await waitForServer(port, spawned, { serverId, paseoHome });
return spawned;
} catch (error) {
throw new Error(