Skip to content

~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.

4.6 KB
Raw Blame
/** Runtime contracts for benchmark.html's current-settings bootstrap. */

import { resolve as resolvePath } from 'node:path';

import { compileTemplateHarness } from '../helpers/template-harness.js';

const TEMPLATE_PATH = resolvePath(
    __dirname,
    '../../../src/local_deep_research/web/templates/pages/benchmark.html',
);

const SETTINGS = [
    ['/settings/api/llm.provider', 'ollama'],
    ['/settings/api/llm.model', 'qwen3:4b'],
    ['/settings/api/search.tool', 'searxng'],
    ['/settings/api/search.iterations', 3],
    ['/settings/api/search.questions_per_iteration', 4],
    ['/settings/api/search.search_strategy', 'focused_iteration'],
    ['/settings/api/benchmark.evaluation.provider', 'openai_endpoint'],
    ['/settings/api/benchmark.evaluation.model', 'judge-model'],
    ['/settings/api/benchmark.evaluation.temperature', 0.2],
    ['/settings/api/benchmark.evaluation.endpoint_url', 'https://judge.test/v1'],
];

function mountCurrentSettings() {
    document.body.innerHTML = `
        <section id="current-settings-display">
            <span class="ldr-metric-value" id="current-provider"></span>
            <span class="ldr-metric-value" id="current-model"></span>
            <span class="ldr-metric-value" id="current-search-tool"></span>
            <span class="ldr-metric-value" id="current-iterations"></span>
            <span class="ldr-metric-value" id="current-questions"></span>
            <span class="ldr-metric-value" id="current-strategy"></span>
        </section>
        <div id="context-window-warning" style="display: none"></div>
    `;
}

function compileCurrentSettings(dependencies) {
    return compileTemplateHarness({
        templatePath: TEMPLATE_PATH,
        functionNames: ['loadCurrentSettings'],
        dependencies,
        returnExpression: '({ loadCurrentSettings })',
    });
}

function jsonResponse(value) {
    return {
        ok: true,
        json: vi.fn().mockResolvedValue({ value }),
    };
}

beforeEach(() => {
    mountCurrentSettings();
    vi.spyOn(console, 'log').mockImplementation(() => {});
    vi.spyOn(console, 'error').mockImplementation(() => {});
});

afterEach(() => {
    vi.restoreAllMocks();
    vi.unstubAllGlobals();
    document.body.replaceChildren();
});

it('hydrates the benchmark summary from every migrated flat setting endpoint', async () => {
    const values = new Map(SETTINGS);
    const fetchMock = vi.fn(url => Promise.resolve(jsonResponse(values.get(url))));
    vi.stubGlobal('fetch', fetchMock);
    const dependencies = {
        checkSearchEngineWarnings: vi.fn(),
        showAlert: vi.fn(),
    };
    const runtime = compileCurrentSettings(dependencies);

    await runtime.loadCurrentSettings();

    expect(fetchMock.mock.calls.map(([url]) => url)).toEqual(
        SETTINGS.map(([url]) => url),
    );
    expect(document.getElementById('current-provider').textContent).toBe('OLLAMA');
    expect(document.getElementById('current-model').textContent).toBe('qwen3:4b');
    expect(document.getElementById('current-search-tool').textContent).toBe('searxng');
    expect(document.getElementById('current-iterations').textContent).toBe('3');
    expect(document.getElementById('current-questions').textContent).toBe('4');
    expect(document.getElementById('current-strategy').textContent)
        .toBe('focused-iteration');
    expect(document.getElementById('context-window-warning').style.display)
        .toBe('block');
    expect(dependencies.checkSearchEngineWarnings).toHaveBeenCalledOnce();
    expect(dependencies.checkSearchEngineWarnings).toHaveBeenCalledWith('searxng');
    expect(dependencies.showAlert).not.toHaveBeenCalled();
});

it('renders one coherent recovery state when any settings request rejects', async () => {
    const fetchMock = vi.fn(url => {
        if (url === '/settings/api/llm.model') {
            return Promise.reject(new Error('settings temporarily unavailable'));
        }
        return Promise.resolve(jsonResponse('unused'));
    });
    vi.stubGlobal('fetch', fetchMock);
    const dependencies = {
        checkSearchEngineWarnings: vi.fn(),
        showAlert: vi.fn(),
    };
    const runtime = compileCurrentSettings(dependencies);

    await runtime.loadCurrentSettings();

    expect(fetchMock).toHaveBeenCalledTimes(SETTINGS.length);
    document.querySelectorAll('#current-settings-display .ldr-metric-value')
        .forEach(element => expect(element.textContent).toBe('Error loading'));
    expect(dependencies.checkSearchEngineWarnings).not.toHaveBeenCalled();
    expect(dependencies.showAlert).toHaveBeenCalledWith(
        'Could not load current settings. Check console for details.',
        'warning',
    );
});