mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-02 05:29:42 +02:00
test: add unit tests for CLAUDE.md template generation
Adds 16 tests covering: - Default template generation with case name and description - Date placeholder replacement - Claudeman environment section inclusion - Work principles and TodoWrite guidance - Ralph Wiggum Loop section - Custom template loading and fallback behavior Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
||||
<a href="https://nodejs.org/"><img src="https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen" alt="Node.js Version"></a>
|
||||
<a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-5.5-blue" alt="TypeScript"></a>
|
||||
<a href="./test"><img src="https://img.shields.io/badge/tests-355%20passing-success" alt="Tests"></a>
|
||||
<a href="./test"><img src="https://img.shields.io/badge/tests-355%20passing-brightgreen" alt="Tests"></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* @fileoverview Tests for template generation functions
|
||||
*
|
||||
* Tests the CLAUDE.md template generation including
|
||||
* default template and custom template loading.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { existsSync, writeFileSync, unlinkSync, mkdirSync, rmSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { generateClaudeMd } from '../src/templates/claude-md.js';
|
||||
|
||||
describe('generateClaudeMd', () => {
|
||||
const testDir = join(tmpdir(), 'claudeman-template-test-' + Date.now());
|
||||
|
||||
beforeEach(() => {
|
||||
if (!existsSync(testDir)) {
|
||||
mkdirSync(testDir, { recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
try {
|
||||
rmSync(testDir, { recursive: true, force: true });
|
||||
} catch (e) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
});
|
||||
|
||||
describe('default template', () => {
|
||||
it('should generate template with case name', () => {
|
||||
const result = generateClaudeMd('my-project');
|
||||
|
||||
expect(result).toContain('**Project Name**: my-project');
|
||||
});
|
||||
|
||||
it('should generate template with description', () => {
|
||||
const result = generateClaudeMd('my-project', 'A test project description');
|
||||
|
||||
expect(result).toContain('**Description**: A test project description');
|
||||
});
|
||||
|
||||
it('should use default description when not provided', () => {
|
||||
const result = generateClaudeMd('my-project');
|
||||
|
||||
expect(result).toContain('**Description**: A new project');
|
||||
});
|
||||
|
||||
it('should include current date', () => {
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
const result = generateClaudeMd('my-project');
|
||||
|
||||
expect(result).toContain(`**Last Updated**: ${today}`);
|
||||
});
|
||||
|
||||
it('should include Claudeman environment section', () => {
|
||||
const result = generateClaudeMd('my-project');
|
||||
|
||||
expect(result).toContain('## Claudeman Environment');
|
||||
expect(result).toContain('CLAUDEMAN_SCREEN=1');
|
||||
});
|
||||
|
||||
it('should include work principles', () => {
|
||||
const result = generateClaudeMd('my-project');
|
||||
|
||||
expect(result).toContain('## Work Principles');
|
||||
expect(result).toContain('### Autonomy');
|
||||
expect(result).toContain('### Git Discipline');
|
||||
});
|
||||
|
||||
it('should include TodoWrite guidance', () => {
|
||||
const result = generateClaudeMd('my-project');
|
||||
|
||||
expect(result).toContain('### Task Tracking (TodoWrite)');
|
||||
expect(result).toContain('**ALWAYS use TodoWrite**');
|
||||
});
|
||||
|
||||
it('should include Ralph Wiggum Loop section', () => {
|
||||
const result = generateClaudeMd('my-project');
|
||||
|
||||
expect(result).toContain('## Ralph Wiggum Loop');
|
||||
expect(result).toContain('/ralph-loop:ralph-loop');
|
||||
expect(result).toContain('/ralph-loop:cancel-ralph');
|
||||
});
|
||||
|
||||
it('should include planning mode section', () => {
|
||||
const result = generateClaudeMd('my-project');
|
||||
|
||||
expect(result).toContain('## Planning Mode');
|
||||
expect(result).toContain('Multi-file changes');
|
||||
});
|
||||
|
||||
it('should include session log table', () => {
|
||||
const result = generateClaudeMd('my-project');
|
||||
|
||||
expect(result).toContain('## Session Log');
|
||||
expect(result).toContain('| Date | Tasks Completed | Files Changed | Notes |');
|
||||
});
|
||||
});
|
||||
|
||||
describe('custom template', () => {
|
||||
it('should use custom template when provided and exists', () => {
|
||||
const templatePath = join(testDir, 'custom-template.md');
|
||||
writeFileSync(templatePath, `
|
||||
# [PROJECT_NAME]
|
||||
|
||||
Description: [PROJECT_DESCRIPTION]
|
||||
Date: [DATE]
|
||||
|
||||
Custom content here.
|
||||
`);
|
||||
|
||||
const result = generateClaudeMd('my-project', 'Test desc', templatePath);
|
||||
|
||||
expect(result).toContain('# my-project');
|
||||
expect(result).toContain('Description: Test desc');
|
||||
expect(result).toContain('Custom content here.');
|
||||
});
|
||||
|
||||
it('should replace all placeholder occurrences', () => {
|
||||
const templatePath = join(testDir, 'multi-placeholder.md');
|
||||
writeFileSync(templatePath, `
|
||||
[PROJECT_NAME] is a project.
|
||||
The name is [PROJECT_NAME].
|
||||
About [PROJECT_NAME]: [PROJECT_DESCRIPTION]
|
||||
`);
|
||||
|
||||
const result = generateClaudeMd('awesome-app', 'Cool stuff', templatePath);
|
||||
|
||||
expect(result).toContain('awesome-app is a project.');
|
||||
expect(result).toContain('The name is awesome-app.');
|
||||
expect(result).toContain('About awesome-app: Cool stuff');
|
||||
});
|
||||
|
||||
it('should use default description in template when not provided', () => {
|
||||
const templatePath = join(testDir, 'desc-template.md');
|
||||
writeFileSync(templatePath, 'Description: [PROJECT_DESCRIPTION]');
|
||||
|
||||
const result = generateClaudeMd('my-project', '', templatePath);
|
||||
|
||||
expect(result).toContain('Description: A new project');
|
||||
});
|
||||
|
||||
it('should fall back to default template if custom file does not exist', () => {
|
||||
const result = generateClaudeMd('my-project', 'desc', '/nonexistent/template.md');
|
||||
|
||||
// Should get default template content
|
||||
expect(result).toContain('## Claudeman Environment');
|
||||
expect(result).toContain('**Project Name**: my-project');
|
||||
});
|
||||
|
||||
it('should fall back to default template if custom path is empty', () => {
|
||||
const result = generateClaudeMd('my-project', 'desc', '');
|
||||
|
||||
expect(result).toContain('## Claudeman Environment');
|
||||
});
|
||||
|
||||
it('should fall back to default template if custom path is undefined', () => {
|
||||
const result = generateClaudeMd('my-project', 'desc', undefined);
|
||||
|
||||
expect(result).toContain('## Claudeman Environment');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user