Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion skills/reverse-engineering-saas/scripts/build-report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
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]*<!--[\s\S]*?-->[ \t]*\r?\n/gm, '').replace(/<!--[\s\S]*?-->/g, '');
const listDir = (kb, dir, filter = () => true) =>
Expand Down
14 changes: 14 additions & 0 deletions tests/kb-scripts.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});