feat(pool): pin a user to one Claude/Codex pool account

An admin pins a server-mode user to one pool account per tool
(account_pins; PUT /api/accounts/pins with the password step-up and audit,
the Users page's Pin a user, agenthub accounts pin|unpin). The workspace
owner's pin wins over the balancer whenever the pane may use the account;
a pinned login still waits while another pool login holds the home.
This commit is contained in:
2026-10-19 10:05:19 +07:00
parent aa8ac6cad9
commit 9c98638ec0
20 changed files with 776 additions and 39 deletions
+34 -1
View File
@@ -9,7 +9,8 @@
* same account; removing the account takes it out of those homes; and the
* Users-page route moves a saved switch-user profile in — the one this
* machine's own Claude Code is logged into with its LIVE login, the host's
* home then being one more placement the server refreshes.
* home then being one more placement the server refreshes. A pin of the
* owner to another login waits while a live pane holds the first.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
@@ -188,6 +189,38 @@ describe("a pool login", () => {
assert.equal(pool.__read("team"), null);
});
it("follows the owner's pin, but never over another login a live pane holds", () => {
const { db } = require("../db");
const pins = require("../lib/account-pins");
const miaId = db.prepare("SELECT id FROM users WHERE username = 'mia'").get().id;
pool.addLoginAccount("alpha", { oauth: oauth("a"), account: ACCOUNT });
pool.addLoginAccount("beta", {
oauth: oauth("b"),
account: { accountUuid: "uuid-beta", emailAddress: "beta@example.com" },
});
assert.equal(pool.forSpawn(acct, miaId).name, "alpha", "unpinned: the balancer's pick");
pins.setPin(miaId, "claude", "beta");
assert.equal(pool.forSpawn(acct, miaId).name, "beta");
assert.equal(pool.forSpawn(acct, null).name, "alpha", "another owner is not pinned");
// A pane of mia's runs on alpha: beta waits until it ends.
pool.forSpawn(acct).place();
fs.mkdirSync(path.join(HOME, "proj"), { recursive: true });
const lane = db
.prepare("INSERT INTO lanes (cwd, owner_id) VALUES (?, ?)")
.run(path.join(HOME, "proj"), miaId).lastInsertRowid;
db.prepare(
`INSERT INTO dashboard_runs (id, mode, cwd, status, started_at, account, lane_id, tool)
VALUES ('pin-run', 'interactive', ?, 'running', ?, 'alpha', ?, 'claude')`
).run(path.join(HOME, "proj"), new Date().toISOString(), lane);
assert.equal(pool.forSpawn(acct, miaId).name, "alpha");
db.prepare("UPDATE dashboard_runs SET status = 'completed' WHERE id = 'pin-run'").run();
assert.equal(pool.forSpawn(acct, miaId).name, "beta");
pool.removeAccount("beta");
assert.equal(pins.pinFor(miaId, "claude"), null, "a removed account drops its pins");
db.prepare("DELETE FROM dashboard_runs WHERE id = 'pin-run'").run();
db.prepare("DELETE FROM lanes WHERE id = ?").run(lane);
});
it("refuses a second copy of one Claude account", () => {
pool.addLoginAccount("team", { oauth: oauth("a"), account: ACCOUNT });
assert.throws(() => pool.addLoginAccount("team-2", { oauth: oauth("b"), account: ACCOUNT }), {