f0500dc592
- Changes panel: Files and Changes merged into one panel; the overview's groups drawn as a folder tree (compacted chains, file counts, fold, stage/unstage a whole folder) - AI-suggested commit message for what is staged (POST /api/lanes/:id/git/commit-message, claude -p --safe-mode, haiku) - AI Router: optional "Behaves as" Claude model id, written as modelPicker options into the router's --settings file (issue #56) - Sidebar: session rows show last activity, live rows their start time; a closed Terminal row can be removed (DELETE /api/run/history/:id) - Every pane's CLI starts only once a client is attached; claude panes no longer forced inline; tmux scrollbar one column wide - Update notifier: "Check for updates" reopens a closed notice
139 lines
4.2 KiB
JavaScript
139 lines
4.2 KiB
JavaScript
/**
|
|
* @file tmux.test.js
|
|
* @description Unit tests for the tmux command wrapper. Injects a fake exec
|
|
* implementation so the suite never shells out to a real `tmux` binary (CI
|
|
* has none installed).
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
const { describe, it, beforeEach } = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const tmux = require("../lib/tmux");
|
|
|
|
describe("tmux wrapper", () => {
|
|
beforeEach(() => {
|
|
tmux.__reset();
|
|
});
|
|
|
|
it("hasSession returns true when execFileSync exits 0", () => {
|
|
tmux.__setExecImpl(() => "");
|
|
assert.equal(tmux.hasSession("agenthub-lane-1"), true);
|
|
});
|
|
|
|
it("hasSession returns false when execFileSync throws", () => {
|
|
tmux.__setExecImpl(() => {
|
|
const e = new Error("no such session");
|
|
e.status = 1;
|
|
throw e;
|
|
});
|
|
assert.equal(tmux.hasSession("agenthub-lane-1"), false);
|
|
});
|
|
|
|
it("newSession builds the correct argv", () => {
|
|
const calls = [];
|
|
tmux.__setExecImpl((args) => {
|
|
calls.push(args);
|
|
return "";
|
|
});
|
|
tmux.newSession({
|
|
name: "agenthub-lane-1",
|
|
cwd: "/tmp/repo",
|
|
argv: ["claude", "--model", "opus"],
|
|
});
|
|
assert.deepEqual(calls[0], [
|
|
"new-session",
|
|
"-d",
|
|
"-s",
|
|
"agenthub-lane-1",
|
|
"-c",
|
|
"/tmp/repo",
|
|
"--",
|
|
"claude",
|
|
"--model",
|
|
"opus",
|
|
]);
|
|
assert.deepEqual(calls[1], ["set-option", "-t", "=agenthub-lane-1:", "mouse", "on"]);
|
|
assert.deepEqual(calls[2], ["set-option", "-t", "=agenthub-lane-1:", "status", "off"]);
|
|
assert.deepEqual(calls[3], ["set-option", "-t", "=agenthub-lane-1:", "pane-scrollbars", "on"]);
|
|
assert.deepEqual(calls[4], [
|
|
"set-option",
|
|
"-t",
|
|
"=agenthub-lane-1:",
|
|
"pane-scrollbars-style",
|
|
"fg=brightwhite,bg=black,width=1,pad=0",
|
|
]);
|
|
});
|
|
|
|
it("newSession still succeeds on a tmux older than 3.7 (no pane-scrollbars)", () => {
|
|
tmux.__setExecImpl((args) => {
|
|
if (args.includes("pane-scrollbars")) throw new Error("invalid option: pane-scrollbars");
|
|
return "";
|
|
});
|
|
assert.doesNotThrow(() =>
|
|
tmux.newSession({ name: "agenthub-lane-1", cwd: "/tmp/repo", argv: ["claude"] })
|
|
);
|
|
});
|
|
|
|
it("sendText types the literal string and presses Enter, with no quoting", () => {
|
|
const calls = [];
|
|
tmux.__setExecImpl((args) => {
|
|
calls.push(args);
|
|
return "";
|
|
});
|
|
tmux.sendText("agenthub-lane-1", 'Reminder: run "agenthub stage implement"');
|
|
assert.deepEqual(calls[0], [
|
|
"send-keys",
|
|
"-t",
|
|
"=agenthub-lane-1:",
|
|
"-l",
|
|
'Reminder: run "agenthub stage implement"',
|
|
]);
|
|
assert.deepEqual(calls[1], ["send-keys", "-t", "=agenthub-lane-1:", "Enter"]);
|
|
});
|
|
|
|
it("targets a session exactly, so lane 1 never resolves to lane 12 by prefix", () => {
|
|
const calls = [];
|
|
tmux.__setExecImpl((args) => {
|
|
calls.push(args);
|
|
return "";
|
|
});
|
|
tmux.hasSession("agenthub-lane-1");
|
|
tmux.killSession("agenthub-lane-1");
|
|
assert.deepEqual(calls, [
|
|
["has-session", "-t", "=agenthub-lane-1"],
|
|
["kill-session", "-t", "=agenthub-lane-1"],
|
|
]);
|
|
});
|
|
|
|
it("killSession never throws when the session is already gone", () => {
|
|
tmux.__setExecImpl(() => {
|
|
const e = new Error("no such session");
|
|
e.status = 1;
|
|
throw e;
|
|
});
|
|
assert.doesNotThrow(() => tmux.killSession("agenthub-lane-1"));
|
|
});
|
|
|
|
it("listSessions filters by prefix and ignores unrelated sessions", () => {
|
|
tmux.__setExecImpl(() => "agenthub-lane-1\nagenthub-lane-2\nsome-other-session\n");
|
|
assert.deepEqual(tmux.listSessions("agenthub-lane-"), ["agenthub-lane-1", "agenthub-lane-2"]);
|
|
});
|
|
|
|
it("listSessions returns [] when tmux has no sessions at all (exit 1)", () => {
|
|
tmux.__setExecImpl(() => {
|
|
const e = new Error("no server running");
|
|
e.status = 1;
|
|
throw e;
|
|
});
|
|
assert.deepEqual(tmux.listSessions("agenthub-lane-"), []);
|
|
});
|
|
|
|
it("isTmuxAvailable reflects whether the binary resolves on PATH", () => {
|
|
tmux.__setExecImpl(() => "tmux 3.4");
|
|
assert.equal(tmux.isTmuxAvailable(), true);
|
|
tmux.__setExecImpl(() => {
|
|
throw new Error("ENOENT");
|
|
});
|
|
assert.equal(tmux.isTmuxAvailable(), false);
|
|
});
|
|
});
|