~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
test(embedding-settings): regression spec for model dropdown reset (#3863) (#3949)
LearningCircuite6d72faa14ce
diff --git a/.github/workflows/playwright-webkit-tests.yml b/.github/workflows/playwright-webkit-tests.ymlindex 8cb00408bb..66b6d24eef 100644--- a/.github/workflows/playwright-webkit-tests.yml+++ b/.github/workflows/playwright-webkit-tests.yml@@ -117,19 +117,20 @@ jobs:TEST_BASE_URL: http://127.0.0.1:5000TEST_USERNAME: test_adminTEST_PASSWORD: testpass123- # Safari CI runs a critical subset (6/20 specs) for fast release gate:+ # Safari CI runs a critical subset for fast release gate:# - all-pages-mobile: overflow, touch targets, nav clearance across all pages# - auth-pages-mobile: login, register, change-password mobile layouts# - desktop-layout: sidebar positioning and breakpoint testing# - interactive-states: advanced options, search, help panels, mobile menus# - settings-subpages-mobile: settings tab navigation and form layouts# - mobile-ui-audit: comprehensive mobile UI quality checks- # Full suite (20 files): run locally via `cd tests/ui_tests/playwright && npm test`+ # - embedding-settings-dropdown: regression for #3863 (model dropdown reset)+ # Full suite: run locally via `cd tests/ui_tests/playwright && npm test`# When adding Safari-critical tests, update this filter pattern.run: |npx playwright test \--project="Desktop Safari" \- "all-pages-mobile|auth-pages-mobile|desktop-layout|interactive-states|settings-subpages-mobile|mobile-ui-audit"+ "all-pages-mobile|auth-pages-mobile|desktop-layout|interactive-states|settings-subpages-mobile|mobile-ui-audit|embedding-settings-dropdown"- name: Upload Playwright Reportif: always()@@ -256,14 +257,16 @@ jobs:TEST_BASE_URL: http://127.0.0.1:5000TEST_USERNAME: test_adminTEST_PASSWORD: testpass123- # Safari CI runs a critical subset (6/20 specs) for fast release gate:+ # Safari CI runs a critical subset for fast release gate:# - all-pages-mobile: overflow, touch targets, nav clearance across all pages# - auth-pages-mobile: login, register, change-password mobile layouts# - desktop-layout: sidebar positioning and breakpoint testing# - interactive-states: advanced options, search, help panels, mobile menus# - settings-subpages-mobile: settings tab navigation and form layouts# - mobile-ui-audit: comprehensive mobile UI quality checks- # Full suite (20 files): run locally via `cd tests/ui_tests/playwright && npm test`+ # Note: embedding-settings-dropdown is desktop-only (skips on isMobile),+ # so it intentionally only appears in the Desktop Safari filter above.+ # Full suite: run locally via `cd tests/ui_tests/playwright && npm test`# When adding Safari-critical tests, update this filter pattern.run: |npx playwright test \diff --git a/tests/ui_tests/playwright/tests/embedding-settings-dropdown.spec.js b/tests/ui_tests/playwright/tests/embedding-settings-dropdown.spec.jsnew file mode 100644index 0000000000..f982fb4886--- /dev/null+++ b/tests/ui_tests/playwright/tests/embedding-settings-dropdown.spec.js@@ -0,0 +1,187 @@+/**+ * Embedding Settings — Model Dropdown Preservation Tests+ *+ * Regression coverage for issue #3863 (PR #3940). The bug was that+ * `updateModelOptions()` cleared and repopulated the model dropdown without+ * preserving the user's selection, then dispatched a synthetic `change`+ * event which auto-saved whatever model landed at index 0. The reporter+ * triggered it via the (now-removed) "Save Default Settings" button; the+ * Ollama-URL-change path triggered the same reset.+ *+ * Also covers the follow-up behavior added in PR #3940 commit 40678b2:+ * clearing the text_separators textarea persists the default array so a+ * stale customization in the DB is replaced.+ *+ * The mock infrastructure lives in `helpers/embedding-settings-mocks.js`+ * so additional embedding-page specs can reuse it.+ *+ * Desktop-only: this is a form-state regression test, not a layout test.+ * Running it on every mobile project just consumes CI cycles.+ */++import { test, expect } from '@playwright/test';+const {+ BASE_MODELS_PAYLOAD,+ DEFAULT_TEXT_SEPARATORS,+ defaultSettings,+ mockEmbeddingApis,+} = require('./helpers/embedding-settings-mocks');++test.describe('Embedding settings — model dropdown preservation (#3863)', () => {+ test.skip(({ isMobile }) => isMobile, 'desktop-only form-state test');++ test('per-field auto-save fires on model change and persists across reload', async ({ page }) => {+ // This is a happy-path smoke test for the per-field auto-save+ // contract that replaced the deleted batch-save button. It does not+ // exercise the dropdown-rebuild path (see the Ollama-URL test for+ // that), but it pins the basic save-and-restore flow that the rest+ // of the spec relies on.+ const state = await mockEmbeddingApis(page, defaultSettings());++ await page.goto('/library/embedding-settings');+ // Wait until loadCurrentSettings has populated the dropdown with the+ // mocked initial value — guarantees attachAutoSaveListeners has run.+ await expect(page.locator('#embedding-model')).toHaveValue('all-MiniLM-L6-v2');++ // Pick the third (non-top) Transformers model.+ await page.locator('#embedding-model').selectOption('multi-qa-MiniLM-L6-cos-v1');++ // Auto-save fires on `change`; wait for the PUT to land.+ await expect.poll(() => state.modelSaves).toContain('multi-qa-MiniLM-L6-cos-v1');+ const finalSave = state.modelSaves[state.modelSaves.length - 1];+ expect(finalSave).toBe('multi-qa-MiniLM-L6-cos-v1');++ // Reload — the mock returns the now-saved model from /rag/settings.+ await page.reload();+ await expect(page.locator('#embedding-model')).toHaveValue('multi-qa-MiniLM-L6-cos-v1');+ });++ test('Ollama URL change does not reset the selected model (#3863 regression)', async ({ page }) => {+ // Start with Ollama already chosen and a non-top Ollama model picked.+ const state = await mockEmbeddingApis(+ page,+ defaultSettings({+ embedding_provider: 'ollama',+ embedding_model: 'mxbai-embed-large',+ }),+ );++ await page.goto('/library/embedding-settings');+ await expect(page.locator('#embedding-model')).toHaveValue('mxbai-embed-large');++ const savesBeforeUrlEdit = state.modelSaves.length;+ const fetchesBeforeUrlEdit = state.modelsFetches;++ // Edit the Ollama URL and tab away — this triggers+ // saveOllamaUrlAuto -> loadAvailableModels -> updateModelOptions,+ // which is the path that historically reset the dropdown.+ const urlField = page.locator('#ollama-url');+ await urlField.fill('http://localhost:11500');+ await urlField.press('Tab');++ // Wait for the URL PUT to land.+ await expect.poll(() => state.ollamaUrl).toBe('http://localhost:11500');+ // Then wait for the post-save loadAvailableModels() call to complete.+ // Once the GET /library/api/rag/models response is processed,+ // updateModelOptions() has run synchronously and any spurious save+ // that the bug would trigger has already fired. This is the+ // deterministic anchor that replaces a `waitForTimeout`.+ await expect+ .poll(() => state.modelsFetches, { timeout: 5000 })+ .toBeGreaterThan(fetchesBeforeUrlEdit);++ // The dropdown must still show the user's pick.+ await expect(page.locator('#embedding-model')).toHaveValue('mxbai-embed-large');+ // And no save with the index-0 model ('nomic-embed-text') should+ // have fired during the URL-change refresh.+ const newSaves = state.modelSaves.slice(savesBeforeUrlEdit);+ expect(newSaves).not.toContain('nomic-embed-text');+ });++ test('provider change preserves selection when the model exists in both lists', async ({ page }) => {+ // Add a model that exists for both providers so we can verify+ // updateModelOptions() restores the previous value when it's still+ // present in the rebuilt option list.+ const sharedPayload = JSON.parse(JSON.stringify(BASE_MODELS_PAYLOAD));+ sharedPayload.providers.ollama.push({+ value: 'all-MiniLM-L6-v2',+ label: 'all-MiniLM-L6-v2 (shared)',+ is_embedding: true,+ });++ const state = await mockEmbeddingApis(+ page,+ defaultSettings({+ embedding_provider: 'sentence_transformers',+ embedding_model: 'all-MiniLM-L6-v2',+ }),+ );+ // Override the rag/models response AFTER mockEmbeddingApis so this+ // last-registered route wins Playwright's match precedence.+ await page.route('**/library/api/rag/models', async (route) => {+ state.modelsFetches += 1;+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify(sharedPayload),+ });+ });++ await page.goto('/library/embedding-settings');+ await expect(page.locator('#embedding-model')).toHaveValue('all-MiniLM-L6-v2');++ const fetchesBefore = state.modelsFetches;++ // Switch provider to ollama; updateModelOptions rebuilds the dropdown+ // and (with the fix) restores the shared model since it exists in+ // both lists.+ await page.locator('#embedding-provider').selectOption('ollama');+ await expect.poll(() => state.providerSaves).toContain('ollama');+ // Wait for the post-save loadAvailableModels() refresh to complete+ // before asserting the dropdown value.+ await expect+ .poll(() => state.modelsFetches, { timeout: 5000 })+ .toBeGreaterThan(fetchesBefore);+ await expect(page.locator('#embedding-model')).toHaveValue('all-MiniLM-L6-v2');+ });++ test('clearing the text_separators textarea saves the default array', async ({ page }) => {+ // Covers the follow-up fix in PR #3940 commit 40678b2: the auto-save+ // blur listener used to early-return on an empty textarea, leaving a+ // stale customization in the DB. Now an empty textarea is treated as+ // "reset to defaults" and persists the default array.+ const customSeparators = ['||'];+ const state = await mockEmbeddingApis(+ page,+ defaultSettings({ text_separators: customSeparators }),+ );++ await page.goto('/library/embedding-settings');+ const textarea = page.locator('#text-separators');+ // Loading the page populates the textarea with the saved custom value.+ await expect(textarea).toHaveValue(JSON.stringify(customSeparators));++ // Clear the textarea, then blur to fire the auto-save handler.+ await textarea.fill('');+ await textarea.blur();++ // The blur listener should save the default separators array.+ await expect+ .poll(() => state.textSeparatorsSaves, { timeout: 5000 })+ .toContainEqual(DEFAULT_TEXT_SEPARATORS);+ // And the persisted state mirrors the default, overwriting the+ // earlier custom value.+ expect(state.settings.text_separators).toEqual(DEFAULT_TEXT_SEPARATORS);+ });++ test('"Save Default Settings" button is gone — auto-save is the only path', async ({ page }) => {+ await mockEmbeddingApis(page, defaultSettings());+ await page.goto('/library/embedding-settings');+ await expect(page.locator('#embedding-model')).toBeVisible();++ // The button was the visible trigger of the bug; if it ever comes+ // back, this regression test forces a fresh look at #3863.+ await expect(page.getByRole('button', { name: /save default settings/i })).toHaveCount(0);+ await expect(page.locator('#rag-config-form')).toHaveCount(0);+ });+});diff --git a/tests/ui_tests/playwright/tests/helpers/embedding-settings-mocks.js b/tests/ui_tests/playwright/tests/helpers/embedding-settings-mocks.jsnew file mode 100644index 0000000000..e2195804f0--- /dev/null+++ b/tests/ui_tests/playwright/tests/helpers/embedding-settings-mocks.js@@ -0,0 +1,194 @@+/**+ * Shared mocks for /library/embedding-settings Playwright specs.+ *+ * Wires up `page.route()` interceptors for the rag/models, rag/settings,+ * and per-field /settings/api endpoints so the page can be exercised+ * without a real Ollama or Sentence-Transformers backend, and returns a+ * `state` object the calling test can read/mutate to simulate persistence+ * and assert what was actually saved.+ *+ * CommonJS to match the existing `mobile-utils.js` helper.+ */++const BASE_MODELS_PAYLOAD = {+ success: true,+ provider_options: [+ {+ value: 'sentence_transformers',+ label: 'Sentence Transformers (Local)',+ available: true,+ },+ { value: 'ollama', label: 'Ollama (Local)', available: true },+ ],+ providers: {+ sentence_transformers: [+ { value: 'all-MiniLM-L6-v2', label: 'all-MiniLM-L6-v2', is_embedding: true },+ { value: 'all-mpnet-base-v2', label: 'all-mpnet-base-v2', is_embedding: true },+ { value: 'multi-qa-MiniLM-L6-cos-v1', label: 'multi-qa-MiniLM-L6-cos-v1', is_embedding: true },+ ],+ ollama: [+ { value: 'nomic-embed-text', label: 'nomic-embed-text', is_embedding: true },+ { value: 'mxbai-embed-large', label: 'mxbai-embed-large', is_embedding: true },+ { value: 'snowflake-arctic-embed', label: 'snowflake-arctic-embed', is_embedding: true },+ ],+ },+};++const DEFAULT_TEXT_SEPARATORS = ['\n\n', '\n', '. ', ' ', ''];++function defaultSettings(overrides = {}) {+ return {+ embedding_provider: 'sentence_transformers',+ embedding_model: 'all-MiniLM-L6-v2',+ chunk_size: 1000,+ chunk_overlap: 200,+ splitter_type: 'recursive',+ distance_metric: 'cosine',+ index_type: 'flat',+ normalize_vectors: true,+ text_separators: [...DEFAULT_TEXT_SEPARATORS],+ ...overrides,+ };+}++/**+ * Wire up route mocks for the embedding-settings page. Returns a `state`+ * object the test can read/mutate to simulate persistence and assert what+ * was actually saved.+ *+ * Note on route order: Playwright matches routes in REVERSE registration+ * order (last-registered wins). The broad catch-all is registered first+ * so the specific endpoint handlers below override it where applicable.+ * Tests that need to override `/library/api/rag/models` (e.g. to add a+ * shared model across providers) should register their override AFTER+ * calling this function.+ */+async function mockEmbeddingApis(page, initialSettings) {+ const state = {+ settings: { ...initialSettings },+ ollamaUrl: 'http://localhost:11434',+ // Every PUT to /settings/api/local_search_embedding_model lands here+ // so the test can assert what was actually persisted.+ modelSaves: [],+ providerSaves: [],+ textSeparatorsSaves: [],+ // Counter incremented on each /library/api/rag/models GET. Tests use+ // this to wait deterministically for `loadAvailableModels()` to+ // finish — once the count increases past a baseline, any synthetic+ // `change` dispatch from `updateModelOptions()` has already fired.+ modelsFetches: 0,+ };++ await page.route('**/settings/api/**', async (route) => {+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ success: true }),+ });+ });++ await page.route('**/library/api/rag/models', async (route) => {+ state.modelsFetches += 1;+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify(BASE_MODELS_PAYLOAD),+ });+ });++ await page.route('**/library/api/rag/settings', async (route) => {+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ success: true, settings: state.settings }),+ });+ });++ await page.route('**/settings/api/embeddings.ollama.url', async (route) => {+ const req = route.request();+ if (req.method() === 'GET') {+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ value: state.ollamaUrl }),+ });+ } else {+ const body = req.postDataJSON() || {};+ state.ollamaUrl = body.value;+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ success: true }),+ });+ }+ });++ await page.route('**/settings/api/local_search_embedding_model', async (route) => {+ const req = route.request();+ if (req.method() === 'GET') {+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ value: state.settings.embedding_model }),+ });+ return;+ }+ const body = req.postDataJSON() || {};+ state.modelSaves.push(body.value);+ state.settings.embedding_model = body.value;+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ success: true }),+ });+ });++ await page.route('**/settings/api/local_search_embedding_provider', async (route) => {+ const req = route.request();+ if (req.method() === 'GET') {+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ value: state.settings.embedding_provider }),+ });+ return;+ }+ const body = req.postDataJSON() || {};+ state.providerSaves.push(body.value);+ state.settings.embedding_provider = body.value;+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ success: true }),+ });+ });++ await page.route('**/settings/api/local_search_text_separators', async (route) => {+ const req = route.request();+ if (req.method() === 'GET') {+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ value: state.settings.text_separators }),+ });+ return;+ }+ const body = req.postDataJSON() || {};+ state.textSeparatorsSaves.push(body.value);+ state.settings.text_separators = body.value;+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ success: true }),+ });+ });++ return state;+}++module.exports = {+ BASE_MODELS_PAYLOAD,+ DEFAULT_TEXT_SEPARATORS,+ defaultSettings,+ mockEmbeddingApis,+};