* 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
242 lines
8.3 KiB
JavaScript
242 lines
8.3 KiB
JavaScript
'use strict';
|
|
|
|
// 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 #2310: plan-phase chunked mode + filesystem fallback.
|
|
*
|
|
* Context: on Windows (and occasionally other platforms), gsd-planner's
|
|
* Task() call may never return even though the subagent finished writing all
|
|
* PLAN.md files to disk. The orchestrator hangs indefinitely. Two mitigations:
|
|
*
|
|
* 1. Filesystem fallback (steps 9a, 11a): if the Task() return lacks the
|
|
* expected marker but PLAN.md files exist on disk, surface a recoverable
|
|
* prompt instead of hanging/failing silently.
|
|
*
|
|
* 2. Chunked mode (step 8.5): --chunked flag / workflow.plan_chunked config
|
|
* splits the single long planner Task into (a) a short outline Task and
|
|
* (b) N short single-plan Tasks. Each Task is shorter-lived, the
|
|
* orchestrator can commit work incrementally, and a hang loses only one
|
|
* plan instead of the entire phase.
|
|
*/
|
|
|
|
const { test, describe } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const PLAN_PHASE = path.join(
|
|
__dirname, '..', 'get-shit-done', 'workflows', 'plan-phase.md'
|
|
);
|
|
|
|
const PLANNER_AGENT = path.join(__dirname, '..', 'agents', 'gsd-planner.md');
|
|
const PLANNER_CHUNKED_REF = path.join(__dirname, '..', 'get-shit-done', 'references', 'planner-chunked.md');
|
|
const CONFIG_SCHEMA = path.join(__dirname, '..', 'get-shit-done', 'bin', 'lib', 'config-schema.cjs');
|
|
const CONFIGURATION_MD = path.join(__dirname, '..', 'docs', 'CONFIGURATION.md');
|
|
|
|
describe('plan-phase.md — filesystem fallback (#2310)', () => {
|
|
const content = fs.readFileSync(PLAN_PHASE, 'utf-8');
|
|
|
|
test('step 9 checks PLAN.md count on disk when planner return lacks completion marker', () => {
|
|
assert.ok(
|
|
content.includes('DISK_PLANS=$(ls "${PHASE_DIR}"/*-PLAN.md'),
|
|
'step 9a must check disk for PLAN.md files via DISK_PLANS variable'
|
|
);
|
|
});
|
|
|
|
test('step 9a fallback section exists', () => {
|
|
assert.ok(
|
|
content.includes('## 9a. Filesystem Fallback'),
|
|
'plan-phase.md must have a ## 9a. Filesystem Fallback section for planner hang recovery'
|
|
);
|
|
});
|
|
|
|
test('step 9a fallback offers Accept plans option', () => {
|
|
assert.ok(
|
|
content.includes('Accept plans'),
|
|
'step 9a must offer "Accept plans" as a recovery option'
|
|
);
|
|
});
|
|
|
|
test('step 9a fallback offers Retry planner option', () => {
|
|
assert.ok(
|
|
content.includes('Retry planner'),
|
|
'step 9a must offer "Retry planner" as a recovery option'
|
|
);
|
|
});
|
|
|
|
test('step 11 has filesystem fallback section', () => {
|
|
assert.ok(
|
|
content.includes('## 11a. Filesystem Fallback'),
|
|
'plan-phase.md must have a ## 11a. Filesystem Fallback section for checker hang recovery'
|
|
);
|
|
});
|
|
|
|
test('step 11a fallback offers Accept verification option', () => {
|
|
assert.ok(
|
|
content.includes('Accept verification'),
|
|
'step 11a must offer "Accept verification" as a recovery option'
|
|
);
|
|
});
|
|
|
|
test('step 11a fallback offers Retry checker option', () => {
|
|
assert.ok(
|
|
content.includes('Retry checker'),
|
|
'step 11a must offer "Retry checker" as a recovery option'
|
|
);
|
|
});
|
|
|
|
test('step 9 routes to step 9a when no recognized marker found', () => {
|
|
assert.ok(
|
|
content.includes('step 9a') || content.includes('9a.'),
|
|
'step 9 handle-return must reference the filesystem fallback path (step 9a)'
|
|
);
|
|
});
|
|
|
|
test('step 11 routes to step 11a when no recognized marker found', () => {
|
|
assert.ok(
|
|
content.includes('step 11a') || content.includes('11a.'),
|
|
'step 11 handle-return must reference the filesystem fallback path (step 11a)'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('plan-phase.md — chunked mode flag and config (#2310)', () => {
|
|
const content = fs.readFileSync(PLAN_PHASE, 'utf-8');
|
|
|
|
test('step 2 parses --chunked flag', () => {
|
|
assert.ok(
|
|
content.includes('--chunked'),
|
|
'step 2 must parse --chunked flag from $ARGUMENTS'
|
|
);
|
|
});
|
|
|
|
test('step 2 reads workflow.plan_chunked config', () => {
|
|
assert.ok(
|
|
content.includes('workflow.plan_chunked'),
|
|
'step 2 must read workflow.plan_chunked config key'
|
|
);
|
|
});
|
|
|
|
test('step 2 sets CHUNKED_MODE variable', () => {
|
|
assert.ok(
|
|
content.includes('CHUNKED_MODE'),
|
|
'step 2 must set CHUNKED_MODE from flag or config'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('plan-phase.md — chunked mode implementation (#2310)', () => {
|
|
const content = fs.readFileSync(PLAN_PHASE, 'utf-8');
|
|
|
|
test('step 8.5 chunked planning section exists', () => {
|
|
assert.ok(
|
|
content.includes('## 8.5.'),
|
|
'plan-phase.md must have a step 8.5 section for chunked planning mode'
|
|
);
|
|
});
|
|
|
|
test('chunked mode produces PLAN-OUTLINE.md', () => {
|
|
assert.ok(
|
|
content.includes('PLAN-OUTLINE.md'),
|
|
'chunked mode outline step must produce a *-PLAN-OUTLINE.md file'
|
|
);
|
|
});
|
|
|
|
test('chunked outline step uses outline-only mode', () => {
|
|
assert.ok(
|
|
content.includes('outline-only'),
|
|
'chunked step 8.5.1 must spawn the planner in outline-only mode'
|
|
);
|
|
});
|
|
|
|
test('chunked per-plan step uses single-plan mode', () => {
|
|
assert.ok(
|
|
content.includes('single-plan'),
|
|
'chunked step 8.5.2 must spawn the planner in single-plan mode for each plan'
|
|
);
|
|
});
|
|
|
|
test('chunked mode checks for existing outline to enable resume', () => {
|
|
// The resume check skips the outline Task if PLAN-OUTLINE.md already exists
|
|
assert.ok(
|
|
content.includes('PLAN-OUTLINE.md') && content.includes('already exists'),
|
|
'chunked mode must detect existing PLAN-OUTLINE.md and skip outline generation (resume safety)'
|
|
);
|
|
});
|
|
|
|
test('chunked mode commits each plan individually', () => {
|
|
assert.ok(
|
|
content.includes('chunked'),
|
|
'chunked mode must commit each individual plan for crash resilience'
|
|
);
|
|
});
|
|
|
|
test('step 8 routes to chunked path when CHUNKED_MODE is true', () => {
|
|
assert.ok(
|
|
content.includes('CHUNKED_MODE') && content.includes('8.5'),
|
|
'step 8 must route to step 8.5 when CHUNKED_MODE is true'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('gsd-planner.md — references planner-chunked.md (#2310)', () => {
|
|
const plannerContent = fs.readFileSync(PLANNER_AGENT, 'utf-8');
|
|
|
|
test('gsd-planner.md references planner-chunked.md for chunked return formats', () => {
|
|
assert.ok(
|
|
plannerContent.includes('planner-chunked.md'),
|
|
'gsd-planner.md must reference planner-chunked.md for ## OUTLINE COMPLETE / ## PLAN COMPLETE formats'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('planner-chunked.md — chunked return formats (#2310)', () => {
|
|
const content = fs.readFileSync(PLANNER_CHUNKED_REF, 'utf-8');
|
|
|
|
test('planner-chunked.md defines OUTLINE COMPLETE structured return', () => {
|
|
assert.ok(
|
|
content.includes('## OUTLINE COMPLETE'),
|
|
'planner-chunked.md must define ## OUTLINE COMPLETE return format for outline-only mode'
|
|
);
|
|
});
|
|
|
|
test('planner-chunked.md defines PLAN COMPLETE structured return for single-plan mode', () => {
|
|
assert.ok(
|
|
content.includes('## PLAN COMPLETE'),
|
|
'planner-chunked.md must define ## PLAN COMPLETE return format for single-plan mode'
|
|
);
|
|
});
|
|
|
|
test('planner-chunked.md describes resume behaviour', () => {
|
|
assert.ok(
|
|
content.includes('Resume') || content.includes('resume'),
|
|
'planner-chunked.md must describe resume behaviour for interrupted chunked runs'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('config-schema.cjs — workflow.plan_chunked key (#2310)', () => {
|
|
test('VALID_CONFIG_KEYS includes workflow.plan_chunked', () => {
|
|
const { VALID_CONFIG_KEYS } = require(CONFIG_SCHEMA);
|
|
assert.ok(
|
|
VALID_CONFIG_KEYS.has('workflow.plan_chunked'),
|
|
'config-schema.cjs VALID_CONFIG_KEYS must include workflow.plan_chunked'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('docs/CONFIGURATION.md — workflow.plan_chunked documented (#2310)', () => {
|
|
const content = fs.readFileSync(CONFIGURATION_MD, 'utf-8');
|
|
|
|
test('CONFIGURATION.md documents workflow.plan_chunked', () => {
|
|
assert.ok(
|
|
content.includes('`workflow.plan_chunked`'),
|
|
'docs/CONFIGURATION.md must document workflow.plan_chunked'
|
|
);
|
|
});
|
|
});
|