fix(run): turn on tmux mouse mode on every attach, not just at session creation

Sessions created before the mouse-on fix landed (or before the server
restarted to pick it up) never got the set-option call, so their pane
still had no drag/wheel scroll. Moving it into pty-attach's attach()
makes it idempotent per-connection instead of once-at-birth.
This commit is contained in:
2026-08-19 11:32:23 +07:00
parent 43d4989f1e
commit aaa67da394
3 changed files with 47 additions and 5 deletions
+25 -1
View File
@@ -5,10 +5,11 @@
* or PTY spawned).
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const { describe, it, beforeEach } = require("node:test");
const { describe, it, beforeEach, afterEach } = require("node:test");
const assert = require("node:assert/strict");
const { EventEmitter } = require("node:events");
const ptyAttach = require("../lib/pty-attach");
const tmux = require("../lib/tmux");
function makeFakePty() {
const emitter = new EventEmitter();
@@ -41,6 +42,10 @@ describe("pty-attach", () => {
beforeEach(() => {
fakePty = makeFakePty();
ptyAttach.__setSpawnImpl(() => fakePty);
tmux.__setExecImpl(() => "");
});
afterEach(() => {
tmux.__reset();
});
it("rejects a runId that doesn't match ccam-lane-<digits>", () => {
@@ -52,6 +57,25 @@ describe("pty-attach", () => {
assert.doesNotThrow(() => ptyAttach.validateRunId("ccam-lane-42"));
});
it("turns tmux mouse mode on for the session it attaches to", () => {
const calls = [];
tmux.__setExecImpl((args) => {
calls.push(args);
return "";
});
ptyAttach.attach(makeFakeWs(), "ccam-lane-1", { cols: 80, rows: 24 });
assert.deepEqual(calls[0], ["set-option", "-t", "ccam-lane-1", "mouse", "on"]);
});
it("still attaches even if the mouse-mode set-option call fails", () => {
tmux.__setExecImpl(() => {
throw new Error("no such session: ccam-lane-1");
});
assert.doesNotThrow(() =>
ptyAttach.attach(makeFakeWs(), "ccam-lane-1", { cols: 80, rows: 24 })
);
});
it("wires PTY data to binary WS frames and WS binary frames to PTY writes", () => {
const ws = makeFakeWs();
ptyAttach.attach(ws, "ccam-lane-1", { cols: 80, rows: 24 });