* feat(#2982): extend no-source-grep lint to catch var-binding readFileSync.includes() The base lint (scripts/lint-no-source-grep.cjs) only catches readFileSync(...).<text-method>() chained directly. The much more common var-binding form escapes it: const src = fs.readFileSync(p, 'utf8'); // 50 lines later if (src.includes('foo')) {} // ← still grep, lint missed it Scan of the test suite found ~141 files using this pattern. Implementation built TDD per #2982 with structured-IR assertions: scripts/lint-no-source-grep-extras.cjs - detectVarBindingViolations(src) — pure detector, two passes: pass 1 collects vars bound from readFileSync, pass 2 finds any <var>.<includes|startsWith|endsWith|match|search>( on those vars. - detectWrappedAssertOkMatch(src) — flags assert.ok(<expr>.match(...)) which escapes the assert.match rule. - VIOLATION enum exposes stable codes for tests to assert on. scripts/lint-no-source-grep.cjs - Wires the new detectors into the existing per-file check; one additional violation row per file with the first 3 sample tokens. tests/bug-2982-lint-var-binding.test.cjs - 13 tests, all assertions on typed VIOLATION enum / structured records. Covers all 5 text-match methods, multi-var, no-bind, string literal (must NOT trigger), wrapped assert.ok(.match), and assert.match (must NOT double-flag). Migration backlog (#2974 expanded scope): - 42 files annotated `// allow-test-rule: source-text-is-the-product` (legitimate — they read .md/.json/.yml files whose deployed text IS the product) - 3 files annotated `// allow-test-rule: pending-migration-to-typed-ir [#2974]` (read .cjs/.js source — clear migration debt) - 95 files annotated `pending-migration-to-typed-ir [#2974]` with `Per-file review may reclassify as source-text-is-the-product during migration` (mixed — manual review under #2974) After this lands the lint reports 0 violations on main; new violations in PRs surface immediately. Closes #2982 Refs #2974 * test(#2982): fix truncated test name per CR The label ended with a bare '(' from a copy-paste mishap. Now reads 'does NOT flag .matchAll(...) — matchAll is not match, so assert.ok(.matchAll(...)) is not flagged'. * chore(#2982): add changeset fragment for PR #2985 * chore(#2982): add changeset fragment for PR #2985
105 lines
4.2 KiB
JavaScript
105 lines
4.2 KiB
JavaScript
'use strict';
|
|
|
|
// allow-test-rule: source-text-is-the-product
|
|
// Reads .md/.json/.yml product files whose deployed text IS what the
|
|
// runtime loads — testing text content tests the deployed contract.
|
|
|
|
/**
|
|
* Tests for gsd-health MILESTONES.md drift detection (#2446).
|
|
*/
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const os = require('node:os');
|
|
|
|
const { cmdValidateHealth } = require('../get-shit-done/bin/lib/verify.cjs');
|
|
|
|
function makeTempProject(files = {}) {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-2446-'));
|
|
fs.mkdirSync(path.join(dir, '.planning', 'milestones'), { recursive: true });
|
|
for (const [rel, content] of Object.entries(files)) {
|
|
const abs = path.join(dir, rel);
|
|
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
fs.writeFileSync(abs, content, 'utf-8');
|
|
}
|
|
return dir;
|
|
}
|
|
|
|
test('W018: warns when archived snapshot has no MILESTONES.md entry', () => {
|
|
const dir = makeTempProject({
|
|
'.planning/PROJECT.md': '# P\n\n## What This Is\n\nX\n\n## Core Value\n\nY\n\n## Requirements\n\nZ\n',
|
|
'.planning/ROADMAP.md': '# Roadmap\n',
|
|
'.planning/STATE.md': '# State\n',
|
|
'.planning/config.json': '{}',
|
|
'.planning/milestones/v1.0-ROADMAP.md': '# Milestone v1.0\n',
|
|
// No MILESTONES.md entry for v1.0
|
|
});
|
|
|
|
const result = cmdValidateHealth(dir, { repair: false }, false);
|
|
|
|
const w018 = result.warnings.find(w => w.code === 'W018');
|
|
assert.ok(w018, 'W018 warning should be emitted');
|
|
assert.ok(w018.message.includes('v1.0'), 'warning should mention v1.0');
|
|
assert.ok(w018.repairable, 'W018 should be marked repairable');
|
|
});
|
|
|
|
test('no W018 when all snapshots have MILESTONES.md entries', () => {
|
|
const dir = makeTempProject({
|
|
'.planning/PROJECT.md': '# P\n\n## What This Is\n\nX\n\n## Core Value\n\nY\n\n## Requirements\n\nZ\n',
|
|
'.planning/ROADMAP.md': '# Roadmap\n',
|
|
'.planning/STATE.md': '# State\n',
|
|
'.planning/config.json': '{}',
|
|
'.planning/milestones/v1.0-ROADMAP.md': '# Milestone v1.0\n',
|
|
'.planning/MILESTONES.md': '# Milestones\n\n## v1.0 My App (Shipped: 2026-01-01)\n\n---\n\n',
|
|
});
|
|
|
|
const result = cmdValidateHealth(dir, { repair: false }, false);
|
|
|
|
const w018 = result.warnings.find(w => w.code === 'W018');
|
|
assert.strictEqual(w018, undefined, 'no W018 when entries are present');
|
|
});
|
|
|
|
test('no W018 when milestones archive dir is empty', () => {
|
|
const dir = makeTempProject({
|
|
'.planning/PROJECT.md': '# P\n\n## What This Is\n\nX\n\n## Core Value\n\nY\n\n## Requirements\n\nZ\n',
|
|
'.planning/ROADMAP.md': '# Roadmap\n',
|
|
'.planning/STATE.md': '# State\n',
|
|
'.planning/config.json': '{}',
|
|
// No snapshots in milestones/
|
|
});
|
|
|
|
const result = cmdValidateHealth(dir, { repair: false }, false);
|
|
|
|
const w018 = result.warnings.find(w => w.code === 'W018');
|
|
assert.strictEqual(w018, undefined, 'no W018 with empty archive dir');
|
|
});
|
|
|
|
test('--backfill synthesizes missing MILESTONES.md entry from snapshot', () => {
|
|
const dir = makeTempProject({
|
|
'.planning/PROJECT.md': '# P\n\n## What This Is\n\nX\n\n## Core Value\n\nY\n\n## Requirements\n\nZ\n',
|
|
'.planning/ROADMAP.md': '# Roadmap\n',
|
|
'.planning/STATE.md': '# State\n',
|
|
'.planning/config.json': '{}',
|
|
'.planning/milestones/v1.0-ROADMAP.md': '# Milestone v1.0 First Release\n',
|
|
});
|
|
|
|
cmdValidateHealth(dir, { repair: true, backfill: true }, false);
|
|
|
|
const milestonesPath = path.join(dir, '.planning', 'MILESTONES.md');
|
|
assert.ok(fs.existsSync(milestonesPath), 'MILESTONES.md should be created');
|
|
const content = fs.readFileSync(milestonesPath, 'utf-8');
|
|
assert.ok(content.includes('## v1.0'), 'backfilled entry should contain v1.0');
|
|
assert.ok(content.includes('Backfilled'), 'should note it was backfilled');
|
|
});
|
|
|
|
test('health.md mentions --backfill flag', () => {
|
|
const healthMd = fs.readFileSync(
|
|
path.join(__dirname, '../get-shit-done/workflows/health.md'), 'utf-8'
|
|
);
|
|
assert.ok(healthMd.includes('--backfill'), 'health.md should document --backfill');
|
|
assert.ok(healthMd.includes('W018'), 'health.md should list W018 error code');
|
|
assert.ok(healthMd.includes('backfillMilestones'), 'repair_actions should include backfillMilestones');
|
|
});
|