* 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
130 lines
4.8 KiB
JavaScript
130 lines
4.8 KiB
JavaScript
// allow-test-rule: pending-migration-to-typed-ir [#2974]
|
|
// Tracked in #2974 for migration to typed-IR assertions per CONTRIBUTING.md
|
|
// "Prohibited: Raw Text Matching on Test Outputs". Per-file review may
|
|
// reclassify some entries as source-text-is-the-product during migration.
|
|
|
|
/**
|
|
* Validates the gates taxonomy reference document (#1715).
|
|
*
|
|
* Ensures the reference file exists, defines all 4 canonical gate types,
|
|
* includes the gate matrix table, and is cross-referenced from workflows.
|
|
*/
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const GATES_REF = path.join(ROOT, 'get-shit-done', 'references', 'gates.md');
|
|
|
|
describe('gates taxonomy (#1715)', () => {
|
|
test('reference file exists', () => {
|
|
assert.ok(
|
|
fs.existsSync(GATES_REF),
|
|
'get-shit-done/references/gates.md must exist'
|
|
);
|
|
});
|
|
|
|
test('defines all 4 canonical gate types', () => {
|
|
const content = fs.readFileSync(GATES_REF, 'utf-8');
|
|
const gateTypes = ['Pre-flight Gate', 'Revision Gate', 'Escalation Gate', 'Abort Gate'];
|
|
|
|
for (const gate of gateTypes) {
|
|
assert.ok(
|
|
content.includes(`### ${gate}`),
|
|
`gates.md must define "${gate}" as an h3 heading`
|
|
);
|
|
}
|
|
});
|
|
|
|
test('each gate type has Purpose, Behavior, Recovery, and Examples', () => {
|
|
const content = fs.readFileSync(GATES_REF, 'utf-8');
|
|
const sections = content.split('### ').slice(1); // split by h3, drop preamble
|
|
|
|
for (const section of sections) {
|
|
const name = section.split('\n')[0].trim();
|
|
// Only check gate type sections (not other h3s if any)
|
|
if (!name.endsWith('Gate')) continue;
|
|
|
|
for (const field of ['**Purpose:**', '**Behavior:**', '**Recovery:**', '**Examples:**']) {
|
|
assert.ok(
|
|
section.includes(field),
|
|
`Gate "${name}" must include ${field}`
|
|
);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('contains Gate Matrix table', () => {
|
|
const content = fs.readFileSync(GATES_REF, 'utf-8');
|
|
assert.ok(
|
|
content.includes('## Gate Matrix'),
|
|
'gates.md must include a "Gate Matrix" section'
|
|
);
|
|
// Verify table header row
|
|
assert.ok(
|
|
content.includes('| Workflow |'),
|
|
'Gate Matrix must contain a table with Workflow column'
|
|
);
|
|
// Verify key workflow rows exist
|
|
assert.ok(content.includes('plan-phase'), 'Gate Matrix must reference plan-phase');
|
|
assert.ok(content.includes('execute-phase'), 'Gate Matrix must reference execute-phase');
|
|
assert.ok(content.includes('verify-work'), 'Gate Matrix must reference verify-work');
|
|
assert.ok(content.includes('| next |'), 'Gate Matrix must reference next workflow');
|
|
});
|
|
|
|
test('plan-phase.md references gates.md', () => {
|
|
const planPhase = path.join(ROOT, 'get-shit-done', 'workflows', 'plan-phase.md');
|
|
const content = fs.readFileSync(planPhase, 'utf-8');
|
|
assert.ok(
|
|
content.includes('references/gates.md'),
|
|
'plan-phase.md must reference gates.md in its required_reading block'
|
|
);
|
|
});
|
|
|
|
test('execute-phase.md references gates.md', () => {
|
|
const execPhase = path.join(ROOT, 'get-shit-done', 'workflows', 'execute-phase.md');
|
|
const content = fs.readFileSync(execPhase, 'utf-8');
|
|
assert.ok(
|
|
content.includes('references/gates.md'),
|
|
'execute-phase.md must reference gates.md in its required_reading block'
|
|
);
|
|
});
|
|
|
|
test('gsd-plan-checker.md references gates.md in required_reading block', () => {
|
|
const planChecker = path.join(ROOT, 'agents', 'gsd-plan-checker.md');
|
|
const content = fs.readFileSync(planChecker, 'utf-8');
|
|
const match = content.match(/<required_reading>\r?\n([\s\S]*?)\r?\n<\/required_reading>/);
|
|
assert.ok(
|
|
match,
|
|
'gsd-plan-checker.md must have a <required_reading> block'
|
|
);
|
|
assert.ok(
|
|
match[1].includes('references/gates.md'),
|
|
'gsd-plan-checker.md must reference gates.md inside <required_reading>'
|
|
);
|
|
});
|
|
|
|
test('gsd-verifier.md references gates.md in required_reading block', () => {
|
|
const verifier = path.join(ROOT, 'agents', 'gsd-verifier.md');
|
|
const content = fs.readFileSync(verifier, 'utf-8');
|
|
const match = content.match(/<required_reading>\r?\n([\s\S]*?)\r?\n<\/required_reading>/);
|
|
assert.ok(
|
|
match,
|
|
'gsd-verifier.md must have a <required_reading> block'
|
|
);
|
|
assert.ok(
|
|
match[1].includes('references/gates.md'),
|
|
'gsd-verifier.md must reference gates.md inside <required_reading>'
|
|
);
|
|
});
|
|
|
|
test('Revision Gate recovery mentions stall detection', () => {
|
|
const content = fs.readFileSync(GATES_REF, 'utf-8');
|
|
assert.ok(
|
|
content.includes('stall detection'),
|
|
'Revision Gate recovery must mention stall detection (early escalation when issues stop decreasing)'
|
|
);
|
|
});
|
|
});
|