* 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
155 lines
6.2 KiB
JavaScript
155 lines
6.2 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.
|
|
|
|
/**
|
|
* GSD Tools Tests - discuss-phase power user mode
|
|
*
|
|
* Validates that the --power flag workflow documentation is present and
|
|
* correctly describes the bulk question generation/answering flow.
|
|
*
|
|
* Closes: #1513
|
|
*/
|
|
|
|
const { test, describe } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
describe('discuss-phase power user mode (#1513)', () => {
|
|
const commandPath = path.join(__dirname, '..', 'commands', 'gsd', 'discuss-phase.md');
|
|
const workflowPath = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'discuss-phase.md');
|
|
const powerWorkflowPath = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'discuss-phase-power.md');
|
|
|
|
describe('command file (discuss-phase.md)', () => {
|
|
test('mentions --power flag in argument-hint or description', () => {
|
|
const content = fs.readFileSync(commandPath, 'utf8');
|
|
assert.ok(
|
|
content.includes('--power'),
|
|
'commands/gsd/discuss-phase.md should document the --power flag'
|
|
);
|
|
});
|
|
|
|
test('references the power workflow file', () => {
|
|
const content = fs.readFileSync(commandPath, 'utf8');
|
|
assert.ok(
|
|
content.includes('discuss-phase-power'),
|
|
'command file should reference discuss-phase-power workflow'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('main workflow file (discuss-phase.md)', () => {
|
|
test('has power_user_mode section or references discuss-phase-power.md', () => {
|
|
// After #2551, the power dispatch lives in discuss-phase/modes/power.md and
|
|
// the parent references it via the dispatch table.
|
|
const parentContent = fs.readFileSync(workflowPath, 'utf8');
|
|
const powerModePath = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'discuss-phase', 'modes', 'power.md');
|
|
const powerMode = fs.existsSync(powerModePath) ? fs.readFileSync(powerModePath, 'utf8') : '';
|
|
const content = parentContent + '\n' + powerMode;
|
|
const hasPowerSection = content.includes('power_user_mode') || content.includes('power user mode') || content.includes('modes/power.md');
|
|
const hasReference = content.includes('discuss-phase-power');
|
|
assert.ok(
|
|
hasPowerSection || hasReference,
|
|
'discuss-phase.md (or modes/power.md after #2551) should have power_user_mode section or reference discuss-phase-power.md'
|
|
);
|
|
});
|
|
|
|
test('describes --power flag routing', () => {
|
|
const content = fs.readFileSync(workflowPath, 'utf8');
|
|
assert.ok(
|
|
content.includes('--power'),
|
|
'discuss-phase.md should describe --power flag handling'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('power workflow file (discuss-phase-power.md)', () => {
|
|
test('file exists', () => {
|
|
assert.ok(
|
|
fs.existsSync(powerWorkflowPath),
|
|
'get-shit-done/workflows/discuss-phase-power.md should exist'
|
|
);
|
|
});
|
|
|
|
test('describes the generate step', () => {
|
|
const content = fs.readFileSync(powerWorkflowPath, 'utf8');
|
|
assert.ok(
|
|
content.includes('generate') || content.includes('Generate'),
|
|
'power workflow should describe generating questions'
|
|
);
|
|
});
|
|
|
|
test('describes the wait/notify step', () => {
|
|
const content = fs.readFileSync(powerWorkflowPath, 'utf8');
|
|
const hasWait = content.includes('wait') || content.includes('Wait');
|
|
const hasNotify = content.includes('notify') || content.includes('Notify') || content.includes('notif');
|
|
assert.ok(
|
|
hasWait || hasNotify,
|
|
'power workflow should describe the wait/notify step after generating files'
|
|
);
|
|
});
|
|
|
|
test('describes the refresh step', () => {
|
|
const content = fs.readFileSync(powerWorkflowPath, 'utf8');
|
|
assert.ok(
|
|
content.includes('refresh') || content.includes('Refresh'),
|
|
'power workflow should describe the refresh step for processing answers'
|
|
);
|
|
});
|
|
|
|
test('describes the finalize step', () => {
|
|
const content = fs.readFileSync(powerWorkflowPath, 'utf8');
|
|
assert.ok(
|
|
content.includes('finalize') || content.includes('Finalize'),
|
|
'power workflow should describe the finalize step for generating CONTEXT.md'
|
|
);
|
|
});
|
|
|
|
test('QUESTIONS.json structure has required fields', () => {
|
|
const content = fs.readFileSync(powerWorkflowPath, 'utf8');
|
|
assert.ok(content.includes('QUESTIONS.json'), 'should mention QUESTIONS.json file');
|
|
assert.ok(content.includes('"phase"'), 'JSON structure should include phase field');
|
|
assert.ok(content.includes('"stats"'), 'JSON structure should include stats field');
|
|
assert.ok(content.includes('"sections"'), 'JSON structure should include sections field');
|
|
assert.ok(
|
|
content.includes('"id"') && content.includes('"title"'),
|
|
'JSON structure should include question id and title fields'
|
|
);
|
|
assert.ok(
|
|
content.includes('"options"'),
|
|
'JSON structure should include options array'
|
|
);
|
|
assert.ok(
|
|
content.includes('"answer"'),
|
|
'JSON structure should include answer field'
|
|
);
|
|
assert.ok(
|
|
content.includes('"status"'),
|
|
'JSON structure should include status field'
|
|
);
|
|
});
|
|
|
|
test('describes HTML generation step', () => {
|
|
const content = fs.readFileSync(powerWorkflowPath, 'utf8');
|
|
assert.ok(
|
|
content.includes('QUESTIONS.html') || content.includes('.html'),
|
|
'power workflow should describe generating the HTML companion file'
|
|
);
|
|
assert.ok(
|
|
content.includes('HTML') || content.includes('html'),
|
|
'power workflow should mention HTML output'
|
|
);
|
|
});
|
|
|
|
test('QUESTIONS.json file naming uses padded phase number', () => {
|
|
const content = fs.readFileSync(powerWorkflowPath, 'utf8');
|
|
assert.ok(
|
|
content.includes('padded_phase') || content.includes('{padded_phase}') || content.includes('QUESTIONS.json'),
|
|
'power workflow should describe file naming with padded phase number'
|
|
);
|
|
});
|
|
});
|
|
});
|