fix(e2e): report signaled host server startups

This commit is contained in:
Vincent Koc
2026-06-20 16:14:16 +02:00
parent d4f68475fd
commit 48b338a5a9
2 changed files with 42 additions and 2 deletions
+6 -2
View File
@@ -151,11 +151,11 @@ async function waitForHostServer(
});
const startedAt = Date.now();
while (Date.now() - startedAt < 10_000) {
if (child.exitCode != null) {
if (hasHostServerChildExited(child)) {
if (!childClosed) {
await Promise.race([childClose, delay(HOST_SERVER_STDERR_DRAIN_MS)]);
}
die(`host artifact server exited early: ${stderr.trim() || `exit ${child.exitCode}`}`);
die(`host artifact server exited early: ${stderr.trim() || formatHostServerExit(child)}`);
}
if (await canConnect(port)) {
return;
@@ -176,6 +176,10 @@ function appendBoundedOutput(previous: string, chunk: Buffer, limitBytes: number
return combined.subarray(combined.byteLength - limitBytes).toString("utf8");
}
function formatHostServerExit(child: ChildProcessWithoutNullStreams): string {
return child.signalCode ? `signal ${child.signalCode}` : `exit ${child.exitCode ?? "unknown"}`;
}
async function canConnect(port: number): Promise<boolean> {
return await new Promise((resolve) => {
const socket = createConnection({ host: "127.0.0.1", port });
@@ -557,6 +557,42 @@ exit 42
},
);
it.runIf(process.platform !== "win32")(
"reports signaled host artifact server startup exits immediately",
async () => {
const tempDir = mkdtempSync(join(tmpdir(), "openclaw-parallels-host-server-signal-"));
const fakePython = join(tempDir, "python3");
writeFileSync(
fakePython,
`#!/usr/bin/env bash
kill -TERM "$$"
`,
);
chmodSync(fakePython, 0o755);
try {
const port = await unusedLoopbackPort();
const result = spawnNodeEvalSync(
`import { startHostServer } from "./${TS_PATHS.hostServer}"; await startHostServer({ dir: ".", hostIp: "127.0.0.1", port: ${port}, artifactPath: "artifact.tgz", label: "artifact" });`,
{
env: {
...process.env,
PATH: `${tempDir}${delimiter}${process.env.PATH ?? ""}`,
},
imports: ["tsx"],
maxBuffer: 1024 * 1024,
},
);
expect(result.status).toBe(1);
expect(result.stderr).toContain("host artifact server exited early: signal SIGTERM");
expect(result.stderr).not.toContain("did not start");
} finally {
rmSync(tempDir, { force: true, recursive: true });
}
},
);
it("quotes shell args and resolves fuzzy snapshot hints through the shared TypeScript helper", () => {
const tempDir = mkdtempSync(join(tmpdir(), "openclaw-parallels-helper-"));
writeFakePrlctl(