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).
145 lines
5.6 KiB
JavaScript
145 lines
5.6 KiB
JavaScript
/**
|
|
* @file Tests for lane-agents.js: agent-template installation into a lane's
|
|
* .claude/agents/, including path resolution, git-exclude idempotence, and
|
|
* missing-repo rejection.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
const { execFileSync } = require("node:child_process");
|
|
const os = require("node:os");
|
|
const path = require("node:path");
|
|
const fs = require("node:fs");
|
|
|
|
const SUITE_ROOT = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-lane-agents-"));
|
|
process.env.DASHBOARD_DB_PATH = path.join(SUITE_ROOT, "dashboard.db");
|
|
process.env.LANES_ROOT = path.join(SUITE_ROOT, "lanes");
|
|
|
|
const { describe, it, after } = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
|
|
const lanesLib = require("../lib/lanes");
|
|
const { installAgents } = require("../lib/lane-agents");
|
|
|
|
after(() => fs.rmSync(SUITE_ROOT, { recursive: true, force: true }));
|
|
|
|
// Strip GIT_* vars a parent git hook (e.g. the pre-commit hook running this
|
|
// very suite) sets in its own environment — those leak to every child
|
|
// process and override an explicit `cwd`, so without this `git init` here
|
|
// operates on the outer repo's .git instead of this fixture's throwaway one.
|
|
// Same scrub `lanes-cli.test.js` and `worktree.js`'s own git() helper use.
|
|
const GIT_ENV = { ...process.env };
|
|
delete GIT_ENV.GIT_DIR;
|
|
delete GIT_ENV.GIT_WORK_TREE;
|
|
delete GIT_ENV.GIT_INDEX_FILE;
|
|
delete GIT_ENV.GIT_COMMON_DIR;
|
|
delete GIT_ENV.GIT_OBJECT_DIRECTORY;
|
|
delete GIT_ENV.GIT_ALTERNATE_OBJECT_DIRECTORIES;
|
|
delete GIT_ENV.GIT_PREFIX;
|
|
delete GIT_ENV.GIT_NAMESPACE;
|
|
delete GIT_ENV.GIT_CONFIG_PARAMETERS;
|
|
|
|
let laneSeq = 0;
|
|
|
|
/** Create a real git repo dir (used as a lane's cwd). */
|
|
function makeRepoDir() {
|
|
const cwd = path.join(SUITE_ROOT, `repo-${++laneSeq}`);
|
|
fs.mkdirSync(cwd, { recursive: true });
|
|
execFileSync("git", ["init", "--initial-branch=main"], { cwd, stdio: "pipe", env: GIT_ENV });
|
|
return cwd;
|
|
}
|
|
|
|
/** Create a lane record backed by an existing directory. */
|
|
function makeLane(cwd) {
|
|
return lanesLib.createLane({ title: "agents-test", cwd, kind: "managed" });
|
|
}
|
|
|
|
describe("installAgents", () => {
|
|
it("copies agent templates from agents/ dir into lane's .claude/agents/", async () => {
|
|
const cwd = makeRepoDir();
|
|
const lane = makeLane(cwd);
|
|
const result = await installAgents(lane);
|
|
|
|
assert.deepEqual([...result.installed].sort(), ["qc-local.md", "senior-gate-reviewer.md"]);
|
|
assert.ok(fs.existsSync(path.join(cwd, ".claude", "agents", "qc-local.md")));
|
|
assert.ok(fs.existsSync(path.join(cwd, ".claude", "agents", "senior-gate-reviewer.md")));
|
|
|
|
// Verify the source path is new (agents/) not old (data/agent-templates/)
|
|
const oldPath = path.join(__dirname, "..", "data", "agent-templates", "ship-feature-lane");
|
|
assert.equal(fs.existsSync(oldPath), false);
|
|
});
|
|
|
|
it("throws ENOTGITREPO when lane cwd has no .git", async () => {
|
|
const cwd = path.join(SUITE_ROOT, "no-git");
|
|
fs.mkdirSync(cwd, { recursive: true });
|
|
const lane = makeLane(cwd);
|
|
await assert.rejects(
|
|
() => installAgents(lane),
|
|
(err) => err.code === "ENOTGITREPO"
|
|
);
|
|
});
|
|
|
|
it("adds .claude/agents/ line to git info/exclude idempotently", async () => {
|
|
const cwd = makeRepoDir();
|
|
const lane = makeLane(cwd);
|
|
|
|
await installAgents(lane); // first
|
|
await installAgents(lane); // reinstall — should not duplicate
|
|
|
|
const excludePath = path.join(cwd, ".git", "info", "exclude");
|
|
const content = fs.readFileSync(excludePath, "utf8");
|
|
const matches = content.split("\n").filter((l) => l === ".claude/agents/");
|
|
assert.equal(matches.length, 1);
|
|
});
|
|
|
|
it("overwrites existing agents on reinstall", async () => {
|
|
const cwd = makeRepoDir();
|
|
const lane = makeLane(cwd);
|
|
|
|
await installAgents(lane);
|
|
|
|
// Tamper with the installed file
|
|
const agentPath = path.join(cwd, ".claude", "agents", "qc-local.md");
|
|
fs.writeFileSync(agentPath, "tampered");
|
|
|
|
// Reinstall
|
|
await installAgents(lane);
|
|
const content = fs.readFileSync(agentPath, "utf8");
|
|
assert.ok(content.includes("#"), "reinstalled file should look like markdown, not 'tampered'");
|
|
assert.notEqual(content, "tampered");
|
|
});
|
|
|
|
it("creates .claude/agents/ dir if it does not exist", async () => {
|
|
const cwd = makeRepoDir();
|
|
const lane = makeLane(cwd);
|
|
assert.equal(fs.existsSync(path.join(cwd, ".claude", "agents")), false);
|
|
await installAgents(lane);
|
|
assert.ok(fs.existsSync(path.join(cwd, ".claude", "agents")));
|
|
});
|
|
|
|
it("installs the AGENTS.md stage block for a codex lane, not .claude/agents/", async () => {
|
|
const cwd = makeRepoDir();
|
|
const lane = lanesLib.createLane({ title: "cx", cwd, kind: "managed", tool: "codex" });
|
|
|
|
const result = await installAgents(lane);
|
|
assert.deepEqual(result.installed, ["AGENTS.md"]);
|
|
assert.equal(fs.existsSync(path.join(cwd, ".claude", "agents")), false);
|
|
const doc = fs.readFileSync(path.join(cwd, "AGENTS.md"), "utf8");
|
|
assert.match(doc, /agenthub stage <stage> --tool codex/);
|
|
});
|
|
|
|
it("preserves the user's own AGENTS.md prose and replaces only the block", async () => {
|
|
const cwd = makeRepoDir();
|
|
const lane = lanesLib.createLane({ title: "cx", cwd, kind: "managed", tool: "codex" });
|
|
const file = path.join(cwd, "AGENTS.md");
|
|
fs.writeFileSync(file, "# House rules\n\nNever force-push.\n");
|
|
|
|
await installAgents(lane);
|
|
await installAgents(lane); // reinstall must not duplicate the block
|
|
|
|
const doc = fs.readFileSync(file, "utf8");
|
|
assert.match(doc, /Never force-push\./);
|
|
assert.equal(doc.split("<!-- agenthub:stage:start -->").length - 1, 1);
|
|
assert.equal(doc.split("<!-- agenthub:stage:end -->").length - 1, 1);
|
|
});
|
|
});
|