17d56d0e01
Clean break, no compatibility alias. Renames the product name, the CLI binary (`ccam` -> `agenthub`), the env var prefix (`CCAM_` -> `AGENTHUB_`), the Prometheus metric namespace (`ccam_*` -> `agenthub_*`), the tmux session prefix (`ccam-lane-<id>` -> `agenthub-lane-<id>`), the per-repo runtime profile directory (`.ccam/profile` -> `.agenthub/profile`), the lanes state root (`~/.claude/ccam-lanes` -> `~/.claude/agenthub-lanes`), the bundled plugins (`plugins/ccam*` -> `plugins/agenthub*`) and their slash commands (`/ccam-doctor` -> `/agenthub-doctor`, `/ccam:*` -> `/agenthub:*`). Because there is no alias, an existing install has to be updated by hand: rename its `.ccam/profile` directory and any `CCAM_*` variables, and reinstall the plugin under its new name. Two other name families are deliberately left alone here, since they are not just strings: the `Claude-Code-Monitor` repository/marketplace name, and the `agent-dashboard` npm package plus its `~/.claude/agent-dashboard` runtime directory, which holds the live database and needs a migration rather than a rename. Verified: server 1406/1406, client 459/459, `grep -i ccam` clean across tracked files, `openapi.yaml` regenerated (95 paths, unchanged count).
57 lines
2.2 KiB
JavaScript
57 lines
2.2 KiB
JavaScript
/**
|
|
* @file websocket-shutdown.test.js
|
|
* @description Regression test for the shutdown race in server/websocket.js:
|
|
* `closeWebSocket()` nulls both WebSocketServer references but cannot
|
|
* unregister the `server.on("upgrade")` listeners it installed, so an upgrade
|
|
* arriving mid-shutdown used to throw an unhandled TypeError
|
|
* ("Cannot read properties of null (reading 'handleUpgrade')") and kill the
|
|
* process. Uses a real http.Server and raw upgrade requests — no ws client.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
const { describe, it } = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const http = require("node:http");
|
|
const net = require("node:net");
|
|
const ws = require("../websocket");
|
|
|
|
/** Send a raw WS upgrade for `path` and resolve once the socket settles. */
|
|
function rawUpgrade(port, path) {
|
|
return new Promise((resolve) => {
|
|
const socket = net.connect(port, "127.0.0.1", () => {
|
|
socket.write(
|
|
`GET ${path} HTTP/1.1\r\nHost: 127.0.0.1:${port}\r\n` +
|
|
`Upgrade: websocket\r\nConnection: Upgrade\r\n` +
|
|
`Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nSec-WebSocket-Version: 13\r\n\r\n`
|
|
);
|
|
});
|
|
let body = "";
|
|
socket.on("data", (d) => {
|
|
body += d.toString("utf8");
|
|
});
|
|
socket.on("close", () => resolve(body));
|
|
socket.on("error", () => resolve(body));
|
|
});
|
|
}
|
|
|
|
describe("websocket shutdown race", () => {
|
|
it("drops upgrades that land after closeWebSocket instead of crashing", async () => {
|
|
const server = http.createServer((req, res) => res.end("ok"));
|
|
ws.initWebSocket(server);
|
|
ws.initPtyWebSocket(server);
|
|
await new Promise((r) => server.listen(0, "127.0.0.1", r));
|
|
const { port } = server.address();
|
|
|
|
// The shutdown the real server performs on SIGTERM.
|
|
ws.closeWebSocket();
|
|
|
|
// Both paths, because each has its own upgrade listener and its own null
|
|
// reference. An unguarded handleUpgrade here takes the process down, so
|
|
// simply reaching the assertions below is the test passing.
|
|
await rawUpgrade(port, "/ws");
|
|
await rawUpgrade(port, "/ws-pty/agenthub-lane-1");
|
|
|
|
assert.equal(ws.getConnectionCount(), 0);
|
|
await new Promise((r) => server.close(r));
|
|
});
|
|
});
|