cmte
Version:
Design by Committee™ except it's just you and LLMs
121 lines (104 loc) • 3.4 kB
JavaScript
/**
* Test script for the --prompts and --dryrun options
*
* This script tests the functionality of saving prompts and dry run mode
*
* Usage: npm run test:options
*/
import path from 'path';
import fs from 'fs/promises';
import getClaudeClient from "../core/llm/claude-adapter.js";
import logger from "../utils/logger.js";
import * as llmxml from "../utils/llmxml.js";
async function saveFileWithDir(filePath, content) {
await fs.mkdir(path.dirname(filePath), {
recursive: true
});
await fs.writeFile(filePath, content);
}
async function main() {
try {
logger.info('Testing --prompts and --dryrun options');
// Create test directory
const testDir = 'test/cli-options';
await fs.mkdir(testDir, {
recursive: true
});
// Create a simple prompt
const prompt = `
# Test Prompt
This is a test prompt to verify the --prompts and --dryrun options.
## Questions
1. What is the capital of France?
2. What is 2+2?
`;
// Output paths
const outputPath = path.join(testDir, 'test-response.o.xml');
const expectedPromptPath = path.join(testDir, 'test-response.sent.xml');
// Convert prompt to XML
const xmlPrompt = await llmxml.toXML(prompt);
// 1. Test saving prompts
logger.info('Testing --prompts option');
const claude = getClaudeClient();
// Clear any existing files first
try {
await fs.unlink(outputPath);
await fs.unlink(expectedPromptPath);
} catch (e) {
// Ignore errors if files don't exist
}
// Call Claude with savePrompt option
await claude.respond(prompt, {
savePrompt: true,
outputPath
});
// Check if prompt file exists
const promptFileExists = await fs.stat(expectedPromptPath).then(() => true).catch(() => false);
if (promptFileExists) {
logger.info('✅ Prompt file was created successfully');
// Read the content to verify
const savedPrompt = await fs.readFile(expectedPromptPath, 'utf-8');
if (savedPrompt.includes('Test Prompt')) {
logger.info('✅ Prompt content is correct');
} else {
logger.error('❌ Prompt content is incorrect');
}
} else {
logger.error('❌ Prompt file was not created');
}
// 2. Test dry run mode
logger.info('Testing --dryrun option');
// Clear any existing files first
try {
await fs.unlink(outputPath);
await fs.unlink(expectedPromptPath);
} catch (e) {
// Ignore errors if files don't exist
}
// Call Claude with dryRun option
const dryRunResponse = await claude.respond(prompt, {
savePrompt: true,
dryRun: true,
outputPath
});
// Check if prompt file exists and response is a dry run message
const dryRunPromptExists = await fs.stat(expectedPromptPath).then(() => true).catch(() => false);
if (dryRunPromptExists) {
logger.info('✅ Prompt file was created in dry run mode');
} else {
logger.error('❌ Prompt file was not created in dry run mode');
}
if (dryRunResponse.includes('DRY RUN MODE')) {
logger.info('✅ Dry run response contains expected placeholder');
} else {
logger.error('❌ Dry run response does not contain expected placeholder');
}
logger.info('Tests completed');
} catch (error) {
logger.error('Test failed', {
error
});
process.exit(1);
}
}
main();