* 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
132 lines
4.9 KiB
JavaScript
132 lines
4.9 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 canonical artifact registry and gsd-health W019 lint (#2448).
|
|
*/
|
|
|
|
const { test, describe } = 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 { isCanonicalPlanningFile, CANONICAL_EXACT } = require('../get-shit-done/bin/lib/artifacts.cjs');
|
|
const { cmdValidateHealth } = require('../get-shit-done/bin/lib/verify.cjs');
|
|
|
|
function makeTempProject(files = {}) {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-2448-'));
|
|
fs.mkdirSync(path.join(dir, '.planning', 'phases'), { 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;
|
|
}
|
|
|
|
const BASE_FILES = {
|
|
'.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': '{}',
|
|
};
|
|
|
|
describe('artifacts.cjs — isCanonicalPlanningFile', () => {
|
|
test('returns true for all exact canonical names', () => {
|
|
for (const name of CANONICAL_EXACT) {
|
|
assert.ok(isCanonicalPlanningFile(name), `Expected ${name} to be canonical`);
|
|
}
|
|
});
|
|
|
|
test('returns true for version-stamped milestone audit file', () => {
|
|
assert.ok(isCanonicalPlanningFile('v1.0-MILESTONE-AUDIT.md'));
|
|
assert.ok(isCanonicalPlanningFile('v2.3.1-MILESTONE-AUDIT.md'));
|
|
});
|
|
|
|
test('returns false for clearly non-canonical names', () => {
|
|
assert.strictEqual(isCanonicalPlanningFile('MY-NOTES.md'), false);
|
|
assert.strictEqual(isCanonicalPlanningFile('scratch.md'), false);
|
|
assert.strictEqual(isCanonicalPlanningFile('random-output.md'), false);
|
|
});
|
|
|
|
test('returns false for phase-level artifacts at the root (they belong in phases/)', () => {
|
|
assert.strictEqual(isCanonicalPlanningFile('01-CONTEXT.md'), false);
|
|
assert.strictEqual(isCanonicalPlanningFile('01-01-PLAN.md'), false);
|
|
});
|
|
});
|
|
|
|
describe('gsd-health W019 — unrecognized .planning/ root files', () => {
|
|
test('W019 fires for a non-canonical .md file at .planning/ root', () => {
|
|
const dir = makeTempProject({
|
|
...BASE_FILES,
|
|
'.planning/MY-NOTES.md': '# notes\n',
|
|
});
|
|
|
|
const result = cmdValidateHealth(dir, { repair: false }, false);
|
|
|
|
const w019 = result.warnings.find(w => w.code === 'W019');
|
|
assert.ok(w019, 'W019 should be emitted for unrecognized file');
|
|
assert.ok(w019.message.includes('MY-NOTES.md'), 'warning should name the file');
|
|
assert.strictEqual(w019.repairable, false, 'W019 is not auto-repairable');
|
|
});
|
|
|
|
test('no W019 for canonical files', () => {
|
|
const dir = makeTempProject({ ...BASE_FILES });
|
|
|
|
const result = cmdValidateHealth(dir, { repair: false }, false);
|
|
|
|
const w019 = result.warnings.find(w => w.code === 'W019');
|
|
assert.strictEqual(w019, undefined, 'no W019 for canonical files');
|
|
});
|
|
|
|
test('no W019 for phase subdirectory files (only root is checked)', () => {
|
|
const dir = makeTempProject({
|
|
...BASE_FILES,
|
|
'.planning/phases/01-foundation/01-01-PLAN.md': '---\nphase: "1"\n---\n',
|
|
});
|
|
|
|
const result = cmdValidateHealth(dir, { repair: false }, false);
|
|
|
|
const w019 = result.warnings.find(w => w.code === 'W019');
|
|
assert.strictEqual(w019, undefined, 'phase subdir files not flagged by W019');
|
|
});
|
|
|
|
test('no W019 for version-stamped files like vX.Y-MILESTONE-AUDIT.md', () => {
|
|
const dir = makeTempProject({
|
|
...BASE_FILES,
|
|
'.planning/v1.0-MILESTONE-AUDIT.md': '# Audit\n',
|
|
});
|
|
|
|
const result = cmdValidateHealth(dir, { repair: false }, false);
|
|
|
|
const w019 = result.warnings.find(w => w.code === 'W019');
|
|
assert.strictEqual(w019, undefined, 'version-stamped audit file is canonical');
|
|
});
|
|
|
|
test('multiple unrecognized files produce multiple W019 warnings', () => {
|
|
const dir = makeTempProject({
|
|
...BASE_FILES,
|
|
'.planning/scratch.md': '# scratch\n',
|
|
'.planning/temp-notes.md': '# temp\n',
|
|
});
|
|
|
|
const result = cmdValidateHealth(dir, { repair: false }, false);
|
|
|
|
const w019s = result.warnings.filter(w => w.code === 'W019');
|
|
assert.strictEqual(w019s.length, 2, 'one W019 per unrecognized file');
|
|
});
|
|
|
|
test('templates/README.md exists and documents W019', () => {
|
|
const readme = fs.readFileSync(
|
|
path.join(__dirname, '../get-shit-done/templates/README.md'), 'utf-8'
|
|
);
|
|
assert.ok(readme.includes('W019'), 'README.md documents W019');
|
|
assert.ok(readme.includes('artifacts.cjs'), 'README.md references artifacts.cjs for adding new artifacts');
|
|
assert.ok(readme.includes('PROJECT.md'), 'README.md lists PROJECT.md as canonical');
|
|
});
|
|
});
|