fix(tui): undo a half-done follow arm

armFollowTyping() set the owner option, then a hook. On tmux before 3.3
there is no client-active hook, so the first set-hook failed and the arm
answered false with the owner still set; restore() disarms only what
armed, so it stayed on the session. A failed arm now drops the owner and
any of our hooks it already set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kamil KaliszandClaude Opus 5.5 committed 2026-11-24 18:42:21 +01:00
1 parent dbf545ce8f
commit 9753ca9d70
2 files changed
+27 -1

No files matched your search

+13 -1
View File
@@ -527,7 +527,9 @@ describe('the follow hooks', () => {
* A fake tmux holding one session's options and hooks, so arm, disarm and
* the sweep run against state rather than a script of canned answers.
*/
function fakeTmux(initial: { owner?: string; hooks?: Record<string, string>; clients?: string[] } = {}) {
function fakeTmux(
initial: { owner?: string; hooks?: Record<string, string>; clients?: string[]; refuseHook?: string } = {}
) {
const state = { owner: initial.owner ?? null, hooks: { ...(initial.hooks ?? {}) } as Record<string, string> };
const writes: string[] = [];
const exec: TuiExecFile = async (_file, args) => {
@@ -544,6 +546,9 @@ describe('the follow hooks', () => {
const lines = Object.entries(state.hooks).map(([name, command]) => `${name} ${command}`);
return { stdout: lines.join('\n'), stderr: '' };
}
if (verb === 'set-hook' && !args.includes('-u') && args.includes(initial.refuseHook ?? '\0')) {
throw new Error(`invalid option: ${initial.refuseHook}`);
}
writes.push(args.slice(2).join(' '));
if (verb === 'set-option' && args.includes('-u')) state.owner = null;
else if (verb === 'set-option') state.owner = args[args.length - 1] ?? null;
@@ -598,6 +603,13 @@ describe('the follow hooks', () => {
expect(state).toEqual({ owner: null, hooks: {} });
});
it('undoes a half-done arm, as on a tmux without client-active (before 3.3)', async () => {
const { client, state } = fakeTmux({ refuseHook: 'client-active[91]' });
await expect(client.armFollowTyping('codeman-1a2b3c4d', '/dev/pts/4')).resolves.toBe(false);
// restore() disarms only what armed, so nothing may be left behind here.
expect(state).toEqual({ owner: null, hooks: {} });
});
it('installs nothing over a hook of the user, and never removes one', async () => {
const { client, state, writes } = fakeTmux({ hooks: { 'after-resize-window[91]': 'display-message mine' } });
await expect(client.armFollowTyping('codeman-1a2b3c4d', '/dev/pts/4')).resolves.toBe(false);