Files
Codeman/test/antigravity-mode.test.ts
Codeman maintainer 2b89f35599 fix(shell,remote-ssh): allowlist the login flags, and keep only CRASHED remote panes
Follow-up to #209 and #210. Both land a real fix (a pane that is a login shell
picks up /etc/profile and the per-user PATH entries an ssh remote command never
sees, which is what was failing agent CLIs with exit 127). Three corrections:

1. `-i -l` is no longer hardcoded onto the resolved shell. That path ultimately
   comes from the passwd entry, which is user data and can name anything, and a
   shell that rejects an unknown flag exits on the spot: nushell, elvish and xonsh
   take neither flag, so a user with one of those in passwd would have gotten a
   dead pane on arrival, which is exactly the #208 failure #209 builds on top of.
   loginShellArgs() applies them only to the POSIX-family shells verified to
   accept both, and a test really launches every allowlisted shell present on the
   machine rather than trusting the set. csh/tcsh are excluded deliberately: tcsh
   honors -l only when it is the ONLY flag.

2. `remain-on-exit on` -> `failed`, moved LAST in the tmux command chain. `on`
   keeps the pane after a CLEAN exit too, so typing `exit` in a remote shell
   stranded a dead pane, the session outlived it, and the next launch's `-A`
   reattached to that corpse: "Pane is dead (status 0)" instead of a shell,
   permanently, on the DEFAULT path. Verified against a real tmux, as was the
   fix: `failed` tears the session down on status 0 and keeps the pane on 127
   with the "command not found" still on screen, which is the case #210 wanted.
   It is last because tmux aborts the remaining commands of a `\;` sequence once
   one errors (also verified) and `failed` needs tmux >= 3.2 on the REMOTE host;
   leading, a rejection there would have silently dropped status/mouse/prefix/
   escape-time/window-size along with it.

3. `$SHELL` -> `"${SHELL:-/bin/sh}"`, via one shared remoteLoginShellCommand()
   helper instead of the string being rebuilt in tmux-manager as well.

Also corrects the rationale both PRs carried: a tmux pane already hands the shell
a tty, so it was interactive all along ($- contains i for a bare /bin/bash in a
pane) and ~/.bashrc was always being sourced. `-l` is the flag doing the work.

End-to-end verified, not just unit-tested: the emitted remote pane command was
run through all three quoting layers under a minimal sshd-style PATH with the
CLI installed only on a login-shell PATH entry, and it resolved and launched the
CLI with its arguments intact and a space-containing remote path preserved.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-05 01:40:37 +02:00

126 lines
4.0 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { CreateSessionSchema, QuickStartSchema } from '../src/web/schemas.js';
import { buildSpawnCommand } from '../src/tmux-manager.js';
import { defaultDockerCommandForMode } from '../src/docker-hosts.js';
import { defaultRemoteCommandForMode } from '../src/remote-hosts.js';
import { isExternalCliMode, isAltScreenStripMode } from '../src/session.js';
describe('Antigravity mode schemas', () => {
it('accepts Antigravity session creation config', () => {
const parsed = CreateSessionSchema.parse({
workingDir: '/tmp',
mode: 'antigravity',
antigravityConfig: {
model: 'gemini-3-pro',
dangerouslySkipPermissions: true,
},
});
expect(parsed.mode).toBe('antigravity');
expect(parsed.antigravityConfig).toEqual({
model: 'gemini-3-pro',
dangerouslySkipPermissions: true,
});
});
it('accepts Antigravity quick-start config', () => {
const parsed = QuickStartSchema.parse({
caseName: 'antigravity-case',
mode: 'antigravity',
antigravityConfig: {
resumeConversationId: 'conv-1234abcd',
},
});
expect(parsed.mode).toBe('antigravity');
expect(parsed.antigravityConfig?.resumeConversationId).toBe('conv-1234abcd');
});
it('rejects unsafe Antigravity model strings', () => {
expect(() =>
CreateSessionSchema.parse({
workingDir: '/tmp',
mode: 'antigravity',
antigravityConfig: { model: 'agy; rm -rf /' },
})
).toThrow();
});
it('allows ANTIGRAVITY_* env overrides and still rejects unknown prefixes', () => {
const parsed = CreateSessionSchema.parse({
workingDir: '/tmp',
mode: 'antigravity',
envOverrides: { ANTIGRAVITY_LOG_LEVEL: 'debug' },
});
expect(parsed.envOverrides).toEqual({ ANTIGRAVITY_LOG_LEVEL: 'debug' });
expect(() =>
CreateSessionSchema.parse({
workingDir: '/tmp',
envOverrides: { RANDOM_PREFIX_KEY: 'x' },
})
).toThrow();
});
});
describe('Antigravity spawn command', () => {
it('builds a bare agy command when no config is sent (safe default, no bypass)', () => {
const cmd = buildSpawnCommand({ mode: 'antigravity', sessionId: 'abc12345' });
expect(cmd).toBe('agy');
});
it('adds --dangerously-skip-permissions only when explicitly requested', () => {
const cmd = buildSpawnCommand({
mode: 'antigravity',
sessionId: 'abc12345',
antigravityConfig: { dangerouslySkipPermissions: true, model: 'gemini-3-pro' },
});
expect(cmd).toBe('agy --dangerously-skip-permissions --model gemini-3-pro');
});
it('passes --conversation for resume and drops unsafe ids', () => {
expect(
buildSpawnCommand({
mode: 'antigravity',
sessionId: 'abc12345',
antigravityConfig: { resumeConversationId: 'conv-99' },
})
).toBe('agy --conversation conv-99');
expect(
buildSpawnCommand({
mode: 'antigravity',
sessionId: 'abc12345',
antigravityConfig: { resumeConversationId: 'x; rm -rf /' },
})
).toBe('agy');
});
it('drops unsafe model strings from the spawn command', () => {
expect(
buildSpawnCommand({
mode: 'antigravity',
sessionId: 'abc12345',
antigravityConfig: { model: 'a`b' },
})
).toBe('agy');
});
});
describe('Antigravity mode gates', () => {
it('is an external CLI mode (readiness/ralph/respawn gating)', () => {
expect(isExternalCliMode('antigravity')).toBe(true);
});
it('is NOT an alt-screen strip mode (unverified Go TUI, like opencode)', () => {
expect(isAltScreenStripMode('antigravity')).toBe(false);
});
it('has docker/remote default commands', () => {
expect(defaultDockerCommandForMode('antigravity')).toBe('exec agy');
// Routed through an interactive login shell so per-user PATH entries resolve —
// same fix as the other remote agent CLIs (see defaultRemoteCommandForMode).
expect(defaultRemoteCommandForMode('antigravity')).toBe('exec "${SHELL:-/bin/sh}" -i -l -c \'agy\'');
});
});