Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(ui-tests): make ctrlEnterSubmit hermetic in accessibility shard (#5056)

LearningCircuit0b3fad909d13
diff --git a/tests/ui_tests/test_keyboard_accessibility_ci.js b/tests/ui_tests/test_keyboard_accessibility_ci.js
index 483c591a6b..b67e0f2d91 100644
--- a/tests/ui_tests/test_keyboard_accessibility_ci.js
+++ b/tests/ui_tests/test_keyboard_accessibility_ci.js
@@ -227,49 +227,129 @@ const KeyboardShortcutsTests = {
async ctrlEnterSubmit(page, baseUrl) {
// The Ctrl/Cmd+Enter "submit from anywhere" shortcut is a document-level
- // keydown handler that calls handleResearchSubmit (which POSTs to
- // /api/start_research) on ctrlKey||metaKey + Enter. The old test asserted the
- // URL changed (navigation), which needs an LLM — start_research returns 400
- // "Model is required" in the no-LLM shard, so it could never pass and was left
- // unregistered. Assert the shortcut fires the submit POST instead (made
- // regardless of the 400, so deterministic).
+ // keydown handler (research.js ~687-705) that calls handleResearchSubmit,
+ // which POSTs to /api/start_research (research modes) or
+ // /api/chat/sessions (chat mode). We assert the shortcut fires that POST —
+ // NOT the navigation, which would need an LLM.
//
- // We type the query, then BLUR the textarea before pressing Ctrl+Enter. This
- // isolates the modifier: the textarea's keydown handler also submits on PLAIN
- // Enter, so pressing Ctrl+Enter while focused there would pass even if the
- // Ctrl/Cmd-specific paths regressed. From <body>, only the document-level
- // Ctrl/Cmd+Enter handler can fire the submit. waitForRequest is armed before
- // the keypress to avoid a race.
+ // Isolation, layered (each guards a confirmed failure mode):
+ // 1. waitForNetworkIdle after navigateTo: research.js's async init
+ // (loadSettings) writes '' to #model_hidden once the settings fetch
+ // settles (llm.model is present-but-empty). Seeding before that lands
+ // gets clobbered, so the client-side model guard (#5048) returns early
+ // with no POST. Waiting for idle makes our seed the last write — the
+ // same guard the sibling escapeKeyFunction test uses.
+ // 2. setRequestInterception + page.on('request') respond 400 JSON to the
+ // submit POST so it never reaches the server. Without this the dummy
+ // model also defeats the server's truthiness-only check, returning
+ // {status:'success'} and redirecting to /progress/{id} AFTER this test
+ // returns — destroying the next sibling test's page context. The 400
+ // instead drives handleResearchSubmit into its self-cleaning error
+ // branch (removes the overlay, re-enables the button). waitForRequest
+ // still fires: Puppeteer emits the request before respond() answers it.
+ // 3. Idempotent cleanup in finally: the page is shared with later tests
+ // (navigateTo short-circuits on path-equality), so interception is
+ // disabled and any residual overlay/alert/button state cleared.
+ //
+ // We BLUR the textarea before pressing Ctrl+Enter: its keydown handler also
+ // submits on PLAIN Enter, so pressing Ctrl+Enter there would pass even if the
+ // Ctrl-specific document handler regressed. From <body>, only the
+ // document-level handler can fire.
await navigateTo(page, `${baseUrl}/`);
+ await page.waitForNetworkIdle({ idleTime: 500, timeout: 15000 }).catch(() => {});
const textarea = await page.$('textarea[name="query"], textarea#query');
if (!textarea) {
return { passed: false, message: 'No query textarea found on /' };
}
await textarea.type('Test query for keyboard submission');
- // Move focus off the textarea so plain Enter can't submit — isolates Ctrl+Enter.
- await page.evaluate(() => document.activeElement?.blur());
-
- // A submit POST goes to /api/start_research (research mode) or
- // /api/chat/sessions (chat mode); either proves the shortcut submitted.
- const submitRequest = page.waitForRequest(
- (req) => req.method() === 'POST'
- && (req.url().includes('/api/start_research') || req.url().includes('/api/chat/sessions')),
- { timeout: 8000 }
- ).catch(() => null);
-
- await page.keyboard.down('Control');
- await page.keyboard.press('Enter');
- await page.keyboard.up('Control');
-
- const req = await submitRequest;
- const passed = !!req;
- return {
- passed,
- message: passed
- ? `Ctrl+Enter (from body) submits the form (POST ${new URL(req.url()).pathname})`
- : 'Ctrl+Enter did not trigger a submit request'
+
+ // Repo convention for request interception (see test_research_api.js):
+ // setRequestInterception + page.on('request'). /api/start_research and
+ // /api/chat/sessions are only POSTed by the submit handler, so this can't
+ // disturb page init; every other request passes through unchanged.
+ const intercept = (request) => {
+ if (request.method() === 'POST'
+ && (request.url().includes('/api/start_research')
+ || request.url().includes('/api/chat/sessions'))) {
+ request.respond({
+ status: 400,
+ contentType: 'application/json',
+ body: JSON.stringify({ status: 'error', message: 'Intercepted by UI test' })
+ });
+ } else {
+ request.continue();
+ }
};
+
+ try {
+ // Satisfy the client-side model-required guard (#5048); read back to
+ // confirm. If the custom dropdown never created #model_hidden, skip
+ // rather than misreport a Ctrl+Enter regression.
+ const modelSeeded = await page.evaluate(() => {
+ const m = document.querySelector('#model_hidden');
+ if (!m) return false;
+ m.value = 'test-model';
+ return m.value.trim() === 'test-model';
+ });
+ if (!modelSeeded) {
+ return { passed: null, skipped: true, message: '#model_hidden not present; cannot exercise submit path' };
+ }
+ // Move focus off the textarea so plain Enter can't submit — isolates Ctrl+Enter.
+ await page.evaluate(() => document.activeElement?.blur());
+
+ // Enable interception only around the keypress window.
+ await page.setRequestInterception(true);
+ page.on('request', intercept);
+
+ // A submit POST goes to /api/start_research (research mode) or
+ // /api/chat/sessions (chat mode); either proves the shortcut submitted.
+ const submitRequest = page.waitForRequest(
+ (req) => req.method() === 'POST'
+ && (req.url().includes('/api/start_research') || req.url().includes('/api/chat/sessions')),
+ { timeout: 8000 }
+ ).catch(() => null);
+
+ // Modifier up is in a nested finally so a mid-press failure can't leave
+ // Control held for sibling tests (this page is reused).
+ try {
+ await page.keyboard.down('Control');
+ await page.keyboard.press('Enter');
+ } finally {
+ await page.keyboard.up('Control');
+ }
+
+ const req = await submitRequest;
+ const passed = !!req;
+
+ // Let the client's own error-branch (driven by our canned 400) remove
+ // the overlay + re-enable the button before we return, so the next test
+ // doesn't inherit them. The intercept makes the response immediate.
+ await page.waitForFunction(
+ () => !document.querySelector('.ldr-loading-overlay'),
+ { timeout: 5000 }
+ ).catch(() => {});
+
+ return {
+ passed,
+ message: passed
+ ? `Ctrl+Enter (from body) submits the form (POST ${new URL(req.url()).pathname})`
+ : 'Ctrl+Enter did not trigger a submit request'
+ };
+ } finally {
+ // Disable interception first (so later requests need no explicit
+ // continue()), then drop the listener. The page is shared, so this must
+ // not leak. DOM cleanup is idempotent in case the client branch stalled.
+ await page.setRequestInterception(false).catch(() => {});
+ page.off('request', intercept);
+ await page.evaluate(() => {
+ document.querySelectorAll('.ldr-loading-overlay').forEach((el) => el.remove());
+ const btn = document.getElementById('start-research-btn');
+ if (btn) btn.disabled = false;
+ const alert = document.getElementById('research-alert');
+ if (alert) { alert.innerHTML = ''; alert.style.display = 'none'; }
+ }).catch(() => {});
+ }
}
};