mirror of
https://github.com/penpot/penpot.git
synced 2026-10-30 06:20:32 +00:00
Extract the WebSocket close-code decision into a pure ReconnectPolicy module and cover it with node:test. The plugin now names the 1008 policy-violation code instead of using a magic number, and the terminal behavior of a 1008 close is pinned by a regression test so a future refactor cannot reintroduce the reconnect storm. Document the contract in mem:mcp/core: 1008 is terminal, it comes from a duplicate user token or a missing token in multi-user mode, and recovery is manual via "Connect here". Closes #11510 AI-assisted-by: deepseek-v4.1-flash
25 lines
918 B
TypeScript
25 lines
918 B
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { WS_CLOSE_POLICY_VIOLATION, shouldReconnectAfterClose } from "./ReconnectPolicy.ts";
|
|
|
|
test("names the policy violation close code used by the MCP server", () => {
|
|
assert.equal(WS_CLOSE_POLICY_VIOLATION, 1008);
|
|
});
|
|
|
|
test("does not reconnect after a policy violation close", () => {
|
|
assert.equal(shouldReconnectAfterClose(WS_CLOSE_POLICY_VIOLATION), false);
|
|
});
|
|
|
|
test("reconnects after transient close codes", () => {
|
|
const transientCodes = [
|
|
{ code: 1000, meaning: "normal closure" },
|
|
{ code: 1001, meaning: "going away" },
|
|
{ code: 1005, meaning: "no status received" },
|
|
{ code: 1006, meaning: "abnormal closure" },
|
|
];
|
|
|
|
for (const { code, meaning } of transientCodes) {
|
|
assert.equal(shouldReconnectAfterClose(code), true, `expected reconnect for ${code} (${meaning})`);
|
|
}
|
|
});
|