~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
/** Distinct validation and monitoring contracts in the full benchmark page. */
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.html',
);
function deferred() {
let resolvePromise;
const promise = new Promise(resolvePromiseArgument => {
resolvePromise = resolvePromiseArgument;
});
return { promise, resolve: resolvePromise };
}
afterEach(() => {
vi.restoreAllMocks();
vi.unstubAllGlobals();
vi.useRealTimers();
delete window.socket;
document.body.replaceChildren();
});
it('validates the serialized configuration with CSRF', async () => {
const config = {
run_name: 'migration validation',
datasets_config: { simpleqa: { count: 3, seed: 3299 } },
};
const showAlert = vi.fn();
const fetchMock = vi.fn().mockResolvedValue({
json: vi.fn().mockResolvedValue({ valid: true, errors: [] }),
});
vi.stubGlobal('fetch', fetchMock);
const harness = compileTemplateHarness({
templatePath: TEMPLATE_PATH,
functionNames: ['validateConfiguration'],
dependencies: {
getConfigurationData: vi.fn(() => config),
showAlert,
},
preamble: "const csrfToken = 'csrf-benchmark';",
returnExpression: '({ validateConfiguration })',
});
harness.validateConfiguration();
await vi.waitFor(() => {
expect(showAlert).toHaveBeenCalledWith(
'Configuration is valid! Ready to start benchmark.',
'success',
);
});
expect(fetchMock).toHaveBeenCalledWith('/benchmark/api/validate-config', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': 'csrf-benchmark',
},
body: JSON.stringify(config),
});
});
it('consumes terminal status, refreshes monitoring, and stops polling', async () => {
const status = {
status: 'completed',
completed_examples: 8,
total_examples: 8,
overall_accuracy: 75,
};
const dependencies = {
updateProgressDisplay: vi.fn(),
updateCurrentQuestion: vi.fn(),
updateRecentResults: vi.fn(),
updateCharts: vi.fn(),
updateSearchQualityMonitoring: vi.fn(),
updateRateLimitingStatus: vi.fn(),
showAlert: vi.fn(),
};
const fetchMock = vi.fn().mockResolvedValue({
json: vi.fn().mockResolvedValue({ success: true, status }),
});
vi.stubGlobal('fetch', fetchMock);
const clearIntervalSpy = vi.spyOn(globalThis, 'clearInterval');
const harness = compileTemplateHarness({
templatePath: TEMPLATE_PATH,
functionNames: ['updateBenchmarkProgress'],
dependencies,
preamble: `
let currentBenchmarkId = 'run-3299';
let lastResultsUpdate = 0;
let lastChartsUpdate = 0;
let progressInterval = 91;
let progressRunGeneration = 1;
let progressStatusRequestId = 0;
let latestAppliedProgressStatusRequestId = 0;
let terminalBenchmarkRunGeneration = 0;
let hydratedTerminalBenchmarkRunGeneration = 0;
`,
returnExpression: `({
updateBenchmarkProgress,
getProgressInterval: () => progressInterval,
})`,
});
harness.updateBenchmarkProgress();
await vi.waitFor(() => {
expect(dependencies.showAlert).toHaveBeenCalledWith(
'Benchmark completed successfully!',
'success',
);
});
expect(fetchMock).toHaveBeenCalledWith(
'/benchmark/api/status/run-3299',
);
expect(dependencies.updateProgressDisplay).toHaveBeenCalledWith(status);
expect(dependencies.updateCurrentQuestion).toHaveBeenCalledWith(status);
expect(dependencies.updateRecentResults).toHaveBeenCalledOnce();
expect(dependencies.updateCharts).toHaveBeenCalledWith(status);
expect(dependencies.updateSearchQualityMonitoring).toHaveBeenCalledOnce();
expect(dependencies.updateRateLimitingStatus).toHaveBeenCalledOnce();
expect(clearIntervalSpy).toHaveBeenCalledWith(91);
expect(harness.getProgressInterval()).toBeNull();
});
it('keeps a newer benchmark authoritative over an older terminal poll', async () => {
vi.useFakeTimers();
const staleStatus = deferred();
const fetchMock = vi.fn(url => {
if (url === '/benchmark/api/status/run-a') return staleStatus.promise;
return new Promise(() => {});
});
vi.stubGlobal('fetch', fetchMock);
const dependencies = {
initializeCharts: vi.fn(),
loadHistoricalChartData: vi.fn(),
handleDetailedProgress: vi.fn(),
updateProgressDisplay: vi.fn(),
updateCurrentQuestion: vi.fn(),
updateRecentResults: vi.fn(),
updateCharts: vi.fn(),
updateSearchQualityMonitoring: vi.fn(),
updateRateLimitingStatus: vi.fn(),
showAlert: vi.fn(),
};
document.body.innerHTML = `
<section id="performance-charts-section" style="display: none"></section>
`;
window.socket = {
getSocketInstance: vi.fn(() => ({})),
subscribeToResearch: vi.fn(),
};
const harness = compileTemplateHarness({
templatePath: TEMPLATE_PATH,
functionNames: ['startProgressTracking', 'updateBenchmarkProgress'],
dependencies,
preamble: `
let currentBenchmarkId = 'run-a';
let progressInterval = null;
let progressRunGeneration = 0;
let progressStatusRequestId = 0;
let latestAppliedProgressStatusRequestId = 0;
let terminalBenchmarkRunGeneration = 0;
let hydratedTerminalBenchmarkRunGeneration = 0;
let recentResultsRequestId = 0;
let historicalChartRequestId = 0;
let searchQualityRequestId = 0;
let lastResultsUpdate = 0;
let lastChartsUpdate = 0;
`,
returnExpression: `({
startProgressTracking,
updateBenchmarkProgress,
setCurrentBenchmarkId: value => { currentBenchmarkId = value; },
getProgressInterval: () => progressInterval,
})`,
});
harness.startProgressTracking();
const staleRequest = harness.updateBenchmarkProgress();
expect(fetchMock).toHaveBeenCalledWith('/benchmark/api/status/run-a');
harness.setCurrentBenchmarkId('run-b');
harness.startProgressTracking();
const runBInterval = harness.getProgressInterval();
staleStatus.resolve({
json: vi.fn().mockResolvedValue({
success: true,
status: {
status: 'completed',
completed_examples: 4,
total_examples: 4,
},
}),
});
await staleRequest;
expect(dependencies.updateProgressDisplay).not.toHaveBeenCalled();
expect(dependencies.showAlert).not.toHaveBeenCalled();
expect(harness.getProgressInterval()).toBe(runBInterval);
clearInterval(runBInterval);
delete window.socket;
vi.useRealTimers();
});
it('clears prior-run results and throttle caches when a new run takes ownership', async () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-09-01T12:00:20Z'));
document.body.innerHTML = `
<section id="performance-charts-section" style="display: none"></section>
<div id="recent-results-container">
<article class="ldr-result-card">stale run A</article>
</div>
`;
window.socket = {};
const status = {
status: 'in_progress',
completed_examples: 1,
total_examples: 10,
};
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
json: vi.fn().mockResolvedValue({ success: true, status }),
}));
const dependencies = {
initializeCharts: vi.fn(),
loadHistoricalChartData: vi.fn(),
updateProgressDisplay: vi.fn(),
updateCurrentQuestion: vi.fn(),
updateRecentResults: vi.fn(),
updateCharts: vi.fn(),
updateSearchQualityMonitoring: vi.fn(),
updateRateLimitingStatus: vi.fn(),
showAlert: vi.fn(),
};
const harness = compileTemplateHarness({
templatePath: TEMPLATE_PATH,
functionNames: [
'startProgressTracking',
'updateBenchmarkProgress',
],
dependencies,
preamble: `
let currentBenchmarkId = 'run-b';
let progressInterval = null;
let progressRunGeneration = 4;
let progressStatusRequestId = 0;
let latestAppliedProgressStatusRequestId = 0;
let terminalBenchmarkRunGeneration = 0;
let hydratedTerminalBenchmarkRunGeneration = 0;
let recentResultsRequestId = 0;
let historicalChartRequestId = 0;
let searchQualityRequestId = 0;
let lastResultsUpdate = Date.now();
let lastChartsUpdate = Date.now();
let lastResultsData = [{ id: 'run-a-result' }];
`,
returnExpression: `({
startProgressTracking,
updateBenchmarkProgress,
getProgressInterval: () => progressInterval,
getLastResultsData: () => lastResultsData,
})`,
});
harness.startProgressTracking();
expect(document.getElementById('recent-results-container').textContent)
.toContain('No results yet');
expect(document.querySelector('.ldr-result-card')).toBeNull();
expect(harness.getLastResultsData()).toBeNull();
await harness.updateBenchmarkProgress();
expect(dependencies.updateRecentResults).toHaveBeenCalledOnce();
expect(dependencies.updateCharts).toHaveBeenCalledWith(status);
clearInterval(harness.getProgressInterval());
});
it('keeps a newer poll authoritative within the same benchmark run', async () => {
const olderStatus = deferred();
const newerStatus = deferred();
const fetchMock = vi.fn()
.mockImplementationOnce(() => olderStatus.promise)
.mockImplementationOnce(() => newerStatus.promise);
vi.stubGlobal('fetch', fetchMock);
const dependencies = {
updateProgressDisplay: vi.fn(),
updateCurrentQuestion: vi.fn(),
updateRecentResults: vi.fn(),
updateCharts: vi.fn(),
updateSearchQualityMonitoring: vi.fn(),
updateRateLimitingStatus: vi.fn(),
showAlert: vi.fn(),
};
const harness = compileTemplateHarness({
templatePath: TEMPLATE_PATH,
functionNames: ['updateBenchmarkProgress'],
dependencies,
preamble: `
let currentBenchmarkId = 'run-overlap';
let lastResultsUpdate = 0;
let lastChartsUpdate = 0;
let progressInterval = 92;
let progressRunGeneration = 1;
let progressStatusRequestId = 0;
let latestAppliedProgressStatusRequestId = 0;
let terminalBenchmarkRunGeneration = 0;
let hydratedTerminalBenchmarkRunGeneration = 0;
`,
returnExpression: `({
updateBenchmarkProgress,
getProgressInterval: () => progressInterval,
})`,
});
const olderRequest = harness.updateBenchmarkProgress();
const newerRequest = harness.updateBenchmarkProgress();
const currentStatus = {
status: 'in_progress',
completed_examples: 7,
total_examples: 10,
};
newerStatus.resolve({
json: vi.fn().mockResolvedValue({ success: true, status: currentStatus }),
});
await newerRequest;
expect(dependencies.updateProgressDisplay).toHaveBeenCalledWith(currentStatus);
olderStatus.resolve({
json: vi.fn().mockResolvedValue({
success: true,
status: {
status: 'in_progress',
completed_examples: 2,
total_examples: 10,
},
}),
});
await olderRequest;
expect(dependencies.updateProgressDisplay).toHaveBeenCalledOnce();
expect(dependencies.showAlert).not.toHaveBeenCalled();
expect(harness.getProgressInterval()).toBe(92);
});
it('accepts an older terminal snapshot after a newer nonterminal poll', async () => {
const terminalResponse = deferred();
const nonterminalResponse = deferred();
vi.stubGlobal('fetch', vi.fn()
.mockImplementationOnce(() => terminalResponse.promise)
.mockImplementationOnce(() => nonterminalResponse.promise));
const dependencies = {
updateProgressDisplay: vi.fn(),
updateCurrentQuestion: vi.fn(),
updateRecentResults: vi.fn(),
updateCharts: vi.fn(),
updateSearchQualityMonitoring: vi.fn(),
updateRateLimitingStatus: vi.fn(),
showAlert: vi.fn(),
};
const harness = compileTemplateHarness({
templatePath: TEMPLATE_PATH,
functionNames: ['updateBenchmarkProgress'],
dependencies,
preamble: `
let currentBenchmarkId = 'run-terminal';
let lastResultsUpdate = 0;
let lastChartsUpdate = 0;
let progressInterval = 93;
let progressRunGeneration = 1;
let progressStatusRequestId = 0;
let latestAppliedProgressStatusRequestId = 0;
let terminalBenchmarkRunGeneration = 0;
let hydratedTerminalBenchmarkRunGeneration = 0;
`,
returnExpression: `({
updateBenchmarkProgress,
getProgressInterval: () => progressInterval,
})`,
});
const terminalLoad = harness.updateBenchmarkProgress();
const nonterminalLoad = harness.updateBenchmarkProgress();
const runningStatus = {
status: 'in_progress',
completed_examples: 8,
total_examples: 10,
};
nonterminalResponse.resolve({
json: vi.fn().mockResolvedValue({ success: true, status: runningStatus }),
});
await nonterminalLoad;
const terminalStatus = {
status: 'completed',
completed_examples: 10,
total_examples: 10,
};
terminalResponse.resolve({
json: vi.fn().mockResolvedValue({ success: true, status: terminalStatus }),
});
await terminalLoad;
expect(dependencies.updateProgressDisplay).toHaveBeenLastCalledWith(
terminalStatus,
);
expect(dependencies.showAlert).toHaveBeenCalledWith(
'Benchmark completed successfully!',
'success',
);
expect(harness.getProgressInterval()).toBeNull();
});
it('retires the original socket owner when HTTP renders terminal state', async () => {
vi.useFakeTimers();
document.body.innerHTML = `
<section id="performance-charts-section" style="display: none"></section>
<div id="current-task"></div>
`;
const subscribeToResearch = vi.fn();
const unsubscribeFromResearch = vi.fn();
window.socket = {
getSocketInstance: vi.fn(() => ({ connected: true })),
subscribeToResearch,
unsubscribeFromResearch,
};
const status = {
status: 'completed',
completed_examples: 5,
total_examples: 5,
overall_accuracy: 80,
};
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
json: vi.fn().mockResolvedValue({ success: true, status }),
}));
const dependencies = {
initializeCharts: vi.fn(),
loadHistoricalChartData: vi.fn(),
updateProgressDisplay: vi.fn(() => {
document.getElementById('current-task').textContent = 'completed';
}),
updateCurrentQuestion: vi.fn(),
updateRecentResults: vi.fn(),
updateCharts: vi.fn(),
updateSearchQualityMonitoring: vi.fn(),
updateRateLimitingStatus: vi.fn(),
showAlert: vi.fn(),
};
const harness = compileTemplateHarness({
templatePath: TEMPLATE_PATH,
functionNames: [
'handleDetailedProgress',
'startProgressTracking',
'updateBenchmarkProgress',
],
dependencies,
preamble: `
let currentBenchmarkId = 'terminal-run';
let progressInterval = null;
let progressRunGeneration = 0;
let progressStatusRequestId = 0;
let latestAppliedProgressStatusRequestId = 0;
let terminalBenchmarkRunGeneration = 0;
let hydratedTerminalBenchmarkRunGeneration = 0;
let recentResultsRequestId = 0;
let historicalChartRequestId = 0;
let searchQualityRequestId = 0;
let lastResultsUpdate = 0;
let lastChartsUpdate = 0;
`,
returnExpression: `({
startProgressTracking,
updateBenchmarkProgress,
})`,
});
harness.startProgressTracking();
await vi.advanceTimersByTimeAsync(500);
const socketCallback = subscribeToResearch.mock.calls[0][1];
socketCallback({ status: 'in_progress', message: 'grading' });
expect(document.getElementById('current-task').textContent).toBe('grading');
await harness.updateBenchmarkProgress();
expect(document.getElementById('current-task').textContent).toBe('completed');
expect(unsubscribeFromResearch).toHaveBeenCalledOnce();
expect(unsubscribeFromResearch).toHaveBeenCalledWith('terminal-run');
socketCallback({
status: 'in_progress',
log_entry: { message: 'late stale work' },
});
expect(document.getElementById('current-task').textContent).toBe('completed');
});
it('renders the migrated search-quality warning for SearXNG throttling', async () => {
document.body.innerHTML = `
<div id="search-status-details">Current status.</div>
`;
const fetchMock = vi.fn().mockResolvedValue({
json: vi.fn().mockResolvedValue({
success: true,
search_quality: [{
engine_type: 'SearXNGSearchEngine',
status: 'WARNING',
success_rate: 72.5,
}],
}),
});
vi.stubGlobal('fetch', fetchMock);
vi.spyOn(console, 'warn').mockImplementation(() => {});
const harness = compileTemplateHarness({
templatePath: TEMPLATE_PATH,
functionNames: ['updateRateLimitingStatus'],
returnExpression: '({ updateRateLimitingStatus })',
});
await harness.updateRateLimitingStatus();
expect(fetchMock).toHaveBeenCalledWith('/benchmark/api/search-quality');
expect(document.getElementById('search-status-details').textContent)
.toContain('High rate-limit failures: 27.5% of requests throttled.');
});