Files
wekan/tests/resourceStreamNames.test.cjs
T
Lauri Ojansivu cfd9a62466 Swap alone is not high RAM usage, and resource monitors are not named like vulnerabilities.
A developer laptop with many programs open showed in Admin Panel /
Problems / Memory usage: "RamBleed, high, high RAM usage started
(>= 90%): RAM 16.1/30.9 GB (52%), swap 18.7/30.9 GB (60%)". Swap at or
above 25% started a high-memory period by itself, made it high severity,
and the text still said ">= 90%". Idle pages in swap while RAM is free
are not pressure.

- Swap now counts only while RAM is also at or above the low threshold
  (80%), and a period ends when RAM is back under it.
- The start row says what started it: (RAM >= 90%) or (swap >= 25% with
  RAM >= 80%). Only RAM at 95% or more is high severity.
- The RAM, CPU, disk and speed monitors named their rows like Hall of
  Fame entries (RamBleed, CpuBleed, DiskBleed, SlowBleed) with CWE-400.
  They are HighRamUsage, HighCpuUsage, HighDiskUsage and SlowRequest now,
  without a CWE, and stored rows are renamed once at startup.

tests/ramHighTracker.test.cjs replays the laptop's numbers as a
negative case; tests/resourceStreamNames.test.cjs pins the names.

Thanks to xet7 !
2026-11-19 00:21:33 +02:00

41 lines
2.1 KiB
JavaScript

'use strict';
// The resource and speed monitors report how busy the machine is, not a
// vulnerability. Their rows were named like Hall of Fame entries - RamBleed,
// CpuBleed, DiskBleed, SlowBleed, with CWE-400 - so a laptop with many programs
// open read as an attack in Admin Panel -> Problems (2026-11-19). They are named
// for what happened, carry no CWE, and old rows are renamed at startup.
// Run: node --test tests/resourceStreamNames.test.cjs
const test = require('node:test');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const read = rel => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
const STREAMS = [
['server/lib/ramLog.js', 'ram', 'HighRamUsage', 'RamBleed'],
['server/lib/cpuLog.js', 'cpu', 'HighCpuUsage', 'CpuBleed'],
['server/lib/diskLog.js', 'disk', 'HighDiskUsage', 'DiskBleed'],
];
test('each monitor names its rows for what happened, and renames the old ones', () => {
for (const [file, stream, name, legacy] of STREAMS) {
assert.match(read(file), new RegExp(`stream: '${stream}'[^}]*bleed: '${name}', legacyBleed: '${legacy}'`), file);
}
const log = read('server/lib/resourceLog.js');
assert.match(log, /renameLegacyRows\(defaults\.stream, defaults\.legacyBleed, defaults\.bleed\)/);
assert.match(log, /updateMany\(\{ stream, bleed: from \}, \{ \$set: \{ bleed: to \}/);
const speed = read('server/lib/speedLog.js');
assert.match(speed, /bleed: evt\.bleed \|\| 'SlowRequest'/);
assert.match(speed, /renameLegacyRows\('speed', 'SlowBleed', 'SlowRequest'\)/);
});
test('negative: no monitor row is named or classed like a vulnerability', () => {
const log = read('server/lib/resourceLog.js');
assert.doesNotMatch(log, /cwe: evt\.cwe \|\| 'CWE-400'/, 'no CWE by default');
for (const file of ['server/lib/ramLog.js', 'server/lib/cpuLog.js', 'server/lib/diskLog.js', 'server/lib/speedLog.js',
'server/lib/ramMonitor.js', 'server/lib/cpuMonitor.js', 'server/lib/diskMonitor.js']) {
const code = read(file).replace(/\/\/.*$/gm, '');
assert.doesNotMatch(code, /bleed: (?:evt\.bleed \|\| )?'[A-Za-z]*Bleed'/, file);
}
});