mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-09-30 12:39:42 +02:00
When the web server is launched from inside a tmux pane it inherits TMUX/
TMUX_PANE. tmux's nesting guard then makes every new attach-bridge PTY
(`tmux attach-session`, used by codex/opencode/gemini and mux-wrapped claude)
exit code 1; the respawn controller recreates the dead bridge → infinite loop.
The existing guard in buildMuxAttachEnv() used `TMUX: undefined` on a
{...process.env} spread, which leaves the KEY present with value undefined —
node-pty serializes it as the literal string "TMUX=undefined", still tripping
the guard. (The working create path in tmux-manager.ts uses `delete`.)
Fix:
- Primary: delete process.env.TMUX / TMUX_PANE at web bootstrap (src/index.ts)
so every downstream {...process.env} spread is clean regardless of launch
context. `delete`, not `= undefined`.
- buildMuxAttachEnv(): build a copy and `delete` TMUX/TMUX_PANE/CLAUDECODE
(and COLORTERM when not truecolor) instead of `: undefined` — same node-pty
quirk affected all of them.
- Test: assert the keys are genuinely ABSENT (`'TMUX' in env === false`), not
merely undefined — the prior test only checked `toBeUndefined()`, which is
why the bug slipped through. Red→green confirmed.
Verified on isolated beta launched from inside tmux (inherited the poisonous
TMUX=codeman,980,7): created a codex session + triggered interactive attach —
the bridge `tmux -L codeman-beta attach-session` spawned with NO TMUX in its
env, attached successfully, zero "exited with code: 1", server healthy.
Circuit-breaker for repeated non-zero bridge exits (AC bullet 4, optional)
split to a follow-up. Deploy-pending (substrate): never auto-deployed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
/**
|
|
* @fileoverview Tests for CLI environment builders.
|
|
*
|
|
* Port: N/A (no server needed)
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { buildMuxAttachEnv } from '../src/session-cli-builder.js';
|
|
|
|
describe('buildMuxAttachEnv', () => {
|
|
it('does not pass an inherited tmux context into tmux attach clients', () => {
|
|
const originalTmux = process.env.TMUX;
|
|
const originalTmuxPane = process.env.TMUX_PANE;
|
|
process.env.TMUX = '/tmp/tmux-1000/codeman,1169416,9';
|
|
process.env.TMUX_PANE = '%9';
|
|
|
|
try {
|
|
const env = buildMuxAttachEnv();
|
|
|
|
expect(env.TMUX).toBeUndefined();
|
|
expect(env.TMUX_PANE).toBeUndefined();
|
|
} finally {
|
|
if (originalTmux === undefined) {
|
|
delete process.env.TMUX;
|
|
} else {
|
|
process.env.TMUX = originalTmux;
|
|
}
|
|
if (originalTmuxPane === undefined) {
|
|
delete process.env.TMUX_PANE;
|
|
} else {
|
|
process.env.TMUX_PANE = originalTmuxPane;
|
|
}
|
|
}
|
|
});
|
|
|
|
// COD-115: `{...process.env, TMUX: undefined}` leaves the KEY present with value
|
|
// undefined; node-pty serializes that as the literal string "TMUX=undefined", which
|
|
// still trips tmux's nesting guard and kills the attach-bridge PTY (exit 1 → respawn
|
|
// loop). The keys must be genuinely ABSENT, which only `delete` achieves.
|
|
it('deletes tmux/claude context keys entirely (absent, not present-with-undefined) (COD-115)', () => {
|
|
const saved = {
|
|
TMUX: process.env.TMUX,
|
|
TMUX_PANE: process.env.TMUX_PANE,
|
|
CLAUDECODE: process.env.CLAUDECODE,
|
|
};
|
|
process.env.TMUX = '/tmp/tmux-1000/codeman,1169416,9';
|
|
process.env.TMUX_PANE = '%9';
|
|
process.env.CLAUDECODE = '1';
|
|
|
|
try {
|
|
const env = buildMuxAttachEnv();
|
|
|
|
expect('TMUX' in env).toBe(false);
|
|
expect('TMUX_PANE' in env).toBe(false);
|
|
expect('CLAUDECODE' in env).toBe(false);
|
|
} finally {
|
|
for (const [k, v] of Object.entries(saved)) {
|
|
if (v === undefined) {
|
|
delete process.env[k];
|
|
} else {
|
|
process.env[k] = v;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|