5fe5d51b1b
AI Proxy (was AI Router): - server/lib/ai-proxies.js, proxy-apply.js, routes/ai-proxies.js mounted at /api/ai-proxies and the old /api/ai-routers; `router` still accepted on the start routes; profiles move to <CLAUDE_HOME>/agenthub-proxies/ - dashboard_runs.router renamed in place to proxy: an older build on the same DB fails on that column, so dev and prod sharing one DB update together - a proxy's baseUrl stored as its root (a typed /v1 made /v1/v1/messages); Test probes Claude /v1/messages and Codex /v1/responses - Settings → AI Proxy (/settings/ai-router redirects), ProxyPicker Updates: - every tab reloads onto the new UI build when its WebSocket reconnects to a server of another version (lib/newBuildReload.ts, once per version) - Update now stops waiting on a plugin chain that failed or pulled nothing (the old server never goes down), and reloads as soon as a new version answers Also: - a pane whose command exits at once says so (EPANEEXITED) instead of "Command failed: tmux set-option … mouse on" - the pane drag preview draws where the pane actually lands
152 lines
4.7 KiB
JavaScript
152 lines
4.7 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 names a command that exited at once instead of tmux's set-option error", () => {
|
|
tmux.__setExecImpl((args) => {
|
|
if (args[0] === "new-session") return "";
|
|
throw Object.assign(new Error("Command failed: tmux " + args.join(" ")), { status: 1 });
|
|
});
|
|
assert.throws(
|
|
() =>
|
|
tmux.newSession({ name: "agenthub-lane-4", cwd: "/tmp/repo", argv: ["claude", "-p", "x"] }),
|
|
(err) =>
|
|
err.code === "EPANEEXITED" && /exited as soon as it started: claude$/.test(err.message)
|
|
);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|