UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

239 lines (237 loc) โ€ข 12.2 kB
/** * Phase 3 Test: State-Aware Tool Behavior * * This test verifies that: * 1. CinematicWorkflowTool respects workflow state constraints * 2. State transitions work correctly (confirm_outline, start_screenplay, enter_iteration) * 3. Tool respects user preferences (auto_generate_sketches, sketch_style) * 4. Tool blocks operations not allowed in current state * 5. Tool allows operations when in correct state */ import { CinematicWorkflowTool } from '../services/tools/CinematicWorkflowTool.js'; import { StateManager } from '../services/stateManager.js'; import fs from 'fs/promises'; import path from 'path'; async function testPhase3() { console.log('๐Ÿงช Phase 3 Test: State-Aware Tool Behavior\n'); const testDir = path.join(process.cwd(), 'test_phase3_output'); try { // Create test directory await fs.mkdir(testDir, { recursive: true }); console.log(`โœ“ Created test directory: ${testDir}\n`); const stateManager = new StateManager(testDir); const cinematicTool = new CinematicWorkflowTool(testDir); // Test 1: Create Story Project console.log('Test 1: Create Story Project'); console.log('='.repeat(60)); await stateManager.createStoryProject('Test Detective Story', 'A detective investigates a mysterious case in a futuristic city.'); const currentState = await stateManager.getCurrentState(); console.log(` โœ“ Story project created with state: ${currentState}`); console.log(` โœ“ State is OUTLINE_DRAFT: ${currentState === 'OUTLINE_DRAFT' ? 'โœ…' : 'โŒ'}`); // Test 2: Try to create scene in OUTLINE_DRAFT (should fail) console.log('\nTest 2: Block Scene Creation in OUTLINE_DRAFT'); console.log('='.repeat(60)); const sceneContent = `## SCENE 1: Opening ### Scene Description Detective enters the lab. ### Visual Sketch Description - **WIDE SHOT**: Detective walking into futuristic lab `; const createResult1 = await cinematicTool.execute({ operation: 'create_scene', scene_file_path: 'scenes/scene_01.md', content: sceneContent }); console.log(` โœ“ Create scene blocked: ${!createResult1.success ? 'โœ…' : 'โŒ'}`); if (!createResult1.success) { console.log(` โœ“ Error message: ${createResult1.error}`); } // Test 3: Confirm Outline console.log('\nTest 3: Confirm Outline (State Transition)'); console.log('='.repeat(60)); const confirmResult = await cinematicTool.execute({ operation: 'confirm_outline' }); console.log(` โœ“ Confirm outline success: ${confirmResult.success ? 'โœ…' : 'โŒ'}`); if (confirmResult.success) { console.log(` โœ“ Message: ${confirmResult.message}`); console.log(` โœ“ New state: ${confirmResult.data?.new_state}`); } const stateAfterConfirm = await stateManager.getCurrentState(); console.log(` โœ“ State is OUTLINE_CONFIRMED: ${stateAfterConfirm === 'OUTLINE_CONFIRMED' ? 'โœ…' : 'โŒ'}`); // Test 4: Try to create scene in OUTLINE_CONFIRMED (should still fail) console.log('\nTest 4: Block Scene Creation in OUTLINE_CONFIRMED'); console.log('='.repeat(60)); const createResult2 = await cinematicTool.execute({ operation: 'create_scene', scene_file_path: 'scenes/scene_01.md', content: sceneContent }); console.log(` โœ“ Create scene blocked: ${!createResult2.success ? 'โœ…' : 'โŒ'}`); if (!createResult2.success) { console.log(` โœ“ Error message: ${createResult2.error}`); } // Test 5: Start Screenplay console.log('\nTest 5: Start Screenplay (State Transition)'); console.log('='.repeat(60)); const startResult = await cinematicTool.execute({ operation: 'start_screenplay' }); console.log(` โœ“ Start screenplay success: ${startResult.success ? 'โœ…' : 'โŒ'}`); if (startResult.success) { console.log(` โœ“ Message: ${startResult.message}`); console.log(` โœ“ New state: ${startResult.data?.new_state}`); } const stateAfterStart = await stateManager.getCurrentState(); console.log(` โœ“ State is SCREENPLAY_WRITING: ${stateAfterStart === 'SCREENPLAY_WRITING' ? 'โœ…' : 'โŒ'}`); // Test 6: Create scene in SCREENPLAY_WRITING (should succeed) console.log('\nTest 6: Allow Scene Creation in SCREENPLAY_WRITING'); console.log('='.repeat(60)); const createResult3 = await cinematicTool.execute({ operation: 'create_scene', scene_file_path: 'scenes/scene_01.md', content: sceneContent, auto_generate_images: false // Disable for test speed }); console.log(` โœ“ Create scene success: ${createResult3.success ? 'โœ…' : 'โŒ'}`); if (createResult3.success) { console.log(` โœ“ File created: ${createResult3.data?.file_path}`); console.log(` โœ“ Lines written: ${createResult3.data?.lines_written}`); } // Test 7: Try to generate sketches in SCREENPLAY_WRITING (should fail) console.log('\nTest 7: Block Sketch Generation in SCREENPLAY_WRITING'); console.log('='.repeat(60)); const sketchResult1 = await cinematicTool.execute({ operation: 'generate_scene_images', scene_file_path: 'scenes/scene_01.md', image_style: 'storyboard' }); console.log(` โœ“ Sketch generation blocked: ${!sketchResult1.success ? 'โœ…' : 'โŒ'}`); if (!sketchResult1.success) { console.log(` โœ“ Error message: ${sketchResult1.error}`); } // Test 8: Enter Iteration console.log('\nTest 8: Enter Iteration (State Transition)'); console.log('='.repeat(60)); const iterationResult = await cinematicTool.execute({ operation: 'enter_iteration' }); console.log(` โœ“ Enter iteration success: ${iterationResult.success ? 'โœ…' : 'โŒ'}`); if (iterationResult.success) { console.log(` โœ“ Message: ${iterationResult.message}`); console.log(` โœ“ New state: ${iterationResult.data?.new_state}`); console.log(` โœ“ Auto-generate sketches: ${iterationResult.data?.auto_generate_sketches}`); console.log(` โœ“ Sketch style: ${iterationResult.data?.sketch_style}`); } const stateAfterIteration = await stateManager.getCurrentState(); console.log(` โœ“ State is ITERATION: ${stateAfterIteration === 'ITERATION' ? 'โœ…' : 'โŒ'}`); // Test 9: Generate sketches in ITERATION (should succeed) console.log('\nTest 9: Allow Sketch Generation in ITERATION'); console.log('='.repeat(60)); const sketchResult2 = await cinematicTool.execute({ operation: 'generate_scene_images', scene_file_path: 'scenes/scene_01.md', image_style: 'storyboard' }); console.log(` โœ“ Sketch generation allowed: ${sketchResult2.success ? 'โœ…' : 'โŒ'}`); if (sketchResult2.success) { console.log(` โœ“ Images generated: ${sketchResult2.data?.successful_generations || 0}`); } else { // It's OK if it fails due to no visual descriptions or image generation issues console.log(` โœ“ Note: ${sketchResult2.error}`); } // Test 10: User Preference Respect console.log('\nTest 10: Respect User Preferences'); console.log('='.repeat(60)); // Update preferences await stateManager.updatePreferences({ auto_generate_sketches: true, sketch_style_preference: 'cinematic' }); const autoSketch = await stateManager.isAutoSketchEnabled(); const sketchStyle = await stateManager.getSketchStyle(); console.log(` โœ“ Auto-sketch preference set: ${autoSketch ? 'โœ…' : 'โŒ'}`); console.log(` โœ“ Sketch style preference: ${sketchStyle}`); console.log(` โœ“ Style is cinematic: ${sketchStyle === 'cinematic' ? 'โœ…' : 'โŒ'}`); // Test 11: Invalid State Transitions console.log('\nTest 11: Block Invalid State Transitions'); console.log('='.repeat(60)); // Try to confirm outline from ITERATION (should fail) const invalidConfirm = await cinematicTool.execute({ operation: 'confirm_outline' }); console.log(` โœ“ Invalid confirm blocked: ${!invalidConfirm.success ? 'โœ…' : 'โŒ'}`); if (!invalidConfirm.success) { console.log(` โœ“ Error: ${invalidConfirm.error}`); } // Test 12: Rollback Always Allowed console.log('\nTest 12: Rollback Always Allowed'); console.log('='.repeat(60)); // Update scene to create a backup await cinematicTool.execute({ operation: 'update_scene', scene_file_path: 'scenes/scene_01.md', content: sceneContent + '\n\n## Updated content', auto_generate_images: false }); const rollbackResult = await cinematicTool.execute({ operation: 'rollback_scene', scene_file_path: 'scenes/scene_01.md' }); console.log(` โœ“ Rollback allowed: ${rollbackResult.success ? 'โœ…' : 'โŒ'}`); if (rollbackResult.success) { console.log(` โœ“ Restored from: ${rollbackResult.data?.restored_from}`); } // Summary console.log('\n' + '='.repeat(60)); console.log('๐Ÿ“Š Phase 3 Test Summary'); console.log('='.repeat(60)); const allTests = [ currentState === 'OUTLINE_DRAFT', !createResult1.success, // Blocked in OUTLINE_DRAFT confirmResult.success && stateAfterConfirm === 'OUTLINE_CONFIRMED', !createResult2.success, // Blocked in OUTLINE_CONFIRMED startResult.success && stateAfterStart === 'SCREENPLAY_WRITING', createResult3.success, // Allowed in SCREENPLAY_WRITING !sketchResult1.success, // Blocked in SCREENPLAY_WRITING iterationResult.success && stateAfterIteration === 'ITERATION', sketchResult2.success || sketchResult2.error?.includes('No visual descriptions'), // Allowed in ITERATION autoSketch === true && sketchStyle === 'cinematic', !invalidConfirm.success, // Invalid transition blocked rollbackResult.success // Rollback always allowed ]; const passedTests = allTests.filter(t => t).length; const totalTests = allTests.length; const passRate = ((passedTests / totalTests) * 100).toFixed(1); console.log(`\nTests Passed: ${passedTests}/${totalTests} (${passRate}%)`); if (passedTests === totalTests) { console.log('\nโœ… All Phase 3 tests passed! State-aware tool behavior is working correctly:'); console.log(' - Tool respects workflow state constraints'); console.log(' - State transitions work correctly'); console.log(' - Operations blocked in wrong states'); console.log(' - Operations allowed in correct states'); console.log(' - User preferences are respected'); console.log(' - Invalid transitions are blocked'); console.log(' - Rollback always allowed'); } else { console.log('\nโš ๏ธ Some tests failed. Review the output above.'); } // Cleanup console.log(`\n๐Ÿงน Cleaning up test directory: ${testDir}`); await fs.rm(testDir, { recursive: true, force: true }); console.log('โœ“ Cleanup complete\n'); } catch (error) { console.error('โŒ Test failed with error:', error); // Cleanup on error try { await fs.rm(testDir, { recursive: true, force: true }); } catch { } throw error; } } // Run the test testPhase3().catch(console.error);