cmte
Version:
Design by Committee™ except it's just you and LLMs
199 lines (156 loc) • 4.92 kB
JavaScript
/**
* Test script for the two-phase processor
*
* This script tests the functionality of the two-phase processor
* without requiring the Claude API.
*
* Usage: node --experimental-strip-types src/processors/test-two-phase.ts
*/
import fs from 'fs/promises';
import path from 'path';
import { ensureDir } from 'fs-extra';
import { TemplateRenderer } from '../templates/renderer.js';
import logger from '../utils/logger.js';
import { resolvePath, writeFile } from '../utils/fs.js';
/**
* A simplified version of the two-phase processor for testing
*/
async function testTwoPhaseProcess(config) {
logger.info(`Starting test two-phase process for ${config.role} in phase ${config.phase}`);
// Get the template directory
const templateDir = path.dirname(config.thinkingPromptTemplate);
// Create a template renderer
const renderer = new TemplateRenderer(config.context, templateDir);
// Resolve output paths
const thinking = resolvePath(config.outputPath.thinking, config.context);
const response = resolvePath(config.outputPath.response, config.context);
// Create output directories
await ensureDir(path.dirname(thinking));
await ensureDir(path.dirname(response));
// Get the template name
const templateName = path.basename(config.thinkingPromptTemplate);
// Mock thinking phase
const thinkingResult = `# Thinking about ${config.context.directiveName}
I am thinking about the ${config.context.directiveName} directive. This is a mock response.
## Analysis
This is a test directive that doesn't do anything.
## Considerations
- Test consideration 1
- Test consideration 2
- Test consideration 3
## Conclusion
This is a simple test directive.`;
// Write thinking output
await writeFile(thinking, thinkingResult);
// Add thinking result to context
const enhancedContext = {
...config.context,
thinking: thinkingResult
};
// Get response template name
const responseTemplateName = path.basename(config.responsePromptTemplate);
// Mock response phase
const responseResult = `# ${config.context.directiveName} Specification
## Overview
The \`${config.context.directiveName}\` is a simple directive for testing purposes.
## Implementation
This is a mock implementation.
## Examples
\`\`\`yaml
test: value
\`\`\`
## Notes
This is a test directive.`;
// Write response output
await writeFile(response, responseResult);
return {
thinking: thinkingResult,
response: responseResult
};
}
/**
* Create test template files
*/
async function createTestTemplates() {
// Create test directory if it doesn't exist
const testDir = path.join(process.cwd(), '_dev', 'test-two-phase');
await fs.mkdir(testDir, {
recursive: true
});
// Create thinking template
const thinkingTemplatePath = path.join(testDir, 'thinking-template.md');
const thinkingTemplate = `
# Test Thinking Template
## Context
I am the {{role}} for the {{directiveName}} directive.
## Task
Think about what the {{directiveName}} directive should do.
Consider:
1. What properties should it have?
2. How should it be processed?
3. What use cases should it support?
## Now think deeply about this problem.
`;
// Create response template
const responseTemplatePath = path.join(testDir, 'response-template.md');
const responseTemplate = `
# Test Response Template
## Context
I am the {{role}} for the {{directiveName}} directive.
## Thinking
Here's what I thought about:
{{thinking}}
## Task
Based on my thinking above, create a draft specification for the {{directiveName}} directive.
`;
// Write templates to disk
await fs.writeFile(thinkingTemplatePath, thinkingTemplate, 'utf8');
await fs.writeFile(responseTemplatePath, responseTemplate, 'utf8');
return {
thinkingTemplatePath,
responseTemplatePath,
outputDir: testDir
};
}
/**
* Run the test
*/
async function runTest() {
try {
// Create test templates
await createTestTemplates();
// Create context
const context = {
directiveName: 'test-directive',
description: 'A test directive',
parameters: ['param1', 'param2'],
examples: ['example1', 'example2']
};
// Configure test
const config = {
role: 'test-role',
phase: 'test-phase',
thinkingPromptTemplate: 'tasks/thinking.md',
responsePromptTemplate: 'tasks/response.md',
context,
outputPath: {
thinking: 'output/thinking.md',
response: 'output/response.md'
},
processType: 'two-phase',
params: {
thinkingPromptTemplate: 'tasks/thinking.md',
responsePromptTemplate: 'tasks/response.md',
outputDir: '_dev/test/two-phase'
}
};
// Run test
await testTwoPhaseProcess(config);
logger.info('Test completed successfully');
} catch (error) {
logger.error('Test failed:', error);
process.exit(1);
}
}
// Run the test
runTest();