Cover arraybuffer smoke requests and replacement close reasons

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 06:11:06 +00:00
1 parent 992532873c
commit d8b62998da
2 files changed
+58 -4

No files matched your search

+48
View File
@@ -1688,6 +1688,54 @@ async function main() {
ws.send(encodedBinaryRequest);
});
await new Promise((resolve, reject) => {
const timer = setTimeout(
() =>
reject(
new Error("Smoke test failed: arraybuffer websocket app.health request timed out."),
),
20_000,
);
const onMessage = (event) => {
let message;
try {
message = JSON.parse(String(event.data));
} catch {
return;
}
if (message.type !== "response" || message.id !== "smoke-arraybuffer-health") {
return;
}
if (
message.ok !== true ||
message.result?.status !== "ok" ||
message.result?.launchCwd !== appRoot
) {
clearTimeout(timer);
ws.removeEventListener("message", onMessage);
reject(
new Error("Smoke test failed: arraybuffer websocket app.health response mismatch."),
);
return;
}
clearTimeout(timer);
ws.removeEventListener("message", onMessage);
resolve();
};
ws.addEventListener("message", onMessage);
const encodedArrayBufferRequest = new TextEncoder().encode(
JSON.stringify({
type: "request",
id: "smoke-arraybuffer-health",
method: "app.health",
}),
);
ws.send(encodedArrayBufferRequest.buffer);
});
ws.send("not-json");
ws.send(JSON.stringify({ foo: "bar" }));
const postMalformedHealthResponse = await sendWsRequest(ws, {
+10 -4
View File
@@ -893,8 +893,10 @@ describe("runtimeApiServer", () => {
const firstClient = await connectClient(server.wsUrl);
await firstClient.nextMessage();
const firstClose = new Promise<{ code: number }>((resolve) => {
firstClient.socket.once("close", (code) => resolve({ code }));
const firstClose = new Promise<{ code: number; reason: string }>((resolve) => {
firstClient.socket.once("close", (code, reason) =>
resolve({ code, reason: reason.toString() }),
);
});
const secondClient = await connectClient(server.wsUrl);
@@ -902,6 +904,7 @@ describe("runtimeApiServer", () => {
const closed = await withTimeout(firstClose);
expect(closed.code).toBe(4000);
expect(closed.reason).toBe("replaced-by-new-client");
const response = await sendRequest(
secondClient.socket,
@@ -925,8 +928,10 @@ describe("runtimeApiServer", () => {
const firstClient = await connectClient(server.wsUrl);
await firstClient.nextMessage();
const firstClose = new Promise<{ code: number }>((resolve) => {
firstClient.socket.once("close", (code) => resolve({ code }));
const firstClose = new Promise<{ code: number; reason: string }>((resolve) => {
firstClient.socket.once("close", (code, reason) =>
resolve({ code, reason: reason.toString() }),
);
});
const secondClient = await connectClient(server.wsUrl);
@@ -934,6 +939,7 @@ describe("runtimeApiServer", () => {
const closed = await withTimeout(firstClose);
expect(closed.code).toBe(4000);
expect(closed.reason).toBe("replaced-by-new-client");
const response = await sendRequest(
secondClient.socket,