UNPKG

cmte

Version:

Design by Committee™ except it's just you and LLMs

234 lines (199 loc) 6.57 kB
import path from 'path'; import { fileURLToPath } from 'url'; import { writeFile } from '../../utils/fs.js'; import { ComponentRegistry, PathGenerator } from './index.js'; import logger from '../../utils/logger.js'; // Get the directory of this file to use for relative paths const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const basePath = path.resolve(__dirname, '../../../'); // Create example task, set, phase, and workflow files for testing async function createExampleFiles() { // Create directory structure const examplesDir = path.join(basePath, 'examples'); const workflowDir = path.join(examplesDir, 'simple'); const templatesDir = path.join(workflowDir, 'templates'); const tasksDir = path.join(templatesDir, 'tasks'); const setsDir = path.join(templatesDir, 'sets'); const phasesDir = path.join(templatesDir, 'phases'); // Create task template const taskContent = `--- name: "example-task" role: "service" requiredInput: ["input1", "input2"] requiredOutput: ["output1"] --- # Example Task Template This is an example task template for testing the component registry. ## Task Instructions Perform the following steps: 1. Process {{input1}} 2. Consider {{input2}} 3. Generate {{output1}} `; // Create set template const setContent = `name: "example-set" description: "Example set for testing" execution: "sequential" tasks: - description: "First task" useTask: "example-task" variables: input1: "value1" input2: "value2" - description: "Second task" useTask: "example-task" variables: input1: "value3" input2: "value4" requiredInput: ["setInput"] requiredOutput: ["setOutput"] `; // Create phase template const phaseContent = `name: "example-phase" description: "Example phase for testing" execution: "sequential" humanInputRequired: [] set: - description: "Example set" useSet: "example-set" variables: setInput: "phaseValue" requiredInput: ["phaseInput"] requiredOutput: ["phaseOutput"] `; // Create workflow template const workflowContent = `name: "simple-workflow" description: "Simple workflow for component registry" outputPath: "examples-output/simple" phases: - usePhase: "example-phase" `; // Create workflow-specific task const workflowTaskContent = `--- name: "workflow-specific-task" role: "architect" requiredInput: ["workflowInput"] requiredOutput: ["workflowOutput"] --- # Workflow-Specific Task This task is specific to the simple workflow. ## Instructions Process {{workflowInput}} to generate {{workflowOutput}}. `; // Write files try { // Write all templates and workflow files await writeFile(path.join(tasksDir, 'example-task.task.md'), taskContent); await writeFile(path.join(tasksDir, 'workflow-specific-task.task.md'), workflowTaskContent); await writeFile(path.join(setsDir, 'example-set.set.yaml'), setContent); await writeFile(path.join(phasesDir, 'example-phase.phase.yaml'), phaseContent); await writeFile(path.join(workflowDir, 'workflow.yaml'), workflowContent); logger.info('Example files created successfully'); } catch (error) { logger.error('Error creating example files', { error }); throw error; } } // Test the component registry async function testComponentRegistry() { try { logger.info('Testing component registry...'); // Create a component registry const registry = new ComponentRegistry(basePath); // Set workflow path for all tests registry.setWorkflowPath('examples/simple'); // Test task loading const task = await registry.loadTask('example-task'); logger.info('Loaded task:', { taskName: task.task.name }); // Test workflow-specific task loading const workflowTask = await registry.loadTask('workflow-specific-task'); logger.info('Loaded workflow-specific task:', { taskName: workflowTask.task.name }); // Test set loading const set = await registry.loadSet('example-set'); logger.info('Loaded set:', { setName: set.name }); // Test phase loading const phase = await registry.loadPhase('example-phase'); logger.info('Loaded phase:', { phaseName: phase.name }); // Test workflow loading const workflow = await registry.loadWorkflow('examples/simple'); logger.info('Loaded workflow:', { workflowName: workflow.name }); logger.info('Component registry testing completed successfully'); } catch (error) { logger.error('Error in component registry test', { error }); throw error; } } // Test the path generator function testPathGenerator() { try { logger.info('Testing path generator...'); // Create a path generator const pathGenerator = new PathGenerator('examples-output/simple'); // Test task output path const taskPath = pathGenerator.generateTaskOutputPath('phase1', 'iteration1', 'set1', 'service1', 'task1', 'thinking'); logger.info('Task path:', { path: taskPath }); // Test set output path const setPath = pathGenerator.generateSetOutputPath('phase1', 'iteration1', 'set1', 'service1'); logger.info('Set path:', { path: setPath }); // Test phase output path const phasePath = pathGenerator.generatePhaseOutputPath('phase1', 'iteration1'); logger.info('Phase path:', { path: phasePath }); // Test iterated task output path generation const iteratedTaskPath = pathGenerator.generateIteratedTaskOutputPath('phase1', 'set1', 'item1', 'task1'); logger.info('Iterated task output path:', { path: iteratedTaskPath }); // Test iterated set output path generation const iteratedSetPath = pathGenerator.generateIteratedSetOutputPath('phase1', 'set1', 'item1'); logger.info('Iterated set output path:', { path: iteratedSetPath }); logger.info('Path generator testing completed successfully'); } catch (error) { logger.error('Error in path generator test', { error }); throw error; } } // Main function to run all tests async function main() { try { logger.info('Starting component tests...'); // Create example files await createExampleFiles(); // Test component registry await testComponentRegistry(); // Test path generator testPathGenerator(); logger.info('All component tests completed successfully'); } catch (error) { logger.error('Error in component tests', { error }); process.exit(1); } } // Run the tests main();