Cover max-length unknown websocket method errors end-to-end
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
d8df4dbecb
commit
6b2bd27c41
2 files changed
+77
No files matched your search
@@ -2637,6 +2637,56 @@ async function main() {
|
||||
);
|
||||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
const timer = setTimeout(
|
||||
() =>
|
||||
reject(
|
||||
new Error("Smoke test failed: max-length unknown-method websocket request timed out."),
|
||||
),
|
||||
20_000,
|
||||
);
|
||||
const onMessage = (event) => {
|
||||
const message = parseWsMessage(event.data);
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type !== "response" || message.id !== "smoke-unknown-method-max-length") {
|
||||
return;
|
||||
}
|
||||
|
||||
ws.removeEventListener("message", onMessage);
|
||||
clearTimeout(timer);
|
||||
|
||||
if (
|
||||
message.ok !== false ||
|
||||
message.error?.code !== "request_failed" ||
|
||||
typeof message.error?.message !== "string" ||
|
||||
!message.error.message.includes("Unknown API method")
|
||||
) {
|
||||
reject(
|
||||
new Error(
|
||||
`Smoke test failed: expected structured max-length unknown-method error response, got ${JSON.stringify(
|
||||
message,
|
||||
)}.`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve();
|
||||
};
|
||||
|
||||
ws.addEventListener("message", onMessage);
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: "request",
|
||||
id: "smoke-unknown-method-max-length",
|
||||
method: "m".repeat(WS_METHOD_MAX_CHARS),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
const invalidShellEditorResponse = await sendWsRequest(ws, {
|
||||
id: "smoke-shell-invalid-editor",
|
||||
method: "shell.openInEditor",
|
||||
|
||||
@@ -1827,6 +1827,33 @@ describe("runtimeApiServer", () => {
|
||||
client.socket.close();
|
||||
});
|
||||
|
||||
it("returns structured errors for unknown methods at max method length", async () => {
|
||||
const server = await startRuntimeApiServer({
|
||||
port: 0,
|
||||
launchCwd: process.cwd(),
|
||||
});
|
||||
servers.push(server);
|
||||
|
||||
const client = await connectClient(server.wsUrl);
|
||||
await client.nextMessage();
|
||||
|
||||
const maxLengthUnknownMethod = "m".repeat(WS_METHOD_MAX_CHARS);
|
||||
const response = await sendRequest(
|
||||
client.socket,
|
||||
client.nextMessage,
|
||||
"unknown-max-method-1",
|
||||
maxLengthUnknownMethod,
|
||||
);
|
||||
expect(response.ok).toBe(false);
|
||||
if (response.ok) {
|
||||
throw new Error("Expected max-length unknown method to fail.");
|
||||
}
|
||||
expect(response.error?.code).toBe("request_failed");
|
||||
expect(response.error?.message).toContain("Unknown API method");
|
||||
|
||||
client.socket.close();
|
||||
});
|
||||
|
||||
it("returns structured errors for invalid shell.openInEditor payloads", async () => {
|
||||
const server = await startRuntimeApiServer({
|
||||
port: 0,
|
||||
|
||||
Reference in new issue
Block a user