* refactor(#455): implement typed surfaces to retire grep tests Production surfaces added: - hooks/managed-hooks-registry.cjs: new CJS module exporting MANAGED_HOOKS as a typed array; gsd-check-update-worker.js now requires it instead of declaring an inline array - bin/install.js: elevate inline gsdHooks to module-level GSD_UNINSTALL_HOOKS, export it alongside runtimeMap/allRuntimes (already exported) - scripts/build-hooks.js: export HOOKS_TO_COPY; guard build() behind require.main===module so tests can require the file without triggering a build - get-shit-done/bin/lib/init.cjs: add --json mode to agent-skills command, emitting typed IR { agent_type, block, skills_count } for test assertions - get-shit-done/bin/gsd-tools.cjs: wire --json flag for agent-skills dispatch Category-B source-grep migrations: - tests/managed-hooks.test.cjs: require MANAGED_HOOKS from registry, drop fs.readFileSync+regex - tests/orphaned-hooks.test.cjs: require MANAGED_HOOKS+HOOKS_TO_COPY as typed exports - tests/hooks-opt-in.test.cjs: replace gsdHooks regex-parse with GSD_UNINSTALL_HOOKS import - tests/install-minimal-hooks.test.cjs: replace gsdHooks regex-parse with GSD_UNINSTALL_HOOKS - tests/copilot-install.test.cjs: replace src.includes() checks with typed assertions on runtimeMap, allRuntimes, parseRuntimeInput, buildRuntimePromptText - tests/agent-skills.test.cjs: migrate to --json typed IR assertions pending-migration-to-typed-ir token cleared (87 of 87 files): - 78 files already had source-text-is-the-product; removed duplicate token - 5 files already used typed assertions; reclassified or annotated - 4 files required individual reclassification to source-text-is-the-product or architectural-invariant Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(#455): update workflow-guard test to typed GSD_UNINSTALL_HOOKS import; isolate HOME in runtime-launcher (D) test Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(#455): guard install.js main() behind require.main===module so the typed export is require-safe Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(#455): document --json typed surfaces for agent-skills, progress, validate context Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(#455): add changeset fragment for new --json surfaces Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(#455): complete grep migration for files flagged by lint-tests The branch commit 4e630d99 stripped `allow-test-rule: pending-migration-to-typed-ir` from ~80 test files without replacing their assertions or adding the correct exemption annotation. The files were NOT source-grep tests — they read .md workflow/agent/command/reference files (source-text-is-the-product) or hook source files for structural invariants (structural-regression-guard). No assertion logic was changed; only the correct allow-test-rule annotation was added to each file per CONTRIBUTING.md exception matrix. 73 files: `source-text-is-the-product` — workflow/agent/command/reference .md 7 files: `structural-regression-guard` — hook .js / bin/install.js structural checks Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: CI Rebase Check <ci@gsd-redux> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
106 lines
3.9 KiB
JavaScript
106 lines
3.9 KiB
JavaScript
// allow-test-rule: source-text-is-the-product
|
|
// Workflow .md / agent .md / command .md / reference .md files — their text
|
|
// IS what the runtime loads. Testing text content tests the deployed contract.
|
|
// Per CONTRIBUTING.md exception matrix.
|
|
|
|
/**
|
|
* Regression tests for #1967 cache invalidation.
|
|
*
|
|
* The disk scan cache in buildStateFrontmatter must be invalidated on
|
|
* writeStateMd to prevent stale reads if multiple state-mutating
|
|
* operations occur within the same Node process. This matters for:
|
|
* - SDK callers that require() gsd-tools.cjs as a module
|
|
* - Future dispatcher extensions that handle compound operations
|
|
* - Tests that import state.cjs directly
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { test, describe, beforeEach, afterEach } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const os = require('node:os');
|
|
|
|
const state = require('../get-shit-done/bin/lib/state.cjs');
|
|
|
|
describe('buildStateFrontmatter cache invalidation (#1967)', () => {
|
|
let tmpDir;
|
|
let planningDir;
|
|
let phasesDir;
|
|
let statePath;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-1967-cache-'));
|
|
planningDir = path.join(tmpDir, '.planning');
|
|
phasesDir = path.join(planningDir, 'phases');
|
|
fs.mkdirSync(phasesDir, { recursive: true });
|
|
|
|
// Create a minimal config and STATE.md
|
|
fs.writeFileSync(
|
|
path.join(planningDir, 'config.json'),
|
|
JSON.stringify({ project_code: 'TEST' })
|
|
);
|
|
|
|
statePath = path.join(planningDir, 'STATE.md');
|
|
fs.writeFileSync(statePath, [
|
|
'# State',
|
|
'',
|
|
'**Current Phase:** 1',
|
|
'**Status:** executing',
|
|
'**Total Phases:** 2',
|
|
'',
|
|
].join('\n'));
|
|
|
|
// Start with one phase directory containing one PLAN
|
|
const phase1 = path.join(phasesDir, '01-foo');
|
|
fs.mkdirSync(phase1);
|
|
fs.writeFileSync(path.join(phase1, '01-1-PLAN.md'), '---\nphase: 1\nplan: 1\n---\n# Plan\n');
|
|
});
|
|
|
|
afterEach(() => {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
test('writeStateMd invalidates cache so subsequent reads see new disk state', () => {
|
|
// First write — populates cache via buildStateFrontmatter
|
|
const content1 = fs.readFileSync(statePath, 'utf-8');
|
|
state.writeStateMd(statePath, content1, tmpDir);
|
|
|
|
// Create a NEW phase directory AFTER the first write
|
|
// Without cache invalidation, the second write would still see only 1 phase
|
|
const phase2 = path.join(phasesDir, '02-bar');
|
|
fs.mkdirSync(phase2);
|
|
fs.writeFileSync(path.join(phase2, '02-1-PLAN.md'), '---\nphase: 2\nplan: 1\n---\n# Plan\n');
|
|
fs.writeFileSync(path.join(phase2, '02-1-SUMMARY.md'), '---\nstatus: complete\n---\n# Summary\n');
|
|
|
|
// Second write in the SAME process — must see the new phase
|
|
const content2 = fs.readFileSync(statePath, 'utf-8');
|
|
state.writeStateMd(statePath, content2, tmpDir);
|
|
|
|
// Read back and parse frontmatter to verify it reflects 2 phases, not 1
|
|
const result = fs.readFileSync(statePath, 'utf-8');
|
|
const fmMatch = result.match(/^---\n([\s\S]*?)\n---/);
|
|
assert.ok(fmMatch, 'STATE.md should have frontmatter after writeStateMd');
|
|
|
|
const fm = fmMatch[1];
|
|
// Should show 2 total phases (the new disk state), not 1 (stale cache)
|
|
const totalPhasesMatch = fm.match(/total_phases:\s*(\d+)/);
|
|
assert.ok(totalPhasesMatch, 'frontmatter should contain total_phases');
|
|
assert.strictEqual(
|
|
parseInt(totalPhasesMatch[1], 10),
|
|
2,
|
|
'total_phases should reflect new disk state (2), not stale cache (1)'
|
|
);
|
|
|
|
// Should show 1 completed phase (phase 2 has SUMMARY)
|
|
const completedMatch = fm.match(/completed_phases:\s*(\d+)/);
|
|
assert.ok(completedMatch, 'frontmatter should contain completed_phases');
|
|
assert.strictEqual(
|
|
parseInt(completedMatch[1], 10),
|
|
1,
|
|
'completed_phases should reflect new disk state (1 complete), not stale cache (0)'
|
|
);
|
|
});
|
|
});
|