~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix: replace hardcoded setTimeout waits with event-driven waits in 5 flaky UI tests (#2884)
LearningCircuit2e0f7ec51806
diff --git a/tests/ui_tests/test_error_handling_ci.js b/tests/ui_tests/test_error_handling_ci.jsindex dd7d1a4176..07f28efbde 100644--- a/tests/ui_tests/test_error_handling_ci.js+++ b/tests/ui_tests/test_error_handling_ci.js@@ -99,6 +99,9 @@ const Error404Tests = {// ============================================================================const Error401Tests = {async unauthenticatedRedirectsToLogin(page, baseUrl) {+ // Navigate to login page first to avoid pending XHR interference+ await page.goto(`${baseUrl}/auth/login`, { waitUntil: 'domcontentloaded', timeout: 15000 });+// Clear cookies to simulate unauthenticated stateconst client = await page.target().createCDPSession();await client.send('Network.clearBrowserCookies');@@ -347,20 +350,26 @@ const FormValidationTests = {if (submitBtn) submitBtn.click();return new Promise(resolve => {- setTimeout(() => {+ let attempts = 0;+ const check = () => {const hasError = !!document.querySelector('.error, .invalid-feedback, .form-error, .alert-danger, [class*="error"]');const hasInvalidInput = !!document.querySelector('input:invalid, textarea:invalid');const errorText = document.querySelector('.error, .invalid-feedback')?.textContent?.trim();- resolve({- hasForm: true,- hasError,- hasInvalidInput,- errorText- });- }, 500);+ if (hasError || hasInvalidInput || ++attempts >= 15) {+ resolve({+ hasForm: true,+ hasError,+ hasInvalidInput,+ errorText+ });+ } else {+ setTimeout(check, 200);+ }+ };+ setTimeout(check, 200);});});@@ -397,18 +406,24 @@ const FormValidationTests = {numericInput.dispatchEvent(new Event('input', { bubbles: true }));return new Promise(resolve => {- setTimeout(() => {+ let attempts = 0;+ const check = () => {const hasError = !!document.querySelector('.error, .invalid-feedback, .form-error, [class*="error"]');const hasInvalidInput = !!document.querySelector('input:invalid');- resolve({- hasInput: true,- hasError,- hasInvalidInput- });- }, 500);+ if (hasError || hasInvalidInput || ++attempts >= 15) {+ resolve({+ hasInput: true,+ hasError,+ hasInvalidInput+ });+ } else {+ setTimeout(check, 200);+ }+ };+ setTimeout(check, 200);});});@@ -484,6 +499,7 @@ async function main() {// (the old page has a stale token from the cleared session)try {await page.goto(`${baseUrl}/auth/login`, { waitUntil: 'domcontentloaded', timeout: 15000 });+ await page.waitForSelector('form[action*="login"], input[type="password"], .login-form', { timeout: 10000 });} catch (reloadError) {log.warning(`Could not reload login page: ${reloadError.message}`);}diff --git a/tests/ui_tests/test_lib/test_utils.js b/tests/ui_tests/test_lib/test_utils.jsindex fded1831ee..30db0aa564 100644--- a/tests/ui_tests/test_lib/test_utils.js+++ b/tests/ui_tests/test_lib/test_utils.js@@ -184,17 +184,18 @@ async function navigateTo(page, url, options = {}) {try {const currentPath = new URL(currentUrl).pathname.replace(/\/$/, '');if (currentPath === targetPath) {- return;+ return null;}} catch (e) {// about:blank or invalid URL — need to navigate}- await page.goto(url, {+ const response = await page.goto(url, {waitUntil: 'domcontentloaded',timeout: config.isCI ? 60000 : config.timeout,...options,});+ return response;}/**diff --git a/tests/ui_tests/test_research_workflow.js b/tests/ui_tests/test_research_workflow.jsindex 36ac6c0c30..56bac93f41 100644--- a/tests/ui_tests/test_research_workflow.js+++ b/tests/ui_tests/test_research_workflow.js@@ -34,6 +34,7 @@ async function testResearchWorkflow() {let testsPassed = 0;let testsFailed = 0;+ let testsSkipped = 0;try {// Setup: Authenticate@@ -69,11 +70,11 @@ async function testResearchWorkflow() {testsPassed++;} else {console.log('⚠️ Model configuration may have issues (continuing)');- testsPassed++; // Don't fail on model config+ testsSkipped++;}} catch (error) {console.log(`⚠️ Model configuration error: ${error.message}`);- testsPassed++; // Continue with test+ testsSkipped++;}// Test 3: Form fields are accessible@@ -111,9 +112,11 @@ async function testResearchWorkflow() {const queryInput = await page.$('#query, input[name="query"]');if (queryInput) {- // Clear and type- await queryInput.click({ clickCount: 3 });- await page.keyboard.type('Test research query for workflow test');+ // Set value atomically to avoid race with page JS event handlers+ await page.$eval('#query', (el) => {+ el.value = 'Test research query for workflow test';+ el.dispatchEvent(new Event('input', { bubbles: true }));+ });const value = await page.$eval('#query, input[name="query"]', el => el.value);if (value.includes('Test research query')) {@@ -188,10 +191,10 @@ async function testResearchWorkflow() {} else {console.log('⚠️ Stayed on home page (may need model configuration)');}- testsPassed++; // Don't fail - config may not be set up+ testsSkipped++;} else {console.log(`⚠️ Unexpected URL after submission: ${url}`);- testsPassed++;+ testsSkipped++;}} else {console.log('❌ Submit button not found');@@ -199,7 +202,7 @@ async function testResearchWorkflow() {}} catch (error) {console.log(`⚠️ Test 5 had issues: ${error.message}`);- testsPassed++; // Don't fail entire test for submission issues+ testsSkipped++;}// Test 6: History page shows research history@@ -273,8 +276,9 @@ async function testResearchWorkflow() {console.log('📊 RESEARCH WORKFLOW TEST SUMMARY');console.log('='.repeat(50));console.log(`✅ Passed: ${testsPassed}`);+ console.log(`⏭️ Skipped: ${testsSkipped}`);console.log(`❌ Failed: ${testsFailed}`);- console.log(`📊 Success Rate: ${Math.round((testsPassed / (testsPassed + testsFailed)) * 100)}%`);+ console.log(`📊 Success Rate: ${Math.round((testsPassed / (testsPassed + testsFailed + testsSkipped)) * 100)}%`);// Take final screenshotawait page.screenshot({@@ -282,7 +286,7 @@ async function testResearchWorkflow() {fullPage: true});- if (testsFailed > 2) { // Allow some failures due to config+ if (testsFailed > 0) {console.log('\n⚠️ Too many workflow tests failed');process.exit(1);}diff --git a/tests/ui_tests/test_settings_save.js b/tests/ui_tests/test_settings_save.jsindex 2e8b18dc17..6c992c02d0 100644--- a/tests/ui_tests/test_settings_save.js+++ b/tests/ui_tests/test_settings_save.js@@ -64,7 +64,7 @@ async function testSettingsSave() {});// Wait for page to load completely- await new Promise(resolve => setTimeout(resolve, 5000));+ await page.waitForSelector('#save-all-btn, button[type="submit"]', { timeout: 15000 });console.log('🔍 Looking for save button...');@@ -74,11 +74,21 @@ async function testSettingsSave() {if (saveButtons.length > 0) {console.log('✅ Clicking save button...');++ // Start listening for the save response BEFORE clicking+ const responsePromise = page.waitForResponse(+ r => r.url().includes('/save_all_settings'),+ { timeout: 15000 }+ );await saveButtons[0].click();- // Wait and monitor for any responses+ // Wait for the save responseconsole.log('⏳ Waiting for save response...');- await new Promise(resolve => setTimeout(resolve, 5000));+ try {+ await responsePromise;+ } catch (e) {+ console.log('⚠️ Save response not captured (endpoint may differ)');+ }// Check for success/error messagesconst messages = await page.$$('.alert, .message, .notification, .success, .error');diff --git a/tests/ui_tests/test_star_reviews.js b/tests/ui_tests/test_star_reviews.jsindex 16f121a7d0..da3aeab418 100644--- a/tests/ui_tests/test_star_reviews.js+++ b/tests/ui_tests/test_star_reviews.js@@ -58,6 +58,13 @@ async function testStarReviews() {// Ensure authenticated before accessing metricsawait authHelper.ensureAuthenticatedWithTimeout();+ // Start listening for the API response BEFORE navigation+ // (the fetch fires on DOMContentLoaded, which may complete during goto)+ const apiResponsePromise = page.waitForResponse(+ r => r.url().includes('/metrics/api/star-reviews'),+ { timeout: 30000 }+ );+// Navigate directly to star reviews pageawait page.goto('http://127.0.0.1:5000/metrics/star-reviews', {waitUntil: 'domcontentloaded',@@ -66,8 +73,8 @@ async function testStarReviews() {console.log('📊 Checking star reviews page elements...');- // Wait for content to load- await new Promise(resolve => setTimeout(resolve, 3000));+ // Wait for the star-reviews API call to complete+ await apiResponsePromise;// Check for main page elementsconst pageElements = await page.evaluate(() => {@@ -95,12 +102,25 @@ async function testStarReviews() {console.log('🕐 Testing period selector...');const periodSelect = await page.$('#period-select');if (periodSelect) {+ // Start listening for reload response BEFORE triggering it+ const reloadResponsePromise = page.waitForResponse(+ r => r.url().includes('/metrics/api/star-reviews'),+ { timeout: 15000 }+ );+// Change to "7d" periodawait page.select('#period-select', '7d');console.log('✅ Period selector changed to 7 days');- // Wait for data reload- await new Promise(resolve => setTimeout(resolve, 2000));+ // Wait for the reload API call to complete+ await reloadResponsePromise;+ }++ // Wait for Chart.js to be available (may not load in CI with no data)+ try {+ await page.waitForFunction(() => typeof window.Chart !== 'undefined', { timeout: 10000 });+ } catch (e) {+ console.log('⚠️ Chart.js not loaded (may not have data in CI)');}// Check if charts are rendered (Canvas elements)