mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-16 19:29:33 +01:00
fix(remote): start csh and tcsh login shells without -i -l
A remote host whose login shell is tcsh came up on 1.48.0, when the local
sh rewrote ${SHELL:-/bin/sh} to the Codeman host's shell. Since #770 the
launch reaches the far end verbatim and runs tcsh itself, and tcsh refuses
-i -l -c, -l -c and -i -l, so every stock launch left a dead pane.
The login flags are now picked on the far end, in the shape of
loginShellArgs(): set -- -i -l, cleared for csh and tcsh, then
exec "${SHELL:-/bin/sh}" "$@". The text is one brace group, so
cd <path> && { ...; } still starts nothing when the cd fails. bsd-csh takes
every flag combination, csh is listed because it is tcsh on macOS and the BSDs.
The version probe keeps its one statement: the login shell parses it, not
/bin/sh, so fish and tcsh refuse it either way, as they did on 1.48.0.
Measured with the real builder on a real sshd in a throwaway Debian container
(tcsh 6.24.07, bsd-csh, fish 3.6, bash) and through a fake sshd with
tcsh 6.24.10, fish, zsh, dash and bash, a real Codeman server on tcsh included.
The tcsh disclosure comes out of the docs and the changeset. They keep the two
limits 1.48.0 had too: tcsh has no export, so the PATH bootstrap only prints an
error, and the tmux probe needs a command executable, which Debian lacks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cd0bbc3e3a
commit
5559aa8294
18 files changed
+161
-56
No files matched your search
@@ -11,7 +11,10 @@
|
||||
* through a real sh with `ssh` and `tmux` defined as functions that report their arguments.
|
||||
*/
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { listClis } from '../src/config/cli-registry/registry.js';
|
||||
import { buildRemoteLaunchCommand } from '../src/tmux-manager.js';
|
||||
import type { SessionMode, SessionRemote } from '../src/types.js';
|
||||
@@ -79,3 +82,73 @@ describe('the shell that parses a remote pane command', () => {
|
||||
expect(sent).toMatch(/set -t codeman-ssh-abcd1234 remain-on-exit failed$/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the login flags a remote launch picks on the far end', () => {
|
||||
let root: string;
|
||||
|
||||
beforeEach(() => {
|
||||
root = mkdtempSync(join(tmpdir(), 'remote-login-flags-'));
|
||||
});
|
||||
afterEach(() => rmSync(root, { recursive: true, force: true }));
|
||||
|
||||
/** A shell that reports what it was started with, under the name the launch reads. */
|
||||
function fakeShell(name: string): string {
|
||||
const path = join(root, 'bin', name);
|
||||
mkdirSync(dirname(path), { recursive: true });
|
||||
writeFileSync(path, `#!/bin/sh\nfor a; do printf '%s\\0' "$a"; done > "${root}/argv"\n`, { mode: 0o755 });
|
||||
return path;
|
||||
}
|
||||
|
||||
/** Runs the pane argv tmux would receive, in a real sh, with `$SHELL` as given. */
|
||||
function runPane(mode: SessionMode, env: NodeJS.ProcessEnv, remotePath = root): void {
|
||||
const [sh, flag, text] = paneArgv(
|
||||
buildRemoteLaunchCommand({ mode, remote: { ...remote, remotePath }, sessionId: SESSION_ID })
|
||||
);
|
||||
execFileSync(sh, [flag, text], { env, stdio: 'ignore' });
|
||||
}
|
||||
|
||||
function shellArgv(): string[] {
|
||||
return readFileSync(join(root, 'argv'), 'utf8').split('\0').slice(0, -1);
|
||||
}
|
||||
|
||||
it.each(['bash', 'zsh', 'dash', 'sh', 'ksh', 'fish'])('%s starts as an interactive login shell', (name) => {
|
||||
runPane('codex', { ...process.env, SHELL: fakeShell(name) });
|
||||
expect(shellArgv()).toEqual(['-i', '-l', '-c', 'codex']);
|
||||
|
||||
runPane('shell', { ...process.env, SHELL: fakeShell(name) });
|
||||
expect(shellArgv()).toEqual(['-i', '-l']);
|
||||
});
|
||||
|
||||
// tcsh exits on `-i -l -c`, `-l -c` and `-i -l`: every stock launch was a dead pane on such a host.
|
||||
it.each(['tcsh', 'csh'])('%s starts with neither flag', (name) => {
|
||||
runPane('codex', { ...process.env, SHELL: fakeShell(name) });
|
||||
expect(shellArgv()).toEqual(['-c', 'codex']);
|
||||
|
||||
runPane('shell', { ...process.env, SHELL: fakeShell(name) });
|
||||
expect(shellArgv()).toEqual([]);
|
||||
});
|
||||
|
||||
it('goes by the name of the shell, not by a folder on its path', () => {
|
||||
runPane('codex', { ...process.env, SHELL: fakeShell('tcsh/bash') });
|
||||
expect(shellArgv()).toEqual(['-i', '-l', '-c', 'codex']);
|
||||
});
|
||||
|
||||
it.each(launches)('%s: a failed cd starts no shell', (_name, options) => {
|
||||
const [sh, flag, text] = paneArgv(
|
||||
buildRemoteLaunchCommand({ ...options, remote: { ...remote, remotePath: join(root, 'missing') } })
|
||||
);
|
||||
|
||||
expect(() =>
|
||||
execFileSync(sh, [flag, text], { env: { ...process.env, SHELL: fakeShell('tcsh') }, stdio: 'ignore' })
|
||||
).toThrow();
|
||||
expect(existsSync(join(root, 'argv'))).toBe(false);
|
||||
});
|
||||
|
||||
it('starts /bin/sh when SHELL is unset', () => {
|
||||
const { SHELL: _unset, ...env } = process.env;
|
||||
const bin = dirname(fakeShell('codex'));
|
||||
|
||||
runPane('codex', { ...env, PATH: `${bin}:${env.PATH ?? ''}`, HOME: root });
|
||||
expect(shellArgv()).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user