From f21ff4c1e5054b0c177f3ba63fa84ef25009469c Mon Sep 17 00:00:00 2001 From: rafaelgaropaba83-gif Date: Tue, 20 Oct 2026 15:03:08 -0300 Subject: [PATCH] fix: build-report reads files with Windows line endings A knowledge base checked out on Windows (git core.autocrlf) or written by Windows tools has CRLF line endings. The rule heading regex in renderRuleFile does not match a line ending in \r, so build-report and pack-kb crash with "object null is not iterable". The ClickUp example fails the same way when the repository is cloned on Windows. read() now normalizes CRLF and lone CR to LF, so every parser in the report sees the same text on every platform. A regression test writes a rule file and a screen file with CRLF and checks the rule card renders. --- .../scripts/build-report.mjs | 3 ++- tests/kb-scripts.test.mjs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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'); +});