mirror of
https://github.com/glittercowboy/get-shit-done
synced 2026-05-14 02:56:38 +02:00
* 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
127 lines
4.7 KiB
JavaScript
127 lines
4.7 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.
|
|
|
|
/**
|
|
* Tests for workflow.inline_plan_threshold config key and routing logic (#1979).
|
|
*
|
|
* Verifies:
|
|
* 1. The config key is accepted by config-set (VALID_CONFIG_KEYS contains it)
|
|
* 2. The key is documented in planning-config.md
|
|
* 3. The execute-plan.md routing instruction uses the correct grep pattern
|
|
* (matches <task at any indentation, since PLAN.md templates differ)
|
|
* 4. The workflow guards threshold=0 to disable inline routing
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { test, describe, beforeEach, afterEach } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
|
|
|
|
const repoRoot = path.resolve(__dirname, '..');
|
|
const executePlanPath = path.join(repoRoot, 'get-shit-done', 'workflows', 'execute-plan.md');
|
|
const planningConfigPath = path.join(repoRoot, 'get-shit-done', 'references', 'planning-config.md');
|
|
|
|
describe('inline_plan_threshold config key (#1979)', () => {
|
|
let tmpDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('config-set accepts workflow.inline_plan_threshold', () => {
|
|
const result = runGsdTools('config-set workflow.inline_plan_threshold 3', tmpDir);
|
|
assert.ok(result.success, `config-set should accept workflow.inline_plan_threshold: ${result.error}`);
|
|
});
|
|
|
|
test('config-set accepts threshold=0 to disable inline routing', () => {
|
|
const result = runGsdTools('config-set workflow.inline_plan_threshold 0', tmpDir);
|
|
assert.ok(result.success, `config-set should accept 0: ${result.error}`);
|
|
});
|
|
|
|
test('planning-config.md documents workflow.inline_plan_threshold', () => {
|
|
const content = fs.readFileSync(planningConfigPath, 'utf-8');
|
|
assert.match(
|
|
content,
|
|
/workflow\.inline_plan_threshold/,
|
|
'planning-config.md must document workflow.inline_plan_threshold'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('execute-plan.md routing instruction (#1979)', () => {
|
|
test('grep pattern matches <task at any indentation level', () => {
|
|
const content = fs.readFileSync(executePlanPath, 'utf-8');
|
|
|
|
// The new pattern should use \s* for leading whitespace, not ^ anchor alone
|
|
// Must match both "<task type=" (unindented) and " <task type=" (indented)
|
|
assert.match(
|
|
content,
|
|
/TASK_COUNT=\$\(grep -cE '\^\\s\*<task/,
|
|
'grep pattern must allow any leading whitespace before <task'
|
|
);
|
|
});
|
|
|
|
test('inline routing is guarded by INLINE_THRESHOLD > 0', () => {
|
|
const content = fs.readFileSync(executePlanPath, 'utf-8');
|
|
assert.match(
|
|
content,
|
|
/INLINE_THRESHOLD\s*>\s*0.*TASK_COUNT\s*<=\s*INLINE_THRESHOLD/s,
|
|
'inline routing must be guarded by INLINE_THRESHOLD > 0 so threshold=0 disables it'
|
|
);
|
|
});
|
|
|
|
test('grep pattern does NOT use ^<task alone (would miss indented tasks)', () => {
|
|
const content = fs.readFileSync(executePlanPath, 'utf-8');
|
|
// The old buggy pattern: grep -c "^<task" with no whitespace allowance
|
|
const buggyPattern = /grep -c "\^<task"/;
|
|
assert.doesNotMatch(
|
|
content,
|
|
buggyPattern,
|
|
'must not use the buggy "^<task" pattern which misses indented tasks'
|
|
);
|
|
});
|
|
|
|
test('grep pattern matches real-world indented task formats', () => {
|
|
// Simulate how the grep pattern would behave against sample PLAN.md content
|
|
// Extract the pattern from execute-plan.md
|
|
const content = fs.readFileSync(executePlanPath, 'utf-8');
|
|
const patternMatch = content.match(/TASK_COUNT=\$\(grep -cE '([^']+)'/);
|
|
assert.ok(patternMatch, 'must find TASK_COUNT grep pattern');
|
|
|
|
const regexSource = patternMatch[1].replace(/\\s/g, '\\s').replace(/\[\[:space:\]>\]/, '[\\s>]');
|
|
const re = new RegExp(regexSource, 'gm');
|
|
|
|
// Test cases: should match all of these as single tasks
|
|
const samples = [
|
|
'<task type="auto">',
|
|
' <task type="auto">',
|
|
' <task type="checkpoint:decision">',
|
|
'\t<task type="auto">',
|
|
];
|
|
for (const sample of samples) {
|
|
const matches = sample.match(re);
|
|
assert.ok(matches && matches.length > 0, `Pattern must match: ${JSON.stringify(sample)}`);
|
|
}
|
|
|
|
// Non-task lines should not match
|
|
const nonMatches = [
|
|
'<tasks>',
|
|
'</task>',
|
|
'// <task comment',
|
|
];
|
|
for (const sample of nonMatches) {
|
|
const matches = sample.match(re);
|
|
assert.ok(!matches || matches.length === 0, `Pattern must NOT match: ${JSON.stringify(sample)}`);
|
|
}
|
|
});
|
|
});
|