Skip to content
41 changes: 41 additions & 0 deletions tests/unit/openclawAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,45 @@ describe("OpenClawGatewayAdapter", () => {

await adapter.stop();
});


it("sends correct minProtocol and maxProtocol in connect request", async () => {
upstream = new WebSocketServer({ port: 0 });
const address = upstream.address();
if (!address || typeof address === "string") {
throw new Error("expected upstream server to provide a numeric port");
}
const upstreamUrl = `ws://127.0.0.1:${address.port}`;
let observedMinProtocol: unknown;
let observedMaxProtocol: unknown;

upstream.on("connection", (ws) => {
ws.send(JSON.stringify({ type: "event", event: "connect.challenge", payload: {} }));
ws.on("message", (raw) => {
const parsed = JSON.parse(String(raw ?? ""));
if (parsed?.method === "connect") {
observedMinProtocol = parsed.params?.minProtocol;
observedMaxProtocol = parsed.params?.maxProtocol;
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test asserts params.minProtocol/params.maxProtocol are 3, but it doesn’t verify the PR’s stated requirement that these fields are not nested under a params.protocol object (or that no protocol object is present at all). Consider also asserting that parsed.params.protocol is undefined (or that the only protocol-related keys are minProtocol/maxProtocol) to fully cover the regression described in #101 and the PR description.

Copilot uses AI. Check for mistakes.
ws.send(
JSON.stringify({
type: "res",
id: parsed.id,
ok: true,
payload: { type: "hello-ok", protocol: 3 },
})
);
}
});
});

const adapter = new OpenClawGatewayAdapter({
loadSettings: () => ({ url: upstreamUrl, token: "tkn" }),
});

await adapter.start();
expect(observedMinProtocol).toBe(3);
expect(observedMaxProtocol).toBe(3);
await adapter.stop();
});

});
Loading