Cover dataview and sliced uint8 websocket request payloads

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 09:43:44 +00:00
1 parent 95a31b71bd
commit 1df8e444e7
2 files changed
+164

No files matched your search

+93
View File
@@ -1783,6 +1783,99 @@ async function main() {
ws.send(encodedArrayBufferRequest.buffer);
});
await new Promise((resolve, reject) => {
const timer = setTimeout(
() =>
reject(new Error("Smoke test failed: dataview 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-dataview-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: dataview websocket app.health response mismatch."));
return;
}
clearTimeout(timer);
ws.removeEventListener("message", onMessage);
resolve();
};
ws.addEventListener("message", onMessage);
const encodedDataViewRequest = new TextEncoder().encode(
JSON.stringify({
type: "request",
id: "smoke-dataview-health",
method: "app.health",
}),
);
ws.send(new DataView(encodedDataViewRequest.buffer));
});
await new Promise((resolve, reject) => {
const timer = setTimeout(
() =>
reject(new Error("Smoke test failed: sliced-uint8 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-sliced-uint8-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: sliced-uint8 websocket app.health response mismatch."),
);
return;
}
clearTimeout(timer);
ws.removeEventListener("message", onMessage);
resolve();
};
ws.addEventListener("message", onMessage);
const encodedSlicedUint8Request = new TextEncoder().encode(
JSON.stringify({
type: "request",
id: "smoke-sliced-uint8-health",
method: "app.health",
}),
);
const padded = new Uint8Array(encodedSlicedUint8Request.length + 10);
padded.fill(32);
padded.set(encodedSlicedUint8Request, 5);
ws.send(padded.subarray(5, 5 + encodedSlicedUint8Request.length));
});
await new Promise((resolve, reject) => {
const timer = setTimeout(
() => reject(new Error("Smoke test failed: buffer websocket app.health request timed out.")),
+71
View File
@@ -889,6 +889,77 @@ describe("runtimeApiServer", () => {
client.socket.close();
});
it("accepts dataview-encoded websocket request payloads", async () => {
const server = await startRuntimeApiServer({
port: 0,
launchCwd: process.cwd(),
});
servers.push(server);
const client = await connectClient(server.wsUrl);
await client.nextMessage();
const encoded = new TextEncoder().encode(
JSON.stringify({
type: "request",
id: "dataview-todos-1",
method: "todos.list",
}),
);
client.socket.send(new DataView(encoded.buffer));
const response = await withTimeout(
(async (): Promise<WsResponseMessage> => {
const message = await client.nextMessage();
if (message.type === "response" && message.id === "dataview-todos-1") {
return message;
}
return Promise.reject(new Error("Expected matching todos response."));
})(),
);
expect(response.ok).toBe(true);
expect(Array.isArray(response.result)).toBe(true);
client.socket.close();
});
it("accepts sliced uint8array-encoded websocket request payloads", async () => {
const server = await startRuntimeApiServer({
port: 0,
launchCwd: process.cwd(),
});
servers.push(server);
const client = await connectClient(server.wsUrl);
await client.nextMessage();
const encoded = new TextEncoder().encode(
JSON.stringify({
type: "request",
id: "uint8array-sliced-todos-1",
method: "todos.list",
}),
);
const padded = new Uint8Array(encoded.length + 8);
padded.fill(32);
padded.set(encoded, 4);
client.socket.send(padded.subarray(4, 4 + encoded.length));
const response = await withTimeout(
(async (): Promise<WsResponseMessage> => {
const message = await client.nextMessage();
if (message.type === "response" && message.id === "uint8array-sliced-todos-1") {
return message;
}
return Promise.reject(new Error("Expected matching todos response."));
})(),
);
expect(response.ok).toBe(true);
expect(Array.isArray(response.result)).toBe(true);
client.socket.close();
});
it("replaces an existing websocket client with a new one", async () => {
const server = await startRuntimeApiServer({
port: 0,