Files
get-shit-done/tests/extract-learnings.test.cjs
Tom Boucher a411e08e88 fix(coderabbit): resolve all 12 findings on PR #3152
MAJOR (security/correctness):
- commands/gsd/debug.md: add Write to allowed-tools (session file creation
  requires it — workflow explicitly says 'use Write tool, never heredoc')
- workflows/debug.md: add SLUG sanitization guard to steps 1b+1c (status/
  continue subcommands used raw user input in file paths — path traversal)
- workflows/thread.md: sanitize $ARGUMENTS in RESUME mode before file path
  construction (was bypassing the sanitization guard in CLOSE/STATUS modes)

MINOR (consistency/correctness):
- docs/INVENTORY-MANIFEST.json: remove stale top-level 'workflows' array
  (duplicate of families.workflows introduced in earlier update)
- commands/gsd/resume-work.md: normalize process to 'Execute end-to-end.'
- commands/gsd/settings.md: normalize process to 'Execute end-to-end.'
- commands/gsd/update.md: normalize otherwise branch to 'execute end-to-end.'
- docs/adr/0002: add Status: Accepted + Date header (ADR convention)
- workflows/extract-learnings.md: rename step extract_learnings → extract-learnings
- tests/extract-learnings.test.cjs: tighten step-name assertion to exact name

ARCHITECTURE:
- scripts/command-contract-helpers.cjs: extract CANONICAL_TOOLS, parseFrontmatter,
  executionContextRefs as shared module — single source of truth consumed by
  both lint script and test suite (prevents silent lint/test disagreement)
- scripts/lint-command-contract.cjs: require() helpers instead of duplicating
- tests/command-contract.test.cjs: require() helpers; move readFileSync calls
  inside test() callbacks (registration-time throws surface as named failures)
2026-05-05 16:06:29 -04:00

178 lines
8.2 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.
/**
* 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'
);
});
});