* 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>
192 lines
7.5 KiB
JavaScript
192 lines
7.5 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.
|
|
|
|
/**
|
|
* Template Tests
|
|
*
|
|
* Tests for cmdTemplateSelect (heuristic template selection) and
|
|
* cmdTemplateFill (summary, plan, verification template generation).
|
|
*/
|
|
|
|
const { test, describe, beforeEach, afterEach } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
|
|
|
|
// ─── template select ──────────────────────────────────────────────────────────
|
|
|
|
describe('template select command', () => {
|
|
let tmpDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
// Create a phase directory with a plan
|
|
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-setup');
|
|
fs.mkdirSync(phaseDir, { recursive: true });
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('selects minimal template for simple plan', () => {
|
|
const planPath = path.join(tmpDir, '.planning', 'phases', '01-setup', '01-01-PLAN.md');
|
|
fs.writeFileSync(planPath, [
|
|
'# Plan',
|
|
'',
|
|
'### Task 1',
|
|
'Do the thing.',
|
|
'',
|
|
'File: `src/index.ts`',
|
|
].join('\n'));
|
|
|
|
const result = runGsdTools(`template select .planning/phases/01-setup/01-01-PLAN.md`, tmpDir);
|
|
assert.ok(result.success, `Failed: ${result.error}`);
|
|
const out = JSON.parse(result.output);
|
|
assert.strictEqual(out.type, 'minimal');
|
|
assert.ok(out.template.includes('summary-minimal'));
|
|
});
|
|
|
|
test('selects standard template for moderate plan', () => {
|
|
const planPath = path.join(tmpDir, '.planning', 'phases', '01-setup', '01-01-PLAN.md');
|
|
fs.writeFileSync(planPath, [
|
|
'# Plan',
|
|
'',
|
|
'### Task 1',
|
|
'Create `src/auth/login.ts`',
|
|
'',
|
|
'### Task 2',
|
|
'Create `src/auth/register.ts`',
|
|
'',
|
|
'### Task 3',
|
|
'Update `src/routes/index.ts`',
|
|
'',
|
|
'Files: `src/auth/login.ts`, `src/auth/register.ts`, `src/routes/index.ts`, `src/middleware/auth.ts`',
|
|
].join('\n'));
|
|
|
|
const result = runGsdTools(`template select .planning/phases/01-setup/01-01-PLAN.md`, tmpDir);
|
|
assert.ok(result.success, `Failed: ${result.error}`);
|
|
const out = JSON.parse(result.output);
|
|
assert.strictEqual(out.type, 'standard');
|
|
});
|
|
|
|
test('selects complex template for plan with decisions and many files', () => {
|
|
const planPath = path.join(tmpDir, '.planning', 'phases', '01-setup', '01-01-PLAN.md');
|
|
const lines = ['# Plan', ''];
|
|
for (let i = 1; i <= 6; i++) {
|
|
lines.push(`### Task ${i}`, `Do task ${i}.`, '');
|
|
}
|
|
lines.push('Made a decision about architecture.', 'Another decision here.');
|
|
for (let i = 1; i <= 8; i++) {
|
|
lines.push(`File: \`src/module${i}/index.ts\``);
|
|
}
|
|
fs.writeFileSync(planPath, lines.join('\n'));
|
|
|
|
const result = runGsdTools(`template select .planning/phases/01-setup/01-01-PLAN.md`, tmpDir);
|
|
assert.ok(result.success, `Failed: ${result.error}`);
|
|
const out = JSON.parse(result.output);
|
|
assert.strictEqual(out.type, 'complex');
|
|
});
|
|
|
|
test('returns standard as fallback for nonexistent file', () => {
|
|
const result = runGsdTools(`template select .planning/phases/01-setup/nonexistent.md`, tmpDir);
|
|
assert.ok(result.success, `Failed: ${result.error}`);
|
|
const out = JSON.parse(result.output);
|
|
assert.strictEqual(out.type, 'standard');
|
|
assert.ok(out.error, 'should include error message');
|
|
});
|
|
});
|
|
|
|
// ─── template fill ────────────────────────────────────────────────────────────
|
|
|
|
describe('template fill command', () => {
|
|
let tmpDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-setup');
|
|
fs.mkdirSync(phaseDir, { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
|
'## Roadmap\n\n### Phase 1: Setup\n**Goal:** Initial setup\n'
|
|
);
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('fills summary template', () => {
|
|
const result = runGsdTools('template fill summary --phase 1', tmpDir);
|
|
assert.ok(result.success, `Failed: ${result.error}`);
|
|
const out = JSON.parse(result.output);
|
|
assert.strictEqual(out.created, true);
|
|
assert.ok(out.path.includes('01-01-SUMMARY.md'));
|
|
|
|
const content = fs.readFileSync(path.join(tmpDir, out.path), 'utf-8');
|
|
assert.ok(content.includes('---'), 'should have frontmatter');
|
|
assert.ok(content.includes('Phase 1'), 'should reference phase');
|
|
assert.ok(content.includes('Accomplishments'), 'should have accomplishments section');
|
|
});
|
|
|
|
test('fills plan template', () => {
|
|
const result = runGsdTools('template fill plan --phase 1', tmpDir);
|
|
assert.ok(result.success, `Failed: ${result.error}`);
|
|
const out = JSON.parse(result.output);
|
|
assert.strictEqual(out.created, true);
|
|
assert.ok(out.path.includes('01-01-PLAN.md'));
|
|
|
|
const content = fs.readFileSync(path.join(tmpDir, out.path), 'utf-8');
|
|
assert.ok(content.includes('---'), 'should have frontmatter');
|
|
assert.ok(content.includes('Objective'), 'should have objective section');
|
|
assert.ok(content.includes('<task type="code">'), 'should have task XML');
|
|
});
|
|
|
|
test('fills verification template', () => {
|
|
const result = runGsdTools('template fill verification --phase 1', tmpDir);
|
|
assert.ok(result.success, `Failed: ${result.error}`);
|
|
const out = JSON.parse(result.output);
|
|
assert.strictEqual(out.created, true);
|
|
assert.ok(out.path.includes('01-VERIFICATION.md'));
|
|
|
|
const content = fs.readFileSync(path.join(tmpDir, out.path), 'utf-8');
|
|
assert.ok(content.includes('Observable Truths'), 'should have truths section');
|
|
assert.ok(content.includes('Required Artifacts'), 'should have artifacts section');
|
|
});
|
|
|
|
test('rejects existing file', () => {
|
|
// Create the file first
|
|
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-setup');
|
|
fs.writeFileSync(path.join(phaseDir, '01-01-SUMMARY.md'), '# Existing');
|
|
|
|
const result = runGsdTools('template fill summary --phase 1', tmpDir);
|
|
assert.ok(result.success); // outputs JSON, doesn't crash
|
|
const out = JSON.parse(result.output);
|
|
assert.ok(out.error, 'should report error for existing file');
|
|
assert.ok(out.error.includes('already exists'));
|
|
});
|
|
|
|
test('errors on unknown template type', () => {
|
|
const result = runGsdTools('template fill bogus --phase 1', tmpDir);
|
|
assert.ok(!result.success, 'should fail for unknown type');
|
|
assert.ok(result.error.includes('Unknown template type'));
|
|
});
|
|
|
|
test('errors when phase not found', () => {
|
|
const result = runGsdTools('template fill summary --phase 99', tmpDir);
|
|
assert.ok(result.success);
|
|
const out = JSON.parse(result.output);
|
|
assert.ok(out.error, 'should report phase not found');
|
|
});
|
|
|
|
test('respects --plan option for plan number', () => {
|
|
const result = runGsdTools('template fill plan --phase 1 --plan 03', tmpDir);
|
|
assert.ok(result.success, `Failed: ${result.error}`);
|
|
const out = JSON.parse(result.output);
|
|
assert.ok(out.path.includes('01-03-PLAN.md'), `Expected plan 03 in path, got ${out.path}`);
|
|
});
|
|
});
|