~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
/**
* Direct runtime contracts for settings-dashboard behaviors that cannot be
* covered by the bulk-submit harness alone: aliased policy controls, redacted
* secrets, tab re-rendering, and destructive reset failure recovery.
*/
import '@js/config/urls.js';
import '@js/services/api.js';
import '@js/utils/alert-helpers.js';
import '@js/utils/provider-options.js';
import '@js/utils/value-helpers.js';
const flushPromises = async (turns = 12) => {
for (let turn = 0; turn < turns; turn += 1) await Promise.resolve();
};
function jsonResponse(payload, status = 200) {
return new Response(JSON.stringify(payload), {
status,
headers: { 'Content-Type': 'application/json' },
});
}
function setting(overrides) {
return {
category: 'general',
description: '',
editable: true,
max_value: null,
min_value: null,
options: null,
step: null,
visible: true,
...overrides,
};
}
afterEach(() => {
vi.restoreAllMocks();
vi.unstubAllGlobals();
vi.useRealTimers();
delete window.ui;
delete window.modelProvidersRequestInProgress;
delete window.searchEnginesRequestInProgress;
delete window.modelDropdownsInitialized;
delete window.searchEngineDropdownInitialized;
delete window.setupCustomDropdown;
delete window.updateDropdownOptions;
document.body.replaceChildren();
});
it('renders aliased policy settings, clears a redacted secret, and recovers from reset failure', async () => {
vi.useFakeTimers();
document.head.insertAdjacentHTML(
'beforeend',
'<meta name="csrf-token" content="csrf-settings-dashboard">',
);
document.body.innerHTML = `
<form id="settings-form">
<input id="settings-search">
<button type="button" class="ldr-settings-tab active" data-tab="all">All</button>
<button type="button" class="ldr-settings-tab" data-tab="search">Search</button>
<button type="button" class="ldr-settings-tab" data-tab="app">App</button>
<div id="settings-alert"></div>
<div id="settings-content"></div>
<button id="reset-to-defaults-button" type="button">Reset defaults</button>
<button id="toggle-raw-config" type="button"><span id="toggle-text"></span></button>
<section id="raw-config" style="display: none">
<textarea id="raw_config_editor"></textarea>
</section>
<div id="llm.model-empty-warning" style="display: none"></div>
</form>
`;
const settings = {
'app.nickname': setting({
name: 'Nickname',
type: 'APP',
ui_element: 'text',
value: 'original',
}),
'policy.egress_scope': setting({
category: 'policy',
name: 'Egress Scope',
type: 'SEARCH',
ui_element: 'select',
value: 'adaptive',
options: [
{ value: 'adaptive', label: 'Adaptive' },
{ value: 'private_only', label: 'Private only' },
],
}),
'llm.require_local_endpoint': setting({
category: 'policy',
name: 'Require Local LLM Endpoint',
type: 'LLM',
ui_element: 'checkbox',
value: false,
}),
'embeddings.require_local': setting({
category: 'policy',
name: 'Require Local Embeddings',
type: 'LLM',
ui_element: 'checkbox',
value: false,
}),
'notifications.service_url': setting({
category: 'notifications',
name: 'Notification Service URL',
type: 'APP',
ui_element: 'textarea',
value: '[REDACTED]',
}),
'llm.provider': setting({
category: 'llm_general',
name: 'Provider',
type: 'LLM',
ui_element: 'select',
value: 'ollama',
options: [
{ value: 'openai', label: 'OpenAI API' },
{ value: 'anthropic', label: 'Anthropic API' },
{ value: 'ollama', label: 'Ollama (Local)' },
],
}),
'llm.ollama.api_key': setting({
category: 'llm_ollama',
name: 'Ollama API Key',
type: 'LLM',
ui_element: 'password',
value: '',
}),
'llm.ollama.url': setting({
category: 'llm_ollama',
name: 'Ollama URL',
type: 'LLM',
ui_element: 'text',
value: 'http://localhost:11434',
}),
'llm.openai.api_key': setting({
category: 'llm_openai',
name: 'OpenAI API Key',
type: 'LLM',
ui_element: 'password',
value: '',
}),
'llm.anthropic.api_key': setting({
category: 'llm_anthropic',
name: 'Anthropic API Key',
type: 'LLM',
ui_element: 'password',
value: '',
}),
'llm.model': setting({
category: 'llm_general',
name: 'Model',
type: 'LLM',
ui_element: 'select',
value: 'llama3',
}),
'search.tool': setting({
category: 'search_general',
name: 'Search Tool',
type: 'SEARCH',
ui_element: 'select',
value: 'searxng',
}),
'report.options': setting({
category: 'report_parameters',
name: 'Report Options',
type: 'REPORT',
ui_element: 'json',
value: {
limit: 3,
enabled: false,
mode: 'ITERATION',
label: 'brief',
},
}),
};
const saveBodies = [];
let resetShouldFail = false;
const fetchMock = vi.fn((url, options = {}) => {
if (url === URLS.SETTINGS_API.BASE) {
return Promise.resolve(jsonResponse({ status: 'success', settings }));
}
if (url === URLS.SETTINGS_API.AVAILABLE_MODELS) {
return Promise.resolve(jsonResponse({
providers: {
ollama_models: [{ value: 'llama3', label: 'Llama 3' }],
openai_models: [{ value: 'gpt-4o', label: 'GPT-4o' }],
},
provider_options: [
{ value: 'ollama', label: 'Ollama' },
{ value: 'openai', label: 'OpenAI' },
],
}));
}
if (url === URLS.SETTINGS_API.AVAILABLE_SEARCH_ENGINES) {
return Promise.resolve(jsonResponse({
engine_options: [{ value: 'searxng', label: 'SearXNG' }],
}));
}
if (url === '/settings/api/data-location') {
return Promise.resolve(jsonResponse({
data_directory: '/tmp/ldr',
security_notice: { encrypted: false },
}));
}
if (url === URLS.SETTINGS_API.BACKUP_STATUS) {
return Promise.resolve(jsonResponse({ enabled: false, count: 0, backups: [] }));
}
if (url === URLS.SETTINGS_API.SAVE_ALL_SETTINGS) {
const body = JSON.parse(options.body);
saveBodies.push(body);
const responseSettings = {};
Object.entries(body).forEach(([key, value]) => {
responseSettings[key] = { ...settings[key], value };
settings[key] = responseSettings[key];
});
return Promise.resolve(jsonResponse({
status: 'success',
settings: responseSettings,
}));
}
if (url === URLS.SETTINGS_API.RESET_TO_DEFAULTS && resetShouldFail) {
return Promise.resolve(jsonResponse({
detail: '<img src=x onerror=alert(1)> reset denied',
}, 422));
}
throw new Error(`Unexpected request: ${url}`);
});
vi.stubGlobal('fetch', fetchMock);
window.ui = { showMessage: vi.fn() };
window.matchMedia = vi.fn(() => ({ matches: false }));
window.setupCustomDropdown = vi.fn((input) => ({
setValue: vi.fn(value => {
input.value = value;
}),
}));
window.updateDropdownOptions = vi.fn();
await import('@js/components/settings.js');
if (document.readyState === 'loading') {
document.dispatchEvent(new Event('DOMContentLoaded'));
}
await flushPromises();
await vi.advanceTimersByTimeAsync(301);
expect(
document.getElementById('setting-llm-ollama-api_key'),
).not.toBeNull();
expect(
document.getElementById('setting-llm-ollama-url'),
).not.toBeNull();
expect(
document.getElementById('setting-llm-openai-api_key'),
).toBeNull();
expect(
document.getElementById('setting-llm-anthropic-api_key'),
).toBeNull();
expect(
document.getElementById('llm.model'),
).not.toBeNull();
expect(fetchMock.mock.calls.map(([url]) => url)).toContain(URLS.SETTINGS_API.BASE);
expect(
document.getElementById('settings-content').innerHTML,
`settings requests: ${fetchMock.mock.calls.map(([url]) => url).join(', ')}`,
).not.toBe('');
await vi.waitFor(() => {
expect(document.getElementById('setting-notifications-service_url')).not.toBeNull();
});
const redactedInput = document.getElementById('setting-notifications-service_url');
expect(redactedInput.value).toBe('');
expect(redactedInput.dataset.redacted).toBe('true');
expect(redactedInput.placeholder).toContain('press Enter while empty to clear');
redactedInput.dispatchEvent(new KeyboardEvent('keydown', {
key: 'Enter',
bubbles: true,
cancelable: true,
}));
await flushPromises();
expect(saveBodies).toContainEqual({ 'notifications.service_url': '' });
expect(window.ui.showMessage).toHaveBeenCalledWith(
'Service url updated',
'success',
6000,
);
expect(window.ui.showMessage.mock.calls.flat().join(' ')).not.toContain('[REDACTED]');
const localToggle = document.getElementById('setting-llm-require_local_endpoint');
const beforeCheckboxReversal = saveBodies.length;
localToggle.click();
localToggle.click();
await flushPromises(40);
expect(saveBodies.slice(beforeCheckboxReversal).map(body => body['llm.require_local_endpoint']))
.toEqual([true, false]);
expect(settings['llm.require_local_endpoint'].value).toBe(false);
expect(localToggle.checked).toBe(false);
const nickname = document.getElementById('setting-app-nickname');
const beforeTextReversal = saveBodies.length;
nickname.value = 'changed';
nickname.dispatchEvent(new Event('blur'));
nickname.value = 'original';
nickname.dispatchEvent(new Event('blur'));
await flushPromises(40);
expect(saveBodies.slice(beforeTextReversal).map(body => body['app.nickname']))
.toEqual(['changed', 'original']);
expect(settings['app.nickname'].value).toBe('original');
expect(nickname.value).toBe('original');
const providerSetup = window.setupCustomDropdown.mock.calls.find(
([input]) => input.id === 'llm.provider',
);
expect(providerSetup).toBeDefined();
providerSetup[3]('openai');
await flushPromises();
await vi.advanceTimersByTimeAsync(150);
await flushPromises();
expect(
document.getElementById('setting-llm-ollama-api_key'),
).toBeNull();
expect(
document.getElementById('setting-llm-ollama-url'),
).toBeNull();
expect(
document.getElementById('setting-llm-openai-api_key'),
).not.toBeNull();
expect(
document.getElementById('setting-llm-anthropic-api_key'),
).toBeNull();
expect(
document.getElementById('llm.model'),
).not.toBeNull();
expect(document.getElementById('llm.provider_hidden').value).toBe('openai');
expect(document.getElementById('llm.model_hidden').value).toBe('gpt-4o');
expect(window.updateDropdownOptions).toHaveBeenCalledWith(
document.getElementById('llm.model'),
[{ value: 'gpt-4o', label: 'GPT-4o', provider: 'OPENAI' }],
);
expect(saveBodies).toContainEqual({ 'llm.provider': 'openai' });
const reportEnabled = document.querySelector('.ldr-json-property-control[data-parent-key="report.options"][data-property="enabled"]');
const saveCountBeforeWrapperClick = saveBodies.length;
reportEnabled.closest('.ldr-boolean-property').click();
await flushPromises();
expect(reportEnabled.checked).toBe(true);
expect(saveBodies.slice(saveCountBeforeWrapperClick)).toEqual([{
'report.options': {
limit: 3,
enabled: true,
mode: 'ITERATION',
label: 'brief',
},
}]);
expect(saveBodies.some(body => Object.hasOwn(
body,
'report.options_enabled',
))).toBe(false);
// The first response has not acknowledged false when the control returns
// to the original true value. Both intents must reach the server.
const beforeReversal = saveBodies.length;
reportEnabled.closest('.ldr-boolean-property').click();
reportEnabled.closest('.ldr-boolean-property').click();
await flushPromises(40);
expect(saveBodies.slice(beforeReversal).map(body => body['report.options'].enabled))
.toEqual([false, true]);
expect(settings['report.options'].value.enabled).toBe(true);
expect(reportEnabled.checked).toBe(true);
const reportLimit = document.querySelector('.ldr-json-property-control[data-parent-key="report.options"][data-property="limit"]');
reportLimit.value = '5';
reportLimit.dispatchEvent(new Event('input', { bubbles: true }));
reportLimit.dispatchEvent(new Event('blur', { bubbles: true }));
await flushPromises();
expect(saveBodies).toContainEqual({
'report.options': {
limit: 5,
enabled: true,
mode: 'ITERATION',
label: 'brief',
},
});
expect(saveBodies.some(body => Object.hasOwn(
body,
'report.options_limit',
))).toBe(false);
const settingsSearch = document.getElementById('settings-search');
settingsSearch.value = 'egress scope';
settingsSearch.dispatchEvent(new Event('input', { bubbles: true }));
await vi.advanceTimersByTimeAsync(251);
expect(document.getElementById('setting-policy-egress_scope')).not.toBeNull();
expect(document.getElementById('setting-notifications-service_url')).toBeNull();
settingsSearch.value = '';
settingsSearch.dispatchEvent(new Event('input', { bubbles: true }));
await vi.advanceTimersByTimeAsync(251);
expect(document.getElementById('setting-notifications-service_url')).not.toBeNull();
settingsSearch.value = 'openai';
settingsSearch.dispatchEvent(new Event('input', { bubbles: true }));
await vi.advanceTimersByTimeAsync(251);
expect(
document.getElementById('setting-llm-openai-api_key'),
).not.toBeNull();
expect(
document.getElementById('setting-llm-ollama-api_key'),
).toBeNull();
settingsSearch.value = '';
settingsSearch.dispatchEvent(new Event('input', { bubbles: true }));
await vi.advanceTimersByTimeAsync(251);
document.querySelector('[data-tab="search"]').click();
await vi.advanceTimersByTimeAsync(101);
const scope = document.getElementById('setting-policy-egress_scope');
const embeddingsLocal = document.getElementById('setting-embeddings-require_local');
expect(scope).not.toBeNull();
expect(embeddingsLocal).not.toBeNull();
scope.value = 'private_only';
scope.dispatchEvent(new Event('change', { bubbles: true }));
await flushPromises();
expect(embeddingsLocal.checked).toBe(true);
expect(embeddingsLocal.disabled).toBe(true);
expect(document.getElementById(
'setting-embeddings-require_local_hidden_fallback',
).disabled).toBe(true);
expect(saveBodies).toContainEqual({ 'policy.egress_scope': 'private_only' });
scope.value = 'adaptive';
scope.dispatchEvent(new Event('change', { bubbles: true }));
await flushPromises();
expect(embeddingsLocal.checked).toBe(false);
expect(embeddingsLocal.disabled).toBe(false);
const confirmMock = vi.fn().mockReturnValue(false);
vi.stubGlobal('confirm', confirmMock);
document.getElementById('reset-to-defaults-button').click();
expect(fetchMock.mock.calls.some(([url]) => (
url === URLS.SETTINGS_API.RESET_TO_DEFAULTS
))).toBe(false);
// Use the component's DOM fallback to prove a FastAPI detail remains
// inert when the destructive operation fails.
Object.defineProperty(window, 'ui', {
value: null,
writable: true,
configurable: true,
});
resetShouldFail = true;
confirmMock.mockReturnValue(true);
document.getElementById('reset-to-defaults-button').click();
await flushPromises();
expect(fetchMock).toHaveBeenCalledWith(
URLS.SETTINGS_API.RESET_TO_DEFAULTS,
expect.objectContaining({ method: 'POST' }),
);
expect(document.getElementById('settings-alert').textContent).toContain(
'<img src=x onerror=alert(1)> reset denied',
);
expect(document.getElementById('settings-alert').querySelector('img')).toBeNull();
// Upgrade migration 0031 replaces the manual corruption-repair control.
expect(document.getElementById('fix-corrupted-button')).toBeNull();
expect(URLS.SETTINGS_API.FIX_CORRUPTED_SETTINGS).toBeUndefined();
});