Files
wekan/tests/eventLogProblems.test.cjs
T
Lauri Ojansivu 1fb382f0eb Stop Admin Panel / Problems showing a finished board-repair and info CPU rows.
#6520: the Problems "Status" page showed "Board data-repair — 146/146 boards"
running forever (plus a matching "Migration or repair" login warning), and the
CPU area showed dozens of "new problems" on an idle server.

Board repair stuck at "running": getInProgress() trusted the raw `running` flag.
The startup repair DOES write running:false on completion, but its progress
callback also fired a NON-awaited running:true write when boardsDone ===
boardsTotal; being fire-and-forget, that write could land AFTER the awaited
completion write and pin the doc at "running, 146/146". A process killed
mid-repair leaves running:true too. Both now clear:
  * the startup progress callback no longer writes the terminal boardsDone ===
    boardsTotal update (the completion write owns the final state), closing the
    race at the source;
  * getInProgress() now asks the new pure isStatusActive() instead of reading
    `running` directly - a doc is "in progress" only while running AND not in a
    terminal phase (completed/error/done) AND not already finished by count
    (done >= total) AND updated recently (a running flag with no recent progress
    write is a crashed run). This also heals docs already stuck on an instance,
    and fixes the same class of stale flag for the text migration. Because the
    login "Migration or repair" warning keys off getInProgress(), it clears too.

CPU "57 new problems" on an idle server: the count in eventLogProblemAreas
counted every unacknowledged row in a stream. The CPU monitor writes one
'detected' row when a high-CPU period starts and several severity:'info' rows
('remediated' when it ends, 'rate-limited' for mitigation, FerretDB governor
chatter), so each brief, already-over spike looked like several "new problems".
The count now excludes severity:'info' rows (via the new newProblemsSelector) -
notices that a problem was handled or cleared are not problems. Rows with no
severity are still counted, so nothing unclassified is silently dropped.

Both decisions are pure, unit- and negative-tested (statusActive.test.cjs,
eventLogProblems.test.cjs), and registered in test:unit:node.

Thanks to Alishara and xet7 !

Fixes #6520,
2026-07-24 10:14:29 +03:00

57 lines
2.4 KiB
JavaScript

'use strict';
// Unit + negative tests for newProblemsSelector (#6520): the Admin Panel →
// Problems "new problems" count must count actual problems, not the severity:
// 'info' rows the CPU stream writes when a spike is mitigated and when it ends.
// Counting those made an idle server report "57 new problems".
//
// Run: node tests/eventLogProblems.test.cjs
const assert = require('assert');
const { newProblemsSelector } = require('../models/lib/eventLogProblems.js');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
console.log('eventLogProblems:');
test('excludes info-severity rows from the count', () => {
const sel = newProblemsSelector('cpu');
assert.deepStrictEqual(sel.severity, { $ne: 'info' });
});
test('scopes to the requested stream', () => {
assert.strictEqual(newProblemsSelector('cpu').stream, 'cpu');
assert.strictEqual(newProblemsSelector('security').stream, 'security');
});
test('an acknowledgment time limits the count to newer events', () => {
const at = new Date('2026-07-01T00:00:00Z');
assert.deepStrictEqual(newProblemsSelector('cpu', at).at, { $gt: at });
});
test('no acknowledgment time means no `at` clause (count everything unseen)', () => {
const sel = newProblemsSelector('cpu');
assert.ok(!('at' in sel), 'must not add an at filter when there is no ack');
// A falsy ack time is ignored, not turned into { $gt: undefined }.
assert.ok(!('at' in newProblemsSelector('cpu', null)));
assert.ok(!('at' in newProblemsSelector('cpu', 0)));
});
// The `$ne` semantics are the whole point: Mongo `{ $ne: 'info' }` matches
// documents where `severity` is missing, so an unclassified event still counts as
// a possible problem rather than being silently dropped.
test('the selector shape counts info-less rows but not info rows (documented $ne semantics)', () => {
const match = (doc) => {
const sev = doc.severity;
// Emulate Mongo $ne: true when the field is absent OR not equal to 'info'.
return sev === undefined ? true : sev !== 'info';
};
assert.strictEqual(match({ severity: 'info' }), false, 'info row is NOT a problem');
assert.strictEqual(match({ severity: 'high' }), true, 'high row IS a problem');
assert.strictEqual(match({ severity: 'medium' }), true, 'medium row IS a problem');
assert.strictEqual(match({}), true, 'unclassified row still counts');
});
console.log(`\n${passed} tests passed`);