Send chat messages with Enter and use Shift+Enter for newlines
This commit is contained in:
@@ -9,12 +9,13 @@ import { launchChrome, waitForPort, waitForPage, connect, sleep } from './pipeli
|
||||
import { axNodes, enableSemantics, waitFor, capture, click, clickAt } from './pipelines_probe_cdp_input.mjs';
|
||||
|
||||
const platform = process.env.PROBE_PLATFORM ?? 'material';
|
||||
const enterSends = process.env.PROBE_ENTER === '1';
|
||||
const output = resolve(process.argv[3] ?? `build/chat-response-pending-${platform}`);
|
||||
await mkdir(output, { recursive: true });
|
||||
const fixture = await startFixture({ root: resolve(process.argv[2]), chatMessages: [] });
|
||||
const profile = await mkdtemp(join(tmpdir(), 'chat-response-pending-'));
|
||||
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank');
|
||||
const log = { platform, checks: [], captures: [] };
|
||||
const log = { platform, enterSends, checks: [], captures: [] };
|
||||
let c;
|
||||
const names = async () => (await axNodes(c)).map(n => n.name?.value ?? '');
|
||||
const pending = async () => (await axNodes(c)).find(n => n.name?.value === 'Assistant is responding' && n.backendDOMNodeId);
|
||||
@@ -40,9 +41,30 @@ try {
|
||||
await clickAt(c, (x1 + x3) / 2, (y1 + y3) / 2);
|
||||
await c.send('Input.insertText', { text: 'Fixture prompt before any response tokens.' });
|
||||
await sleep(150);
|
||||
await click(c, 'Send');
|
||||
if (enterSends) {
|
||||
await c.send('Input.dispatchKeyEvent', { type: 'keyDown', key: 'Shift', code: 'ShiftLeft', windowsVirtualKeyCode: 16, modifiers: 8 });
|
||||
await c.send('Input.dispatchKeyEvent', { type: 'keyDown', key: 'Enter', code: 'Enter', windowsVirtualKeyCode: 13, modifiers: 8, text: '\r' });
|
||||
await c.send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'Enter', code: 'Enter', windowsVirtualKeyCode: 13, modifiers: 8 });
|
||||
await c.send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'Shift', code: 'ShiftLeft', windowsVirtualKeyCode: 16 });
|
||||
await sleep(150);
|
||||
const beforeSend = await (await fetch(fixture.url + '/fixture/state')).json();
|
||||
assert.equal(beforeSend.chatPrompts.length, 0, 'Shift+Enter does not submit');
|
||||
assert.equal(await pending(), undefined);
|
||||
await c.send('Input.insertText', { text: 'Second line.' });
|
||||
await c.send('Input.dispatchKeyEvent', { type: 'keyDown', key: 'Enter', code: 'Enter', windowsVirtualKeyCode: 13, text: '\r' });
|
||||
await c.send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'Enter', code: 'Enter', windowsVirtualKeyCode: 13 });
|
||||
log.checks.push('real Shift+Enter inserts a newline; plain Enter submits');
|
||||
} else {
|
||||
await click(c, 'Send');
|
||||
}
|
||||
assert.ok(await waitFor(pending, 10000), 'assistant bubble before a server response frame');
|
||||
await sleep(500); // The accepted prompt still has no assistant frames.
|
||||
if (enterSends) {
|
||||
const state = await (await fetch(fixture.url + '/fixture/state')).json();
|
||||
assert.equal(state.chatPrompts.length, 1, 'Enter submits once');
|
||||
assert.equal(state.chatPrompts[0].text, 'Fixture prompt before any response tokens.\nSecond line.');
|
||||
log.checks.push('exact multiline prompt submitted once without Control or Command');
|
||||
}
|
||||
await capture(c, output, log, '01-before-first-frame');
|
||||
log.checks.push('normal assistant response bubble before any frames or tokens');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user