Add a new pattern mapper agent that analyzes the codebase for existing patterns before planning, producing PATTERNS.md with per-file analog assignments and code excerpts. Integrated into plan-phase workflow as Step 7.8 (between research and planning), controlled by the workflow.pattern_mapper config key (default: true). Changes: - New agent: agents/gsd-pattern-mapper.md - New config key: workflow.pattern_mapper in VALID_CONFIG_KEYS and CONFIG_DEFAULTS - init plan-phase: patterns_path field in JSON output - plan-phase.md: Step 7.8 spawns pattern mapper, PATTERNS_PATH in planner files_to_read - gsd-plan-checker.md: Dimension 12 (Pattern Compliance) - model-profiles.cjs: gsd-pattern-mapper profile entry - Tests: tests/pattern-mapper.test.cjs (5 tests) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
112 lines
4.0 KiB
JavaScript
112 lines
4.0 KiB
JavaScript
/**
|
|
* Tests for Pattern Mapper feature (#1861)
|
|
*
|
|
* Covers:
|
|
* - Config key workflow.pattern_mapper in VALID_CONFIG_KEYS
|
|
* - Default value is true
|
|
* - Config round-trip (set/get)
|
|
* - init plan-phase output includes patterns_path (null when missing, path when present)
|
|
*/
|
|
|
|
const { describe, test, 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');
|
|
|
|
describe('pattern-mapper config key', () => {
|
|
let tmpDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('workflow.pattern_mapper is a valid config key', () => {
|
|
// Setting an invalid key produces an error; a valid key succeeds
|
|
const result = runGsdTools('config-set workflow.pattern_mapper true', tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `Expected success but got error: ${result.error}`);
|
|
});
|
|
|
|
test('default value is true in CONFIG_DEFAULTS', () => {
|
|
// Create a new project config and verify the default
|
|
const result = runGsdTools('config-new-project', tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `config-new-project failed: ${result.error}`);
|
|
|
|
const configPath = path.join(tmpDir, '.planning', 'config.json');
|
|
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
assert.strictEqual(config.workflow.pattern_mapper, true);
|
|
});
|
|
|
|
test('config round-trip set/get', () => {
|
|
// Ensure config exists first
|
|
runGsdTools('config-new-project', tmpDir, { HOME: tmpDir });
|
|
|
|
// Set to false
|
|
const setResult = runGsdTools('config-set workflow.pattern_mapper false', tmpDir, { HOME: tmpDir });
|
|
assert.ok(setResult.success, `config-set failed: ${setResult.error}`);
|
|
|
|
// Get should return false
|
|
const getResult = runGsdTools('config-get workflow.pattern_mapper', tmpDir, { HOME: tmpDir });
|
|
assert.ok(getResult.success, `config-get failed: ${getResult.error}`);
|
|
assert.strictEqual(getResult.output, 'false');
|
|
});
|
|
});
|
|
|
|
describe('init plan-phase patterns_path', () => {
|
|
let tmpDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
// Create minimal planning structure for init plan-phase
|
|
const planningDir = path.join(tmpDir, '.planning');
|
|
fs.writeFileSync(path.join(planningDir, 'STATE.md'), [
|
|
'# State',
|
|
'',
|
|
'## Current Phase',
|
|
'Phase 1 — Foundation',
|
|
].join('\n'));
|
|
fs.writeFileSync(path.join(planningDir, 'ROADMAP.md'), [
|
|
'# Roadmap',
|
|
'',
|
|
'## Phase 1: Foundation',
|
|
'Build the foundation.',
|
|
'**Status:** Planning',
|
|
'**Requirements:** [FOUND-01]',
|
|
].join('\n'));
|
|
|
|
// Create phase directory
|
|
const phaseDir = path.join(planningDir, 'phases', '01-foundation');
|
|
fs.mkdirSync(phaseDir, { recursive: true });
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('patterns_path is null when no PATTERNS.md exists', () => {
|
|
const result = runGsdTools('init plan-phase 1', tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `init plan-phase failed: ${result.error}`);
|
|
|
|
const data = JSON.parse(result.output);
|
|
assert.strictEqual(data.patterns_path, null);
|
|
});
|
|
|
|
test('patterns_path contains correct path when PATTERNS.md exists', () => {
|
|
// Create a PATTERNS.md in the phase directory
|
|
const phaseDir = path.join(tmpDir, '.planning', 'phases', '01-foundation');
|
|
fs.writeFileSync(path.join(phaseDir, '01-PATTERNS.md'), '# Patterns\n');
|
|
|
|
const result = runGsdTools('init plan-phase 1', tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `init plan-phase failed: ${result.error}`);
|
|
|
|
const data = JSON.parse(result.output);
|
|
assert.ok(data.patterns_path, 'patterns_path should not be null');
|
|
assert.ok(data.patterns_path.includes('PATTERNS.md'), `Expected path to contain PATTERNS.md, got: ${data.patterns_path}`);
|
|
assert.ok(data.patterns_path.includes('01-foundation'), `Expected path to include phase dir, got: ${data.patterns_path}`);
|
|
});
|
|
});
|