refactor: resolve the tmux socket from the instance config

The socket name was computed inside tmux-manager, which the TUI cannot import
just to learn which `-L` name its degraded-mode listing belongs on (that module
is the server's tmux driver, not a lookup table). The resolver moves next to
`dataPath()`, where the other half of the instance identity already lives, so
both processes agree by construction instead of by a copied default.

Behaviour is unchanged: the override still wins only when it is a name that can
be passed to `tmux -L` safely, and TmuxManager keeps warning about one that
cannot.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer
2026-08-16 21:35:31 +02:00
parent 4060696faa
commit 00ef72c80e
3 changed files with 43 additions and 7 deletions
+20 -1
View File
@@ -18,7 +18,7 @@ vi.mock('node:fs', async (orig) => {
return { ...actual, mkdirSync: vi.fn() };
});
const ENV_KEYS = ['CODEMAN_INSTANCE', 'CODEMAN_DATA_DIR'] as const;
const ENV_KEYS = ['CODEMAN_INSTANCE', 'CODEMAN_DATA_DIR', 'CODEMAN_TMUX_SOCKET'] as const;
const ORIG: Record<string, string | undefined> = Object.fromEntries(ENV_KEYS.map((k) => [k, process.env[k]]));
async function load(env: Partial<Record<(typeof ENV_KEYS)[number], string | undefined>> = {}) {
@@ -77,3 +77,22 @@ describe('config/instance', () => {
expect(m.DEFAULT_TMUX_SOCKET).toBe('codeman-beta');
});
});
describe('resolveTmuxSocketName', () => {
it('is the instance socket when no override is set', async () => {
const m = await load({ CODEMAN_INSTANCE: 'beta', CODEMAN_TMUX_SOCKET: undefined });
expect(m.resolveTmuxSocketName()).toBe('codeman-beta');
});
it('honours a safe CODEMAN_TMUX_SOCKET override', async () => {
const m = await load({ CODEMAN_INSTANCE: undefined, CODEMAN_TMUX_SOCKET: 'codeman-test.1' });
expect(m.resolveTmuxSocketName()).toBe('codeman-test.1');
});
it('ignores an override that could not be passed to `tmux -L` safely', async () => {
// A socket name reaches a command line, so anything outside the pattern
// falls back to the instance default rather than being escaped.
const m = await load({ CODEMAN_INSTANCE: undefined, CODEMAN_TMUX_SOCKET: 'bad; rm -rf /' });
expect(m.resolveTmuxSocketName()).toBe('codeman');
});
});