Files
nntrivi2001 17d56d0e01 refactor!: rebrand CCAM to AgentHub
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).
2026-09-07 12:09:15 +07:00

128 lines
4.2 KiB
JavaScript

/**
* @file Tests for GET/POST /api/locks — the HTTP surface over
* server/lib/named-lock.js. Boots a real Express app + in-memory-ish SQLite
* (temp file) like the other route test files in this suite.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const os = require("node:os");
const path = require("node:path");
const fs = require("node:fs");
const http = require("node:http");
const SUITE_ROOT = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-locks-api-"));
process.env.DASHBOARD_DB_PATH = path.join(SUITE_ROOT, "dashboard.db");
process.env.LANES_ROOT = path.join(SUITE_ROOT, "lanes");
const { describe, it, before, after } = require("node:test");
const assert = require("node:assert/strict");
const { createApp } = require("../index");
const namedLock = require("../lib/named-lock");
let server;
let PORT;
before(async () => {
const app = createApp();
server = http.createServer(app);
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
PORT = server.address().port;
});
after(async () => {
await new Promise((resolve) => server.close(resolve));
fs.rmSync(SUITE_ROOT, { recursive: true, force: true });
});
function request(method, urlPath, body) {
return new Promise((resolve, reject) => {
const data = body ? JSON.stringify(body) : null;
const req = http.request(
{
method,
hostname: "127.0.0.1",
port: PORT,
path: urlPath,
headers: {
"Content-Type": "application/json",
...(data ? { "Content-Length": Buffer.byteLength(data) } : {}),
},
},
(res) => {
let raw = "";
res.on("data", (chunk) => (raw += chunk));
res.on("end", () => {
let json = null;
try {
json = JSON.parse(raw);
} catch {
/* empty body is fine for some responses */
}
resolve({ status: res.statusCode, body: json });
});
}
);
req.on("error", reject);
if (data) req.write(data);
req.end();
});
}
describe("GET /api/locks", () => {
it("lists currently-held locks", async () => {
namedLock.tryAcquire("api-build", "lane1");
const res = await request("GET", "/api/locks");
assert.equal(res.status, 200);
assert.ok(res.body.locks.some((l) => l.name === "api-build" && l.holder === "lane1"));
namedLock.release("api-build", "lane1");
});
});
describe("POST /api/locks/:name/acquire", () => {
it("acquires a free lock", async () => {
const res = await request("POST", "/api/locks/api-acquire/acquire", { holder: "lane1" });
assert.equal(res.status, 200);
assert.deepEqual(res.body, { acquired: true });
namedLock.release("api-acquire", "lane1");
});
it("409s with the current holder when already held", async () => {
namedLock.tryAcquire("api-busy", "lane1");
const res = await request("POST", "/api/locks/api-busy/acquire", { holder: "lane2" });
assert.equal(res.status, 409);
assert.equal(res.body.acquired, false);
assert.equal(res.body.holder, "lane1");
namedLock.release("api-busy", "lane1");
});
it("400s when holder is missing", async () => {
const res = await request("POST", "/api/locks/api-nobody/acquire", {});
assert.equal(res.status, 400);
assert.equal(res.body.error.code, "EBADHOLDER");
});
});
describe("POST /api/locks/:name/release", () => {
it("releases a held lock", async () => {
namedLock.tryAcquire("api-release", "lane1");
const res = await request("POST", "/api/locks/api-release/release", { holder: "lane1" });
assert.equal(res.status, 200);
assert.equal(res.body.ok, true);
assert.equal(namedLock.status("api-release").held, false);
});
it("409s when the holder doesn't match", async () => {
namedLock.tryAcquire("api-release-2", "lane1");
const res = await request("POST", "/api/locks/api-release-2/release", { holder: "lane2" });
assert.equal(res.status, 409);
assert.equal(res.body.error.code, "ENOTHOLDER");
namedLock.release("api-release-2", "lane1");
});
it("404s when the lock doesn't exist", async () => {
const res = await request("POST", "/api/locks/never-held/release", { holder: "lane1" });
assert.equal(res.status, 404);
assert.equal(res.body.error.code, "ENOLOCK");
});
});