mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
test(tmux): the review item of #840 that goes on top
The live-pane close case moves into test/kill-pid-guard.test.ts, whose harness answers ps from a fixed table. In tmux-manager.test.ts the mock keeps the real execFile, so the walk read this machine's process table. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
a4201b34a8
commit
d5fe0adfe7
2 files changed
+23
-62
No files matched your search
@@ -1406,66 +1406,6 @@ describe('TmuxManager (unit)', () => {
|
||||
nonTestManager.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
// The counterpart: the dead-pane rule must not stop a close from killing a
|
||||
// pane whose program still runs.
|
||||
it('still signals the process tree of a live pane on close', async () => {
|
||||
const defaultExec = mockedExec.getMockImplementation();
|
||||
mockedExec.mockImplementation(((cmd: string, optionsOrCallback?: unknown, maybeCallback?: unknown) => {
|
||||
const callback = (typeof optionsOrCallback === 'function' ? optionsOrCallback : maybeCallback) as
|
||||
| ((err: Error | null, out: unknown, stderr: string) => void)
|
||||
| undefined;
|
||||
// promisify(exec) on this mock resolves with the second argument. A live
|
||||
// pane: not dead, its own pid, no exit time.
|
||||
const stdout = cmd.includes(' display-message ') ? (cmd.includes('#{pane_dead}') ? '0|4343|\n' : '4343\n') : '';
|
||||
if (callback) setImmediate(() => callback(null, { stdout, stderr: '' }, ''));
|
||||
return { on: vi.fn(), kill: vi.fn(), pid: 12345 };
|
||||
}) as unknown as typeof exec);
|
||||
// The pane's process exits on its first real signal, as a live CLI does.
|
||||
// Afterwards the liveness probe (`kill(pid, 0)`) throws, so the kill path
|
||||
// stops waiting before it reads /proc, which this file mocks (Linux CI).
|
||||
let paneAlive = true;
|
||||
const kill = vi.spyOn(process, 'kill').mockImplementation(((pid: number, signal?: string | number) => {
|
||||
if (Math.abs(pid) !== 4343) return true;
|
||||
if (signal === 0) {
|
||||
if (paneAlive) return true;
|
||||
throw Object.assign(new Error('kill ESRCH'), { code: 'ESRCH' });
|
||||
}
|
||||
paneAlive = false;
|
||||
return true;
|
||||
}) as typeof process.kill);
|
||||
const NonTestTmuxManager = await importWithTmuxCommandsEnabled();
|
||||
const nonTestManager = new NonTestTmuxManager();
|
||||
nonTestManager.registerSession({
|
||||
sessionId: 'beef5555',
|
||||
muxName: 'codeman-beef5555',
|
||||
pid: 4242,
|
||||
createdAt: Date.now(),
|
||||
workingDir: '/tmp',
|
||||
mode: 'claude',
|
||||
attached: false,
|
||||
});
|
||||
|
||||
try {
|
||||
expect(await nonTestManager.killSession('beef5555')).toBe(true);
|
||||
// The pid tmux printed is signalled, not the recorded one.
|
||||
expect(kill.mock.calls.some(([pid]) => Math.abs(Number(pid)) === 4343)).toBe(true);
|
||||
expect(kill.mock.calls.filter(([pid]) => Math.abs(Number(pid)) === 4242)).toEqual([]);
|
||||
const commands = mockedExec.mock.calls.map(([cmd]) => String(cmd));
|
||||
// The whole kill read: dropping `#{pane_dead_time}` would trust a pre-3.7 dead flag again.
|
||||
expect(
|
||||
commands.some(
|
||||
(cmd) => cmd.includes('display-message') && cmd.includes("'#{pane_dead}|#{pane_pid}|#{pane_dead_time}'")
|
||||
)
|
||||
).toBe(true);
|
||||
expect(commands.some((cmd) => cmd.includes('kill-session -t "codeman-beef5555"'))).toBe(true);
|
||||
expect(nonTestManager.getSession('beef5555')).toBeUndefined();
|
||||
} finally {
|
||||
kill.mockRestore();
|
||||
mockedExec.mockImplementation(defaultExec!);
|
||||
nonTestManager.destroy();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user