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.8 KB
Raw Blame
import { resolve } from 'node:path';
import { compileTemplateHarness } from '../helpers/template-harness.js';

async function flushPromises() {
    for (let turn = 0; turn < 20; turn++) await Promise.resolve();
}

afterEach(() => {
    vi.clearAllTimers();
    vi.useRealTimers();
    vi.unstubAllGlobals();
    delete window.socket;
    document.body.replaceChildren();
});

it.each([
    ['benchmark_simple.html', 2000, 'updateProgress'],
    ['benchmark.html', 3000, 'updateBenchmarkProgress'],
])('renders slow, in-order running responses in %s', async (page, interval, updateFunction) => {
    vi.useFakeTimers();
    document.body.innerHTML = `
        <div id="progress-fill"></div>
        <span id="stat-accuracy"></span>
        <span id="stat-completed"></span>
        <span id="stat-rate"></span>
        <span id="stat-remaining"></span>
        <section id="performance-charts-section"></section>
    `;
    const responses = [];
    vi.stubGlobal('fetch', vi.fn(() => new Promise(resolveResponse => {
        responses.push(resolveResponse);
    })));
    let renderedCount = 0;
    const noop = () => {};
    const harness = compileTemplateHarness({
        templatePath: resolve(__dirname, '../../../src/local_deep_research/web/templates/pages', page),
        functionNames: [
            'startProgressTracking', updateFunction,
            ...(page === 'benchmark_simple.html' ? ['formatBenchmarkAccuracy'] : []),
        ],
        dependencies: {
            initializeCharts: noop,
            loadHistoricalChartData: noop,
            handleDetailedProgress: noop,
            updateProgressDisplay: status => { renderedCount = status.completed_examples; },
            updateCurrentQuestion: noop,
            updateRecentResults: noop,
            updateCharts: noop,
            updateSearchQualityMonitoring: noop,
            updateRateLimitingStatus: noop,
            showAlert: noop,
            hideProgress: noop,
        },
        preamble: `
            let currentBenchmarkId = 'slow-run';
            let progressInterval = null;
            let progressRunGeneration = 0;
            let progressStatusRequestId = 0;
            let latestAppliedProgressStatusRequestId = 0;
            let terminalProgressRunGeneration = null;
            let terminalBenchmarkRunGeneration = null;
            let hydratedTerminalBenchmarkRunGeneration = null;
            let recentResultsRequestId = 0;
            let historicalChartRequestId = 0;
            let searchQualityRequestId = 0;
            let lastResultsUpdate = 0;
            let lastChartsUpdate = 0;
            let lastResultsData = null;
        `,
        returnExpression: '({ startProgressTracking })',
    });
    harness.startProgressTracking();
    if (page === 'benchmark.html') {
        // The full page starts its first poll on the interval tick.
        await vi.advanceTimersByTimeAsync(interval);
    }
    expect(responses).toHaveLength(1);

    for (let completed = 1; completed <= 4; completed++) {
        // Each response takes longer than the interval, so the next request
        // starts first. Responses still return in request order.
        await vi.advanceTimersByTimeAsync(interval);
        expect(responses).toHaveLength(2);
        responses.shift()({ json: async () => ({
            success: true,
            status: {
                status: 'in_progress', completed_examples: completed,
                total_examples: 10, overall_accuracy: 50, processing_rate: 1,
            },
        }) });
        await flushPromises();
        if (page === 'benchmark_simple.html') {
            expect(document.getElementById('stat-completed').textContent)
                .toBe(`${completed}/10`);
        } else {
            expect(renderedCount).toBe(completed);
        }
    }
    vi.clearAllTimers();
    responses.shift()({ json: async () => ({ success: false }) });
    await flushPromises();
});