Files
msd-core/tests/bug-3072-optional-sketch-findings-guard.test.cjs
Tom Boucher aac6d3635b fix(3597): make markdown-fence regex CRLF-tolerant in 3 windows-failing tests
bug-2801, bug-3072, bug-3321 each read .md workflow files from disk and
parse fenced code blocks with /\`\`\`bash\n(...)\`\`\`/ — on a Windows
checkout with autocrlf=true the file content is CRLF, the regex never
matches, code blocks come back empty, and the assertion fails with
"expected bash code blocks in workflow" (and similar).

Fix: accept optional \r before each literal \n in the fence delimiter
and split lines on /\r?\n/. Same pattern bug-2839 had with its local
parseFrontmatter copy (already migrated to the CRLF-aware shared helper
in 1be0e4e2). bug-2995 + tests/security-scan.test.cjs also match this
grep but use \n in literal-string fixtures (not file-content regexes);
not affected.

Validated: holodeck (ubuntu docker) 11224/0 pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 11:55:55 -04:00

63 lines
1.9 KiB
JavaScript

'use strict';
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const ROOT = path.join(__dirname, '..', 'get-shit-done', 'workflows');
function read(rel) {
return fs.readFileSync(path.join(ROOT, rel), 'utf8');
}
function extractFindingsProbesFromBashBlocks(markdown) {
const probes = [];
const fenceRe = /```bash\r?\n([\s\S]*?)```/g;
let fenceMatch;
while ((fenceMatch = fenceRe.exec(markdown)) !== null) {
const block = fenceMatch[1];
const baseLine = markdown.slice(0, fenceMatch.index).split(/\r?\n/).length;
const lines = block.split(/\r?\n/);
lines.forEach((line, idx) => {
if (!line.includes('.claude/skills/')) return;
const kind = line.includes('sketch-findings-*/SKILL.md')
? 'sketch'
: line.includes('spike-findings-*/SKILL.md')
? 'spike'
: null;
if (!kind) return;
probes.push({
lineNumber: baseLine + idx,
commandText: line.trim(),
kind,
hasNonFatalGuard: /\|\|\s*true/.test(line),
});
});
}
return probes;
}
describe('bug #3072: optional sketch/spike findings probes are non-fatal', () => {
test('all sketch/spike findings SKILL.md ls probes include || true', () => {
const files = ['ui-phase.md', 'plan-phase.md', 'discuss-phase.md', 'new-project.md'];
const offenders = [];
for (const file of files) {
const content = read(file);
const probes = extractFindingsProbesFromBashBlocks(content);
for (const probe of probes) {
if (!probe.hasNonFatalGuard) {
offenders.push(`${file}:${probe.lineNumber} ${probe.commandText}`);
}
}
}
assert.deepStrictEqual(offenders, [], `missing non-fatal guard on optional findings probe:\n${offenders.join('\n')}`);
});
});