Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions backend/src/infrastructure/docker/TerminalManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { PassThrough } from 'stream';
import docker from './DockerClient';
import { TerminalManager } from './TerminalManager';

jest.mock('./DockerClient', () => ({
__esModule: true,
default: {
getContainer: jest.fn()
}
}));

const mockedDocker = docker as jest.Mocked<typeof docker>;

describe('TerminalManager', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('starts an interactive exec as a raw TTY stream', async () => {
const stream = new PassThrough();
const start = jest.fn((_options, callback) => callback(null, stream));
const exec = { start };
const createExec = jest.fn().mockResolvedValue(exec);
(mockedDocker.getContainer as jest.Mock).mockReturnValue({ exec: createExec });

const session = await TerminalManager.createTerminalSession('container-1');

expect(createExec).toHaveBeenCalledWith({
Cmd: ['/bin/bash'],
AttachStdin: true,
AttachStdout: true,
AttachStderr: true,
Tty: true
});
expect(start).toHaveBeenCalledWith(
{ hijack: true, stdin: true, Tty: true },
expect.any(Function)
);
expect(session).toEqual({ stream, exec });
});
});
2 changes: 1 addition & 1 deletion backend/src/infrastructure/docker/TerminalManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class TerminalManager {
});

const stream = await new Promise<NodeJS.ReadWriteStream>((resolve, reject) => {
exec.start({ hijack: true, stdin: true }, (err, execStream) => {
exec.start({ hijack: true, stdin: true, Tty: true }, (err, execStream) => {
if (err || !execStream) return reject(err || new Error('Failed to start terminal stream'));
resolve(execStream);
});
Expand Down
Loading