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
This commit is contained in:
committed by
GitHub
parent
f5b4a267c0
commit
d4a8c4d2e1
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import type { TerminalAPI, TerminalHandlers } from './api/types';
|
||||
import { waitForTerminalExit } from './projectActionTerminal';
|
||||
import { detectDevServerCommand } from './detectDevServer';
|
||||
|
||||
const fakeTerminal = () => {
|
||||
let handlers: TerminalHandlers | null = null;
|
||||
let closed = false;
|
||||
const terminal: TerminalAPI = {
|
||||
createSession: async () => ({ sessionId: 'term-1', cols: 80, rows: 24, status: 'running' }),
|
||||
connect: (_id, nextHandlers) => { handlers = nextHandlers; return { close: () => { closed = true; } }; },
|
||||
sendInput: async () => {}, resize: async () => {}, close: async () => {},
|
||||
};
|
||||
return { terminal, emit: (event: Parameters<TerminalHandlers['onEvent']>[0]) => handlers?.onEvent(event), isClosed: () => closed };
|
||||
};
|
||||
|
||||
describe('project action terminal lifecycle', () => {
|
||||
test('preserves a configured dev action preview URL', async () => {
|
||||
const detected = await detectDevServerCommand('/repo', [{
|
||||
id: 'dev',
|
||||
name: 'Dev server',
|
||||
command: 'bun run dev',
|
||||
openUrl: 'http://localhost:4321',
|
||||
}], null);
|
||||
expect(detected?.previewUrlHint).toBe('http://localhost:4321');
|
||||
});
|
||||
|
||||
test('resolves on live exit and closes its temporary subscription', async () => {
|
||||
const fake = fakeTerminal();
|
||||
const result = waitForTerminalExit(fake.terminal, 'term-1', 100);
|
||||
fake.emit({ type: 'exit', sequence: 2, exitCode: 0 });
|
||||
expect(await result).toBe(true);
|
||||
expect(fake.isClosed()).toBe(true);
|
||||
});
|
||||
|
||||
test('recognizes an already-exited reconnect snapshot', async () => {
|
||||
const fake = fakeTerminal();
|
||||
const result = waitForTerminalExit(fake.terminal, 'term-1', 100);
|
||||
fake.emit({ type: 'snapshot', sequence: 2, status: 'exited', data: 'done' });
|
||||
expect(await result).toBe(true);
|
||||
});
|
||||
|
||||
test('returns false on timeout so the caller can force-kill', async () => {
|
||||
const fake = fakeTerminal();
|
||||
expect(await waitForTerminalExit(fake.terminal, 'term-1', 5)).toBe(false);
|
||||
expect(fake.isClosed()).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user