~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(ui-tests): real assertions for document upload + delete + bulk-select (#4187)
LearningCircuit3bf056c0eec2
diff --git a/tests/ui_tests/test_crud_operations_ci.js b/tests/ui_tests/test_crud_operations_ci.jsindex 0b6646752b..86dcd054f9 100644--- a/tests/ui_tests/test_crud_operations_ci.js+++ b/tests/ui_tests/test_crud_operations_ci.js@@ -127,24 +127,16 @@ const CollectionCrudTests = {// detail page, or anywhere in the templates), so the old test was// a permanent SKIP for a feature that simply does not exist.- // Seed.+ // Seed via the shared helper (also used by the document tests). It+ // returns the id and the generated name; we wait for that name to land+ // on the detail page before clicking. seedCollection reads the CSRF+ // meta from the current page, so be on an app page first.await navigateTo(page, `${baseUrl}/library/collections`);- const fixtureName = `ldr-ui-test-collection-${Date.now()}`;- const seed = await page.evaluate(async (name) => {- const csrf = document.querySelector('meta[name="csrf-token"]')?.content;- const r = await fetch('/library/api/collections', {- method: 'POST',- credentials: 'same-origin',- headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrf || '' },- body: JSON.stringify({ name, description: 'UI test fixture', type: 'user_uploads' }),- });- const body = await r.json().catch(() => ({}));- return { ok: r.ok, status: r.status, body };- }, fixtureName);- if (!seed.ok || !seed.body?.success) {- return { passed: false, message: `Could not seed test collection (status=${seed.status}, body=${JSON.stringify(seed.body).slice(0, 120)})` };+ const seeded = await seedCollection(page);+ if (!seeded) {+ return { passed: false, message: 'Could not seed test collection' };}- const collectionId = seed.body.collection.id;+ const { id: collectionId, name: fixtureName } = seeded;try {// Listen for the native confirm() before clicking — Puppeteer@@ -191,22 +183,8 @@ const CollectionCrudTests = {: `Dialog fired but contract failed (type=${dialog.type}, message="${dialog.message.slice(0, 80)}")`};} finally {- // Cleanup — best-effort; even if the test failed before the- // dismiss, we want to remove the seeded collection. Wrap the- // page.evaluate itself so a torn-down page during cleanup can- // never throw and mask the real test result.- try {- await page.evaluate(async (id) => {- const csrf = document.querySelector('meta[name="csrf-token"]')?.content;- try {- await fetch(`/library/api/collections/${id}`, {- method: 'DELETE',- credentials: 'same-origin',- headers: { 'X-CSRFToken': csrf || '' },- });- } catch { /* swallow fetch errors */ }- }, collectionId);- } catch { /* swallow page.evaluate errors so cleanup never masks the test result */ }+ // Best-effort cleanup via the shared helper.+ await deleteCollection(page, collectionId);}}};@@ -523,121 +501,247 @@ const SubscriptionCrudTests = {// ============================================================================const DocumentCrudTests = {async documentUploadFormExists(page, baseUrl) {- await navigateTo(page, `${baseUrl}/library`);-- const result = await page.evaluate(() => {- const uploadBtn = document.querySelector(- 'button[class*="upload"], ' +- 'a[href*="upload"], ' +- '.upload-btn, ' +- 'input[type="file"]'- );-- const uploadText = Array.from(document.querySelectorAll('button, a.btn')).find(b =>- b.textContent?.toLowerCase().includes('upload')- );-+ // The previous version checked /library for an "upload" button or+ // file input. That page is the *research-library* index (filter ++ // results), not an upload form — it never had upload UI, so the+ // test was a permanent SKIP. Direct upload lives at+ // /library/collections/<id>/upload (rag_routes.py).+ //+ // Seed a throwaway collection so the upload page is reachable on+ // a fresh DB, navigate to it, and assert the form exists with a+ // multiple-file input and the submit affordance. Clean up the+ // collection afterwards.++ // Land on an app page first so seedCollection / uploadFixtureDocument+ // can read the CSRF meta tag, rather than depending on the page state+ // the previous test happened to leave behind.+ await navigateTo(page, `${baseUrl}/library/collections`);+ const collId = (await seedCollection(page))?.id;+ if (!collId) {+ return { passed: false, message: 'Could not seed collection for upload form test' };+ }+ try {+ await navigateTo(page, `${baseUrl}/library/collections/${collId}/upload`);+ const result = await page.evaluate(() => {+ const form = document.querySelector('form#upload-files-form, form[enctype*="multipart"]');+ const fileInput = document.querySelector('input[type="file"]');+ const submit = document.querySelector('button[type="submit"], input[type="submit"]');+ return {+ hasForm: !!form,+ hasFileInput: !!fileInput,+ fileInputMultiple: !!fileInput?.multiple,+ fileInputAccept: fileInput?.accept || '',+ hasSubmit: !!submit,+ submitText: submit?.textContent?.trim() || submit?.value || '',+ };+ });+ const passed = result.hasForm && result.hasFileInput && result.hasSubmit;return {- hasUploadButton: !!uploadBtn || !!uploadText,- hasFileInput: !!document.querySelector('input[type="file"]'),- buttonText: (uploadBtn || uploadText)?.textContent?.trim()+ passed,+ message: passed+ ? `Upload form ok (file input multiple=${result.fileInputMultiple}, accept includes ${result.fileInputAccept.split(',').length} types, submit="${result.submitText.slice(0, 30)}")`+ : `Upload form missing parts (form=${result.hasForm}, file=${result.hasFileInput}, submit=${result.hasSubmit})`,};- });-- if (!result.hasUploadButton && !result.hasFileInput) {- return { passed: null, skipped: true, message: 'No upload functionality found' };+ } finally {+ await deleteCollection(page, collId);}-- return {- passed: true,- message: result.hasFileInput- ? 'File upload input found'- : `Upload button found: "${result.buttonText}"`- };},async documentDeleteConfirmation(page, baseUrl) {- await navigateTo(page, `${baseUrl}/library`);-- const result = await page.evaluate(() => {- const documents = document.querySelectorAll('.document-item, .library-item, tr[data-id], [data-document-id]');- if (documents.length === 0) return { hasDocs: false };-- const firstDoc = documents[0];- const deleteBtn = firstDoc.querySelector(- 'button[class*="delete"], ' +- '.delete-btn, ' +- '.btn-danger, ' +- '.fa-trash'- );-- if (!deleteBtn) return { hasDocs: true, hasDeleteButton: false };+ // The list-page document rows use DeleteManager.deleteDocument+ // (deletion/delete_manager.js), which shows the Bootstrap+ // #deleteConfirmModal (components/delete_confirmation_modal.html).+ // The old test scanned for generic doc-row selectors that never+ // matched and SKIPped on empty DB.+ //+ // Pipeline: seed a collection, upload a tiny text fixture via the+ // multipart API (the real upload path), navigate to+ // /library/?collection=<id> so only our fixture row is in scope,+ // click .ldr-btn-delete-doc, and assert #deleteConfirmModal goes+ // from hidden to visible. Bootstrap drives the .show class via+ // its Modal API, so we wait on that rather than racing a fixed+ // timeout.++ // Land on an app page first so seedCollection / uploadFixtureDocument+ // can read the CSRF meta tag, rather than depending on the page state+ // the previous test happened to leave behind.+ await navigateTo(page, `${baseUrl}/library/collections`);+ const collId = (await seedCollection(page))?.id;+ if (!collId) {+ return { passed: false, message: 'Could not seed collection for delete test' };+ }+ try {+ const upload = await uploadFixtureDocument(page, collId);+ if (!upload.ok) {+ return { passed: false, message: `Could not upload fixture document (status=${upload.status})` };+ }- deleteBtn.click();+ await navigateTo(page, `${baseUrl}/library/?collection=${collId}`);+ await page.waitForSelector('.ldr-btn-delete-doc', { timeout: 5000 });- return new Promise(resolve => {- setTimeout(() => {- const confirmModal = document.querySelector('.modal, .confirm-dialog, [role="alertdialog"]');- resolve({- hasDocs: true,- hasDeleteButton: true,- hasConfirmModal: !!confirmModal- });- }, 300);+ // Pre-flight: the bootstrap modal node is always present in+ // the include; only its .show class flips when invoked.+ const preState = await page.evaluate(() => {+ const m = document.getElementById('deleteConfirmModal');+ return { exists: !!m, visible: m?.classList.contains('show') ?? null };});- });+ if (!preState.exists) {+ return { passed: false, message: '#deleteConfirmModal not in DOM — components/delete_confirmation_modal.html include broken?' };+ }- if (!result.hasDocs) {- return { passed: null, skipped: true, message: 'No documents to test delete' };- }+ await page.click('.ldr-btn-delete-doc');+ // Wait for Bootstrap to add the .show class.+ await page.waitForFunction(+ () => document.getElementById('deleteConfirmModal')?.classList.contains('show') === true,+ { timeout: 5000 }+ );- if (!result.hasDeleteButton) {- return { passed: null, skipped: true, message: 'No delete button found on documents' };+ const postState = await page.evaluate(() => {+ const m = document.getElementById('deleteConfirmModal');+ return {+ visible: m?.classList.contains('show'),+ title: document.getElementById('deleteConfirmModalLabel')?.textContent?.trim().slice(0, 50),+ };+ });+ return {+ passed: postState.visible === true,+ message: postState.visible+ ? `#deleteConfirmModal opens on document delete click (title="${postState.title}")`+ : `Modal did not become visible (post.visible=${postState.visible})`,+ };+ } finally {+ await deleteCollection(page, collId);}-- return {- passed: result.hasConfirmModal,- message: result.hasConfirmModal- ? 'Document delete confirmation modal appears'- : 'No delete confirmation found'- };},async bulkDeleteSelection(page, baseUrl) {- await navigateTo(page, `${baseUrl}/library`);+ // Without at least one document the library page renders an+ // empty-state placeholder and no row checkboxes — the old+ // selectors (input[type=checkbox][name*=select] / .bulk-select /+ // .select-all) couldn't find anything anyway. Seed a fixture+ // document so the bulk-selection surface is actually present,+ // then check for a row checkbox AND the bulk action affordance.++ // Land on an app page first so seedCollection / uploadFixtureDocument+ // can read the CSRF meta tag, rather than depending on the page state+ // the previous test happened to leave behind.+ await navigateTo(page, `${baseUrl}/library/collections`);+ const collId = (await seedCollection(page))?.id;+ if (!collId) {+ return { passed: false, message: 'Could not seed collection for bulk-select test' };+ }+ try {+ const upload = await uploadFixtureDocument(page, collId);+ if (!upload.ok) {+ return { passed: false, message: `Could not upload fixture document (status=${upload.status})` };+ }- const result = await page.evaluate(() => {- const checkboxes = document.querySelectorAll(- 'input[type="checkbox"][name*="select"], ' +- '.bulk-select, ' +- '.select-all, ' +- 'th input[type="checkbox"]'- );+ await navigateTo(page, `${baseUrl}/library/?collection=${collId}`);+ await page.waitForSelector('.ldr-btn-delete-doc', { timeout: 5000 });- const bulkDeleteBtn = document.querySelector(- 'button[class*="bulk-delete"], ' +- '.bulk-actions button, ' +- '.delete-selected'- );+ const result = await page.evaluate(() => {+ const rowCheckboxes = document.querySelectorAll(+ 'input[type="checkbox"][name*="select"], ' ++ '.bulk-select, ' ++ '.select-all, ' ++ 'th input[type="checkbox"], ' ++ '.ldr-doc-checkbox'+ );+ const bulkDeleteBtn = document.querySelector(+ 'button[class*="bulk-delete"], ' ++ '.bulk-actions button, ' ++ '.delete-selected, ' ++ '#bulk-delete-btn'+ );+ return {+ checkboxCount: rowCheckboxes.length,+ hasBulkDeleteBtn: !!bulkDeleteBtn,+ };+ });+ if (result.checkboxCount === 0 && !result.hasBulkDeleteBtn) {+ // No checkboxes AND no bulk-delete button: the listing+ // doesn't expose a bulk-selection surface even with docs+ // present. Skip with a precise message — different from+ // the old "no documents" SKIP which masked this case.+ return { passed: null, skipped: true, message: 'Library listing has no per-row checkboxes and no bulk-action button (feature not implemented for this view)' };+ }return {- hasCheckboxes: checkboxes.length > 0,- checkboxCount: checkboxes.length,- hasBulkDeleteBtn: !!bulkDeleteBtn+ passed: true,+ message: `Bulk-selection surface present (checkboxes=${result.checkboxCount}, bulkAction=${result.hasBulkDeleteBtn})`,};- });-- if (!result.hasCheckboxes) {- return { passed: null, skipped: true, message: 'No bulk selection checkboxes found' };+ } finally {+ await deleteCollection(page, collId);}-- return {- passed: true,- message: `Bulk selection: ${result.checkboxCount} checkboxes, bulkDelete=${result.hasBulkDeleteBtn}`- };}};+// ============================================================================+// Shared fixture helpers for the collection + document CRUD tests.+//+// seedCollection/deleteCollection back both collectionDeleteConfirmation and+// the document tests (which need a collection to upload into). Cleanup wraps+// page.evaluate in a Node-side try/catch so a torn-down page during teardown+// can never throw and mask a test result. Kept in this file (not test_lib/)+// while the per-test seed pattern is still proving out across PRs #4174 /+// #4180 / this one; graduates to test_lib/ once a second test file needs it.+// ============================================================================++async function seedCollection(page) {+ const r = await page.evaluate(async () => {+ const csrf = document.querySelector('meta[name="csrf-token"]')?.content;+ const name = `ldr-ui-test-collection-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;+ const res = await fetch('/library/api/collections', {+ method: 'POST',+ credentials: 'same-origin',+ headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrf || '' },+ body: JSON.stringify({ name, description: 'UI test fixture', type: 'user_uploads' }),+ });+ const body = await res.json().catch(() => ({}));+ return { ok: res.ok, name, success: body?.success === true, id: body?.collection?.id };+ });+ return r.ok && r.success && r.id ? { id: r.id, name: r.name } : null;+}++async function deleteCollection(page, collectionId) {+ if (!collectionId) return;+ // Wrap the page.evaluate itself so a torn-down page during teardown can+ // never throw and mask the real test result (matches the #4174 guard).+ try {+ await page.evaluate(async (id) => {+ const csrf = document.querySelector('meta[name="csrf-token"]')?.content;+ try {+ await fetch(`/library/api/collections/${id}`, {+ method: 'DELETE',+ credentials: 'same-origin',+ headers: { 'X-CSRFToken': csrf || '' },+ });+ } catch { /* swallow fetch errors */ }+ }, collectionId);+ } catch { /* swallow page.evaluate errors so cleanup never masks the test result */ }+}++async function uploadFixtureDocument(page, collectionId) {+ return await page.evaluate(async (id) => {+ const csrf = document.querySelector('meta[name="csrf-token"]')?.content;+ const file = new File(+ [new Blob(['UI test fixture document\n'], { type: 'text/plain' })],+ 'ldr-ui-test.txt',+ { type: 'text/plain' }+ );+ const fd = new FormData();+ fd.append('files', file);+ fd.append('storage_mode', 'database');+ const r = await fetch(`/library/api/collections/${id}/upload`, {+ method: 'POST',+ credentials: 'same-origin',+ headers: { 'X-CSRFToken': csrf || '' },+ body: fd,+ });+ return { ok: r.ok, status: r.status };+ }, collectionId);+}+// ============================================================================// Research History CRUD Tests// ============================================================================