Add websocket contract guards for empty requests and hello version

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 09:21:59 +00:00
1 parent 2af6a90fab
commit 22c644927f
1 file changed
+30
+30
View File
@@ -19,6 +19,26 @@ describe("wsClientMessageSchema", () => {
expect(parsed.method).toBe("providers.startSession");
});
it("rejects empty request ids", () => {
expect(() =>
wsClientMessageSchema.parse({
type: "request",
id: "",
method: "providers.startSession",
}),
).toThrow();
});
it("rejects empty request methods", () => {
expect(() =>
wsClientMessageSchema.parse({
type: "request",
id: "req-1",
method: "",
}),
).toThrow();
});
});
describe("wsServerMessageSchema", () => {
@@ -87,6 +107,16 @@ describe("wsServerMessageSchema", () => {
expect(parsed.type).toBe("hello");
});
it("rejects hello messages with unsupported versions", () => {
expect(() =>
wsServerMessageSchema.parse({
type: "hello",
version: 2,
launchCwd: "/workspace",
}),
).toThrow();
});
});
describe("ws close metadata", () => {