* 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
92 lines
3.5 KiB
JavaScript
92 lines
3.5 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.
|
|
|
|
/**
|
|
* Regression test for bug #2784
|
|
*
|
|
* /gsd-update cache-clear step only cleared per-runtime cache paths
|
|
* (e.g. ~/.claude/cache/gsd-update-check.json) but the SessionStart hook
|
|
* (hooks/gsd-check-update.js) writes to the shared tool-agnostic path
|
|
* ~/.cache/gsd/gsd-update-check.json. After a successful update, the statusline
|
|
* kept showing the stale "⬆ /gsd-update" indicator because the actual cache
|
|
* file was never deleted.
|
|
*
|
|
* Fix: add `rm -f "$HOME/.cache/gsd/gsd-update-check.json"` to the
|
|
* run_update step's cache-clear block in get-shit-done/workflows/update.md.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const REPO_ROOT = path.join(__dirname, '..');
|
|
const UPDATE_WORKFLOW = path.join(
|
|
REPO_ROOT,
|
|
'get-shit-done',
|
|
'workflows',
|
|
'update.md'
|
|
);
|
|
const CHECK_UPDATE_HOOK = path.join(REPO_ROOT, 'hooks', 'gsd-check-update.js');
|
|
|
|
describe('bug-2784: update.md cache-clear covers shared cache path', () => {
|
|
test('gsd-check-update.js hook constructs cache dir from .cache and gsd path segments', () => {
|
|
const hookContent = fs.readFileSync(CHECK_UPDATE_HOOK, 'utf-8');
|
|
// Parse the path.join() call structurally rather than text-grepping.
|
|
const m = hookContent.match(/const cacheDir\s*=\s*path\.join\(([^)]+)\)/);
|
|
assert.ok(
|
|
m !== null,
|
|
'hook must assign cacheDir via path.join() with explicit path segments'
|
|
);
|
|
const segments = m[1].split(',').map((a) => a.trim().replace(/^['"]|['"]$/g, ''));
|
|
assert.ok(
|
|
segments.includes('.cache'),
|
|
`hook cacheDir path.join() must include '.cache' segment; got: ${JSON.stringify(segments)}`
|
|
);
|
|
assert.ok(
|
|
segments.includes('gsd'),
|
|
`hook cacheDir path.join() must include 'gsd' segment; got: ${JSON.stringify(segments)}`
|
|
);
|
|
});
|
|
|
|
test('update.md run_update bash commands include rm for shared gsd cache file', () => {
|
|
const workflowContent = fs.readFileSync(UPDATE_WORKFLOW, 'utf-8');
|
|
// Parse the step block structurally, then extract only bash fenced code lines.
|
|
const stepMatch = workflowContent.match(/<step name="run_update">[\s\S]*?<\/step>/);
|
|
assert.ok(stepMatch, 'update.md must have a <step name="run_update"> block');
|
|
const stepContent = stepMatch[0];
|
|
|
|
const bashLines = [];
|
|
const fenceRe = /```(?:bash|sh)\n([\s\S]*?)```/g;
|
|
let m;
|
|
while ((m = fenceRe.exec(stepContent)) !== null) {
|
|
for (const line of m[1].split('\n')) {
|
|
const trimmed = line.trim();
|
|
if (trimmed) bashLines.push(trimmed);
|
|
}
|
|
}
|
|
|
|
const sharedCacheClearCmds = bashLines.filter(
|
|
(line) => /^rm\b/.test(line) && line.includes('.cache/gsd/gsd-update-check.json')
|
|
);
|
|
assert.ok(
|
|
sharedCacheClearCmds.length > 0,
|
|
[
|
|
'run_update step bash blocks must include an `rm` command targeting .cache/gsd/gsd-update-check.json.',
|
|
`Bash lines found: ${JSON.stringify(bashLines)}`,
|
|
].join('\n')
|
|
);
|
|
const hasHomeExpansion = sharedCacheClearCmds.some(
|
|
(line) => line.includes('$HOME') || line.includes('~/')
|
|
);
|
|
assert.ok(
|
|
hasHomeExpansion,
|
|
`shared cache rm command must use $HOME or ~/ expansion; found: ${JSON.stringify(sharedCacheClearCmds)}`
|
|
);
|
|
});
|
|
});
|