a9c71cd905
Usage panel (status bar): - every account shows its plan (Claude subscriptionType, Codex chatgpt_plan_type, Cursor membershipType, Grok subscriptionTier) - new quota rows: Cursor CLI (cursor.com usage-summary), Antigravity (`agy --print /usage`, two model pools; AGENTHUB_AGY_USAGE=0 never runs agy), Grok Build, Kimi Code, OpenCode Go — each login read from the tool's own file, sent only to its own host while valid, never refreshed - in-flight quota reads are shared between tabs AI Tools catalog: Grok Build (`grok`) and Kimi Code (`kimi`) added; Gemini CLI, Hermes and OpenClaw removed. Also: Quit AgentHub (#65, `agenthub stop`), status-area icon, Add to Chat on an editor selection, Settings in three groups, JetBrains-style Changes panel (ticked files/hunks, ignore, blame, file history), terminal font. --no-verify: :3000 is taken by another dev server (lane-detect tests); both suites run by hand — server 2636/2639 (the 3 are :3000), client 1131/1131.
132 lines
4.6 KiB
JavaScript
132 lines
4.6 KiB
JavaScript
/**
|
|
* @file Tests Quit AgentHub (issue #65, server/lib/quit.js and
|
|
* POST /api/settings/quit): the stopped flag, stopping through the service
|
|
* manager when a unit of ours runs the server (a SIGTERM would be restarted),
|
|
* and the route killing every lane pane before it stops. tmux runs only in the
|
|
* isolated server `npm run test:server` sets up.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
const { describe, it, before, after } = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs");
|
|
const os = require("node:os");
|
|
const path = require("node:path");
|
|
const http = require("node:http");
|
|
const { execFileSync } = require("node:child_process");
|
|
|
|
const TMP = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-quit-"));
|
|
process.env.DASHBOARD_DATA_DIR = TMP;
|
|
process.env.DASHBOARD_DB_PATH = path.join(TMP, "dashboard.db");
|
|
process.env.DASHBOARD_LIVENESS_PROBE = "0";
|
|
|
|
const quit = require("../lib/quit");
|
|
|
|
after(() => fs.rmSync(TMP, { recursive: true, force: true }));
|
|
|
|
describe("stopped flag", () => {
|
|
it("is set by markQuit and cleared by clearQuit, in the data dir's runtime", () => {
|
|
assert.equal(quit.flagPath(), path.join(TMP, "runtime", "stopped"));
|
|
assert.equal(quit.isQuit(), false);
|
|
quit.markQuit();
|
|
assert.equal(quit.isQuit(), true);
|
|
quit.clearQuit();
|
|
assert.equal(quit.isQuit(), false);
|
|
quit.clearQuit(); // already gone: fine
|
|
});
|
|
});
|
|
|
|
describe("stopServer", () => {
|
|
const fakeSvc = (kind, active) => ({
|
|
kind,
|
|
systemctlAvailable: () => true,
|
|
unitIsOurs: () => true,
|
|
unitIsActive: () => active,
|
|
});
|
|
const spawned = [];
|
|
const spawn = (cmd, args) => {
|
|
spawned.push([cmd, ...args].join(" "));
|
|
return { unref() {} };
|
|
};
|
|
|
|
it("SIGTERMs itself when no unit of ours is running", () => {
|
|
let killed = 0;
|
|
quit.stopServer({ svc: fakeSvc("systemd", false), spawn, kill: () => killed++ });
|
|
assert.equal(killed, 1);
|
|
assert.deepEqual(spawned, []);
|
|
});
|
|
|
|
it("stops a running unit through systemd, never by a signal Restart=always undoes", () => {
|
|
let killed = 0;
|
|
quit.stopServer({ svc: fakeSvc("systemd", true), spawn, kill: () => killed++ });
|
|
assert.equal(killed, 0);
|
|
assert.deepEqual(spawned.splice(0), ["systemctl --user stop --no-block agenthub.service"]);
|
|
});
|
|
|
|
it("boots a running LaunchAgent out", { skip: process.platform === "win32" }, () => {
|
|
quit.stopServer({ svc: fakeSvc("launchd", true), spawn, kill: () => {} });
|
|
assert.match(spawned.splice(0)[0], /^launchctl bootout gui\/\d+\/io\.smartgift\.agenthub$/);
|
|
});
|
|
});
|
|
|
|
// Only inside the runner's private tmux server: never the developer's own.
|
|
const isolatedTmux = !!process.env.TMUX_TMPDIR && !process.env.TMUX;
|
|
let hasTmux = false;
|
|
try {
|
|
execFileSync("tmux", ["-V"], { stdio: "ignore" });
|
|
hasTmux = true;
|
|
} catch {
|
|
/* not installed */
|
|
}
|
|
|
|
describe(
|
|
"POST /api/settings/quit",
|
|
{ skip: !(isolatedTmux && hasTmux) && "needs the runner's isolated tmux" },
|
|
() => {
|
|
let server;
|
|
let base;
|
|
let stops = 0;
|
|
const realStop = quit.stopServer;
|
|
|
|
before(async () => {
|
|
quit.stopServer = () => stops++; // this process is the test runner
|
|
const { createApp, startServer } = require("../index");
|
|
server = await startServer(createApp(), 0);
|
|
base = `http://127.0.0.1:${server.address().port}`;
|
|
});
|
|
|
|
after(() => {
|
|
quit.stopServer = realStop;
|
|
server?.close();
|
|
require("../db").db.close();
|
|
});
|
|
|
|
it("closes every lane pane, sets the flag, then stops the server", async () => {
|
|
execFileSync("tmux", ["new-session", "-d", "-s", "agenthub-lane-9001", "sleep 60"]);
|
|
execFileSync("tmux", ["new-session", "-d", "-s", "agenthub-lane-9001-2", "sleep 60"]);
|
|
execFileSync("tmux", ["new-session", "-d", "-s", "not-ours", "sleep 60"]);
|
|
try {
|
|
const body = await new Promise((resolve, reject) => {
|
|
const req = http.request(`${base}/api/settings/quit`, { method: "POST" }, (res) => {
|
|
let text = "";
|
|
res.on("data", (c) => (text += c));
|
|
res.on("end", () => resolve(JSON.parse(text)));
|
|
});
|
|
req.on("error", reject);
|
|
req.end();
|
|
});
|
|
assert.deepEqual(body, { ok: true, killed: 2 });
|
|
assert.equal(quit.isQuit(), true);
|
|
const left = execFileSync("tmux", ["list-sessions", "-F", "#{session_name}"], {
|
|
encoding: "utf8",
|
|
});
|
|
assert.deepEqual(left.trim().split("\n"), ["not-ours"]);
|
|
await new Promise((r) => setImmediate(r));
|
|
assert.equal(stops, 1);
|
|
} finally {
|
|
execFileSync("tmux", ["kill-session", "-t", "not-ours"]);
|
|
}
|
|
});
|
|
}
|
|
);
|