Files
AgentHub/server/__tests__/lane-agents.test.js
T
nntrivi2001 2b8f83d2dd refactor(lanes): drop the workflow skills and Superpowers link; pipelines go dormant
The plugin stops shipping its workflow layer:
- skills/ship-feature and skills/ship-feature-lane, the 18 stage/ship slash
  commands (plugin.json keeps agenthub-doctor/update/open), and all four
  agents/ (qc-local, senior-gate-reviewer, backend-reviewer, frontend-reviewer).
- CLI `agenthub skills install`, `agenthub lanes agents install`,
  `agenthub ship-full|ship-quick`; routes POST /api/skills/install and
  POST /api/lanes/:id/agents/install; the Settings button, the lane Tools
  menu item and the Add-lane setup step that called them.
- The Superpowers auto-install: server/lib/skill-plugins.js, the bootstrap's
  autoInstallSkillPlugins / skillPluginsSettled gate and the doctor row.

Pipelines are kept but dormant: server/data/pipelines/ is deleted, so no
template ships. `default` resolves to EMPTY_PIPELINE (no nodes, progress 0),
createLane still accepts it, POST /api/lanes/:id/stage answers 400
ENOPIPELINE, and the Workspace hides the stage timer, pickers, PipelineMap
and strip stage chip for a lane with no nodes. A template dropped into
DASHBOARD_PIPELINES_DIR turns it all back on. The server suite loads its
templates from server/__tests__/fixtures/pipelines/.

Docs: CLAUDE.md (marker, retired rules), README(.vi), INSTALL, ARCHITECTURE,
docs/LANES|PLUGINS|CLI|API, agenthub-introduction.html.
2026-09-28 17:49:05 +07:00

113 lines
4.6 KiB
JavaScript

/**
* @file Tests for lane-agents.js's removeStageDoc and the codex pipeline
* cleanup it pairs with (clearCodexPipelines).
* @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 { removeStageDoc } = 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;
}
describe("codex pipeline cleanup", () => {
const START = "<!-- agenthub:stage:start -->";
const END = "<!-- agenthub:stage:end -->";
const BLOCK = `${START}\n## Declare your lane stage as you work\n\nagenthub stage …\n${END}\n`;
it("removes only the AgentHub block, keeping the user's own AGENTS.md prose", () => {
const cwd = makeRepoDir();
const file = path.join(cwd, "AGENTS.md");
fs.writeFileSync(file, `# House rules\n\nNever force-push.\n\n${BLOCK}\n## More\n\nKeep me.\n`);
assert.equal(removeStageDoc(cwd), true);
const doc = fs.readFileSync(file, "utf8");
assert.ok(!doc.includes(START) && !doc.includes(END));
assert.match(doc, /Never force-push\./);
assert.match(doc, /Keep me\./);
});
it("deletes an AGENTS.md that held nothing but the block", () => {
const cwd = makeRepoDir();
fs.writeFileSync(path.join(cwd, "AGENTS.md"), BLOCK);
assert.equal(removeStageDoc(cwd), true);
assert.equal(fs.existsSync(path.join(cwd, "AGENTS.md")), false);
});
it("leaves a file without the block, or no file at all, untouched", () => {
const cwd = makeRepoDir();
assert.equal(removeStageDoc(cwd), false);
fs.writeFileSync(path.join(cwd, "AGENTS.md"), "# Mine\n");
assert.equal(removeStageDoc(cwd), false);
assert.equal(fs.readFileSync(path.join(cwd, "AGENTS.md"), "utf8"), "# Mine\n");
});
it("wipes a codex lane's stage, detection, stage log and features — and no claude lane's", () => {
const codex = lanesLib.createLane({ title: "cx", cwd: makeRepoDir(), tool: "codex" });
const claude = lanesLib.createLane({ title: "cc", cwd: makeRepoDir(), tool: "claude" });
for (const lane of [codex, claude]) {
lanesLib.setStage(lane.id, { stage: "tests", evidence: "old" });
lanesLib.recordDetection(lane.id, { nodeId: "review", signal: "npm test" });
}
const { db } = require("../db");
const insertFeature = db.prepare("INSERT INTO lane_features (lane_id, slug) VALUES (?, ?)");
insertFeature.run(codex.id, "old-feature");
insertFeature.run(claude.id, "kept-feature");
assert.equal(lanesLib.clearCodexPipelines(), 1);
const cx = lanesLib.getLane(codex.id);
assert.equal(cx.stage, "idle");
assert.deepEqual(cx.stages, {});
assert.equal(cx.detected_stage, null);
const count = (table, id) =>
db.prepare(`SELECT COUNT(*) AS n FROM ${table} WHERE lane_id = ?`).get(id).n;
assert.equal(count("lane_stage_events", codex.id), 0);
assert.equal(count("lane_features", codex.id), 0);
const cc = lanesLib.getLane(claude.id);
assert.equal(cc.stage, "tests");
assert.ok(count("lane_stage_events", claude.id) > 0);
assert.equal(count("lane_features", claude.id), 1);
assert.equal(lanesLib.clearCodexPipelines(), 0); // idempotent
});
});