Files
openchamber/packages/web/server/lib/terminal/shells.test.js
T
Bohdan Triapitsyn d4a8c4d2e1 feat(terminal): refactor runtime and add mobile workspace (#2280)
Replace the legacy terminal flow with a shared authenticated WebSocket
runtime used across web, desktop, relay, and mobile surfaces.

- introduce the v3 terminal protocol with scoped attachments, snapshots,
  ordered output, bounded replay history, reconnects, and explicit lifecycle
- harden PTY creation, restart, resize, close, force-kill, idle cleanup,
  shell selection, login mode, environment sanitization, and appearance sync
- add runtime-aware terminal APIs with relay authentication and Electron parity
- add a fullscreen mobile terminal workspace with touch scrolling,
  long-press selection, safe-area controls, quick keys, and Ctrl/Alt input
- add terminal selection attachments, preview detection, project actions,
  shell settings, and localized UI
- harden Ghostty rendering, resize recovery, Unicode handling, block
  characters, line height, and stale-row behavior
- remove the obsolete terminal SSE path and update reverse-proxy guidance
- expand terminal runtime, transport, input, selection, and store coverage
- avoid duplicate web builds when preparing mobile assets in root CI builds
2026-07-17 13:17:21 +03:00

74 lines
3.1 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import { createTerminalShellResolver, getTerminalShellLoginArgs } from './shells.js';
const createResolver = ({ platform = 'linux', env = {}, augmentedPath = '/augmented/bin', executables = [] } = {}) => {
const available = new Set(executables);
const path = {
delimiter: platform === 'win32' ? ';' : ':',
extname: (value) => /\.[^./\\]+$/.exec(value)?.[0] ?? '',
join: (...parts) => parts.join(platform === 'win32' ? '\\' : '/'),
};
const searches = [];
return {
searches,
resolver: createTerminalShellResolver({
fs: { promises: { readFile: async () => '' } },
path,
platform,
env,
buildAugmentedPath: () => augmentedPath,
searchPathFor: (name, searchPath) => {
searches.push([name, searchPath]);
const suffixes = platform === 'win32' ? ['', '.exe'] : [''];
for (const suffix of suffixes) {
const match = [...available].find((candidate) => candidate.toLowerCase().endsWith(`${platform === 'win32' ? '\\' : '/'}${name}${suffix}`.toLowerCase()));
if (match) return match;
}
return null;
},
isExecutable: (candidate) => available.has(candidate),
}),
};
};
describe('terminal shell resolver', () => {
it('discovers shells from the augmented PTY PATH', async () => {
const { resolver, searches } = createResolver({ executables: ['/augmented/bin/fish'] });
await expect(resolver.list()).resolves.toContainEqual({ id: 'fish', name: 'fish', executable: '/augmented/bin/fish', supportsLogin: true });
expect(searches).toContainEqual(['fish', '/augmented/bin']);
});
it('discovers supported PATH-installed shells on Windows', async () => {
const { resolver } = createResolver({
platform: 'win32',
augmentedPath: 'C:\\Tools',
executables: ['C:\\Tools\\bash.exe', 'C:\\Tools\\nu.exe'],
});
await expect(resolver.list()).resolves.toEqual(expect.arrayContaining([
{ id: 'bash', name: 'bash', executable: 'C:\\Tools\\bash.exe', supportsLogin: true },
{ id: 'nu', name: 'nu', executable: 'C:\\Tools\\nu.exe', supportsLogin: true },
]));
});
it('uses environment overrides before platform defaults for auto', async () => {
const { resolver } = createResolver({
env: { OPENCHAMBER_TERMINAL_SHELL: '/custom/zsh', SHELL: '/bin/bash' },
executables: ['/custom/zsh', '/bin/bash'],
});
await expect(resolver.resolve('auto')).resolves.toEqual({ id: 'auto', executables: ['/custom/zsh', '/bin/bash'] });
});
it('uses only known platform-safe login arguments', () => {
expect(getTerminalShellLoginArgs('/bin/bash', 'linux')).toEqual(['-l']);
expect(getTerminalShellLoginArgs('/opt/homebrew/bin/fish', 'darwin')).toEqual(['--login']);
expect(getTerminalShellLoginArgs('/usr/bin/nu', 'linux')).toEqual(['--login']);
expect(getTerminalShellLoginArgs('/usr/bin/pwsh', 'linux')).toEqual(['-Login']);
expect(getTerminalShellLoginArgs('C:\\Program Files\\PowerShell\\7\\pwsh.exe', 'win32')).toBeNull();
expect(getTerminalShellLoginArgs('/bin/dash', 'linux')).toBeNull();
});
});