~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
test(logpanel): cover ordering invariants for #2610 fix (#3872)
LearningCircuite03eccc77e90
diff --git a/tests/js/components/logpanel.test.js b/tests/js/components/logpanel.test.jsindex 870dec3402..251afd7c3a 100644--- a/tests/js/components/logpanel.test.js+++ b/tests/js/components/logpanel.test.js@@ -310,6 +310,171 @@ describe('addConsoleLog — placeholder removal', () => {});});+// Ordering invariants for the #2610 fix (PR #3850). The log panel uses+// `flex-direction: column-reverse` so DOM end == visual top. happy-dom+// does not render CSS, so these tests assert on DOM order directly --+// the contract being locked in is "DOM order is chronological+// oldest -> newest", and the CSS flip is taken as given.+//+// Mirrors of source-side constants (kept inline because both are `const`+// inside the IIFE in logpanel.js and not exported). If either source+// constant changes, update here:+// MAX_LOG_ENTRIES src/local_deep_research/web/static/js/components/logpanel.js:21+// DEDUP_WINDOW src/local_deep_research/web/static/js/components/logpanel.js+// (the `existingEntries.length - 10` lower bound in+// addLogEntryToPanel's dedup-by-content scan)+const MAX_LOG_ENTRIES = 500;+const DEDUP_WINDOW = 10;++describe('addLog / loadLogs — ordering invariants', () => {+ function messageTextsInDomOrder(container) {+ return Array.from(container.querySelectorAll('.ldr-log-message')).map(+ (el) => el.textContent+ );+ }++ beforeEach(() => {+ // Drive entries through addLogEntryToPanel rather than the queue.+ window._logPanelState.expanded = true;+ // Fake only Date so setTimeout(autoscroll, 0) keeps working.+ vi.useFakeTimers({ toFake: ['Date'] });+ });++ afterEach(() => {+ vi.useRealTimers();+ // Vitest isolates globals between files, but ordering changes+ // within this file should not expose latent reliance on a prior+ // test's fetch mock.+ delete globalThis.fetch;+ });++ it('inserts live entries in chronological DOM order (newest at DOM end)', () => {+ const container = document.getElementById('console-log-container');++ vi.setSystemTime(new Date('2026-05-08T12:00:00Z'));+ logPanel.addLog('first', 'info');+ vi.setSystemTime(new Date('2026-05-08T12:00:01Z'));+ logPanel.addLog('second', 'info');+ vi.setSystemTime(new Date('2026-05-08T12:00:02Z'));+ logPanel.addLog('third', 'info');++ expect(messageTextsInDomOrder(container)).toEqual([+ 'first',+ 'second',+ 'third',+ ]);++ // data-log-time-ms must be monotonically non-decreasing oldest -> newest.+ const times = Array.from(+ container.querySelectorAll('.ldr-console-log-entry')+ ).map((el) => Number(el.dataset.logTimeMs));+ expect(times).toEqual([...times].sort((a, b) => a - b));+ });++ it('merges late-arriving older history into chronological position', async () => {+ const container = document.getElementById('console-log-container');++ // Two live entries arrive first (recent times).+ vi.setSystemTime(new Date('2026-05-08T12:00:00Z'));+ logPanel.addLog('live-A', 'info');+ vi.setSystemTime(new Date('2026-05-08T12:00:01Z'));+ logPanel.addLog('live-B', 'info');++ // Then loadLogs returns one historical entry whose timestamp is+ // older than both live entries. The merge path routes through+ // addLogEntryToPanel, which must insert it before live-A.+ globalThis.fetch = vi.fn(() =>+ Promise.resolve({+ json: () =>+ Promise.resolve([+ {+ timestamp: '2026-05-08T11:59:00Z',+ message: 'historical',+ log_type: 'info',+ },+ ]),+ })+ );++ await logPanel.loadLogs('test-research-ordering-merge');++ expect(messageTextsInDomOrder(container)).toEqual([+ 'historical',+ 'live-A',+ 'live-B',+ ]);+ });++ it('prunes the oldest entries when count exceeds MAX_LOG_ENTRIES', () => {+ const container = document.getElementById('console-log-container');++ // One insert over the cap. The live-insert prune in+ // addLogEntryToPanel must drop the oldest entry, not the newest.+ const totalInserts = MAX_LOG_ENTRIES + 1;+ const base = new Date('2026-05-08T12:00:00Z').getTime();+ for (let i = 0; i < totalInserts; i++) {+ vi.setSystemTime(new Date(base + i * 1000));+ logPanel.addLog(`msg-${i}`, 'info');+ }++ const entries = container.querySelectorAll('.ldr-console-log-entry');+ expect(entries.length).toBe(MAX_LOG_ENTRIES);++ const messages = messageTextsInDomOrder(container);+ // Oldest (msg-0) was pruned; msg-1 is now the oldest in DOM,+ // msg-${totalInserts - 1} is the newest.+ expect(messages).not.toContain('msg-0');+ expect(messages[0]).toBe('msg-1');+ expect(messages[messages.length - 1]).toBe(`msg-${totalInserts - 1}`);+ });++ it('dedupes a duplicate inside the 10-newest window', () => {+ const container = document.getElementById('console-log-container');++ vi.setSystemTime(new Date('2026-05-08T12:00:00Z'));+ logPanel.addLog('dup-msg', 'info');+ vi.setSystemTime(new Date('2026-05-08T12:00:01Z'));+ logPanel.addLog('dup-msg', 'info');++ // Only one DOM entry, with a duplicate-counter badge.+ const entries = container.querySelectorAll('.ldr-console-log-entry');+ expect(entries.length).toBe(1);+ expect(entries[0].dataset.counter).toBe('2');+ const badge = entries[0].querySelector('.ldr-duplicate-counter');+ expect(badge).not.toBeNull();+ expect(badge.textContent).toBe('(2×)');+ });++ it('does not dedupe a duplicate that has fallen outside the 10-newest window', () => {+ const container = document.getElementById('console-log-container');++ // DEDUP_WINDOW + 1 distinct messages: msg-0 ends up at DOM index 0+ // (oldest), msg-${DEDUP_WINDOW} at the newest end. The+ // dedup-by-content scan only covers the DEDUP_WINDOW newest, so+ // msg-0 is one slot outside it.+ const distinctCount = DEDUP_WINDOW + 1;+ const base = new Date('2026-05-08T12:00:00Z').getTime();+ for (let i = 0; i < distinctCount; i++) {+ vi.setSystemTime(new Date(base + i * 1000));+ logPanel.addLog(`msg-${i}`, 'info');+ }++ // Re-add msg-0 with a fresh timestamp so dedup-by-id misses+ // (different id -> ${timestamp}-${hash}). Dedup-by-content would+ // catch it only if msg-0 were in the DEDUP_WINDOW newest.+ vi.setSystemTime(new Date(base + distinctCount * 1000));+ logPanel.addLog('msg-0', 'info');++ const entries = container.querySelectorAll('.ldr-console-log-entry');+ expect(entries.length).toBe(distinctCount + 1);++ // The two msg-0 entries sit at the chronological extremes.+ const messages = messageTextsInDomOrder(container);+ expect(messages[0]).toBe('msg-0');+ expect(messages[messages.length - 1]).toBe('msg-0');+ });+});+/*** Toggle handler tests — locks in the contract introduced by PR #3851.*