~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): exercise negative counter clamp (#5230)
LearningCircuit820fce1e4032
diff --git a/tests/js/components/logpanel.test.js b/tests/js/components/logpanel.test.jsindex b2325b917f..03eecf6ea3 100644--- a/tests/js/components/logpanel.test.js+++ b/tests/js/components/logpanel.test.js@@ -2034,11 +2034,11 @@ describe('loadLogsForResearch — counter drift when live entries already exist'// and the header indicator drift below zero even though the DOM// ends up back at the cap.//- // The structural fix (recompute from the DOM in- // loadLogsForResearch before exiting the merge path) is what this- // suite locks in. A second test pins the defensive Math.max(0, ...)- // floor in updateLogCounter / updateFilterCounters so a future- // refactor that drops the clamp doesn't surface as "Info -1".+ // The first test locks in the structural fix (recompute from the+ // DOM in loadLogsForResearch before exiting the merge path). The+ // second pins updateFilterCounters' defensive Math.max(0, ...) floor+ // while verifying that updateLogCounter keeps the indicator and All+ // badge DOM-derived, so a future refactor cannot surface "Info -1".//// setupPanelDom() is intentionally NOT used here: it calls// logPanel.initialize(rid), which auto-fires a pre-fetch and@@ -2136,49 +2136,66 @@ describe('loadLogsForResearch — counter drift when live entries already exist'});});- it('clamps the indicator and badges to >= 0 when the underlying state is negative', () => {+ it('clamps negative category badges while indicator and All follow the rendered DOM', () => {// Guards the defensive Math.max(0, ...) floor in- // updateLogCounter / updateFilterCounters. The structural- // recompute in loadLogsForResearch handles the bulk-merge- // path; this test pins that a future insertion path that- // bypasses the recompute (e.g. a regression in- // addLogEntryToPanel's prune/increment pairing) can't surface- // as "Info -1" before the recompute is extended to cover it.- //- // Seed DOM/state directly so the test stays fast and- // deterministic — no initialize(), no real fetch, no real- // addLog round-trip.+ // updateFilterCounters. The structural recompute in+ // loadLogsForResearch handles bulk paths; this test pins that+ // a future live insertion path with stale negative category+ // state cannot surface a negative badge before the state is+ // structurally recomputed.buildPanelDom();window._logPanelState.counts = emptyCounts();window._logPanelState.counts.info = -50;window._logPanelState.counts.warning = -10;+ window._logPanelState.expanded = true;+ // Stale indicator text is the one piece of pre-seeded DOM the+ // code path can read back: updateFilterCounters derives the All+ // badge from the indicator, so the insert must refresh it from+ // the rendered DOM before that read. The filter badges are pure+ // outputs and need no seeding.document.getElementById('log-indicator').textContent = '-60';- // Trigger a re-render via the public addLog path, which- // reaches updateFilterCounters. We have to initialize()- // first so window._socketAddLogEntry is registered and the- // addConsoleLog fallback (which logs-and-bails after #5128)- // doesn't drop the entry. initialize() with a fresh research- // id is cheap (no DOM changes happen because state is- // already seeded) and bounded by the fetch mock below.- globalThis.fetch = vi.fn(() =>- Promise.resolve({ json: () => Promise.resolve([]) })- );- logPanel.initialize('clamp-guard-rid');-- // addLog writes through _socketAddLogEntry (set up by- // initialize) into addLogEntryToPanel(logEntry, true), which- // calls updateLogCounter(1) and updateFilterCounters(). With- // counts.info seeded at -50, incrementCounter=true adds +1 to- // counts.info (now -49) and updateFilterCounters' clamp keeps- // the badge at "0". Indicator textContent was "-60"; +1 from- // updateLogCounter clamps to "0".logPanel.addLog('trigger-render', 'info');- expect(getIndicatorCount()).toBeGreaterThanOrEqual(0);- expect(getFilterCount('info')).toBeGreaterThanOrEqual(0);- expect(getFilterCount('warning')).toBeGreaterThanOrEqual(0);- expect(getFilterCount('all')).toBeGreaterThanOrEqual(0);+ expect(+ document.querySelectorAll('.ldr-console-log-entry')+ ).toHaveLength(1);+ expect(window._logPanelState.counts.info).toBe(-49);+ expect(window._logPanelState.counts.warning).toBe(-10);+ expect(document.getElementById('log-indicator').textContent).toBe('1');+ expect(+ document.querySelector('[data-filter-count="all"]').textContent+ ).toBe('1');+ expect(+ document.querySelector('[data-filter-count="info"]').textContent+ ).toBe('0');+ expect(+ document.querySelector('[data-filter-count="warning"]').textContent+ ).toBe('0');+ });++ it('recovers through the exact zero boundary as inserts land on a negative counter', () => {+ // Companion to the clamp test above, covering the boundary where+ // the clamp stops being the deciding factor: with info at -1 the+ // first insert lands exactly on 0 (state and clamped badge agree),+ // and the second proves the badge resumes tracking the true count+ // once the state itself turns positive.+ buildPanelDom();+ window._logPanelState.counts = emptyCounts();+ window._logPanelState.counts.info = -1;+ window._logPanelState.expanded = true;++ logPanel.addLog('first render', 'info');+ expect(window._logPanelState.counts.info).toBe(0);+ expect(+ document.querySelector('[data-filter-count="info"]').textContent+ ).toBe('0');++ logPanel.addLog('second render', 'info');+ expect(window._logPanelState.counts.info).toBe(1);+ expect(+ document.querySelector('[data-filter-count="info"]').textContent+ ).toBe('1');});it('counts untracked categories (e.g. DEBUG) toward the header indicator and All badge after a bulk load', async () => {