~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 collection delete + subscription toggle/delete via API seeding (#4174)
LearningCircuit0c8f917e2fb0
diff --git a/tests/ui_tests/test_crud_operations_ci.js b/tests/ui_tests/test_crud_operations_ci.jsindex 130fb50245..939a6c881a 100644--- a/tests/ui_tests/test_crud_operations_ci.js+++ b/tests/ui_tests/test_crud_operations_ci.js@@ -103,99 +103,111 @@ const CollectionCrudTests = {};},- async collectionEditButton(page, baseUrl) {- await navigateTo(page, `${baseUrl}/library/collections`);-- const result = await page.evaluate(() => {- const cards = document.querySelectorAll('.collection-card, .collection-item, [data-collection-id]');- if (cards.length === 0) return { hasCards: false };-- const firstCard = cards[0];- const editBtn = firstCard.querySelector(- 'button[class*="edit"], ' +- 'a[class*="edit"], ' +- '.edit-btn, ' +- '[title*="edit"], ' +- '.fa-edit, .fa-pencil'- );-- return {- hasCards: true,- cardCount: cards.length,- hasEditButton: !!editBtn,- editBtnText: editBtn?.textContent?.trim() || editBtn?.title- };- });-- if (!result.hasCards) {- return { passed: null, skipped: true, message: 'No collections to test edit button' };- }-- if (!result.hasEditButton) {- return { passed: null, skipped: true, message: 'No edit button found on collection cards' };- }-- return {- passed: true,- message: `Edit button found on ${result.cardCount} collections`- };- },-async collectionDeleteConfirmation(page, baseUrl) {+ // The previous version scanned /library/collections for cards with an+ // inline delete button and SKIPped on an empty DB. The actual list+ // page renders collection cards as plain anchor links to the detail+ // page — no per-card delete affordance exists. Delete lives on+ // /library/collections/<id> as #delete-collection-btn, and the+ // confirmation is a *native* window.confirm() prompt (see+ // collection_details.js::deleteCollection), not a DOM modal — so+ // the old `document.querySelector('.modal, ...')` would never find+ // anything even if we did navigate to the right page.+ //+ // We:+ // 1. Seed a collection via POST /library/api/collections so the+ // test does not depend on pre-existing DB state.+ // 2. Navigate to the detail page and click #delete-collection-btn.+ // 3. Capture the native confirm() prompt via page.on('dialog')+ // and dismiss it so the seeded collection survives for cleanup.+ // 4. DELETE the seed via the API.+ //+ // The sibling collectionEditButton test was removed: the app has no+ // collection-edit UI anywhere (no analog on the list page, the+ // detail page, or anywhere in the templates), so the old test was+ // a permanent SKIP for a feature that simply does not exist.++ // Seed.await navigateTo(page, `${baseUrl}/library/collections`);-- const result = await page.evaluate(() => {- const cards = document.querySelectorAll('.collection-card, .collection-item, [data-collection-id]');- if (cards.length === 0) return { hasCards: false };-- const firstCard = cards[0];- const deleteBtn = firstCard.querySelector(- 'button[class*="delete"], ' +- 'button[class*="remove"], ' +- '.delete-btn, ' +- '.btn-danger, ' +- '.fa-trash, .fa-times'- );-- if (!deleteBtn) return { hasCards: true, hasDeleteButton: false };-- // Click delete to check for confirmation- deleteBtn.click();-- return new Promise(resolve => {- setTimeout(() => {- const confirmModal = document.querySelector(- '.modal, .confirm-dialog, [role="alertdialog"], .confirmation'- );- const confirmText = document.body.textContent?.toLowerCase() || '';- const hasConfirmText = confirmText.includes('are you sure') ||- confirmText.includes('confirm') ||- confirmText.includes('delete');-- resolve({- hasCards: true,- hasDeleteButton: true,- hasConfirmModal: !!confirmModal,- hasConfirmText- });- }, 300);+ 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' }),});- });-- if (!result.hasCards) {- return { passed: null, skipped: true, message: 'No collections to test delete' };+ 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 collectionId = seed.body.collection.id;- if (!result.hasDeleteButton) {- return { passed: null, skipped: true, message: 'No delete button found on collections' };- }+ try {+ // Listen for the native confirm() before clicking — Puppeteer+ // delivers the dialog asynchronously once the event listener is+ // wired.+ let dialog = null;+ const onDialog = async d => {+ dialog = { type: d.type(), message: d.message() };+ await d.dismiss();+ };+ page.on('dialog', onDialog);++ try {+ await navigateTo(page, `${baseUrl}/library/collections/${collectionId}`);+ // The detail page populates collectionData via an async fetch on+ // DOMContentLoaded, and deleteCollection() dereferences+ // collectionData.name — clicking before that fetch lands throws a+ // TypeError (no dialog) instead of firing confirm(). Wait for the+ // name to swap in from the "Loading..." placeholder, mirroring the+ // waitForSelector guard the subscription tests use before clicking.+ await page.waitForFunction(+ (name) => document.querySelector('#collection-name')?.textContent?.trim() === name,+ { timeout: 5000 },+ fixtureName,+ );+ await page.click('#delete-collection-btn');+ // Native confirm() resolves synchronously inside the click+ // handler, but the dialog event hop costs a tick or two.+ await new Promise(r => setTimeout(r, 300));+ } finally {+ page.off('dialog', onDialog);+ }- return {- passed: result.hasConfirmModal || result.hasConfirmText,- message: result.hasConfirmModal- ? 'Delete confirmation modal appears'- : (result.hasConfirmText ? 'Delete confirmation text shown' : 'No delete confirmation found')- };+ if (!dialog) {+ return { passed: false, message: 'No confirm() dialog fired when clicking #delete-collection-btn' };+ }+ const lowered = dialog.message.toLowerCase();+ const passed = dialog.type === 'confirm' &&+ (lowered.includes('are you sure') || lowered.includes('delete'));+ return {+ passed,+ message: passed+ ? `confirm() prompt fired: "${dialog.message.slice(0, 60)}..."`+ : `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 */ }+ }}};@@ -351,88 +363,187 @@ const SubscriptionCrudTests = {},async subscriptionToggleStatus(page, baseUrl) {- await navigateTo(page, `${baseUrl}/news/subscriptions`);+ // The old version scanned the listing for a button matching+ // `class*="toggle"` / `class*="pause"` / `class*="resume"` /+ // `.toggle-status` / `input[type=checkbox]`. The real card markup+ // (pages/subscriptions.js::renderSubscriptionCard) uses+ // `<button class="btn btn-sm ldr-btn-icon" title="Pause|Resume">`+ // — none of the old selectors match. Combined with an empty test+ // DB, the test was a permanent SKIP for a real product feature.+ //+ // Seed an *active* subscription via the API, click the Pause+ // toggle, and assert the status flips to "paused" (both the badge+ // text and the button's title attribute). This exercises the+ // actual pause/resume contract.- const result = await page.evaluate(() => {- const cards = document.querySelectorAll('.subscription-card, .subscription-item, [data-subscription-id]');- if (cards.length === 0) return { hasCards: false };-- const firstCard = cards[0];- const toggleBtn = firstCard.querySelector(- 'button[class*="toggle"], ' +- 'button[class*="pause"], ' +- 'button[class*="resume"], ' +- '.toggle-status, ' +- 'input[type="checkbox"]'- );+ await navigateTo(page, `${baseUrl}/news/subscriptions`);- return {- hasCards: true,- cardCount: cards.length,- hasToggle: !!toggleBtn,- toggleType: toggleBtn?.tagName.toLowerCase()- };+ const seed = await page.evaluate(async () => {+ const csrf = document.querySelector('meta[name="csrf-token"]')?.content;+ const r = await fetch('/news/api/subscribe', {+ method: 'POST',+ credentials: 'same-origin',+ headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrf || '' },+ body: JSON.stringify({+ query: `ldr-ui-test-toggle-${Date.now()}`,+ subscription_type: 'search',+ is_active: true,+ }),+ });+ return { ok: r.ok, status: r.status, body: await r.json().catch(() => ({})) };});-- if (!result.hasCards) {- return { passed: null, skipped: true, message: 'No subscriptions to test toggle' };+ const subId = seed.body?.subscription_id;+ if (!seed.ok || !subId) {+ return { passed: false, message: `Could not seed subscription (status=${seed.status}, body=${JSON.stringify(seed.body).slice(0, 120)})` };}- if (!result.hasToggle) {- return { passed: null, skipped: true, message: 'No status toggle found on subscriptions' };- }+ try {+ // navigateTo no-ops when already on the same path, so use+ // page.reload() to force renderSubscriptions to pick up the+ // freshly-seeded card. (Same applies to the delete test below.)+ await page.reload({ waitUntil: 'domcontentloaded' });+ // Card insertion is async — give the page tick(s) to fetch + render.+ await page.waitForSelector(`[data-subscription-id="${subId}"]`, { timeout: 5000 });++ const before = await page.evaluate((id) => {+ const card = document.querySelector(`[data-subscription-id="${id}"]`);+ const toggle = card?.querySelector('button[title="Pause"], button[title="Resume"]');+ const badge = card?.querySelector('.ldr-status-badge');+ return {+ toggleTitle: toggle?.title,+ status: badge?.textContent?.trim(),+ };+ }, subId);+ if (before.toggleTitle !== 'Pause' || before.status !== 'active') {+ return { passed: false, message: `Seeded card not in expected active state (toggle="${before.toggleTitle}", badge="${before.status}")` };+ }- return {- passed: true,- message: `Status toggle found (type: ${result.toggleType})`- };+ await page.click(`[data-subscription-id="${subId}"] button[title="Pause"]`);+ // The toggle round-trips to PUT /news/api/subscriptions/<id>+ // (toggleSubscription) and re-renders the list in place. Wait+ // for the button's title to flip rather than racing a fixed+ // setTimeout.+ await page.waitForFunction((id) => {+ const card = document.querySelector(`[data-subscription-id="${id}"]`);+ return card?.querySelector('button[title="Resume"]') != null;+ }, { timeout: 5000 }, subId);++ const after = await page.evaluate((id) => {+ const card = document.querySelector(`[data-subscription-id="${id}"]`);+ const toggle = card?.querySelector('button[title="Pause"], button[title="Resume"]');+ const badge = card?.querySelector('.ldr-status-badge');+ return {+ toggleTitle: toggle?.title,+ status: badge?.textContent?.trim(),+ };+ }, subId);++ const flipped = after.toggleTitle === 'Resume' && after.status === 'paused';+ return {+ passed: flipped,+ message: flipped+ ? `Pause → Resume toggle works (active → paused, button retitled)`+ : `Toggle did not flip state (toggle="${after.toggleTitle}", badge="${after.status}")`+ };+ } catch (err) {+ return { passed: false, message: `Toggle test threw: ${err.message?.slice(0, 100)}` };+ } finally {+ // Best-effort cleanup — 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(`/news/api/subscriptions/${id}`, {+ method: 'DELETE',+ credentials: 'same-origin',+ headers: { 'X-CSRFToken': csrf || '' },+ });+ } catch { /* swallow fetch errors */ }+ }, subId);+ } catch { /* swallow page.evaluate errors so cleanup never masks the test result */ }+ }},async subscriptionDeleteConfirmation(page, baseUrl) {- await navigateTo(page, `${baseUrl}/news/subscriptions`);+ // Same shape as the collection delete rewrite (#4174). The card+ // delete button (.btn-danger inside the card) calls+ // deleteSubscriptionDirect, which guards on a *native*+ // window.confirm() — not a DOM modal. The old `.modal,+ // .confirm-dialog, [role="alertdialog"]` query never matched+ // anything even on a populated list. Seed via the API, click+ // delete, capture the dialog, dismiss to keep the fixture for+ // explicit cleanup.- const result = await page.evaluate(() => {- const cards = document.querySelectorAll('.subscription-card, .subscription-item, [data-subscription-id]');- if (cards.length === 0) return { hasCards: false };-- const firstCard = cards[0];- const deleteBtn = firstCard.querySelector(- 'button[class*="delete"], ' +- 'button[class*="remove"], ' +- '.delete-btn, ' +- '.btn-danger'- );-- if (!deleteBtn) return { hasCards: true, hasDeleteButton: false };-- deleteBtn.click();+ await navigateTo(page, `${baseUrl}/news/subscriptions`);- return new Promise(resolve => {- setTimeout(() => {- const confirmModal = document.querySelector('.modal, .confirm-dialog, [role="alertdialog"]');- resolve({- hasCards: true,- hasDeleteButton: true,- hasConfirmModal: !!confirmModal- });- }, 300);+ const seed = await page.evaluate(async () => {+ const csrf = document.querySelector('meta[name="csrf-token"]')?.content;+ const r = await fetch('/news/api/subscribe', {+ method: 'POST',+ credentials: 'same-origin',+ headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrf || '' },+ body: JSON.stringify({+ query: `ldr-ui-test-delete-${Date.now()}`,+ subscription_type: 'search',+ is_active: false,+ }),});+ return { ok: r.ok, status: r.status, body: await r.json().catch(() => ({})) };});-- if (!result.hasCards) {- return { passed: null, skipped: true, message: 'No subscriptions to test delete' };+ const subId = seed.body?.subscription_id;+ if (!seed.ok || !subId) {+ return { passed: false, message: `Could not seed subscription (status=${seed.status}, body=${JSON.stringify(seed.body).slice(0, 120)})` };}- if (!result.hasDeleteButton) {- return { passed: null, skipped: true, message: 'No delete button found' };- }+ try {+ await page.reload({ waitUntil: 'domcontentloaded' });+ await page.waitForSelector(`[data-subscription-id="${subId}"] .btn-danger`, { timeout: 5000 });- return {- passed: result.hasConfirmModal,- message: result.hasConfirmModal- ? 'Delete confirmation modal appears'- : 'No delete confirmation found'- };+ let dialog = null;+ const onDialog = async d => {+ dialog = { type: d.type(), message: d.message() };+ await d.dismiss();+ };+ page.on('dialog', onDialog);++ try {+ await page.click(`[data-subscription-id="${subId}"] .btn-danger`);+ await new Promise(r => setTimeout(r, 300));+ } finally {+ page.off('dialog', onDialog);+ }++ if (!dialog) {+ return { passed: false, message: 'No confirm() dialog fired when clicking subscription delete' };+ }+ const lowered = dialog.message.toLowerCase();+ const passed = dialog.type === 'confirm' &&+ (lowered.includes('are you sure') || lowered.includes('delete'));+ return {+ passed,+ message: passed+ ? `confirm() prompt fired: "${dialog.message.slice(0, 60)}..."`+ : `Dialog fired but contract failed (type=${dialog.type}, message="${dialog.message.slice(0, 80)}")`+ };+ } finally {+ // Best-effort cleanup — 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(`/news/api/subscriptions/${id}`, {+ method: 'DELETE',+ credentials: 'same-origin',+ headers: { 'X-CSRFToken': csrf || '' },+ });+ } catch { /* swallow fetch errors */ }+ }, subId);+ } catch { /* swallow page.evaluate errors so cleanup never masks the test result */ }+ }}};@@ -656,7 +767,6 @@ async function main() {log.section('Collection CRUD');await run('Collections', 'Create Collection Form Opens', (p, u) => CollectionCrudTests.createCollectionFormOpens(p, u));await run('Collections', 'Create Collection Form Validation', (p, u) => CollectionCrudTests.createCollectionFormValidation(p, u));- await run('Collections', 'Collection Edit Button', (p, u) => CollectionCrudTests.collectionEditButton(p, u));await run('Collections', 'Collection Delete Confirmation', (p, u) => CollectionCrudTests.collectionDeleteConfirmation(p, u));// Subscription CRUD Tests