Files
Codeman/test/pty-interactive.test.ts
arkonandClaude Opus 4.6 0314de7789 fix: bulletproof test safety — IS_TEST_MODE guards prevent tests from killing real tmux sessions
Added IS_TEST_MODE (process.env.VITEST) guards to every method in TmuxManager and
ScreenManager that touches real tmux/screen sessions. Tests can never create, kill,
discover, or send input to real sessions. Removed broken E2E test suite entirely.
Rewrote test/setup.ts from 459 lines to minimal cleanup. Rewrote tmux-related tests
to verify test-mode safety behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 18:26:16 +01:00

81 lines
2.8 KiB
TypeScript

/**
* @fileoverview Unit tests for Session state management
*
* Tests Session object lifecycle, state transitions, and buffer management.
* SAFETY: No real Claude CLI processes are spawned. Tests verify in-memory
* state transitions and API contracts only.
*
* Port: N/A (no server or real processes needed)
*/
import { describe, it, expect } from 'vitest';
import { Session } from '../src/session.js';
describe('Session State Management', () => {
const testDir = '/tmp';
it('should start in idle state', () => {
const session = new Session({ workingDir: testDir });
expect(session.status).toBe('idle');
expect(session.isIdle()).toBe(true);
expect(session.isBusy()).toBe(false);
});
it('should provide state snapshots', () => {
const session = new Session({ workingDir: testDir });
const state = session.toState();
expect(state).toHaveProperty('id');
expect(state).toHaveProperty('pid');
expect(state).toHaveProperty('status');
expect(state).toHaveProperty('workingDir');
expect(state).toHaveProperty('createdAt');
expect(state).toHaveProperty('lastActivityAt');
const detailedState = session.toDetailedState();
expect(detailedState).toHaveProperty('totalCost');
expect(detailedState).toHaveProperty('textOutput');
expect(detailedState).toHaveProperty('terminalBuffer');
expect(detailedState).toHaveProperty('messageCount');
});
it('should have empty buffers initially', () => {
const session = new Session({ workingDir: testDir });
expect(session.terminalBuffer).toBe('');
expect(session.textOutput).toBe('');
expect(session.errorBuffer).toBe('');
});
it('should clear buffers', () => {
const session = new Session({ workingDir: testDir });
session.clearBuffers();
expect(session.terminalBuffer).toBe('');
expect(session.textOutput).toBe('');
expect(session.errorBuffer).toBe('');
});
it('should track working directory', () => {
const session = new Session({ workingDir: '/home/test/project' });
expect(session.workingDir).toBe('/home/test/project');
});
it('should generate unique session IDs', () => {
const session1 = new Session({ workingDir: testDir });
const session2 = new Session({ workingDir: testDir });
expect(session1.id).not.toBe(session2.id);
});
it('should accept custom session names', () => {
const session = new Session({ workingDir: testDir, name: 'My Session' });
expect(session.name).toBe('My Session');
});
it('should use specified mode', () => {
const claudeSession = new Session({ workingDir: testDir, mode: 'claude' });
expect(claudeSession.mode).toBe('claude');
const shellSession = new Session({ workingDir: testDir, mode: 'shell' });
expect(shellSession.mode).toBe('shell');
});
});