Merge branch 'main' into feat/materialize-new-project-config
This commit is contained in:
@@ -567,6 +567,98 @@ describe('todo complete command', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// todo match-phase command
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('todo match-phase command', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
afterEach(() => cleanup(tmpDir));
|
||||
|
||||
test('returns empty matches when no todos exist', () => {
|
||||
const result = runGsdTools('todo match-phase 01', tmpDir);
|
||||
assert.ok(result.success, 'should succeed');
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.todo_count, 0);
|
||||
assert.deepStrictEqual(output.matches, []);
|
||||
});
|
||||
|
||||
test('matches todo by keyword overlap with phase name', () => {
|
||||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||||
fs.mkdirSync(pendingDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(pendingDir, 'auth-todo.md'),
|
||||
'title: Add OAuth token refresh\narea: auth\ncreated: 2026-03-01\n\nNeed to handle token expiry for OAuth flows.');
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||||
'# Roadmap\n\n### Phase 01: Authentication and Session Management\n\n**Goal:** Implement OAuth login and session handling\n');
|
||||
|
||||
const result = runGsdTools('todo match-phase 01', tmpDir);
|
||||
assert.ok(result.success, 'should succeed');
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.todo_count, 1, 'should find 1 todo');
|
||||
assert.ok(output.matches.length > 0, 'should have matches');
|
||||
assert.strictEqual(output.matches[0].title, 'Add OAuth token refresh');
|
||||
assert.ok(output.matches[0].score > 0, 'score should be positive');
|
||||
assert.ok(output.matches[0].reasons.length > 0, 'should have reasons');
|
||||
});
|
||||
|
||||
test('does not match unrelated todo', () => {
|
||||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||||
fs.mkdirSync(pendingDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(pendingDir, 'auth-todo.md'),
|
||||
'title: Add OAuth token refresh\narea: auth\ncreated: 2026-03-01\n\nOAuth token expiry.');
|
||||
fs.writeFileSync(path.join(pendingDir, 'unrelated-todo.md'),
|
||||
'title: Fix CSS grid layout in dashboard\narea: ui\ncreated: 2026-03-01\n\nGrid columns break on mobile.');
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||||
'# Roadmap\n\n### Phase 01: Authentication and Session Management\n\n**Goal:** Implement OAuth login and session handling\n');
|
||||
|
||||
const result = runGsdTools('todo match-phase 01', tmpDir);
|
||||
assert.ok(result.success, 'should succeed');
|
||||
const output = JSON.parse(result.output);
|
||||
const matchTitles = output.matches.map(m => m.title);
|
||||
assert.ok(matchTitles.includes('Add OAuth token refresh'), 'auth todo should match');
|
||||
assert.ok(!matchTitles.includes('Fix CSS grid layout in dashboard'), 'unrelated todo should not match');
|
||||
});
|
||||
|
||||
test('matches todo by area overlap', () => {
|
||||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||||
fs.mkdirSync(pendingDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(pendingDir, 'auth-todo.md'),
|
||||
'title: Add OAuth token refresh\narea: auth\ncreated: 2026-03-01\n\nOAuth token handling.');
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||||
'# Roadmap\n\n### Phase 01: Auth System\n\n**Goal:** Build auth module\n');
|
||||
|
||||
const result = runGsdTools('todo match-phase 01', tmpDir);
|
||||
const output = JSON.parse(result.output);
|
||||
const authMatch = output.matches.find(m => m.title === 'Add OAuth token refresh');
|
||||
assert.ok(authMatch, 'should find auth todo');
|
||||
const hasAreaReason = authMatch.reasons.some(r => r.startsWith('area:'));
|
||||
assert.ok(hasAreaReason, 'should match on area');
|
||||
});
|
||||
|
||||
test('sorts matches by score descending', () => {
|
||||
const pendingDir = path.join(tmpDir, '.planning', 'todos', 'pending');
|
||||
fs.mkdirSync(pendingDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(pendingDir, 'weak-match.md'),
|
||||
'title: Check token format\narea: general\ncreated: 2026-03-01\n\nToken format validation.');
|
||||
fs.writeFileSync(path.join(pendingDir, 'strong-match.md'),
|
||||
'title: Session management authentication OAuth token handling\narea: auth\ncreated: 2026-03-01\n\nSession auth OAuth tokens.');
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||||
'# Roadmap\n\n### Phase 01: Authentication and Session Management\n\n**Goal:** Implement OAuth login, session handling, and token management\n');
|
||||
|
||||
const result = runGsdTools('todo match-phase 01', tmpDir);
|
||||
const output = JSON.parse(result.output);
|
||||
assert.ok(output.matches.length >= 2, 'should have multiple matches');
|
||||
for (let i = 1; i < output.matches.length; i++) {
|
||||
assert.ok(output.matches[i - 1].score >= output.matches[i].score,
|
||||
`match ${i-1} score (${output.matches[i-1].score}) should be >= match ${i} score (${output.matches[i].score})`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// scaffold command
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -625,7 +625,7 @@ describe('copyCommandsAsCopilotSkills', () => {
|
||||
// Count gsd-* directories — should be 31
|
||||
const dirs = fs.readdirSync(tempDir, { withFileTypes: true })
|
||||
.filter(e => e.isDirectory() && e.name.startsWith('gsd-'));
|
||||
assert.strictEqual(dirs.length, 39, `expected 39 skill folders, got ${dirs.length}`);
|
||||
assert.strictEqual(dirs.length, 43, `expected 43 skill folders, got ${dirs.length}`);
|
||||
} finally {
|
||||
fs.rmSync(tempDir, { recursive: true });
|
||||
}
|
||||
@@ -1119,7 +1119,7 @@ const { execFileSync } = require('child_process');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const INSTALL_PATH = path.join(__dirname, '..', 'bin', 'install.js');
|
||||
const EXPECTED_SKILLS = 39;
|
||||
const EXPECTED_SKILLS = 43;
|
||||
const EXPECTED_AGENTS = 16;
|
||||
|
||||
function runCopilotInstall(cwd) {
|
||||
|
||||
@@ -10,6 +10,7 @@ const assert = require('node:assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const { createTempProject, cleanup } = require('./helpers.cjs');
|
||||
|
||||
const {
|
||||
loadConfig,
|
||||
@@ -35,14 +36,13 @@ describe('loadConfig', () => {
|
||||
let originalCwd;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-core-test-'));
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning'), { recursive: true });
|
||||
tmpDir = createTempProject();
|
||||
originalCwd = process.cwd();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.chdir(originalCwd);
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
function writeConfig(obj) {
|
||||
@@ -129,12 +129,11 @@ describe('resolveModelInternal', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-core-test-'));
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning'), { recursive: true });
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
function writeConfig(obj) {
|
||||
@@ -276,62 +275,11 @@ describe('generateSlugInternal', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ─── normalizePhaseName ────────────────────────────────────────────────────────
|
||||
|
||||
describe('normalizePhaseName', () => {
|
||||
test('pads single digit', () => {
|
||||
assert.strictEqual(normalizePhaseName('1'), '01');
|
||||
});
|
||||
|
||||
test('preserves double digit', () => {
|
||||
assert.strictEqual(normalizePhaseName('12'), '12');
|
||||
});
|
||||
|
||||
test('handles letter suffix', () => {
|
||||
assert.strictEqual(normalizePhaseName('1A'), '01A');
|
||||
});
|
||||
|
||||
test('handles decimal phases', () => {
|
||||
assert.strictEqual(normalizePhaseName('2.1'), '02.1');
|
||||
});
|
||||
|
||||
test('handles multi-level decimals', () => {
|
||||
assert.strictEqual(normalizePhaseName('1.2.3'), '01.2.3');
|
||||
});
|
||||
|
||||
test('returns non-matching input unchanged', () => {
|
||||
assert.strictEqual(normalizePhaseName('abc'), 'abc');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── comparePhaseNum ───────────────────────────────────────────────────────────
|
||||
|
||||
describe('comparePhaseNum', () => {
|
||||
test('sorts integer phases numerically', () => {
|
||||
assert.ok(comparePhaseNum('1', '2') < 0);
|
||||
assert.ok(comparePhaseNum('10', '2') > 0);
|
||||
});
|
||||
|
||||
test('sorts letter suffixes', () => {
|
||||
assert.ok(comparePhaseNum('12', '12A') < 0);
|
||||
assert.ok(comparePhaseNum('12A', '12B') < 0);
|
||||
});
|
||||
|
||||
test('sorts decimal phases', () => {
|
||||
assert.ok(comparePhaseNum('2', '2.1') < 0);
|
||||
assert.ok(comparePhaseNum('2.1', '2.2') < 0);
|
||||
});
|
||||
|
||||
test('handles multi-level decimals', () => {
|
||||
assert.ok(comparePhaseNum('1.1', '1.1.2') < 0);
|
||||
assert.ok(comparePhaseNum('1.1.2', '1.2') < 0);
|
||||
});
|
||||
|
||||
test('returns 0 for equal phases', () => {
|
||||
assert.strictEqual(comparePhaseNum('1', '1'), 0);
|
||||
assert.strictEqual(comparePhaseNum('2.1', '2.1'), 0);
|
||||
});
|
||||
});
|
||||
// ─── normalizePhaseName / comparePhaseNum ──────────────────────────────────────
|
||||
// NOTE: Comprehensive tests for normalizePhaseName and comparePhaseNum are in
|
||||
// phase.test.cjs (which covers all edge cases: hybrid, letter-suffix,
|
||||
// multi-level decimal, case-insensitive, directory-slug, and full sort order).
|
||||
// Removed duplicates here to keep a single authoritative test location.
|
||||
|
||||
// ─── safeReadFile ──────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -343,7 +291,7 @@ describe('safeReadFile', () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('reads existing file', () => {
|
||||
@@ -363,12 +311,11 @@ describe('pathExistsInternal', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-core-test-'));
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning'), { recursive: true });
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('returns true for existing path', () => {
|
||||
@@ -390,12 +337,11 @@ describe('getMilestoneInfo', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-core-test-'));
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning'), { recursive: true });
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('extracts version and name from roadmap', () => {
|
||||
@@ -502,7 +448,7 @@ describe('searchPhaseInDir', () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('finds phase directory by normalized prefix', () => {
|
||||
@@ -564,12 +510,11 @@ describe('findPhaseInternal', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-core-test-'));
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases'), { recursive: true });
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('finds phase in current phases directory', () => {
|
||||
@@ -605,12 +550,11 @@ describe('getRoadmapPhaseInternal', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-core-test-'));
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning'), { recursive: true });
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
// Bug: getRoadmapPhaseInternal was missing from module.exports
|
||||
@@ -687,12 +631,11 @@ describe('getMilestonePhaseFilter', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-core-test-'));
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases'), { recursive: true });
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('filters directories to only current milestone phases', () => {
|
||||
|
||||
81
tests/cursor-conversion.test.cjs
Normal file
81
tests/cursor-conversion.test.cjs
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Cursor conversion regression tests.
|
||||
*
|
||||
* Ensures Cursor frontmatter names are emitted as plain identifiers
|
||||
* (without surrounding quotes), so Cursor does not treat quotes as
|
||||
* literal parts of skill/subagent names.
|
||||
*/
|
||||
|
||||
process.env.GSD_TEST_MODE = '1';
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const {
|
||||
convertClaudeCommandToCursorSkill,
|
||||
convertClaudeAgentToCursorAgent,
|
||||
} = require('../bin/install.js');
|
||||
|
||||
describe('convertClaudeCommandToCursorSkill', () => {
|
||||
test('writes unquoted Cursor skill name in frontmatter', () => {
|
||||
const input = `---
|
||||
name: quick
|
||||
description: Execute a quick task
|
||||
---
|
||||
|
||||
<objective>
|
||||
Test body
|
||||
</objective>
|
||||
`;
|
||||
|
||||
const result = convertClaudeCommandToCursorSkill(input, 'gsd-quick');
|
||||
const nameMatch = result.match(/^name:\s*(.+)$/m);
|
||||
|
||||
assert.ok(nameMatch, 'frontmatter contains name field');
|
||||
assert.equal(nameMatch[1], 'gsd-quick', 'skill name is plain scalar');
|
||||
assert.ok(!result.includes('name: "gsd-quick"'), 'quoted skill name is not emitted');
|
||||
});
|
||||
|
||||
test('preserves slash for slash commands in markdown body', () => {
|
||||
const input = `---
|
||||
name: gsd:plan-phase
|
||||
description: Plan a phase
|
||||
---
|
||||
|
||||
Next:
|
||||
/gsd:execute-phase 17
|
||||
/gsd-help
|
||||
gsd:progress
|
||||
`;
|
||||
|
||||
const result = convertClaudeCommandToCursorSkill(input, 'gsd-plan-phase');
|
||||
|
||||
assert.ok(result.includes('/gsd-execute-phase 17'), 'slash command remains slash-prefixed');
|
||||
assert.ok(result.includes('/gsd-help'), 'existing slash command is preserved');
|
||||
assert.ok(result.includes('gsd-progress'), 'non-slash gsd: references still normalize');
|
||||
assert.ok(!result.includes('/gsd:execute-phase'), 'legacy colon command form is removed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertClaudeAgentToCursorAgent', () => {
|
||||
test('writes unquoted Cursor agent name in frontmatter', () => {
|
||||
const input = `---
|
||||
name: gsd-planner
|
||||
description: Planner agent
|
||||
tools: Read, Write
|
||||
color: green
|
||||
---
|
||||
|
||||
<role>
|
||||
Planner body
|
||||
</role>
|
||||
`;
|
||||
|
||||
const result = convertClaudeAgentToCursorAgent(input);
|
||||
const nameMatch = result.match(/^name:\s*(.+)$/m);
|
||||
|
||||
assert.ok(nameMatch, 'frontmatter contains name field');
|
||||
assert.equal(nameMatch[1], 'gsd-planner', 'agent name is plain scalar');
|
||||
assert.ok(!result.includes('name: "gsd-planner"'), 'quoted agent name is not emitted');
|
||||
});
|
||||
});
|
||||
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* GSD Tools Tests - Gemini agent conversion
|
||||
*
|
||||
* Verifies Gemini-specific agent frontmatter conversion removes
|
||||
* unsupported fields while preserving converted tools and body text.
|
||||
*/
|
||||
|
||||
process.env.GSD_TEST_MODE = '1';
|
||||
|
||||
const { test, describe } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const { convertClaudeToGeminiAgent } = require('../bin/install.js');
|
||||
|
||||
describe('convertClaudeToGeminiAgent', () => {
|
||||
test('drops unsupported skills frontmatter while keeping converted tools', () => {
|
||||
const input = `---
|
||||
name: gsd-codebase-mapper
|
||||
description: Explores codebase and writes structured analysis documents.
|
||||
tools: Read, Bash, Grep, Glob, Write
|
||||
color: cyan
|
||||
skills:
|
||||
- gsd-mapper-workflow
|
||||
---
|
||||
|
||||
<role>
|
||||
Use \${PHASE} in shell examples.
|
||||
</role>`;
|
||||
|
||||
const result = convertClaudeToGeminiAgent(input);
|
||||
const frontmatter = result.split('---')[1] || '';
|
||||
|
||||
assert.ok(frontmatter.includes('name: gsd-codebase-mapper'), 'keeps name');
|
||||
assert.ok(frontmatter.includes('description: Explores codebase and writes structured analysis documents.'), 'keeps description');
|
||||
assert.ok(frontmatter.includes('tools:'), 'adds Gemini tools array');
|
||||
assert.ok(frontmatter.includes(' - read_file'), 'maps Read -> read_file');
|
||||
assert.ok(frontmatter.includes(' - run_shell_command'), 'maps Bash -> run_shell_command');
|
||||
assert.ok(frontmatter.includes(' - search_file_content'), 'maps Grep -> search_file_content');
|
||||
assert.ok(frontmatter.includes(' - glob'), 'maps Glob -> glob');
|
||||
assert.ok(frontmatter.includes(' - write_file'), 'maps Write -> write_file');
|
||||
assert.ok(!frontmatter.includes('color:'), 'drops unsupported color field');
|
||||
assert.ok(!frontmatter.includes('skills:'), 'drops unsupported skills field');
|
||||
assert.ok(!frontmatter.includes('gsd-mapper-workflow'), 'drops skills list items');
|
||||
assert.ok(result.includes('$PHASE'), 'escapes ${PHASE} shell variable for Gemini');
|
||||
assert.ok(!result.includes('${PHASE}'), 'removes Gemini template-string pattern');
|
||||
});
|
||||
});
|
||||
134
tests/model-profiles.test.cjs
Normal file
134
tests/model-profiles.test.cjs
Normal file
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* Model Profiles Tests
|
||||
*
|
||||
* Tests for MODEL_PROFILES data structure, VALID_PROFILES list,
|
||||
* formatAgentToModelMapAsTable, and getAgentToModelMapForProfile.
|
||||
*/
|
||||
|
||||
const { test, describe } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const {
|
||||
MODEL_PROFILES,
|
||||
VALID_PROFILES,
|
||||
formatAgentToModelMapAsTable,
|
||||
getAgentToModelMapForProfile,
|
||||
} = require('../get-shit-done/bin/lib/model-profiles.cjs');
|
||||
|
||||
// ─── MODEL_PROFILES data integrity ────────────────────────────────────────────
|
||||
|
||||
describe('MODEL_PROFILES', () => {
|
||||
test('contains all expected GSD agents', () => {
|
||||
const expectedAgents = [
|
||||
'gsd-planner', 'gsd-roadmapper', 'gsd-executor',
|
||||
'gsd-phase-researcher', 'gsd-project-researcher', 'gsd-research-synthesizer',
|
||||
'gsd-debugger', 'gsd-codebase-mapper', 'gsd-verifier',
|
||||
'gsd-plan-checker', 'gsd-integration-checker', 'gsd-nyquist-auditor',
|
||||
'gsd-ui-researcher', 'gsd-ui-checker', 'gsd-ui-auditor',
|
||||
];
|
||||
for (const agent of expectedAgents) {
|
||||
assert.ok(MODEL_PROFILES[agent], `Missing agent: ${agent}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('every agent has quality, balanced, and budget profiles', () => {
|
||||
for (const [agent, profiles] of Object.entries(MODEL_PROFILES)) {
|
||||
assert.ok(profiles.quality, `${agent} missing quality profile`);
|
||||
assert.ok(profiles.balanced, `${agent} missing balanced profile`);
|
||||
assert.ok(profiles.budget, `${agent} missing budget profile`);
|
||||
}
|
||||
});
|
||||
|
||||
test('all profile values are valid model aliases', () => {
|
||||
const validModels = ['opus', 'sonnet', 'haiku'];
|
||||
for (const [agent, profiles] of Object.entries(MODEL_PROFILES)) {
|
||||
for (const [profile, model] of Object.entries(profiles)) {
|
||||
assert.ok(
|
||||
validModels.includes(model),
|
||||
`${agent}.${profile} has invalid model "${model}" — expected one of ${validModels.join(', ')}`
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('quality profile never uses haiku', () => {
|
||||
for (const [agent, profiles] of Object.entries(MODEL_PROFILES)) {
|
||||
assert.notStrictEqual(
|
||||
profiles.quality, 'haiku',
|
||||
`${agent} quality profile should not use haiku`
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ─── VALID_PROFILES ───────────────────────────────────────────────────────────
|
||||
|
||||
describe('VALID_PROFILES', () => {
|
||||
test('contains quality, balanced, and budget', () => {
|
||||
assert.deepStrictEqual(VALID_PROFILES.sort(), ['balanced', 'budget', 'quality']);
|
||||
});
|
||||
|
||||
test('is derived from MODEL_PROFILES keys', () => {
|
||||
const fromData = Object.keys(MODEL_PROFILES['gsd-planner']);
|
||||
assert.deepStrictEqual(VALID_PROFILES.sort(), fromData.sort());
|
||||
});
|
||||
});
|
||||
|
||||
// ─── getAgentToModelMapForProfile ─────────────────────────────────────────────
|
||||
|
||||
describe('getAgentToModelMapForProfile', () => {
|
||||
test('returns correct models for balanced profile', () => {
|
||||
const map = getAgentToModelMapForProfile('balanced');
|
||||
assert.strictEqual(map['gsd-planner'], 'opus');
|
||||
assert.strictEqual(map['gsd-codebase-mapper'], 'haiku');
|
||||
assert.strictEqual(map['gsd-verifier'], 'sonnet');
|
||||
});
|
||||
|
||||
test('returns correct models for budget profile', () => {
|
||||
const map = getAgentToModelMapForProfile('budget');
|
||||
assert.strictEqual(map['gsd-planner'], 'sonnet');
|
||||
assert.strictEqual(map['gsd-phase-researcher'], 'haiku');
|
||||
});
|
||||
|
||||
test('returns correct models for quality profile', () => {
|
||||
const map = getAgentToModelMapForProfile('quality');
|
||||
assert.strictEqual(map['gsd-planner'], 'opus');
|
||||
assert.strictEqual(map['gsd-executor'], 'opus');
|
||||
});
|
||||
|
||||
test('returns all agents in the map', () => {
|
||||
const map = getAgentToModelMapForProfile('balanced');
|
||||
const agentCount = Object.keys(MODEL_PROFILES).length;
|
||||
assert.strictEqual(Object.keys(map).length, agentCount);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── formatAgentToModelMapAsTable ─────────────────────────────────────────────
|
||||
|
||||
describe('formatAgentToModelMapAsTable', () => {
|
||||
test('produces a table with header and separator', () => {
|
||||
const map = { 'gsd-planner': 'opus', 'gsd-executor': 'sonnet' };
|
||||
const table = formatAgentToModelMapAsTable(map);
|
||||
assert.ok(table.includes('Agent'), 'should have Agent header');
|
||||
assert.ok(table.includes('Model'), 'should have Model header');
|
||||
assert.ok(table.includes('─'), 'should have separator line');
|
||||
assert.ok(table.includes('gsd-planner'), 'should list agent');
|
||||
assert.ok(table.includes('opus'), 'should list model');
|
||||
});
|
||||
|
||||
test('pads columns correctly', () => {
|
||||
const map = { 'a': 'opus', 'very-long-agent-name': 'haiku' };
|
||||
const table = formatAgentToModelMapAsTable(map);
|
||||
const lines = table.split('\n').filter(l => l.trim());
|
||||
// Separator line uses ┼, data/header lines use │
|
||||
const dataLines = lines.filter(l => l.includes('│'));
|
||||
const pipePositions = dataLines.map(l => l.indexOf('│'));
|
||||
const unique = [...new Set(pipePositions)];
|
||||
assert.strictEqual(unique.length, 1, 'all data lines should align on │');
|
||||
});
|
||||
|
||||
test('handles empty map', () => {
|
||||
const table = formatAgentToModelMapAsTable({});
|
||||
assert.ok(table.includes('Agent'), 'should still have header');
|
||||
});
|
||||
});
|
||||
197
tests/profile-output.test.cjs
Normal file
197
tests/profile-output.test.cjs
Normal file
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* Profile Output Tests
|
||||
*
|
||||
* Tests for profile rendering commands and PROFILING_QUESTIONS data.
|
||||
*/
|
||||
|
||||
const { test, describe, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { runGsdTools, createTempProject, createTempGitProject, cleanup } = require('./helpers.cjs');
|
||||
|
||||
const {
|
||||
PROFILING_QUESTIONS,
|
||||
CLAUDE_INSTRUCTIONS,
|
||||
} = require('../get-shit-done/bin/lib/profile-output.cjs');
|
||||
|
||||
// ─── PROFILING_QUESTIONS data ─────────────────────────────────────────────────
|
||||
|
||||
describe('PROFILING_QUESTIONS', () => {
|
||||
test('is a non-empty array', () => {
|
||||
assert.ok(Array.isArray(PROFILING_QUESTIONS));
|
||||
assert.ok(PROFILING_QUESTIONS.length > 0);
|
||||
});
|
||||
|
||||
test('each question has required fields', () => {
|
||||
for (const q of PROFILING_QUESTIONS) {
|
||||
assert.ok(q.dimension, `question missing dimension`);
|
||||
assert.ok(q.header, `${q.dimension} missing header`);
|
||||
assert.ok(q.question, `${q.dimension} missing question`);
|
||||
assert.ok(Array.isArray(q.options), `${q.dimension} options should be array`);
|
||||
assert.ok(q.options.length >= 2, `${q.dimension} should have at least 2 options`);
|
||||
}
|
||||
});
|
||||
|
||||
test('each option has label, value, and rating', () => {
|
||||
for (const q of PROFILING_QUESTIONS) {
|
||||
for (const opt of q.options) {
|
||||
assert.ok(opt.label, `${q.dimension} option missing label`);
|
||||
assert.ok(opt.value, `${q.dimension} option missing value`);
|
||||
assert.ok(opt.rating, `${q.dimension} option missing rating`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('all dimension keys are unique', () => {
|
||||
const dims = PROFILING_QUESTIONS.map(q => q.dimension);
|
||||
const unique = [...new Set(dims)];
|
||||
assert.strictEqual(dims.length, unique.length);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── CLAUDE_INSTRUCTIONS ──────────────────────────────────────────────────────
|
||||
|
||||
describe('CLAUDE_INSTRUCTIONS', () => {
|
||||
test('is a non-empty object', () => {
|
||||
assert.ok(typeof CLAUDE_INSTRUCTIONS === 'object');
|
||||
assert.ok(Object.keys(CLAUDE_INSTRUCTIONS).length > 0);
|
||||
});
|
||||
|
||||
test('each dimension has at least one instruction', () => {
|
||||
for (const [dim, instructions] of Object.entries(CLAUDE_INSTRUCTIONS)) {
|
||||
assert.ok(typeof instructions === 'object', `${dim} should be an object`);
|
||||
assert.ok(Object.keys(instructions).length > 0, `${dim} should have instructions`);
|
||||
}
|
||||
});
|
||||
|
||||
test('every PROFILING_QUESTIONS dimension has CLAUDE_INSTRUCTIONS', () => {
|
||||
for (const q of PROFILING_QUESTIONS) {
|
||||
assert.ok(
|
||||
CLAUDE_INSTRUCTIONS[q.dimension],
|
||||
`${q.dimension} has questions but no CLAUDE_INSTRUCTIONS`
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ─── write-profile command ────────────────────────────────────────────────────
|
||||
|
||||
describe('write-profile command', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('writes USER-PROFILE.md from analysis JSON', () => {
|
||||
const analysis = {
|
||||
profile_version: '1.0',
|
||||
dimensions: {
|
||||
communication_style: { rating: 'terse-direct', confidence: 'HIGH' },
|
||||
decision_speed: { rating: 'fast-intuitive', confidence: 'MEDIUM' },
|
||||
explanation_depth: { rating: 'concise', confidence: 'HIGH' },
|
||||
debugging_approach: { rating: 'fix-first', confidence: 'LOW' },
|
||||
ux_philosophy: { rating: 'function-first', confidence: 'MEDIUM' },
|
||||
vendor_philosophy: { rating: 'pragmatic', confidence: 'HIGH' },
|
||||
frustration_triggers: { rating: 'over-explanation', confidence: 'LOW' },
|
||||
learning_style: { rating: 'hands-on', confidence: 'MEDIUM' },
|
||||
},
|
||||
};
|
||||
|
||||
const analysisPath = path.join(tmpDir, 'analysis.json');
|
||||
fs.writeFileSync(analysisPath, JSON.stringify(analysis));
|
||||
|
||||
const result = runGsdTools(['write-profile', '--input', analysisPath, '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.ok(out.profile_path, 'should return profile_path');
|
||||
assert.ok(out.dimensions_scored > 0, 'should have scored dimensions');
|
||||
});
|
||||
|
||||
test('errors when --input is missing', () => {
|
||||
const result = runGsdTools('write-profile --raw', tmpDir);
|
||||
assert.ok(!result.success, 'should fail without --input');
|
||||
assert.ok(result.error.includes('--input'), 'should mention --input');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── generate-claude-md command ───────────────────────────────────────────────
|
||||
|
||||
describe('generate-claude-md command', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createTempGitProject();
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'PROJECT.md'),
|
||||
'# My Project\n\nA test project.\n\n## Tech Stack\n\n- Node.js\n- TypeScript\n'
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('generates CLAUDE.md with --auto flag', () => {
|
||||
const outputPath = path.join(tmpDir, 'CLAUDE.md');
|
||||
const result = runGsdTools(['generate-claude-md', '--output', outputPath, '--auto', '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
|
||||
if (fs.existsSync(outputPath)) {
|
||||
const content = fs.readFileSync(outputPath, 'utf-8');
|
||||
assert.ok(content.length > 0, 'should have content');
|
||||
}
|
||||
});
|
||||
|
||||
test('does not overwrite existing CLAUDE.md without --force', () => {
|
||||
const outputPath = path.join(tmpDir, 'CLAUDE.md');
|
||||
fs.writeFileSync(outputPath, '# Custom CLAUDE.md\n\nUser content.\n');
|
||||
|
||||
const result = runGsdTools(['generate-claude-md', '--output', outputPath, '--auto', '--raw'], tmpDir);
|
||||
// Should merge, not overwrite
|
||||
const content = fs.readFileSync(outputPath, 'utf-8');
|
||||
assert.ok(content.length > 0, 'should still have content');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── generate-dev-preferences ─────────────────────────────────────────────────
|
||||
|
||||
describe('generate-dev-preferences command', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('errors when --analysis is missing', () => {
|
||||
const result = runGsdTools('generate-dev-preferences --raw', tmpDir);
|
||||
assert.ok(!result.success, 'should fail without --analysis');
|
||||
assert.ok(result.error.includes('--analysis'), 'should mention --analysis');
|
||||
});
|
||||
|
||||
test('generates preferences from analysis file', () => {
|
||||
const analysis = {
|
||||
profile_version: '1.0',
|
||||
dimensions: {
|
||||
communication_style: { rating: 'terse-direct', confidence: 'HIGH' },
|
||||
decision_speed: { rating: 'fast-intuitive', confidence: 'MEDIUM' },
|
||||
},
|
||||
};
|
||||
const analysisPath = path.join(tmpDir, 'analysis.json');
|
||||
fs.writeFileSync(analysisPath, JSON.stringify(analysis));
|
||||
|
||||
const result = runGsdTools(['generate-dev-preferences', '--analysis', analysisPath, '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.ok(out.command_path || out.command_name, 'should return command output');
|
||||
});
|
||||
});
|
||||
160
tests/profile-pipeline.test.cjs
Normal file
160
tests/profile-pipeline.test.cjs
Normal file
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* Profile Pipeline Tests
|
||||
*
|
||||
* Tests for session scanning, message extraction, and profile sampling.
|
||||
* Uses synthetic session data in temp directories via --path override.
|
||||
*/
|
||||
|
||||
const { test, describe, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
|
||||
|
||||
// ─── scan-sessions ────────────────────────────────────────────────────────────
|
||||
|
||||
describe('scan-sessions command', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-profile-test-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('returns empty array for empty sessions directory', () => {
|
||||
const sessionsDir = path.join(tmpDir, 'projects');
|
||||
fs.mkdirSync(sessionsDir, { recursive: true });
|
||||
const result = runGsdTools(`scan-sessions --path ${sessionsDir} --raw`, tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.ok(Array.isArray(out), 'should return an array');
|
||||
assert.strictEqual(out.length, 0, 'should be empty');
|
||||
});
|
||||
|
||||
test('scans synthetic project directory', () => {
|
||||
const sessionsDir = path.join(tmpDir, 'projects');
|
||||
const projectDir = path.join(sessionsDir, 'test-project-abc123');
|
||||
fs.mkdirSync(projectDir, { recursive: true });
|
||||
|
||||
// Create a synthetic session file
|
||||
const sessionData = [
|
||||
JSON.stringify({ type: 'user', userType: 'external', message: { content: 'hello' }, timestamp: Date.now() }),
|
||||
JSON.stringify({ type: 'assistant', message: { content: 'hi' }, timestamp: Date.now() }),
|
||||
].join('\n');
|
||||
fs.writeFileSync(path.join(projectDir, 'session-001.jsonl'), sessionData);
|
||||
|
||||
const result = runGsdTools(`scan-sessions --path ${sessionsDir} --raw`, tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.ok(Array.isArray(out), 'should return array');
|
||||
assert.strictEqual(out.length, 1, 'should find 1 project');
|
||||
assert.strictEqual(out[0].sessionCount, 1, 'should have 1 session');
|
||||
});
|
||||
|
||||
test('reports multiple sessions and sizes', () => {
|
||||
const sessionsDir = path.join(tmpDir, 'projects');
|
||||
const projectDir = path.join(sessionsDir, 'multi-session-project');
|
||||
fs.mkdirSync(projectDir, { recursive: true });
|
||||
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
const data = JSON.stringify({ type: 'user', userType: 'external', message: { content: `msg ${i}` }, timestamp: Date.now() });
|
||||
fs.writeFileSync(path.join(projectDir, `session-${i}.jsonl`), data + '\n');
|
||||
}
|
||||
|
||||
const result = runGsdTools(`scan-sessions --path ${sessionsDir} --raw`, tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.strictEqual(out[0].sessionCount, 3);
|
||||
assert.ok(out[0].totalSize > 0, 'should have non-zero size');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── extract-messages ─────────────────────────────────────────────────────────
|
||||
|
||||
describe('extract-messages command', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-profile-test-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('extracts user messages from synthetic session', () => {
|
||||
const sessionsDir = path.join(tmpDir, 'projects');
|
||||
const projectDir = path.join(sessionsDir, 'my-project');
|
||||
fs.mkdirSync(projectDir, { recursive: true });
|
||||
|
||||
const messages = [
|
||||
{ type: 'user', userType: 'external', message: { content: 'fix the login bug' }, timestamp: Date.now() },
|
||||
{ type: 'assistant', message: { content: 'I will fix it.' }, timestamp: Date.now() },
|
||||
{ type: 'user', userType: 'external', message: { content: 'add dark mode' }, timestamp: Date.now() },
|
||||
{ type: 'user', userType: 'internal', isMeta: true, message: { content: '<local-command' }, timestamp: Date.now() },
|
||||
];
|
||||
fs.writeFileSync(
|
||||
path.join(projectDir, 'session-001.jsonl'),
|
||||
messages.map(m => JSON.stringify(m)).join('\n')
|
||||
);
|
||||
|
||||
const result = runGsdTools(`extract-messages my-project --path ${sessionsDir} --raw`, tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.strictEqual(out.messages_extracted, 2, 'should extract 2 genuine user messages');
|
||||
assert.strictEqual(out.project, 'my-project');
|
||||
assert.ok(out.output_file, 'should have output file path');
|
||||
});
|
||||
|
||||
test('filters out meta and internal messages', () => {
|
||||
const sessionsDir = path.join(tmpDir, 'projects');
|
||||
const projectDir = path.join(sessionsDir, 'filter-test');
|
||||
fs.mkdirSync(projectDir, { recursive: true });
|
||||
|
||||
const messages = [
|
||||
{ type: 'user', userType: 'external', message: { content: 'real message' }, timestamp: Date.now() },
|
||||
{ type: 'user', userType: 'internal', message: { content: 'internal msg' }, timestamp: Date.now() },
|
||||
{ type: 'user', userType: 'external', isMeta: true, message: { content: 'meta msg' }, timestamp: Date.now() },
|
||||
{ type: 'user', userType: 'external', message: { content: '<local-command test' }, timestamp: Date.now() },
|
||||
{ type: 'user', userType: 'external', message: { content: '' }, timestamp: Date.now() },
|
||||
{ type: 'user', userType: 'external', message: { content: 'second real' }, timestamp: Date.now() },
|
||||
];
|
||||
fs.writeFileSync(
|
||||
path.join(projectDir, 'session-001.jsonl'),
|
||||
messages.map(m => JSON.stringify(m)).join('\n')
|
||||
);
|
||||
|
||||
const result = runGsdTools(`extract-messages filter-test --path ${sessionsDir} --raw`, tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.strictEqual(out.messages_extracted, 2, 'should only extract 2 genuine external messages');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── profile-questionnaire ────────────────────────────────────────────────────
|
||||
|
||||
describe('profile-questionnaire command', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('returns questionnaire structure', () => {
|
||||
const result = runGsdTools('profile-questionnaire --raw', tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.ok(out.questions, 'should have questions array');
|
||||
assert.ok(out.questions.length > 0, 'should have at least one question');
|
||||
assert.ok(out.questions[0].dimension, 'each question should have a dimension');
|
||||
assert.ok(out.questions[0].options, 'each question should have options');
|
||||
});
|
||||
});
|
||||
@@ -1,19 +1,23 @@
|
||||
/**
|
||||
* OpenCode Agent Frontmatter Conversion Tests
|
||||
* Runtime Converter Tests — OpenCode + Gemini
|
||||
*
|
||||
* Validates that convertClaudeToOpencodeFrontmatter correctly converts
|
||||
* agent frontmatter for OpenCode compatibility when isAgent: true.
|
||||
* Tests for small runtime-specific conversion functions from install.js.
|
||||
* Larger runtime test suites (Copilot, Codex, Antigravity) have their own files.
|
||||
*
|
||||
* Bug: Without isAgent flag, the function strips name: (agents need it),
|
||||
* keeps color:/skills:/tools: record (should strip), and doesn't add
|
||||
* model: inherit / mode: subagent (required by OpenCode agents).
|
||||
* OpenCode: convertClaudeToOpencodeFrontmatter (agent + command modes)
|
||||
* model: inherit is NOT added (OpenCode doesn't support it — see #1156)
|
||||
* but mode: subagent IS added (required by OpenCode agents).
|
||||
* Gemini: convertClaudeToGeminiAgent (frontmatter + tool mapping + body escaping)
|
||||
*/
|
||||
|
||||
const { test, describe } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
|
||||
process.env.GSD_TEST_MODE = '1';
|
||||
const { convertClaudeToOpencodeFrontmatter } = require('../bin/install.js');
|
||||
const {
|
||||
convertClaudeToOpencodeFrontmatter,
|
||||
convertClaudeToGeminiAgent,
|
||||
} = require('../bin/install.js');
|
||||
|
||||
// Sample Claude agent frontmatter (matches actual GSD agent format)
|
||||
const SAMPLE_AGENT = `---
|
||||
@@ -54,10 +58,10 @@ describe('OpenCode agent conversion (isAgent: true)', () => {
|
||||
assert.ok(frontmatter.includes('name: gsd-executor'), 'name: should be preserved for agents');
|
||||
});
|
||||
|
||||
test('adds model: inherit', () => {
|
||||
test('does not add model: inherit (OpenCode does not support it)', () => {
|
||||
const result = convertClaudeToOpencodeFrontmatter(SAMPLE_AGENT, { isAgent: true });
|
||||
const frontmatter = result.split('---')[1];
|
||||
assert.ok(frontmatter.includes('model: inherit'), 'model: inherit should be added');
|
||||
assert.ok(!frontmatter.includes('model: inherit'), 'model: inherit should NOT be added — OpenCode throws ProviderModelNotFoundError');
|
||||
});
|
||||
|
||||
test('adds mode: subagent', () => {
|
||||
@@ -141,3 +145,41 @@ describe('OpenCode command conversion (isAgent: false, default)', () => {
|
||||
assert.ok(frontmatter.includes('description:'), 'description should be kept');
|
||||
});
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Gemini CLI agent conversion (merged from gemini-config.test.cjs)
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('convertClaudeToGeminiAgent', () => {
|
||||
test('drops unsupported skills frontmatter while keeping converted tools', () => {
|
||||
const input = `---
|
||||
name: gsd-codebase-mapper
|
||||
description: Explores codebase and writes structured analysis documents.
|
||||
tools: Read, Bash, Grep, Glob, Write
|
||||
color: cyan
|
||||
skills:
|
||||
- gsd-mapper-workflow
|
||||
---
|
||||
|
||||
<role>
|
||||
Use \${PHASE} in shell examples.
|
||||
</role>`;
|
||||
|
||||
const result = convertClaudeToGeminiAgent(input);
|
||||
const frontmatter = result.split('---')[1] || '';
|
||||
|
||||
assert.ok(frontmatter.includes('name: gsd-codebase-mapper'), 'keeps name');
|
||||
assert.ok(frontmatter.includes('description: Explores codebase and writes structured analysis documents.'), 'keeps description');
|
||||
assert.ok(frontmatter.includes('tools:'), 'adds Gemini tools array');
|
||||
assert.ok(frontmatter.includes(' - read_file'), 'maps Read -> read_file');
|
||||
assert.ok(frontmatter.includes(' - run_shell_command'), 'maps Bash -> run_shell_command');
|
||||
assert.ok(frontmatter.includes(' - search_file_content'), 'maps Grep -> search_file_content');
|
||||
assert.ok(frontmatter.includes(' - glob'), 'maps Glob -> glob');
|
||||
assert.ok(frontmatter.includes(' - write_file'), 'maps Write -> write_file');
|
||||
assert.ok(!frontmatter.includes('color:'), 'drops unsupported color field');
|
||||
assert.ok(!frontmatter.includes('skills:'), 'drops unsupported skills field');
|
||||
assert.ok(!frontmatter.includes('gsd-mapper-workflow'), 'drops skills list items');
|
||||
assert.ok(result.includes('$PHASE'), 'escapes ${PHASE} shell variable for Gemini');
|
||||
assert.ok(!result.includes('${PHASE}'), 'removes Gemini template-string pattern');
|
||||
});
|
||||
});
|
||||
186
tests/template.test.cjs
Normal file
186
tests/template.test.cjs
Normal file
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* 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');
|
||||
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}`);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user