#!/usr/bin/env node // run-2026-09-25-ch, job 3723: the pickNewest case finding #136 asks for. // // #136 names `research/qc/pick-newest-check.js` as the place for this case; that file // does not exist in the served corpus (404), and research/qc/checks.js carries no // pickNewest case at all. This harness is the equivalent check, run against the // REVISED module, until a check file with a home for it exists. // // Usage: cd work/mirror && node ../pick_newest_harness.js const path = require('path'); const M = require(path.join(__dirname, 'mirror', 'research', 'qc', 'questions.js')); const { pickNewest } = M; // The keys git emits: repository-relative, forward slashes. pickNewest reads a Map // (dates.has / dates.get), so the fixture is a Map, exactly as fileLastDates returns. const GIT = new Map([ ['research/qc/questions.js', '2026-09-01'], ['research/TODO.md', '2026-06-01'], ]); // On win32, path.relative prints '\'; on this platform it prints '/'. Both are // spelled explicitly here so the harness tests the CONVENTION, not the OS. const slashKeys = f => f.replace(/\\/g, '/'); // the file's own helper const winRel = f => f.replace(/\//g, '\\'); // what C.rel did pre-#1715 const group = [{ file: 'research/qc/questions.js' }, { file: 'research/TODO.md' }]; const shown = f => (f === 'research/qc/questions.js' ? 'questions.js' : 'TODO.md'); let fail = 0; const check = (name, got, want) => { const ok = got === want; if (!ok) fail++; console.log(`${ok ? 'ok ' : 'FAIL'} ${name}: ${got}${ok ? '' : ` (want ${want})`}`); }; // 1. The defect #136 describes: backslash keys miss every entry, so all notes count // as unknown/new and the rule silently becomes "last in path order". check('win32-style keys fall back to path order', shown(pickNewest(group, GIT, winRel).file), 'TODO.md'); // 2. The fix: with '/'-normalised keys the newest date wins. check('slash keys pick the newest date', shown(pickNewest(group, GIT, slashKeys).file), 'questions.js'); // 3. On this platform path.relative already emits '/', so the switch changes nothing: // the two key functions agree, key for key. check('slash and C.rel agree here (no behaviour change)', group.map(r => slashKeys(r.file)).join() === group.map(r => winRel(r.file).replace(/\\/g, '/')).join() && slashKeys(group[0].file) === group[0].file, true); // 4. A newer date still wins; a tie resolves to the last in path order. const tie = new Map([['research/qc/questions.js', '2026-09-01'], ['research/TODO.md', '2026-09-01']]); check('a tie resolves to the last in path order', shown(pickNewest(group, tie, slashKeys).file), 'TODO.md'); // questions.js is FIRST in path order but NEWER, so only the date rule can pick it. const newer = new Map([['research/qc/questions.js', '2026-09-01'], ['research/TODO.md', '2026-06-01']]); check('a newer date wins over path order', shown(pickNewest(group, newer, slashKeys).file), 'questions.js'); check('...and the win32 keys would have picked the other one', shown(pickNewest(group, newer, winRel).file), 'TODO.md'); // 5. No dates at all: the path-order fallback, unchanged. check('no dates -> last in path order', shown(pickNewest(group, new Map(), slashKeys).file), 'TODO.md'); console.log(fail ? `${fail} FAILURES` : 'all harness cases pass'); process.exit(fail ? 1 : 0);