diff --git a/skills/reverse-engineering-saas/scripts/build-report.mjs b/skills/reverse-engineering-saas/scripts/build-report.mjs index 132d2ed..bf7aaea 100644 --- a/skills/reverse-engineering-saas/scripts/build-report.mjs +++ b/skills/reverse-engineering-saas/scripts/build-report.mjs @@ -18,7 +18,8 @@ const UNSEEN = /^\s*(not tested|not measured|not reached|not studied|not seen|no const GALLERY_LIMIT = 6; const escapeHtml = (text) => String(text).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); -const read = (kb, file) => (existsSync(join(kb, file)) ? readFileSync(join(kb, file), 'utf8') : ''); +// Files checked out on Windows (git core.autocrlf) or written by Windows tools end lines with CRLF. +const read = (kb, file) => (existsSync(join(kb, file)) ? readFileSync(join(kb, file), 'utf8').replace(/\r\n?/g, '\n') : ''); // A comment on its own line goes with its line, so tables around it stay intact. const stripComments = (text) => text.replace(/^[ \t]*[ \t]*\r?\n/gm, '').replace(//g, ''); const listDir = (kb, dir, filter = () => true) => diff --git a/tests/kb-scripts.test.mjs b/tests/kb-scripts.test.mjs index 3b912eb..67a122a 100644 --- a/tests/kb-scripts.test.mjs +++ b/tests/kb-scripts.test.mjs @@ -367,3 +367,17 @@ test('--next prints the next free ID per prefix', () => { assert.match(result.stdout, /EV-013/); assert.match(result.stdout, /R-001/); }); + +test('build-report reads files with Windows line endings', () => { + const crlf = (text) => text.replace(/\n/g, '\r\n'); + write('rules/board.md', crlf('# Rules: board\n\n### R-001 Cards keep their order\n- Given a board with two cards\n- When the page reloads\n- Then the cards keep their order\n- Evidence: [doc SRC-001]\n')); + write('screens/S-001-board.md', crlf('# S-001 Board\nRules: R-001\n\n## Not tested\n- Drag.\n')); + appendFileSync(join(kb, 'sources.md'), '| SRC-001 | Docs | https://example.com/docs | docs | 2026-10-16 | x |\r\n'); + const result = run('build-report.mjs', kb); + assert.equal(result.status, 0, result.stderr); + const html = readFileSync(join(kb, 'REPORT.html'), 'utf8'); + assert.match(html, /id="R-001"/); + assert.match(html, /Cards keep their order/); + assert.match(html, /the cards keep their order/); + assert.doesNotMatch(html, /\r/, 'no carriage returns reach the page'); +});