mirror of
https://github.com/glittercowboy/get-shit-done
synced 2026-05-15 11:36:37 +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
120 lines
5.4 KiB
JavaScript
120 lines
5.4 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 - autonomous --interactive flag
|
|
*
|
|
* Validates that the autonomous workflow and command definition
|
|
* correctly document and support the --interactive flag.
|
|
*
|
|
* Closes: #1413
|
|
*/
|
|
|
|
const { test, describe } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
describe('autonomous --interactive flag (#1413)', () => {
|
|
const workflowPath = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'autonomous.md');
|
|
const commandPath = path.join(__dirname, '..', 'commands', 'gsd', 'autonomous.md');
|
|
|
|
test('command definition includes --interactive in argument-hint', () => {
|
|
const content = fs.readFileSync(commandPath, 'utf8');
|
|
assert.ok(content.includes('--interactive'), 'command should document --interactive flag');
|
|
assert.ok(content.includes('argument-hint:') && content.includes('--interactive'),
|
|
'argument-hint should include --interactive');
|
|
});
|
|
|
|
test('command definition describes interactive mode behavior', () => {
|
|
const content = fs.readFileSync(commandPath, 'utf8');
|
|
assert.ok(content.includes('discuss') && content.includes('inline'),
|
|
'command should describe discuss running inline');
|
|
assert.ok(content.includes('background'),
|
|
'command should mention background agents for plan+execute');
|
|
});
|
|
|
|
test('workflow parses --interactive flag', () => {
|
|
const content = fs.readFileSync(workflowPath, 'utf8');
|
|
assert.ok(content.includes("--interactive") && content.includes('INTERACTIVE'),
|
|
'workflow should parse --interactive into INTERACTIVE variable');
|
|
});
|
|
|
|
test('workflow uses discuss-phase skill in interactive mode', () => {
|
|
// Per #2697 the user-facing form is the hyphen invariant gsd-discuss-phase;
|
|
// the colon form was retired and is enforced absent by bug-2543 tests.
|
|
//
|
|
// Don't `.includes()` against the full file — both tokens could appear in
|
|
// unrelated sections (e.g. INTERACTIVE="" initialization + a stray
|
|
// gsd-discuss-phase mention in prose) and falsely pass. Instead, isolate
|
|
// the structural region that gates on INTERACTIVE and assert the Skill
|
|
// invocation lives inside it.
|
|
const content = fs.readFileSync(workflowPath, 'utf8');
|
|
const interactiveMarker = '**If `INTERACTIVE` is set:**';
|
|
const branchStart = content.indexOf(interactiveMarker);
|
|
assert.notStrictEqual(
|
|
branchStart, -1,
|
|
`workflow must define an explicit '${interactiveMarker}' branch`,
|
|
);
|
|
// Bound the branch by the next "**If `..." prose marker (the non-interactive
|
|
// sibling) or, failing that, the next `<step ...>`/`</step>` boundary.
|
|
const afterStart = branchStart + interactiveMarker.length;
|
|
const candidates = [
|
|
content.indexOf('**If `INTERACTIVE` is NOT set', afterStart),
|
|
content.indexOf('**If `', afterStart),
|
|
content.indexOf('</step>', afterStart),
|
|
content.indexOf('<step ', afterStart),
|
|
].filter((i) => i !== -1);
|
|
assert.ok(candidates.length > 0, 'INTERACTIVE branch must have a closing boundary');
|
|
const branchEnd = Math.min(...candidates);
|
|
const branch = content.slice(branchStart, branchEnd);
|
|
|
|
// The branch must invoke the hyphen-form Skill. Tolerate whitespace
|
|
// around `(`, `skill`, and `=` so harmless reformatting doesn't break this.
|
|
const skillCall = /Skill\(\s*skill\s*=\s*['"]gsd-discuss-phase['"]/.test(branch);
|
|
assert.ok(
|
|
skillCall,
|
|
`INTERACTIVE branch must invoke Skill(skill="gsd-discuss-phase"). Got branch:\n${branch}`,
|
|
);
|
|
});
|
|
|
|
test('workflow dispatches plan as background agent in interactive mode', () => {
|
|
const content = fs.readFileSync(workflowPath, 'utf8');
|
|
// Should have Agent() with run_in_background for plan
|
|
assert.ok(
|
|
content.includes('run_in_background') && content.includes('plan-phase'),
|
|
'workflow should dispatch plan-phase as background agent in interactive mode'
|
|
);
|
|
});
|
|
|
|
test('workflow dispatches execute as background agent in interactive mode', () => {
|
|
const content = fs.readFileSync(workflowPath, 'utf8');
|
|
assert.ok(
|
|
content.includes('run_in_background') && content.includes('execute-phase'),
|
|
'workflow should dispatch execute-phase as background agent in interactive mode'
|
|
);
|
|
});
|
|
|
|
test('workflow describes pipeline parallelism in interactive mode', () => {
|
|
const content = fs.readFileSync(workflowPath, 'utf8');
|
|
assert.ok(
|
|
content.includes('pipeline parallelism') || content.includes('Phase N+1'),
|
|
'workflow should describe overlapping discuss/execute between phases'
|
|
);
|
|
});
|
|
|
|
test('success criteria include --interactive requirements', () => {
|
|
const content = fs.readFileSync(workflowPath, 'utf8');
|
|
const criteriaMatch = content.match(/<success_criteria>([\s\S]*?)<\/success_criteria>/);
|
|
const criteria = criteriaMatch ? criteriaMatch[1] : '';
|
|
assert.ok(criteria.includes('--interactive'),
|
|
'success criteria should include --interactive requirements');
|
|
assert.ok(criteria.includes('discuss inline'),
|
|
'success criteria should mention discuss inline');
|
|
assert.ok(criteria.includes('background agents'),
|
|
'success criteria should mention background agents');
|
|
});
|
|
});
|