mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 00:39:32 +01:00
fix(web): scroll to the prompt on toolbar Enter, retire app.sendInput (#830)
submitFromToolbar() puts the CR on the FIFO, bypassing xterm scrollOnUserInput; scroll the focused pane before sending. Remove app.sendInput(), which has no production caller; update @dependency headers and test stubs. Retarget the codex predictive-echo recorders to _enqueueReliableInput. Correct the docs and the _sendInputAsync JSDoc for the session FIFO; drop stale _pendingInput stubs.
This commit is contained in:
1 parent
ddb5a647ba
commit
05fc2f990b
16 files changed
+86
-95
No files matched your search
@@ -373,7 +373,7 @@ A raw `npx vitest` used to find no config, so `setup.ts` never ran and the suite
|
||||
|
||||
**Ports**: every in-process test server binds port 0 (the one exception, `test/codex-predictive-echo.test.ts`, starts a separate lab server process on 3222). A test that constructs `WebServer` reads `server.boundPort` (mobile tests: `createTestServer()`, then `server.boundPort`); a raw `http`/`net`/Fastify/`ws` server listens on `0` and reads `address().port`. `test/test-ports-guard.test.ts` fails a `WebServer` built on any other port and a raw `listen` on a number or `…PORT` constant. A test that needs a port nothing listens on binds 0, reads it and closes (`closedPort()` in `test/daemon-control.test.ts`), never "the server's port + 1". Never 3000 (the live instance).
|
||||
|
||||
⚠️ **Browser tests can pass vacuously on mobile input paths.** Two traps, both hit on 2026-07-27 while fixing the phone Enter button: **(1)** driving input with `app.sendInput('…')` writes PAST the `LocalEchoOverlay`, so `pendingText` stays empty and any overlay bug is invisible — type with `page.keyboard.type()` instead; **(2)** headless Chromium reports `MobileDetection.isTouchDevice()` **false even with `hasTouch: true`**, so `_localEchoEnabled` is off and the local-echo branch never executes. Force it (`app._localEchoEnabled = true`) or the test proves nothing. Assert on real state (`app._localEchoOverlay.pendingText`, plus `tmux -L codeman capture-pane -p -t <pane>` for what actually reached the PTY), not on HTTP 200.
|
||||
⚠️ **Browser tests can pass vacuously on mobile input paths.** Two traps, both hit on 2026-07-27 while fixing the phone Enter button: **(1)** driving input with `app._sendInputAsync(id, '…')` writes PAST the `LocalEchoOverlay`, so `pendingText` stays empty and any overlay bug is invisible — type with `page.keyboard.type()` instead; **(2)** headless Chromium reports `MobileDetection.isTouchDevice()` **false even with `hasTouch: true`**, so `_localEchoEnabled` is off and the local-echo branch never executes. Force it (`app._localEchoEnabled = true`) or the test proves nothing. Assert on real state (`app._localEchoOverlay.pendingText`, plus `tmux -L codeman capture-pane -p -t <pane>` for what actually reached the PTY), not on HTTP 200.
|
||||
|
||||
**Testing against the live instance**: prod is HTTPS-only on :3000 (`curl -sk https://localhost:3000/...`). ⚠️ `w1`/`w2`/`w3` are the user's REAL sessions — never send input to them. Create your own throwaway session (`POST /api/sessions` then `POST /api/sessions/:id/shell`; creation alone leaves `pid: null` and no pane), test against that, and `DELETE` it by exact id when done.
|
||||
|
||||
|
||||
@@ -1285,7 +1285,7 @@ Mapping is `ctrlByteFor()` (`code & 0x1f` over @A-Z[\]^_ and a-z, plus Ctrl+Spac
|
||||
|
||||
⚠️ **Drafts are per-session and in memory only** (`_composerDrafts`, never persisted: prompts routinely carry secrets, and persisting them would need the 0600 treatment the intent store gets). Every non-Send exit (Cancel, backdrop, Escape, "Use terminal keyboard") leaves the taken text ONLY in the draft, with the dot on the key (`has-draft`, kept in step by `_syncComposerDraftIndicator`) as the signal that the terminal prompt is empty on purpose, and `_cleanupSessionData` discards the draft with the session.
|
||||
|
||||
⚠️ **Delivery is a hand-built bracketed-paste frame** (`\x1b[200~` + the text with newlines mapped to `\r` + `\x1b[201~`, byte-identical to what `terminal.paste()` would emit) through `_sendInputAsync` WITHOUT `{ useMux: true }`, plus a SEPARATE Enter 120 ms later WITH it (codex drops keys that share a PTY read with a bracketed paste). Not `terminal.paste()`, for two reasons: xterm's `bracketedPasteMode` mirror is false for every session after a tab switch or reload (`terminal.reset()` in the replay re-clones the DEC modes, the tmux capture carries no `?2004h`, and tmux never forwards the pane's DECSET to a client after attach), so a paste through xterm would go out unbracketed and the CLI would submit at the first `\r`; and xterm's onData is where the local-echo paste branch flushes pending overlay text AHEAD of the block, text the composer has already taken and erased from the PTY, so the frame goes straight to the wire with the composer as the prompt's only owner. The unconditional frame is safe for a CLI that never enabled DECSET 2004 because tmux does the gating (measured against a live pane: markers stripped for a `cat -v` pane, forwarded intact to a process that had emitted `?2004h`).
|
||||
⚠️ **Delivery is a hand-built bracketed-paste frame** (`\x1b[200~` + the text with newlines mapped to `\r` + `\x1b[201~`, byte-identical to what `terminal.paste()` would emit) enqueued on the session FIFO (`_enqueueInput`, `_sendBracketedPaste()`) WITHOUT `{ useMux: true }`, then a 120 ms `gap` and a SEPARATE Enter WITH it, all reserved for the composer's session at Send (codex drops keys that share a PTY read with a bracketed paste). Not `terminal.paste()`, for two reasons: xterm's `bracketedPasteMode` mirror is false for every session after a tab switch or reload (`terminal.reset()` in the replay re-clones the DEC modes, the tmux capture carries no `?2004h`, and tmux never forwards the pane's DECSET to a client after attach), so a paste through xterm would go out unbracketed and the CLI would submit at the first `\r`; and xterm's onData is where the local-echo paste branch flushes pending overlay text AHEAD of the block, text the composer has already taken and erased from the PTY, so the frame goes straight to the wire with the composer as the prompt's only owner. The unconditional frame is safe for a CLI that never enabled DECSET 2004 because tmux does the gating (measured against a live pane: markers stripped for a `cat -v` pane, forwarded intact to a process that had emitted `?2004h`).
|
||||
|
||||
⚠️ The frame must never take the mux fallback: `TmuxManager.sendInput()` strips every `\r`, the frame's line separator, so the lines weld into one, pasted inside a second pair of markers, and get submitted.
|
||||
|
||||
|
||||
@@ -579,7 +579,7 @@ step 1 is a real step). Before shipping:
|
||||
browser, confirm the reply renders and scrollback survives a tab switch. Do not touch
|
||||
`w1`/`w2`/`w3`.
|
||||
4. **Local-echo policy gate (§2.10):** on a phone profile, type into the pi editor through the
|
||||
buffer overlay (drive with `page.keyboard.type()`, never `app.sendInput()`, and force
|
||||
buffer overlay (drive with `page.keyboard.type()`, never `app._sendInputAsync()`, and force
|
||||
`app._localEchoEnabled = true`; headless Chromium reports touch as false) and confirm pi's
|
||||
composer renders the flushed text correctly on Enter. If it mis-renders, flip pi to the `'off'`
|
||||
branch in `_updateLocalEchoState` and pin that instead.
|
||||
|
||||
@@ -75,7 +75,7 @@ Both transports refuse a frame longer than `MAX_INPUT_LENGTH` (64 KiB,
|
||||
at the head of the queue, was re-sent every 2 s forever, blocked every later
|
||||
input for the session, and came back from localStorage on each reload.
|
||||
|
||||
- `_sendInputAsync()` splits a paste over the frame limit into in-limit frames
|
||||
- `_enqueueReliableInput()` (the session FIFO's transport edge) splits a paste over the frame limit into in-limit frames
|
||||
(`CodemanInputLimit.split`, constants.js, never cutting a surrogate pair). They
|
||||
go out in seq order, so the PTY sees one contiguous stream. A paste over
|
||||
`PASTE_MAX_CHARS` (1 MiB), or an oversized `useMux` write (one paste plus its own Enter, never
|
||||
|
||||
@@ -4198,8 +4198,10 @@ class CodemanApp {
|
||||
|
||||
/**
|
||||
* Public input entry point — name/signature kept for all call sites.
|
||||
* Records the input durably, then delivers it reliably (exactly-once). Never
|
||||
* blocks the keystroke flush; never silently drops on a half-open socket.
|
||||
* Seals the session's batched keystrokes, then enqueues the input on that
|
||||
* session's FIFO, which hands it to the durable exactly-once layer
|
||||
* (_enqueueReliableInput). It can wait behind an earlier `gap` (a delayed
|
||||
* Enter); it never silently drops on a half-open socket.
|
||||
* @param {string} sessionId
|
||||
* @param {string} input
|
||||
* @param {{useMux?: boolean}} [opts] - useMux only affects the POST fallback.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
* For drag-and-drop: listens on the terminal container for file drops.
|
||||
*
|
||||
* @dependency app.js (uses global `app` for sendInput, activeSessionId, showToast)
|
||||
* @dependency app.js (uses global `app` for _sendInputAsync, _prepareExternalInput, activeSessionId, showToast)
|
||||
* @dependency panels-ui.js (provides showToast)
|
||||
*/
|
||||
|
||||
@@ -397,10 +397,9 @@ Object.assign(CodemanApp.prototype, {
|
||||
const paths = results.filter(Boolean);
|
||||
if (paths.length > 0 && options.insert !== false) {
|
||||
// Insert all paths in one shot, space-separated, in selection order, into
|
||||
// the session the batch was uploaded TO. Not sendInput(): it re-reads
|
||||
// activeSessionId, and after the awaits above that is whatever tab the
|
||||
// user switched to mid-upload, so the paths landed in the wrong session.
|
||||
// Same delivery sendInput() uses (durable queue, useMux for the POST path).
|
||||
// the session the batch was uploaded to, captured before the awaits above,
|
||||
// not the active tab the user may have switched to mid-upload.
|
||||
// Delivery uses the durable session-bound path, with useMux for the POST fallback.
|
||||
const pane = this._paneForSession?.(sessionId);
|
||||
if (pane) this._prepareExternalInput?.(pane, 'upload-insert', { flushEcho: true });
|
||||
this._sendInputAsync(sessionId, paths.join(' '), { useMux: true });
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
* @globals {class} FocusTrap
|
||||
*
|
||||
* @dependency mobile-handlers.js (MobileDetection.isTouchDevice)
|
||||
* @dependency app.js (uses global `app` for sendInput, activeSessionId, terminal)
|
||||
* @dependency app.js (uses global `app` for _enqueueInput, _sendInputAsync, _prepareExternalInput, activeSessionId, terminal)
|
||||
* @loadorder 5 of 15 — loaded after notification-manager.js, before app.js
|
||||
*/
|
||||
|
||||
|
||||
@@ -857,6 +857,12 @@ Object.assign(CodemanApp.prototype, {
|
||||
submitFromToolbar() {
|
||||
const pane = this._focusedPane();
|
||||
if (!pane?.terminal || !pane.sessionId || pane.tile?._destroyed || !this.sessions.has(pane.sessionId)) return;
|
||||
// The CR goes on the FIFO, not through xterm's triggerDataEvent(data, true),
|
||||
// so its scrollOnUserInput never runs; scroll to the prompt as it would.
|
||||
const terminal = pane.terminal;
|
||||
if (terminal.options?.scrollOnUserInput !== false && typeof terminal.scrollToBottom === 'function') {
|
||||
terminal.scrollToBottom();
|
||||
}
|
||||
this._prepareExternalInput(pane, 'submit');
|
||||
if (pane.isPrimary) this._submitMainInput(pane.sessionId);
|
||||
else this._sendInputAsync(pane.sessionId, '\r');
|
||||
@@ -7198,19 +7204,6 @@ Object.assign(CodemanApp.prototype, {
|
||||
this.showToast('Another device is setting the width — scroll sideways', 'info');
|
||||
},
|
||||
|
||||
/**
|
||||
* Send input to the active session.
|
||||
* @param {string} input - Text to send (include \r for Enter)
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async sendInput(input) {
|
||||
if (!this.activeSessionId || !input) return;
|
||||
// Route through the durable, exactly-once delivery layer (useMux for the
|
||||
// POST fallback) so voice / keyboard-accessory / paste input also survives a
|
||||
// dropped link instead of being lost in a single best-effort fetch.
|
||||
this._sendInputAsync(this.activeSessionId, input, { useMux: true });
|
||||
},
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// Directory Input
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
* @globals {object} VoiceInput
|
||||
*
|
||||
* @dependency mobile-handlers.js (MobileDetection for device checks)
|
||||
* @dependency app.js (uses global `app` for sendInput, showToast, terminal focus)
|
||||
* @dependency app.js (uses global `app` for _sendInputAsync, _enqueueInput, _prepareExternalInput, showToast, terminal focus)
|
||||
* @loadorder 3 of 15 — loaded after mobile-handlers.js, before notification-manager.js
|
||||
*/
|
||||
|
||||
|
||||
@@ -40,6 +40,16 @@ let untrustedWorkdir: string;
|
||||
let sessionId: string;
|
||||
const createdSessions: string[] = [];
|
||||
|
||||
/** The transport edge the recorders wrap: every typed producer reaches it through the session FIFO. */
|
||||
type ReliableSend = (sid: string, data: string, opts?: unknown) => void;
|
||||
interface RecorderWindow {
|
||||
app: { _enqueueReliableInput: ReliableSend };
|
||||
__dbg: Array<[string, string]>;
|
||||
__trace: string[];
|
||||
__origSend?: ReliableSend;
|
||||
__origSend2?: ReliableSend;
|
||||
}
|
||||
|
||||
function hasCodex(): boolean {
|
||||
try {
|
||||
execSync(`PATH="${CODEX_BIN_DIR}:$PATH" codex --version`, { stdio: 'pipe' });
|
||||
@@ -324,12 +334,13 @@ d('codex predictive echo E2E (real codex TUI)', () => {
|
||||
await resetComposer();
|
||||
const pidBefore = execSync(`${TMUX} list-panes -a -F '#{pane_id} #{pane_pid}'`, { encoding: 'utf8' }).trim();
|
||||
await page.evaluate(() => {
|
||||
const app = (window as any).app;
|
||||
(window as any).__dbg = [];
|
||||
if (!(window as any).__origSend2) (window as any).__origSend2 = app._sendInputAsync.bind(app);
|
||||
app._sendInputAsync = (sid: string, data: string, opts?: unknown) => {
|
||||
(window as any).__dbg.push([sid.slice(0, 8), JSON.stringify(data)]);
|
||||
return (window as any).__origSend2(sid, data, opts);
|
||||
const w = window as unknown as RecorderWindow;
|
||||
const app = w.app;
|
||||
w.__dbg = [];
|
||||
const original = (w.__origSend2 ??= app._enqueueReliableInput.bind(app));
|
||||
app._enqueueReliableInput = (sid, data, opts) => {
|
||||
w.__dbg.push([sid.slice(0, 8), JSON.stringify(data)]);
|
||||
return original(sid, data, opts);
|
||||
};
|
||||
});
|
||||
await page.keyboard.type('abc', { delay: 30 });
|
||||
@@ -471,15 +482,16 @@ d('codex predictive echo E2E (real codex TUI)', () => {
|
||||
|
||||
const record = () =>
|
||||
page.evaluate(() => {
|
||||
const app = (window as any).app;
|
||||
(window as any).__trace = [];
|
||||
if (!(window as any).__origSend) (window as any).__origSend = app._sendInputAsync.bind(app);
|
||||
app._sendInputAsync = (sid: string, data: string, opts?: unknown) => {
|
||||
(window as any).__trace.push(data);
|
||||
return (window as any).__origSend(sid, data, opts);
|
||||
const w = window as unknown as RecorderWindow;
|
||||
const app = w.app;
|
||||
w.__trace = [];
|
||||
const original = (w.__origSend ??= app._enqueueReliableInput.bind(app));
|
||||
app._enqueueReliableInput = (sid, data, opts) => {
|
||||
w.__trace.push(data);
|
||||
return original(sid, data, opts);
|
||||
};
|
||||
});
|
||||
const trace = () => page.evaluate(() => ((window as any).__trace as string[]).join(''));
|
||||
const trace = () => page.evaluate(() => (window as unknown as RecorderWindow).__trace.join(''));
|
||||
|
||||
await record();
|
||||
await script();
|
||||
|
||||
@@ -191,7 +191,6 @@ function loadPasteHarness(options: PasteHarnessOptions = {}): Harness {
|
||||
if (options.localEchoPending !== undefined) {
|
||||
pendingEcho = options.localEchoPending;
|
||||
app._localEchoEnabled = true;
|
||||
app._pendingInput = '';
|
||||
app._localEchoOverlay = {
|
||||
get pendingText() {
|
||||
return pendingEcho;
|
||||
@@ -252,7 +251,6 @@ function loadImageInputApp() {
|
||||
const app = new CodemanApp();
|
||||
app.activeSessionId = 'session-1';
|
||||
app.showToast = vi.fn();
|
||||
app.sendInput = vi.fn(async () => {});
|
||||
app._sendInputAsync = vi.fn();
|
||||
app._normalizeImageForUpload = vi.fn(async (file) => file);
|
||||
app._uploadPasteImage = vi.fn(async (_sessionId, file: { path: string }) => file.path);
|
||||
@@ -473,7 +471,6 @@ describe('image upload insertion policy', () => {
|
||||
const paths = await app._uploadAndInsertImages(files, { insert: false });
|
||||
|
||||
expect(Array.from(paths)).toEqual(['/tmp/first.png', '/tmp/second.png']);
|
||||
expect(app.sendInput).not.toHaveBeenCalled();
|
||||
expect(app._sendInputAsync).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -483,15 +480,15 @@ describe('image upload insertion policy', () => {
|
||||
const paths = await app._uploadAndInsertImages([{ path: '/tmp/legacy.png' }]);
|
||||
|
||||
expect(Array.from(paths)).toEqual(['/tmp/legacy.png']);
|
||||
// The same delivery sendInput() uses (durable queue, useMux for the POST
|
||||
// fallback), but addressed to the session the batch was uploaded to.
|
||||
// Durable delivery with useMux for the POST fallback, addressed to the
|
||||
// captured session the batch was uploaded to.
|
||||
expect(app._sendInputAsync).toHaveBeenCalledWith('session-1', '/tmp/legacy.png', { useMux: true });
|
||||
});
|
||||
|
||||
it('inserts into the session the upload started in, even after a tab switch mid-upload', async () => {
|
||||
const app = loadImageInputApp();
|
||||
// The user switches tabs while the upload is in flight. sendInput() re-read
|
||||
// activeSessionId after the awaits, so the paths used to land in session-2.
|
||||
// The user switches tabs while the upload is in flight. The captured session
|
||||
// must remain the destination after the awaits, rather than the active tab.
|
||||
app._uploadPasteImage = vi.fn(async (_sessionId, file: { path: string }) => {
|
||||
app.activeSessionId = 'session-2';
|
||||
return file.path;
|
||||
@@ -501,7 +498,6 @@ describe('image upload insertion policy', () => {
|
||||
|
||||
expect(app._uploadPasteImage).toHaveBeenCalledWith('session-1', { path: '/tmp/shot.png' });
|
||||
expect(app._sendInputAsync).toHaveBeenCalledWith('session-1', '/tmp/shot.png', { useMux: true });
|
||||
expect(app.sendInput).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uploads to and inserts into an explicitly named session', async () => {
|
||||
|
||||
@@ -236,6 +236,32 @@ describe('iOS native input served-app wiring (#830)', () => {
|
||||
});
|
||||
expect(viewport.viewportY).toBe(viewport.baseY);
|
||||
});
|
||||
|
||||
it(`toolbar Enter while scrolled back returns the viewport to the prompt (echo ${echo})`, async () => {
|
||||
await setup(echo);
|
||||
const scrolled = await page.evaluate(async () => {
|
||||
const terminal = (window as unknown as TestWindow).app.terminal;
|
||||
const written = Promise.withResolvers<void>();
|
||||
terminal.write('line\r\n'.repeat(200) + '❯ ', written.resolve);
|
||||
await written.promise;
|
||||
terminal.scrollToTop();
|
||||
return { viewportY: terminal.buffer.active.viewportY, baseY: terminal.buffer.active.baseY };
|
||||
});
|
||||
expect(scrolled.viewportY).toBe(0);
|
||||
expect(scrolled.baseY).toBeGreaterThan(0);
|
||||
await page
|
||||
.locator('button[onclick="app.sendEnterKey()"]')
|
||||
.evaluate((button: HTMLButtonElement) => button.click());
|
||||
// Echo on delivers the CR after the local-echo gap: wait for it on the wire.
|
||||
await page.waitForFunction(() => (window as unknown as TestWindow).__sent.some((x) => x.input === '\r'));
|
||||
const sent = await page.evaluate(() => (window as unknown as TestWindow).__sent.map((x) => x.input));
|
||||
expect(sent).toEqual(['\r']);
|
||||
const viewport = await page.evaluate(() => {
|
||||
const buffer = (window as unknown as TestWindow).app.terminal.buffer.active;
|
||||
return { viewportY: buffer.viewportY, baseY: buffer.baseY };
|
||||
});
|
||||
expect(viewport.viewportY).toBe(viewport.baseY);
|
||||
});
|
||||
}
|
||||
|
||||
for (const target of ['main', 'tile'] as const) {
|
||||
|
||||
@@ -606,7 +606,7 @@ describe('Send on Enter: a held answer goes out with Enter as its own write', ()
|
||||
it('types a single character, then Enter 120 ms later on the same session FIFO across a switch', () => {
|
||||
// Codex folds an Enter that arrives in the same burst as the text into a
|
||||
// paste, even for `1\r`; a selection dialog ignores a pasted digit. Same
|
||||
// split as TmuxManager.sendInput (submitsAsKeys).
|
||||
// split as the tmux manager's submitsAsKeys path.
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const { app, composed, writes } = promptApp();
|
||||
@@ -732,7 +732,6 @@ describe('composer nav keys from the bar', () => {
|
||||
const app = loaded.app as unknown as Record<string, unknown>;
|
||||
app._localEchoEnabled = true;
|
||||
app._localEchoOverlay = overlay;
|
||||
app.sendInput = vi.fn();
|
||||
app._flushedOffsets = new Map([['session-1', 3]]);
|
||||
app._flushedTexts = new Map([['session-1', 'dra']]);
|
||||
return { ...loaded, app, overlay };
|
||||
@@ -810,7 +809,6 @@ describe('composer nav keys from the bar', () => {
|
||||
bar.handleAction('arrow-right');
|
||||
|
||||
expect(sentKeys(app._enqueueInput as ReturnType<typeof vi.fn>)).toEqual(['\x1b[A', '\x1b[B', '\x1b[D', '\x1b[C']);
|
||||
expect(app.sendInput).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ function loadKeyboardModule() {
|
||||
terminal: { focus: vi.fn() },
|
||||
clearTerminalInput: vi.fn(),
|
||||
insertTerminalText: vi.fn(),
|
||||
sendInput: vi.fn(),
|
||||
_enqueueInput: vi.fn(),
|
||||
_sendInputAsync: vi.fn(),
|
||||
_focusedPane: () => ({ sessionId: 'session-1', isPrimary: true }),
|
||||
@@ -92,7 +91,6 @@ describe('accessory Tab key', () => {
|
||||
const { app, bar, fetchMock } = loadKeyboardModule();
|
||||
bar.handleAction('tab');
|
||||
|
||||
expect(app.sendInput).not.toHaveBeenCalled();
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
expect(app._enqueueInput).toHaveBeenCalledWith('session-1', [{ write: '\t' }]);
|
||||
});
|
||||
@@ -156,10 +154,8 @@ describe('toolbar Enter', () => {
|
||||
const context = vm.createContext({ CodemanApp: function () {} });
|
||||
vm.runInContext(`${sessionSource}\nglobalThis.__mixin = CodemanApp.prototype;`, context);
|
||||
const submitFromToolbar = vi.fn();
|
||||
const sendInput = vi.fn();
|
||||
context.__mixin.sendEnterKey.call({ submitFromToolbar, sendInput });
|
||||
context.__mixin.sendEnterKey.call({ submitFromToolbar });
|
||||
expect(submitFromToolbar).toHaveBeenCalledOnce();
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -169,7 +165,6 @@ describe('mobile filesystem picker actions', () => {
|
||||
bar.handleAction('clear-input');
|
||||
|
||||
expect(app.clearTerminalInput).toHaveBeenCalledOnce();
|
||||
expect(app.sendInput).not.toHaveBeenCalled();
|
||||
expect(keyboardSource).toContain('data-action="clear-input"');
|
||||
expect(keyboardSource).toContain('data-action="clear" title="/clear"');
|
||||
});
|
||||
@@ -189,7 +184,6 @@ describe('mobile filesystem picker actions', () => {
|
||||
});
|
||||
options.onSelect('/mnt/d/AI/project/file.ts');
|
||||
expect(app._sendInputAsync).toHaveBeenCalledWith('session-1', '/mnt/d/AI/project/file.ts', { useMux: true });
|
||||
expect(app.sendInput).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([false, true])(
|
||||
@@ -247,14 +241,12 @@ describe('mobile filesystem picker actions', () => {
|
||||
|
||||
it('inserts a selected path into the editable local-echo prompt without sending it', () => {
|
||||
const appendText = vi.fn();
|
||||
const sendInput = vi.fn();
|
||||
const focus = vi.fn();
|
||||
const app = {
|
||||
activeSessionId: 'session-1',
|
||||
_localEchoEnabled: true,
|
||||
_localEchoOverlay: { appendText },
|
||||
terminal: { focus },
|
||||
sendInput,
|
||||
_focusedPane: () => ({ terminal: app.terminal, sessionId: app.activeSessionId, isPrimary: true }),
|
||||
_prepareExternalInput: vi.fn(),
|
||||
};
|
||||
@@ -262,20 +254,17 @@ describe('mobile filesystem picker actions', () => {
|
||||
terminalHarness.mixin.insertTerminalText.call(app, '/mnt/d/AI/project');
|
||||
|
||||
expect(appendText).toHaveBeenCalledWith('/mnt/d/AI/project');
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
expect(focus).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('clears pending and already-flushed prompt text without invoking /clear', () => {
|
||||
const clear = vi.fn();
|
||||
const suppressBufferDetection = vi.fn();
|
||||
const sendInput = vi.fn(() => Promise.resolve());
|
||||
const showToast = vi.fn();
|
||||
const focus = vi.fn();
|
||||
const app = {
|
||||
activeSessionId: 'session-1',
|
||||
_inputFlushTimeout: null,
|
||||
_pendingInput: 'pending text',
|
||||
_localEchoEnabled: true,
|
||||
_localEchoOverlay: {
|
||||
getFlushed: () => ({ count: 4, text: 'a😀b' }),
|
||||
@@ -284,7 +273,6 @@ describe('mobile filesystem picker actions', () => {
|
||||
},
|
||||
_flushedOffsets: new Map([['session-1', 4]]),
|
||||
_flushedTexts: new Map([['session-1', 'a😀b']]),
|
||||
sendInput,
|
||||
_sendInputAsync: vi.fn(),
|
||||
_focusedPane: () => ({ terminal: app.terminal, sessionId: app.activeSessionId, isPrimary: true }),
|
||||
_prepareExternalInput: vi.fn(),
|
||||
@@ -301,7 +289,6 @@ describe('mobile filesystem picker actions', () => {
|
||||
expect(clear).toHaveBeenCalledOnce();
|
||||
expect(suppressBufferDetection).toHaveBeenCalledOnce();
|
||||
expect(app._sendInputAsync).toHaveBeenCalledWith('session-1', '\x7f'.repeat(3), { useMux: true });
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
expect(app._flushedOffsets.size).toBe(0);
|
||||
expect(app._flushedTexts.size).toBe(0);
|
||||
expect(showToast).toHaveBeenCalledWith('Input cleared', 'success');
|
||||
@@ -311,7 +298,6 @@ describe('mobile filesystem picker actions', () => {
|
||||
|
||||
it('sends a picked path to the tile or Pane B that holds the keyboard, never the parked main overlay', () => {
|
||||
const appendText = vi.fn();
|
||||
const sendInput = vi.fn();
|
||||
const _sendInputAsync = vi.fn();
|
||||
const mainFocus = vi.fn();
|
||||
const tileFocus = vi.fn();
|
||||
@@ -320,7 +306,6 @@ describe('mobile filesystem picker actions', () => {
|
||||
_localEchoEnabled: true,
|
||||
_localEchoOverlay: { appendText },
|
||||
terminal: { focus: mainFocus },
|
||||
sendInput,
|
||||
_sendInputAsync,
|
||||
_prepareExternalInput: vi.fn(),
|
||||
_focusedPane: () => ({ terminal: { focus: tileFocus }, sessionId: 'tile-2', isPrimary: false, tile: {} }),
|
||||
@@ -330,24 +315,20 @@ describe('mobile filesystem picker actions', () => {
|
||||
|
||||
expect(_sendInputAsync).toHaveBeenCalledWith('tile-2', '/mnt/d/AI/project');
|
||||
expect(appendText).not.toHaveBeenCalled();
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
expect(tileFocus).toHaveBeenCalledOnce();
|
||||
expect(mainFocus).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('clears the prompt of the tile or Pane B that holds the keyboard with Ctrl+U, leaving the main overlay alone', () => {
|
||||
const clear = vi.fn();
|
||||
const sendInput = vi.fn(() => Promise.resolve());
|
||||
const _sendInputAsync = vi.fn();
|
||||
const showToast = vi.fn();
|
||||
const tileFocus = vi.fn();
|
||||
const app = {
|
||||
activeSessionId: 'session-1',
|
||||
_inputFlushTimeout: null,
|
||||
_pendingInput: 'main pane text',
|
||||
_localEchoEnabled: true,
|
||||
_localEchoOverlay: { getFlushed: () => ({ count: 0, text: '' }), clear, suppressBufferDetection: vi.fn() },
|
||||
sendInput,
|
||||
_sendInputAsync,
|
||||
_prepareExternalInput: vi.fn(),
|
||||
showToast,
|
||||
@@ -358,22 +339,17 @@ describe('mobile filesystem picker actions', () => {
|
||||
terminalHarness.mixin.clearTerminalInput.call(app);
|
||||
|
||||
expect(_sendInputAsync).toHaveBeenCalledWith('tile-2', '\x15');
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
expect(clear).not.toHaveBeenCalled();
|
||||
expect(app._pendingInput).toBe('main pane text');
|
||||
expect(showToast).toHaveBeenCalledWith('Input cleared', 'success');
|
||||
expect(tileFocus).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('uses Ctrl+U to clear the TUI-owned prompt when local echo is disabled', () => {
|
||||
const sendInput = vi.fn(() => Promise.resolve());
|
||||
const app = {
|
||||
activeSessionId: 'session-1',
|
||||
_inputFlushTimeout: null,
|
||||
_pendingInput: '',
|
||||
_localEchoEnabled: false,
|
||||
_localEchoOverlay: null,
|
||||
sendInput,
|
||||
_sendInputAsync: vi.fn(),
|
||||
_focusedPane: () => ({ terminal: app.terminal, sessionId: app.activeSessionId, isPrimary: true }),
|
||||
_prepareExternalInput: vi.fn(),
|
||||
|
||||
@@ -49,7 +49,6 @@ function loadToolbar(sessionId: string | null = 'session-1', localEcho = true, k
|
||||
const app = new CodemanApp();
|
||||
app.activeSessionId = sessionId;
|
||||
app.showToast = vi.fn();
|
||||
app.sendInput = vi.fn(async () => {});
|
||||
app.terminal = { focus: vi.fn() };
|
||||
app._isMobileTerminalInputFocused = vi.fn(() => keyboardUp);
|
||||
app._blurMobileTerminalInput = vi.fn();
|
||||
|
||||
@@ -36,7 +36,6 @@ type Voice = {
|
||||
type Pane = { sessionId: string; isPrimary?: boolean; terminal?: { focus: () => void } };
|
||||
|
||||
function load(opts: { insertMode?: string; localEcho?: boolean; focused?: string; tiles?: boolean; pane?: Pane } = {}) {
|
||||
const sendInput = vi.fn(async () => {});
|
||||
const sendInputAsync = vi.fn();
|
||||
const appendText = vi.fn();
|
||||
const overlayClear = vi.fn();
|
||||
@@ -57,7 +56,6 @@ function load(opts: { insertMode?: string; localEcho?: boolean; focused?: string
|
||||
['session-a', {}],
|
||||
['session-b', {}],
|
||||
]),
|
||||
sendInput,
|
||||
_sendInputAsync: sendInputAsync,
|
||||
_enqueueInput: vi.fn(),
|
||||
_prepareExternalInput: vi.fn(),
|
||||
@@ -104,7 +102,7 @@ function load(opts: { insertMode?: string; localEcho?: boolean; focused?: string
|
||||
// Recording itself is out of scope: start() only has to pick the target.
|
||||
voice._resolveProvider = () => 'webspeech';
|
||||
voice._startWebSpeech = vi.fn();
|
||||
return { voice, app, sendInput, sendInputAsync, appendText, overlayClear, showToast, gear, doc };
|
||||
return { voice, app, sendInputAsync, appendText, overlayClear, showToast, gear, doc };
|
||||
}
|
||||
|
||||
function clickGreenSend(gear: { addEventListener: { mock: { calls: unknown[][] } } }) {
|
||||
@@ -114,23 +112,21 @@ function clickGreenSend(gear: { addEventListener: { mock: { calls: unknown[][] }
|
||||
|
||||
describe('dictation target', () => {
|
||||
it('sends to the session recording started in, even after a tab switch', () => {
|
||||
const { voice, app, sendInput, sendInputAsync } = load();
|
||||
const { voice, app, sendInputAsync } = load();
|
||||
voice.start();
|
||||
app.activeSessionId = 'session-b'; // user switched tabs while speaking
|
||||
|
||||
voice._insertText('fix the login bug');
|
||||
|
||||
expect(sendInputAsync).toHaveBeenCalledWith('session-a', 'fix the login bug', { useMux: true });
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uses the session-bound path even while the target is still active', () => {
|
||||
const { voice, app, sendInput, sendInputAsync } = load({ pane: { sessionId: 'session-a', isPrimary: true } });
|
||||
const { voice, app, sendInputAsync } = load({ pane: { sessionId: 'session-a', isPrimary: true } });
|
||||
voice.start();
|
||||
|
||||
voice._insertText('hello');
|
||||
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
expect(sendInputAsync).toHaveBeenCalledWith('session-a', 'hello', { useMux: true });
|
||||
expect(app._prepareExternalInput).toHaveBeenCalledWith({ sessionId: 'session-a', isPrimary: true }, 'voice-send');
|
||||
});
|
||||
@@ -147,7 +143,7 @@ describe('dictation target', () => {
|
||||
});
|
||||
|
||||
it('still uses the local-echo overlay for the active session', () => {
|
||||
const { voice, app, appendText, sendInput } = load({
|
||||
const { voice, app, appendText } = load({
|
||||
localEcho: true,
|
||||
pane: { sessionId: 'session-a', isPrimary: true },
|
||||
});
|
||||
@@ -157,7 +153,6 @@ describe('dictation target', () => {
|
||||
|
||||
expect(appendText).toHaveBeenCalledWith('typed locally');
|
||||
expect(app._prepareExternalInput).toHaveBeenCalledWith({ sessionId: 'session-a', isPrimary: true }, 'voice-insert');
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('takes its target from the focused pane when one is reported', () => {
|
||||
@@ -170,7 +165,7 @@ describe('dictation target', () => {
|
||||
});
|
||||
|
||||
it('the green send button sends Enter to the dictation target', () => {
|
||||
const { voice, app, gear, sendInput, sendInputAsync } = load();
|
||||
const { voice, app, gear, sendInputAsync } = load();
|
||||
voice.start();
|
||||
voice._insertText('ship it');
|
||||
app.activeSessionId = 'session-b';
|
||||
@@ -179,25 +174,23 @@ describe('dictation target', () => {
|
||||
handler();
|
||||
|
||||
expect(sendInputAsync).toHaveBeenLastCalledWith('session-a', '\r', { useMux: true });
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('drops dictation for a session that closed meanwhile, with a toast', () => {
|
||||
const { voice, app, sendInput, sendInputAsync, showToast } = load();
|
||||
const { voice, app, sendInputAsync, showToast } = load();
|
||||
voice.start();
|
||||
app.activeSessionId = 'session-b';
|
||||
(app.sessions as Map<string, unknown>).delete('session-a');
|
||||
|
||||
voice._insertText('too late');
|
||||
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
expect(sendInputAsync).not.toHaveBeenCalled();
|
||||
expect(showToast).toHaveBeenCalledWith('That session has closed; dictation not sent', 'warning');
|
||||
});
|
||||
|
||||
it('with the tile grid open, dictation goes to the focused tile, not the parked overlay', () => {
|
||||
const tileTerminal = { focus: vi.fn() };
|
||||
const { voice, app, appendText, sendInput, sendInputAsync } = load({
|
||||
const { voice, app, appendText, sendInputAsync } = load({
|
||||
localEcho: true,
|
||||
tiles: true,
|
||||
pane: { sessionId: 'session-a', isPrimary: false, terminal: tileTerminal },
|
||||
@@ -207,7 +200,6 @@ describe('dictation target', () => {
|
||||
voice._insertText('into the tile');
|
||||
|
||||
expect(appendText).not.toHaveBeenCalled();
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
expect(sendInputAsync).toHaveBeenCalledWith('session-a', 'into the tile', { useMux: true });
|
||||
// The keyboard goes back to the tile; the main terminal is display: none.
|
||||
expect(tileTerminal.focus).toHaveBeenCalled();
|
||||
@@ -216,7 +208,7 @@ describe('dictation target', () => {
|
||||
|
||||
it('with the tile grid open, the green send button sends only Enter to the tile session', () => {
|
||||
const tileTerminal = { focus: vi.fn() };
|
||||
const { voice, app, gear, sendInput, sendInputAsync, overlayClear } = load({
|
||||
const { voice, app, gear, sendInputAsync, overlayClear } = load({
|
||||
localEcho: true,
|
||||
tiles: true,
|
||||
pane: { sessionId: 'session-a', isPrimary: false, terminal: tileTerminal },
|
||||
@@ -229,7 +221,6 @@ describe('dictation target', () => {
|
||||
clickGreenSend(gear);
|
||||
|
||||
expect(overlayClear).not.toHaveBeenCalled();
|
||||
expect(sendInput).not.toHaveBeenCalledWith('stale main-terminal text');
|
||||
expect(sendInputAsync).toHaveBeenLastCalledWith('session-a', '\r', { useMux: true });
|
||||
// The parked main terminal's predictions are not this pane's.
|
||||
expect(
|
||||
@@ -239,7 +230,7 @@ describe('dictation target', () => {
|
||||
|
||||
it('preserves Pane A pending text and dictation ordering when focus moves to B', () => {
|
||||
const paneB = { focus: vi.fn() };
|
||||
const { voice, app, appendText, overlayClear, gear, sendInput, sendInputAsync } = load({
|
||||
const { voice, app, appendText, overlayClear, gear, sendInputAsync } = load({
|
||||
localEcho: true,
|
||||
focused: 'session-a',
|
||||
});
|
||||
@@ -270,7 +261,6 @@ describe('dictation target', () => {
|
||||
{ write: '\r', useMux: true },
|
||||
]);
|
||||
expect(overlay.pendingText).toBe('');
|
||||
expect(sendInput).not.toHaveBeenCalled();
|
||||
expect(sendInputAsync).not.toHaveBeenCalled();
|
||||
expect(app._prepareExternalInput).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
|
||||
Reference in new issue
Block a user