Files
get-shit-done/tests/thinking-partner.test.cjs
Tom Boucher 918f987a19 feat(#2982): extend no-source-grep lint to catch var-binding readFileSync.includes() (#2985)
* 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
2026-05-01 19:50:10 -04:00

211 lines
8.7 KiB
JavaScript

// allow-test-rule: source-text-is-the-product
// Reads .md/.json/.yml product files whose deployed text IS what the
// runtime loads — testing text content tests the deployed contract.
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
const GSD_ROOT = path.join(__dirname, '..', 'get-shit-done');
describe('Thinking Partner Integration (#1726)', () => {
// Reference doc tests
describe('Reference document', () => {
const refPath = path.join(GSD_ROOT, 'references', 'thinking-partner.md');
test('thinking-partner.md exists', () => {
assert.ok(fs.existsSync(refPath), 'references/thinking-partner.md should exist');
});
test('documents all 3 integration points', () => {
const content = fs.readFileSync(refPath, 'utf-8');
assert.ok(content.includes('### 1. Discuss Phase'), 'should document Discuss Phase integration');
assert.ok(content.includes('### 2. Plan Phase'), 'should document Plan Phase integration');
assert.ok(content.includes('### 3. Explore'), 'should document Explore integration');
});
test('documents keyword tradeoff signals', () => {
const content = fs.readFileSync(refPath, 'utf-8');
assert.ok(content.includes('"or"'), 'should list "or" as keyword signal');
assert.ok(content.includes('"versus"'), 'should list "versus" as keyword signal');
assert.ok(content.includes('"tradeoff"'), 'should list "tradeoff" as keyword signal');
assert.ok(content.includes('"pros and cons"'), 'should list "pros and cons" as keyword signal');
assert.ok(content.includes('"torn between"'), 'should list "torn between" as keyword signal');
});
test('documents structural tradeoff signals', () => {
const content = fs.readFileSync(refPath, 'utf-8');
assert.ok(content.includes('2+ competing options'), 'should list competing options signal');
assert.ok(content.includes('which is better'), 'should list "which is better" signal');
assert.ok(content.includes('reverses a previous decision'), 'should list decision reversal signal');
});
test('documents when NOT to activate', () => {
const content = fs.readFileSync(refPath, 'utf-8');
assert.ok(content.includes('When NOT to activate'), 'should document non-activation cases');
assert.ok(content.includes('already made a clear choice'), 'should mention clear choices');
});
test('feature is opt-in with default false', () => {
const content = fs.readFileSync(refPath, 'utf-8');
assert.ok(content.includes('Default: `false`'), 'should document default as false');
assert.ok(content.includes('opt-in'), 'should describe feature as opt-in');
});
test('documents design principles', () => {
const content = fs.readFileSync(refPath, 'utf-8');
assert.ok(content.includes('Lightweight'), 'should list Lightweight principle');
assert.ok(content.includes('Opt-in'), 'should list Opt-in principle');
assert.ok(content.includes('Skippable'), 'should list Skippable principle');
assert.ok(content.includes('Brief'), 'should list Brief principle');
assert.ok(content.includes('Aligned'), 'should list Aligned principle');
});
test('explore integration deferred to #1729', () => {
const content = fs.readFileSync(refPath, 'utf-8');
assert.ok(content.includes('#1729'), 'should reference issue #1729 for explore integration');
});
});
// Config tests
describe('Config integration', () => {
test('config-set accepts features.thinking_partner', () => {
// Exercises VALID_CONFIG_KEYS membership and KNOWN_TOP_LEVEL acceptance in one call.
// Replaces two source-grep tests that read config-schema.cjs and core.cjs (see #2691).
const tmpDir = createTempProject();
try {
const setResult = runGsdTools('config-set features.thinking_partner true', tmpDir);
assert.ok(setResult.success, `config-set should accept features.thinking_partner: ${setResult.error}`);
const configPath = path.join(tmpDir, '.planning', 'config.json');
assert.ok(fs.existsSync(configPath), 'config-set should create .planning/config.json');
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
assert.strictEqual(
config.features?.thinking_partner,
true,
'config-set should persist features.thinking_partner=true'
);
} finally {
cleanup(tmpDir);
}
});
});
// Workflow integration tests
// After #2551 progressive-disclosure refactor, the thinking-partner block
// moved into the per-mode files (default.md, advisor.md) since the prompt
// is mode-specific (only fires inside discuss_areas, after a user answer).
describe('Discuss-phase integration', () => {
function readDiscussFamily() {
const candidates = [
path.join(GSD_ROOT, 'workflows', 'discuss-phase.md'),
path.join(GSD_ROOT, 'workflows', 'discuss-phase', 'modes', 'default.md'),
path.join(GSD_ROOT, 'workflows', 'discuss-phase', 'modes', 'advisor.md'),
];
return candidates
.filter(p => fs.existsSync(p))
.map(p => fs.readFileSync(p, 'utf-8'))
.join('\n');
}
test('discuss-phase.md contains thinking partner conditional block', () => {
const content = readDiscussFamily();
assert.ok(
content.includes('Thinking partner (conditional)'),
'discuss-phase workflow family should contain thinking partner conditional block'
);
});
test('discuss-phase references features.thinking_partner config', () => {
const content = readDiscussFamily();
assert.ok(
content.includes('features.thinking_partner'),
'discuss-phase workflow family should reference the config key'
);
});
test('discuss-phase references thinking-partner.md for signal list', () => {
const content = readDiscussFamily();
assert.ok(
content.includes('references/thinking-partner.md'),
'discuss-phase workflow family should reference the signal list doc'
);
});
test('discuss-phase offers skip option', () => {
const content = readDiscussFamily();
assert.ok(
content.includes('No, decision made'),
'discuss-phase workflow family should offer a skip/decline option'
);
});
});
describe('Plan-phase integration', () => {
test('plan-phase.md contains thinking partner conditional block', () => {
const content = fs.readFileSync(
path.join(GSD_ROOT, 'workflows', 'plan-phase.md'),
'utf-8'
);
assert.ok(
content.includes('Thinking partner for architectural tradeoffs (conditional)'),
'plan-phase.md should contain thinking partner conditional block'
);
});
test('plan-phase references features.thinking_partner config', () => {
const content = fs.readFileSync(
path.join(GSD_ROOT, 'workflows', 'plan-phase.md'),
'utf-8'
);
assert.ok(
content.includes('features.thinking_partner'),
'plan-phase.md should reference the config key'
);
});
test('plan-phase scans for architectural tradeoff keywords', () => {
const content = fs.readFileSync(
path.join(GSD_ROOT, 'workflows', 'plan-phase.md'),
'utf-8'
);
assert.ok(
content.includes('"architecture"'),
'plan-phase.md should list architecture as a keyword'
);
assert.ok(
content.includes('"approach"'),
'plan-phase.md should list approach as a keyword'
);
assert.ok(
content.includes('"alternative"'),
'plan-phase.md should list alternative as a keyword'
);
});
test('plan-phase offers skip option', () => {
const content = fs.readFileSync(
path.join(GSD_ROOT, 'workflows', 'plan-phase.md'),
'utf-8'
);
assert.ok(
content.includes("No, I'll decide"),
'plan-phase.md should offer a skip/decline option'
);
});
test('plan-phase block is between step 11 and step 12', () => {
const content = fs.readFileSync(
path.join(GSD_ROOT, 'workflows', 'plan-phase.md'),
'utf-8'
);
const step11Idx = content.indexOf('## 11. Handle Checker Return');
const thinkingIdx = content.indexOf('Thinking partner for architectural tradeoffs');
const step12Idx = content.indexOf('## 12. Revision Loop');
assert.ok(step11Idx < thinkingIdx, 'thinking partner block should come after step 11');
assert.ok(thinkingIdx < step12Idx, 'thinking partner block should come before step 12');
});
});
});