Files
msd-core/tests/enh-2433-todo-phase-linking.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

87 lines
4.0 KiB
JavaScript

'use strict';
// 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.
/**
* Tests for gsd-new-milestone todo-to-phase linking (#2433).
* Verifies the workflow text contains the correct linking and auto-close steps.
*/
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const ROOT = path.resolve(__dirname, '..');
const NEW_MILESTONE = fs.readFileSync(
path.join(ROOT, 'get-shit-done/workflows/new-milestone.md'), 'utf-8'
);
const EXECUTE_PHASE = fs.readFileSync(
path.join(ROOT, 'get-shit-done/workflows/execute-phase.md'), 'utf-8'
);
test('new-milestone.md: step 10.5 links pending todos to roadmap phases', () => {
assert.ok(NEW_MILESTONE.includes('10.5'), 'step 10.5 should exist');
assert.ok(NEW_MILESTONE.includes('resolves_phase'), 'should reference resolves_phase field');
assert.ok(NEW_MILESTONE.includes('.planning/todos/pending'), 'should scan pending todos directory');
});
test('new-milestone.md: todo linking runs after roadmap commit', () => {
const roadmapCommitIdx = NEW_MILESTONE.indexOf('docs: create milestone v[X.Y] roadmap');
const step105Idx = NEW_MILESTONE.indexOf('10.5. Link Pending Todos');
const step11Idx = NEW_MILESTONE.indexOf('## 11. Done');
assert.ok(roadmapCommitIdx < step105Idx, 'step 10.5 should come after roadmap commit');
assert.ok(step105Idx < step11Idx, 'step 10.5 should come before step 11');
});
test('new-milestone.md: todo linking is best-effort and leaves unmatched todos unmodified', () => {
assert.ok(NEW_MILESTONE.includes('best-effort'), 'should describe best-effort matching');
assert.ok(NEW_MILESTONE.includes('unmatched'), 'should mention leaving unmatched todos alone');
assert.ok(NEW_MILESTONE.includes('confident match'), 'should gate on confident match');
});
test('new-milestone.md: step 10.5 commits tagged todos', () => {
assert.ok(NEW_MILESTONE.includes('gsd-sdk query commit'), 'should commit tagged todos');
assert.ok(NEW_MILESTONE.includes('resolves_phase after milestone'), 'commit message should mention resolves_phase');
});
test('new-milestone.md: success_criteria includes todo linking', () => {
assert.ok(NEW_MILESTONE.includes('resolves_phase: N'), 'success_criteria should mention resolves_phase tagging');
});
test('execute-phase.md: close_phase_todos step exists', () => {
assert.ok(EXECUTE_PHASE.includes('close_phase_todos'), 'close_phase_todos step should exist');
assert.ok(EXECUTE_PHASE.includes('resolves_phase'), 'should check resolves_phase in todos');
});
test('execute-phase.md: auto-close moves todos to completed directory', () => {
assert.ok(EXECUTE_PHASE.includes('.planning/todos/completed'), 'should move to completed dir');
assert.ok(EXECUTE_PHASE.includes('.planning/todos/pending'), 'should scan pending dir');
assert.ok(EXECUTE_PHASE.includes('mv "$TODO_FILE" "$COMPLETED_DIR/"'), 'should use mv to move files');
});
test('execute-phase.md: close_phase_todos runs after update_roadmap', () => {
const updateRoadmapIdx = EXECUTE_PHASE.indexOf('name="update_roadmap"');
const closeTodosIdx = EXECUTE_PHASE.indexOf('name="close_phase_todos"');
assert.ok(updateRoadmapIdx < closeTodosIdx, 'close_phase_todos should run after update_roadmap');
});
test('execute-phase.md: auto-close never blocks phase completion', () => {
const closeTodosSection = EXECUTE_PHASE.slice(
EXECUTE_PHASE.indexOf('name="close_phase_todos"'),
EXECUTE_PHASE.indexOf('name="update_project_md"')
);
assert.ok(
closeTodosSection.includes('never blocks') || closeTodosSection.includes('additive'),
'close_phase_todos should be non-blocking'
);
});
test('execute-phase.md: awk extracts resolves_phase from YAML frontmatter', () => {
assert.ok(EXECUTE_PHASE.includes('awk'), 'should use awk for frontmatter extraction');
assert.ok(EXECUTE_PHASE.includes('resolves_phase:'), 'awk pattern should match resolves_phase key');
});