* 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>
178 lines
8.2 KiB
JavaScript
178 lines
8.2 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.
|
|
|
|
/**
|
|
* Extract-Learnings Command & Workflow Tests
|
|
*
|
|
* Validates command file existence, frontmatter correctness, workflow content,
|
|
* 4 learning categories, capture_thought handling, graceful degradation,
|
|
* LEARNINGS.md output, and missing artifact handling.
|
|
*/
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const COMMAND_PATH = path.join(__dirname, '..', 'commands', 'gsd', 'extract-learnings.md');
|
|
const WORKFLOW_PATH = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'extract-learnings.md');
|
|
|
|
describe('extract-learnings command', () => {
|
|
test('command file exists', () => {
|
|
assert.ok(fs.existsSync(COMMAND_PATH), 'commands/gsd/extract-learnings.md should exist');
|
|
});
|
|
|
|
test('command file has correct name frontmatter', () => {
|
|
const content = fs.readFileSync(COMMAND_PATH, 'utf-8');
|
|
assert.ok(content.includes('name: gsd:extract-learnings'), 'Command must have name: gsd:extract-learnings');
|
|
});
|
|
|
|
test('command file has description frontmatter', () => {
|
|
const content = fs.readFileSync(COMMAND_PATH, 'utf-8');
|
|
assert.ok(content.includes('description:'), 'Command must have description frontmatter');
|
|
});
|
|
|
|
test('command file has argument-hint for phase-number', () => {
|
|
const content = fs.readFileSync(COMMAND_PATH, 'utf-8');
|
|
assert.ok(content.includes('argument-hint:'), 'Command must have argument-hint');
|
|
assert.ok(content.includes('<phase-number>'), 'argument-hint must reference <phase-number>');
|
|
});
|
|
|
|
test('command file has allowed-tools list', () => {
|
|
const content = fs.readFileSync(COMMAND_PATH, 'utf-8');
|
|
assert.ok(content.includes('allowed-tools:'), 'Command must have allowed-tools');
|
|
assert.ok(content.includes('Read'), 'allowed-tools must include Read');
|
|
assert.ok(content.includes('Write'), 'allowed-tools must include Write');
|
|
assert.ok(content.includes('Bash'), 'allowed-tools must include Bash');
|
|
assert.ok(content.includes('Grep'), 'allowed-tools must include Grep');
|
|
assert.ok(content.includes('Glob'), 'allowed-tools must include Glob');
|
|
assert.ok(content.includes('Agent'), 'allowed-tools must include Agent');
|
|
});
|
|
|
|
test('command file has type: prompt', () => {
|
|
const content = fs.readFileSync(COMMAND_PATH, 'utf-8');
|
|
assert.ok(content.includes('type: prompt'), 'Command must have type: prompt');
|
|
});
|
|
|
|
test('command references the workflow via execution_context', () => {
|
|
const content = fs.readFileSync(COMMAND_PATH, 'utf-8');
|
|
assert.ok(
|
|
content.includes('workflows/extract-learnings.md'),
|
|
'Command must reference workflows/extract-learnings.md in execution_context'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('extract-learnings workflow', () => {
|
|
test('workflow file exists', () => {
|
|
assert.ok(fs.existsSync(WORKFLOW_PATH), 'workflows/extract-learnings.md should exist');
|
|
});
|
|
|
|
test('workflow has objective tag', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.includes('<objective>'), 'Workflow must have <objective> tag');
|
|
assert.ok(content.includes('</objective>'), 'Workflow must close <objective> tag');
|
|
});
|
|
|
|
test('workflow has process tag', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.includes('<process>'), 'Workflow must have <process> tag');
|
|
assert.ok(content.includes('</process>'), 'Workflow must close <process> tag');
|
|
});
|
|
|
|
test('workflow has step tags', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.includes('<step name='), 'Workflow must have named step tags');
|
|
assert.ok(content.includes('</step>'), 'Workflow must close step tags');
|
|
assert.ok(
|
|
content.includes('<step name="extract-learnings">'),
|
|
'Workflow step must use hyphen convention: <step name="extract-learnings">',
|
|
);
|
|
});
|
|
|
|
test('workflow has success_criteria tag', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.includes('<success_criteria>'), 'Workflow must have <success_criteria> tag');
|
|
assert.ok(content.includes('</success_criteria>'), 'Workflow must close <success_criteria> tag');
|
|
});
|
|
|
|
test('workflow has critical_rules tag', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.includes('<critical_rules>'), 'Workflow must have <critical_rules> tag');
|
|
assert.ok(content.includes('</critical_rules>'), 'Workflow must close <critical_rules> tag');
|
|
});
|
|
|
|
test('workflow reads required artifacts (PLAN.md and SUMMARY.md)', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.includes('PLAN.md'), 'Workflow must reference PLAN.md');
|
|
assert.ok(content.includes('SUMMARY.md'), 'Workflow must reference SUMMARY.md');
|
|
});
|
|
|
|
test('workflow reads optional artifacts (VERIFICATION.md, UAT.md, STATE.md)', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.includes('VERIFICATION.md'), 'Workflow must reference VERIFICATION.md');
|
|
assert.ok(content.includes('UAT.md'), 'Workflow must reference UAT.md');
|
|
assert.ok(content.includes('STATE.md'), 'Workflow must reference STATE.md');
|
|
});
|
|
|
|
test('workflow extracts all 4 learning categories', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.toLowerCase().includes('decision'), 'Workflow must extract decisions');
|
|
assert.ok(content.toLowerCase().includes('lesson'), 'Workflow must extract lessons');
|
|
assert.ok(content.toLowerCase().includes('pattern'), 'Workflow must extract patterns');
|
|
assert.ok(content.toLowerCase().includes('surprise'), 'Workflow must extract surprises');
|
|
});
|
|
|
|
test('workflow handles capture_thought tool availability', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.includes('capture_thought'), 'Workflow must reference capture_thought tool');
|
|
});
|
|
|
|
test('workflow degrades gracefully when capture_thought is unavailable', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(
|
|
content.includes('graceful') || content.includes('not available') || content.includes('unavailable') || content.includes('fallback'),
|
|
'Workflow must handle graceful degradation when capture_thought is unavailable'
|
|
);
|
|
});
|
|
|
|
test('workflow outputs LEARNINGS.md', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.includes('LEARNINGS.md'), 'Workflow must output LEARNINGS.md');
|
|
});
|
|
|
|
test('workflow handles missing artifacts gracefully', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(
|
|
content.includes('missing') || content.includes('not found') || content.includes('optional'),
|
|
'Workflow must handle missing artifacts'
|
|
);
|
|
});
|
|
|
|
test('workflow includes source attribution for extracted items', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(
|
|
content.includes('source') || content.includes('attribution') || content.includes('Source:'),
|
|
'Workflow must include source attribution for extracted items'
|
|
);
|
|
});
|
|
|
|
test('workflow specifies LEARNINGS.md YAML frontmatter fields', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(content.includes('phase'), 'LEARNINGS.md frontmatter must include phase');
|
|
assert.ok(content.includes('phase_name'), 'LEARNINGS.md frontmatter must include phase_name');
|
|
assert.ok(content.includes('generated'), 'LEARNINGS.md frontmatter must include generated');
|
|
assert.ok(content.includes('missing_artifacts'), 'LEARNINGS.md frontmatter must include missing_artifacts');
|
|
});
|
|
|
|
test('workflow supports overwriting previous LEARNINGS.md on re-run', () => {
|
|
const content = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
assert.ok(
|
|
content.includes('overwrite') || content.includes('overwrit') || content.includes('replace'),
|
|
'Workflow must support overwriting previous LEARNINGS.md'
|
|
);
|
|
});
|
|
});
|