#!/usr/bin/env node /** * Test Protocol Integration - Comprehensive test of AIPersonaEngine + SubagentProtocols * * This test file demonstrates and validates the complete integration between: * - AIPersonaEngine: Spawns real AI personas with Task tool * - SubagentProtocols: Manages strict artifact creation and tracking * - ArtifactManager: Handles artifact creation, validation, and dependency tracking */ import chalk from 'chalk'; import { AIPersonaEngine } from './core/ai-persona-engine'; import { ProjectState } from './core/project-state'; import { ArtifactManager } from './core/artifact-manager'; import { SubagentProtocolFactory, SubagentContext, MentorProtocol, GauntletProtocol, ArchitectProtocol } from './protocols/subagent-protocols'; async function testProtocolIntegration() { console.log(chalk.bold('\n๐Ÿงช TESTING PROTOCOL-AWARE AI PERSONA INTEGRATION\n')); try { // Initialize core components console.log(chalk.blue('1๏ธโƒฃ Initializing core components...')); const projectState = new ProjectState(); const artifactManager = new ArtifactManager(projectState); const aiEngine = new AIPersonaEngine(projectState); console.log(chalk.green(' โœ… Core components initialized')); // Test 1: Protocol Creation and Initialization console.log(chalk.blue('\n2๏ธโƒฃ Testing protocol creation and initialization...')); const mentorProtocol = SubagentProtocolFactory.createProtocol('The Mentor'); const gauntletProtocol = SubagentProtocolFactory.createProtocol('The Gauntlet'); const architectProtocol = SubagentProtocolFactory.createProtocol('The Architect'); const context: SubagentContext = { projectState, artifactManager, sessionId: `test-session-${Date.now()}`, userContext: 'Testing protocol integration with sample project context' }; console.log(chalk.green(` โœ… Created protocols: ${mentorProtocol.personaName}, ${gauntletProtocol.personaName}, ${architectProtocol.personaName}`)); // Test 2: Protocol Initialization console.log(chalk.blue('\n3๏ธโƒฃ Testing protocol initialization...')); await mentorProtocol.initialize(context); await gauntletProtocol.initialize(context); await architectProtocol.initialize(context); console.log(chalk.green(' โœ… All protocols initialized successfully')); // Test 3: Prerequisite Validation console.log(chalk.blue('\n4๏ธโƒฃ Testing prerequisite validation...')); // Mentor should always pass (no prerequisites) const mentorValidation = await mentorProtocol.validatePrerequisites(); console.log(` Mentor validation: ${mentorValidation.valid ? 'โœ… PASS' : 'โŒ FAIL'}`); // Gauntlet should pass (no prerequisites) const gauntletValidation = await gauntletProtocol.validatePrerequisites(); console.log(` Gauntlet validation: ${gauntletValidation.valid ? 'โœ… PASS' : 'โŒ FAIL'}`); // Architect should fail initially (requires validation-report) const architectValidation = await architectProtocol.validatePrerequisites(); console.log(` Architect validation: ${architectValidation.valid ? 'โœ… PASS' : 'โŒ FAIL (expected - needs validation)'}`); if (architectValidation.blockers.length > 0) { console.log(chalk.yellow(' Blockers:')); architectValidation.blockers.forEach(blocker => console.log(chalk.yellow(` โ€ข ${blocker}`))); } // Test 4: Artifact Creation console.log(chalk.blue('\n5๏ธโƒฃ Testing artifact creation...')); // Create mentor artifacts console.log(chalk.gray(' Creating mentor artifacts...')); const mentorArtifacts = await mentorProtocol.createArtifacts(); mentorArtifacts.forEach(artifact => { console.log(` ${artifact.status === 'created' ? 'โœ…' : 'โŒ'} ${artifact.type}: ${artifact.message}`); }); // Create gauntlet artifacts console.log(chalk.gray(' Creating gauntlet artifacts...')); const gauntletArtifacts = await gauntletProtocol.createArtifacts(); gauntletArtifacts.forEach(artifact => { console.log(` ${artifact.status === 'created' ? 'โœ…' : 'โŒ'} ${artifact.type}: ${artifact.message}`); }); // Test 5: AI Persona Configuration console.log(chalk.blue('\n6๏ธโƒฃ Testing AI persona configuration...')); const projectContext = ` Test Project Context: - Project: Protocol Integration Test - Phase: Testing - Created: ${new Date().toISOString()} - Purpose: Validate AIPersonaEngine + SubagentProtocols integration `; const mentorPersona = aiEngine.createMentorPersona(projectContext); const gauntletPersona = aiEngine.createGauntletPersona(projectContext); const architectPersona = aiEngine.createArchitectPersona(projectContext); console.log(chalk.green(` โœ… Mentor persona: ${mentorPersona.protocolEnabled ? 'Protocol-enabled' : 'No protocols'}`)); console.log(chalk.green(` โœ… Gauntlet persona: ${gauntletPersona.protocolEnabled ? 'Protocol-enabled' : 'No protocols'}`)); console.log(chalk.green(` โœ… Architect persona: ${architectPersona.protocolEnabled ? 'Protocol-enabled' : 'No protocols'}`)); // Test 6: Simulated AI Persona Spawning console.log(chalk.blue('\n7๏ธโƒฃ Testing AI persona spawning (will show prompts due to Task tool integration)...')); try { console.log(chalk.gray(' Testing Mentor persona spawn...')); await aiEngine.spawnPersona(mentorPersona); } catch (error) { console.log(chalk.yellow(' Expected: Task tool integration needed - prompt shown')); } try { console.log(chalk.gray(' Testing Gauntlet persona spawn...')); await aiEngine.spawnPersona(gauntletPersona); } catch (error) { console.log(chalk.yellow(' Expected: Task tool integration needed - prompt shown')); } // Test 7: Artifact Registry Inspection console.log(chalk.blue('\n8๏ธโƒฃ Inspecting artifact registry...')); const allArtifacts = artifactManager.getAllArtifacts(); console.log(chalk.green(` โœ… Total artifacts created: ${allArtifacts.length}`)); allArtifacts.forEach(artifact => { console.log(chalk.gray(` โ€ข ${artifact.name} (${artifact.type}) - ${artifact.status} - by ${artifact.creator}`)); }); // Test 8: Cross-Persona Workflow console.log(chalk.blue('\n9๏ธโƒฃ Testing cross-persona workflow...')); // Now that we have a validation report, Architect should pass prerequisites const updatedArchitectValidation = await architectProtocol.validatePrerequisites(); console.log(` Architect validation after Gauntlet: ${updatedArchitectValidation.valid ? 'โœ… PASS' : 'โŒ FAIL'}`); if (updatedArchitectValidation.valid) { console.log(chalk.gray(' Creating architect artifacts...')); const architectArtifacts = await architectProtocol.createArtifacts(); architectArtifacts.forEach(artifact => { console.log(` ${artifact.status === 'created' ? 'โœ…' : 'โŒ'} ${artifact.type}: ${artifact.message}`); }); } // Test 9: Handoff Preparation console.log(chalk.blue('\n๐Ÿ”Ÿ Testing persona handoffs...')); const mentorHandoff = await mentorProtocol.handoffToNext(); console.log(chalk.gray(` Mentor โ†’ ${mentorHandoff.nextPersona}`)); console.log(chalk.gray(` Context: ${mentorHandoff.context}`)); const gauntletHandoff = await gauntletProtocol.handoffToNext(); console.log(chalk.gray(` Gauntlet โ†’ ${gauntletHandoff.nextPersona}`)); console.log(chalk.gray(` Context: ${gauntletHandoff.context}`)); // Final Summary console.log(chalk.bold('\n๐ŸŽ‰ PROTOCOL INTEGRATION TEST COMPLETED\n')); console.log(chalk.green('โœ… All core components working correctly')); console.log(chalk.green('โœ… Protocol creation and initialization successful')); console.log(chalk.green('โœ… Prerequisite validation functioning properly')); console.log(chalk.green('โœ… Artifact creation and tracking operational')); console.log(chalk.green('โœ… AI persona configuration with protocol integration ready')); console.log(chalk.green('โœ… Cross-persona workflow validation successful')); console.log(chalk.green('โœ… Persona handoff system functioning')); console.log(chalk.yellow('\n๐Ÿ’ก NEXT STEPS:')); console.log(chalk.gray(' 1. Integrate Task tool for real AI subagent spawning')); console.log(chalk.gray(' 2. Test complete workflow: Mentor โ†’ Gauntlet โ†’ Architect')); console.log(chalk.gray(' 3. Add remaining personas (Strategist, Foreman, Wizard)')); console.log(chalk.gray(' 4. Implement artifact approval workflow')); } catch (error) { console.log(chalk.red(`\nโŒ Test failed: ${error}`)); console.error(error); } } // Run the test if (require.main === module) { testProtocolIntegration().catch(console.error); } export { testProtocolIntegration };