← back to Desktop Dotbar
test/dw-segment.test.js
58 lines
'use strict';
// The bar's dw / non-dw counts must mean EXACTLY what the Fleet board means by those words —
// click the "dw 121" chip and the board has to show 121 tickets. dw-segment.js copies the board's
// five classifier constants verbatim because board.html is not requireable; this test re-reads
// board.html and fails the moment either side is edited without the other. Without it the copy
// rots silently and the chip becomes a number nobody can reconcile (a false-green of its own:
// a wrong count looks exactly like a right one).
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const test = require('node:test');
const assert = require('node:assert');
const seg = require('../dw-segment.js');
const BOARD = path.join(os.homedir(), 'Projects', 'ticket-system', 'board.html');
test('classifier constants stay byte-identical to the board (anti-drift)', (t) => {
if (!fs.existsSync(BOARD)) return t.skip(`board.html not present at ${BOARD} — NOT MEASURED`);
const src = fs.readFileSync(BOARD, 'utf8');
// Pull the board's own declaration for each constant and compare to ours, rendered the same way.
const ours = {
DW_DENY: `new Set(${JSON.stringify([...seg.DW_DENY])})`,
DW_RE: String(seg.DW_RE),
DW_KW: String(seg.DW_KW),
DW_VENDOR: String(seg.DW_VENDOR),
DW_EXTRA: `new Set(${JSON.stringify([...seg.DW_EXTRA])})`,
};
for (const name of Object.keys(ours)) {
const m = src.match(new RegExp(`^const ${name}=(.*?);`, 'm'));
assert.ok(m, `${name} not found in board.html — the board was restructured; re-sync dw-segment.js by hand`);
const theirs = m[1].replace(/'/g, '"').replace(/,\s*$/, '');
assert.strictEqual(theirs.replace(/\s+/g, ''), ours[name].replace(/\s+/g, ''),
`${name} DRIFTED between board.html and dw-segment.js — the bar's dw/non-dw counts no longer match the board`);
}
});
test('hand-set segment overrides the auto guess, both directions', () => {
assert.strictEqual(seg.isDW({ project: 'dw-infra' }), true);
assert.strictEqual(seg.isDW({ project: 'dw-infra', segment: 'nondw' }), false);
assert.strictEqual(seg.isDW({ project: 'butlr' }), false);
assert.strictEqual(seg.isDW({ project: 'butlr', segment: 'dw' }), true);
});
test('deny-list beats the wallpaper keyword; empty project is NOT DW', () => {
assert.strictEqual(seg.isDW({ project: 'wallpapersback' }), false); // separate business
assert.strictEqual(seg.isDW({ project: 'abramsego' }), false);
assert.strictEqual(seg.isDW({ project: '' }), false);
assert.strictEqual(seg.isDW({}), false);
assert.strictEqual(seg.isDW(null), false);
});
// NEGATIVE TEST (CLAUDE.md TK-11431 amendment 3): prove the drift guard actually goes RED.
test('drift guard reddens on an injected divergence', () => {
const mutated = { ...seg, DW_KW: /wallcover/i }; // one char short of the board's /wallcover|wallpaper/i
assert.notStrictEqual(String(mutated.DW_KW), String(seg.DW_KW),
'injected fault must differ from the real constant, else the guard proves nothing');
});