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.

3.1 KB
Raw Blame
/**
 * Browser contract for the simple benchmark page's settings bootstrap.
 *
 * The code lives inline in the Jinja template, so extract and execute the
 * checked-in functions. This keeps the test bound to the URL and response
 * shape that the browser actually receives after the FastAPI migration.
 */

import { resolve } from 'node:path';

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

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

function compileConfigLoader() {
    return compileTemplateHarness({
        templatePath: TEMPLATE_PATH,
        functionNames: ['displayConfig', 'loadCurrentConfig'],
        dependencies: { escapeHtml: value => String(value) },
        returnExpression: 'loadCurrentConfig',
    });
}

beforeEach(() => {
    document.body.innerHTML = `
        <div id="config-display">
            <span class="ldr-config-label">Loading...</span>
        </div>
    `;
});

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

it('loads and renders the FastAPI bulk-settings response', async () => {
    const fetchMock = vi.fn().mockResolvedValue({
        json: vi.fn().mockResolvedValue({
            settings: {
                'llm.provider': { value: 'openai_endpoint' },
                'llm.model': { value: 'local-model' },
                'search.tool': { value: 'searxng' },
                'search.iterations': { value: 6 },
            },
        }),
    });
    vi.stubGlobal('fetch', fetchMock);

    await compileConfigLoader()();

    expect(fetchMock).toHaveBeenCalledOnce();
    expect(fetchMock).toHaveBeenCalledWith('/settings/api');
    const values = Array.from(
        document.querySelectorAll('.ldr-config-value'),
        element => element.textContent,
    );
    expect(values).toEqual([
        'openai_endpoint',
        'local-model',
        'searxng',
        '6',
    ]);
});

it('uses browser-facing defaults when optional settings are absent', async () => {
    vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
        json: vi.fn().mockResolvedValue({ settings: {} }),
    }));

    await compileConfigLoader()();

    const values = Array.from(
        document.querySelectorAll('.ldr-config-value'),
        element => element.textContent,
    );
    expect(values).toEqual([
        'Not configured',
        'Not configured',
        'searxng',
        '8',
    ]);
});

it('replaces stale configuration with a recoverable loading state on failure', async () => {
    vi.spyOn(console, 'error').mockImplementation(() => {});
    vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new Error('offline')));
    document.getElementById('config-display').textContent = 'stale provider';

    await compileConfigLoader()();

    const values = Array.from(
        document.querySelectorAll('.ldr-config-value'),
        element => element.textContent,
    );
    expect(values).toEqual(['Loading...', 'Loading...', 'Loading...', '-']);
    expect(console.error).toHaveBeenCalledWith(
        'Error loading config:',
        expect.any(Error),
    );
});