mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
Keep the unsent draft out of slash-command keys; settle the iOS owner without flushing local echo. Restore the overlay last-prompt fallback and the #520 Shift/Ctrl+Enter gate guard. Pin the xterm privates the iOS owner needs; retarget browser/mobile harnesses to the session FIFO edge. Document the session FIFO invariants and link #830 for the device sequences.
This commit is contained in:
1 parent
c4b382b727
commit
db5ab5a701
11 files changed
+128
-53
No files matched your search
@@ -865,7 +865,7 @@ describe('Virtual Keyboard', () => {
|
||||
},
|
||||
suppressBufferDetection() {},
|
||||
};
|
||||
app._sendInputAsync = (_sessionId: string, input: string) => {
|
||||
app._enqueueReliableInput = (_sessionId: string, input: string) => {
|
||||
window.__sentInputs.push(input);
|
||||
};
|
||||
const settings = app.loadAppSettingsFromStorage();
|
||||
@@ -1018,7 +1018,7 @@ describe('Virtual Keyboard', () => {
|
||||
cliVersion: '2.1.220',
|
||||
status: 'running',
|
||||
});
|
||||
app._sendInputAsync = (_sessionId: string, input: string) => {
|
||||
app._enqueueReliableInput = (_sessionId: string, input: string) => {
|
||||
window.__sentInputs.push(input);
|
||||
};
|
||||
app.hideWelcome();
|
||||
@@ -1074,7 +1074,7 @@ describe('Virtual Keyboard', () => {
|
||||
mode: 'codex',
|
||||
status: 'running',
|
||||
});
|
||||
app._sendInputAsync = (_sessionId: string, input: string) => {
|
||||
app._enqueueReliableInput = (_sessionId: string, input: string) => {
|
||||
window.__sentInputs.push(input);
|
||||
};
|
||||
app.hideWelcome();
|
||||
@@ -1120,7 +1120,7 @@ describe('Virtual Keyboard', () => {
|
||||
cliVersion: '2.1.220',
|
||||
status: 'working',
|
||||
});
|
||||
app._sendInputAsync = (_sessionId: string, input: string) => {
|
||||
app._enqueueReliableInput = (_sessionId: string, input: string) => {
|
||||
window.__sentInputs.push(input);
|
||||
};
|
||||
app.hideWelcome();
|
||||
@@ -1179,7 +1179,7 @@ describe('Virtual Keyboard', () => {
|
||||
cliVersion: '2.1.220',
|
||||
status: 'working',
|
||||
});
|
||||
app._sendInputAsync = (_sessionId: string, input: string) => {
|
||||
app._enqueueReliableInput = (_sessionId: string, input: string) => {
|
||||
window.__sentInputs.push(input);
|
||||
};
|
||||
app.hideWelcome();
|
||||
@@ -1273,7 +1273,7 @@ describe('Virtual Keyboard', () => {
|
||||
mode: 'codex',
|
||||
status: 'running',
|
||||
});
|
||||
app._sendInputAsync = (_sessionId: string, input: string) => {
|
||||
app._enqueueReliableInput = (_sessionId: string, input: string) => {
|
||||
window.__sentInputs.push(input);
|
||||
};
|
||||
app.hideWelcome();
|
||||
@@ -1317,7 +1317,7 @@ describe('Virtual Keyboard', () => {
|
||||
mode: 'claude',
|
||||
status: 'running',
|
||||
});
|
||||
app._sendInputAsync = (_sessionId: string, input: string) => {
|
||||
app._enqueueReliableInput = (_sessionId: string, input: string) => {
|
||||
window.__sentInputs.push(input);
|
||||
};
|
||||
app.hideWelcome();
|
||||
@@ -1461,7 +1461,7 @@ describe('Virtual Keyboard', () => {
|
||||
status: 'running',
|
||||
});
|
||||
app.hideWelcome();
|
||||
app._sendInputAsync = (_sessionId: string, input: string) => {
|
||||
app._enqueueReliableInput = (_sessionId: string, input: string) => {
|
||||
window.__sentInputs.push(input);
|
||||
};
|
||||
const settings = app.loadAppSettingsFromStorage();
|
||||
@@ -1542,7 +1542,7 @@ describe('Virtual Keyboard', () => {
|
||||
status: 'running',
|
||||
});
|
||||
app.hideWelcome();
|
||||
app._sendInputAsync = (_sessionId: string, input: string) => {
|
||||
app._enqueueReliableInput = (_sessionId: string, input: string) => {
|
||||
window.__sentInputs.push(input);
|
||||
};
|
||||
const settings = app.loadAppSettingsFromStorage();
|
||||
@@ -1591,7 +1591,7 @@ describe('Virtual Keyboard', () => {
|
||||
// applied to the next character typed on the SYSTEM keyboard, which on a
|
||||
// phone reaches the app as xterm onData text, not a key event. These drive
|
||||
// the real xterm instance with page.keyboard.type() and assert on what would
|
||||
// go out on the wire (_sendInputAsync), not on DOM state alone.
|
||||
// go out on the wire (_enqueueReliableInput, behind the session FIFO), not on DOM state alone.
|
||||
|
||||
describe('Shell keyboard bar', () => {
|
||||
let context: BrowserContext;
|
||||
@@ -1620,14 +1620,14 @@ describe('Virtual Keyboard', () => {
|
||||
async function typeAndCapture(text: string): Promise<string[]> {
|
||||
await page.evaluate(`(function () {
|
||||
window.__sent = [];
|
||||
if (!app.__origSend) app.__origSend = app._sendInputAsync;
|
||||
app._sendInputAsync = function (sessionId, input) { window.__sent.push(input); };
|
||||
if (!app.__origSend) app.__origSend = app._enqueueReliableInput;
|
||||
app._enqueueReliableInput = function (sessionId, input) { window.__sent.push(input); };
|
||||
app.terminal.focus();
|
||||
})()`);
|
||||
await page.keyboard.type(text);
|
||||
await page.waitForTimeout(200);
|
||||
const sent = (await page.evaluate(`window.__sent`)) as string[];
|
||||
await page.evaluate(`(function () { app._sendInputAsync = app.__origSend; })()`);
|
||||
await page.evaluate(`(function () { app._enqueueReliableInput = app.__origSend; })()`);
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// @vitest-environment node
|
||||
// Regression guard: xterm runs the custom key handler for keydown AND keypress.
|
||||
// It discards a keypress carrying Ctrl/Alt but not one carrying only Shift, so
|
||||
// a handler that returns false for keydown alone lets Shift+Enter's keypress
|
||||
// through as a bare \r (submit). The Enter gate must therefore not be keyed on
|
||||
// ev.type === 'keydown'; only the send-key fetch is. The main pane may add an
|
||||
// iOS clause after the modifier test (#830), which must not test ev.type either.
|
||||
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const PUBLIC = join(new URL('.', import.meta.url).pathname, '../src/web/public');
|
||||
const GATE = /if \(ev\.key === 'Enter' && \(ev\.shiftKey \|\| ev\.ctrlKey\)(.*)\) \{/;
|
||||
|
||||
describe.each(['terminal-ui.js', 'terminal-tile.js'])('%s Shift/Ctrl+Enter handler', (file) => {
|
||||
const src = readFileSync(join(PUBLIC, file), 'utf8');
|
||||
|
||||
it('swallows every event type for Shift/Ctrl+Enter', () => {
|
||||
const gate = src.match(GATE);
|
||||
expect(gate, 'Shift/Ctrl+Enter gate not found').not.toBeNull();
|
||||
expect(gate![0]).not.toContain('ev.type');
|
||||
});
|
||||
});
|
||||
@@ -38,6 +38,25 @@ interface Pressed {
|
||||
focused: boolean;
|
||||
}
|
||||
|
||||
/** The slice of the page's `app` and probe globals that pressMain() swaps and restores. */
|
||||
interface MainProbeWindow {
|
||||
app: {
|
||||
activeSessionId: string | null;
|
||||
_localEchoEnabled: boolean;
|
||||
_enqueueReliableInput: (sessionId: string, chunk: string) => void;
|
||||
_pendingInput?: Map<string, string>;
|
||||
sessions: Map<string, { id: string; mode: string }>;
|
||||
terminal: { focus(): void; textarea?: HTMLTextAreaElement };
|
||||
};
|
||||
__mainSaved?: {
|
||||
id: string | null;
|
||||
echo: boolean;
|
||||
send: (sessionId: string, chunk: string) => void;
|
||||
};
|
||||
__mainData: string[];
|
||||
__sendKeys: string[];
|
||||
}
|
||||
|
||||
describe('Shift/Ctrl+Enter through the shipped key handlers (keypress must be swallowed too)', () => {
|
||||
let server: WebServer;
|
||||
let browser: Browser;
|
||||
@@ -105,36 +124,49 @@ describe('Shift/Ctrl+Enter through the shipped key handlers (keypress must be sw
|
||||
|
||||
/**
|
||||
* Press `key` in the main pane. `sessionId` null is the welcome screen; otherwise the app thinks
|
||||
* that session is active, local echo is off (the desktop default) and its real send path,
|
||||
* `_sendInputAsync`, is recorded instead of posting.
|
||||
* that session is active, local echo is off (the desktop default), the probe id is registered in
|
||||
* `app.sessions` (the session FIFO drops input for unknown ids), and the transport edge,
|
||||
* `_enqueueReliableInput`, is recorded instead of posting.
|
||||
*/
|
||||
async function pressMain(key: string, sessionId: string | null): Promise<Pressed> {
|
||||
await page.evaluate((id) => {
|
||||
const w = window as any;
|
||||
const w = window as unknown as MainProbeWindow;
|
||||
const app = w.app;
|
||||
w.__mainSaved ??= { id: app.activeSessionId, echo: app._localEchoEnabled, send: app._sendInputAsync };
|
||||
w.__mainData = [] as string[];
|
||||
w.__mainSaved ??= { id: app.activeSessionId, echo: app._localEchoEnabled, send: app._enqueueReliableInput };
|
||||
w.__mainData = [];
|
||||
w.__sendKeys.length = 0;
|
||||
app.activeSessionId = id;
|
||||
app._localEchoEnabled = false;
|
||||
app._pendingInput = '';
|
||||
app._sendInputAsync = (_sid: string, chunk: string) => void w.__mainData.push(chunk);
|
||||
if (id) {
|
||||
app._pendingInput?.delete(id);
|
||||
app.sessions.set(id, { id, mode: 'claude' });
|
||||
}
|
||||
app._enqueueReliableInput = (_sid: string, chunk: string) => void w.__mainData.push(chunk);
|
||||
app.terminal.focus();
|
||||
}, sessionId);
|
||||
const focused = await page.evaluate(() => document.activeElement === (window as any).app.terminal.textarea);
|
||||
const focused = await page.evaluate(
|
||||
() => document.activeElement === (window as unknown as MainProbeWindow).app.terminal.textarea
|
||||
);
|
||||
await page.keyboard.press(key);
|
||||
// The main pane batches onData through a short flush timer before _sendInputAsync.
|
||||
// The main pane batches onData through a short flush timer before the session FIFO.
|
||||
await page.waitForTimeout(150);
|
||||
return page.evaluate((f) => {
|
||||
const w = window as any;
|
||||
const app = w.app;
|
||||
const out = { data: [...w.__mainData], sendKeys: [...w.__sendKeys], focused: f };
|
||||
app.activeSessionId = w.__mainSaved.id;
|
||||
app._localEchoEnabled = w.__mainSaved.echo;
|
||||
app._sendInputAsync = w.__mainSaved.send;
|
||||
app._pendingInput = '';
|
||||
return out;
|
||||
}, focused);
|
||||
return page.evaluate(
|
||||
({ f, id }) => {
|
||||
const w = window as unknown as MainProbeWindow;
|
||||
const app = w.app;
|
||||
const saved = w.__mainSaved!;
|
||||
const out = { data: [...w.__mainData], sendKeys: [...w.__sendKeys], focused: f };
|
||||
app.activeSessionId = saved.id;
|
||||
app._localEchoEnabled = saved.echo;
|
||||
app._enqueueReliableInput = saved.send;
|
||||
if (id) {
|
||||
app._pendingInput?.delete(id);
|
||||
app.sessions.delete(id);
|
||||
}
|
||||
return out;
|
||||
},
|
||||
{ f: focused, id: sessionId }
|
||||
);
|
||||
}
|
||||
|
||||
async function pressIn(which: 'paneB' | 'old', key: string): Promise<Pressed> {
|
||||
|
||||
@@ -620,7 +620,7 @@ describe('native main transactions and boundaries', () => {
|
||||
}
|
||||
);
|
||||
|
||||
it.each(['upload', 'voice', 'Esc', 'command', 'paste'])(
|
||||
it.each(['upload', 'voice', 'Esc', 'paste'])(
|
||||
'%s preserves the typed prefix before direct writes with echo on or off',
|
||||
async (producer) => {
|
||||
for (const echo of [true, false]) {
|
||||
@@ -668,14 +668,6 @@ describe('native main transactions and boundaries', () => {
|
||||
['old', 'hel'],
|
||||
['old', '\x1b'],
|
||||
]);
|
||||
} else if (producer === 'command') {
|
||||
vm.runInContext("KeyboardAccessoryBar.sendCommand('/help')", context);
|
||||
expect(wire).toEqual([
|
||||
['old', 'hel'],
|
||||
['old', '/help'],
|
||||
]);
|
||||
vi.advanceTimersByTime(120);
|
||||
expect(wire.at(-1)).toEqual(['old', '\r']);
|
||||
} else {
|
||||
vm.runInContext("KeyboardAccessoryBar._sendBracketedPaste('old', 'world', 'Paste')", context);
|
||||
expect(wire).toEqual([
|
||||
@@ -688,6 +680,20 @@ describe('native main transactions and boundaries', () => {
|
||||
}
|
||||
);
|
||||
|
||||
it('sends a slash command without submitting the unsent local-echo draft', () => {
|
||||
for (const echo of [true, false]) {
|
||||
const { app, wire, context } = harness();
|
||||
loadProducerModules(app, context);
|
||||
app._localEchoEnabled = echo;
|
||||
app._handleTerminalData('hel', 'old');
|
||||
vm.runInContext("KeyboardAccessoryBar.sendCommand('/help')", context);
|
||||
vi.advanceTimersByTime(120);
|
||||
// Echo on: `hel` stays in the overlay. Echo off: it was already typed into the PTY.
|
||||
expect(wire).toEqual([...(echo ? [] : [['old', 'hel']]), ['old', '/help'], ['old', '\r']]);
|
||||
expect(app._localEchoOverlay.pendingText).toBe(echo ? 'hel' : '');
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps the typed prefix in the overlay when a toolbar attachment appends', async () => {
|
||||
const { app, wire, context } = harness();
|
||||
loadProducerModules(app, context);
|
||||
|
||||
@@ -51,7 +51,9 @@ describe('xterm private-API dependency guard', () => {
|
||||
'CompositionHelper fields installEditSync() uses (terminal-keycode229-recovery.js: ' +
|
||||
'_handleAnyTextareaChanges, _coreService, _isComposing, _isSendingComposition, _dataAlreadySent) ' +
|
||||
'and the mouse-encoding read _shouldForwardTouchToApp makes (terminal-ui.js: ' +
|
||||
'_core.coreMouseService.activeEncoding), then update VERIFIED_XTERM_VERSION here. ' +
|
||||
'_core.coreMouseService.activeEncoding) and the iOS native-input owner (terminal-ios-native-input.js: ' +
|
||||
'_core._inputEvent, _core._handleTextAreaBlur, _compositionHelper._finalizeComposition, ' +
|
||||
'_compositionHelper._compositionView), then update VERIFIED_XTERM_VERSION here. ' +
|
||||
'The accessor is optional-chained, so a renamed field ' +
|
||||
'degrades to a silent no-op and the freeze it heals comes back unnoticed.'
|
||||
).toBe(VERIFIED_XTERM_VERSION);
|
||||
@@ -67,6 +69,9 @@ describe('xterm private-API dependency guard', () => {
|
||||
// only to an app that asked for SGR mouse reports; if either name changes the read is undefined
|
||||
// and touch quietly stops forwarding to native SGR tracking apps. Property names survive
|
||||
// minification, so a string check on the shipped bundle catches a rename on upgrade.
|
||||
// terminal-ios-native-input.js wraps `_inputEvent`, `_handleTextAreaBlur` and `_finalizeComposition`
|
||||
// and reads `_compositionView`; if any is missing its create() returns null, and iOS then gets
|
||||
// neither the native-input owner nor the keyCode-229 recovery, so #830 returns without a signal.
|
||||
it('still ships the composition-helper and mouse-service fields terminal input depends on', () => {
|
||||
const bundle = readFileSync(resolve(root, 'node_modules/@xterm/xterm/lib/xterm.js'), 'utf8');
|
||||
for (const name of [
|
||||
@@ -78,12 +83,17 @@ describe('xterm private-API dependency guard', () => {
|
||||
'_dataAlreadySent',
|
||||
'coreMouseService',
|
||||
'activeEncoding',
|
||||
'_inputEvent',
|
||||
'_handleTextAreaBlur',
|
||||
'_finalizeComposition',
|
||||
'_compositionView',
|
||||
]) {
|
||||
expect(
|
||||
bundle,
|
||||
`xterm no longer mentions ${name}: re-verify terminal-keycode229-recovery.js installEditSync() ` +
|
||||
'against the new CompositionHelper, and terminal-ui.js _shouldForwardTouchToApp against the ' +
|
||||
'new CoreMouseService (both in src/web/public), before bumping VERIFIED_XTERM_VERSION'
|
||||
'against the new CompositionHelper, terminal-ios-native-input.js create() against the new ' +
|
||||
'CoreBrowserTerminal and CompositionHelper, and terminal-ui.js _shouldForwardTouchToApp against the ' +
|
||||
'new CoreMouseService (all in src/web/public), before bumping VERIFIED_XTERM_VERSION'
|
||||
).toContain(name);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user