#!/usr/bin/env python3 """ Test CLI plugin integration by directly calling the core logic """ import sys from pathlib import Path # Add current directory to path for imports sys.path.insert(0, str(Path(__file__).parent)) def test_cli_integration(): """Test CLI integration logic without Click framework.""" print("๐Ÿงช Testing CLI Plugin Integration Logic") print("=" * 50) try: # Import required components from markitect.plugins import PluginManager, RenderingEngineManager, RenderingConfig # Test input input_file = "test_cli_plugin.md" output_file = "/tmp/test_cli_integration.html" if not Path(input_file).exists(): print(f"โŒ Test file {input_file} not found") return False # Read markdown content content = Path(input_file).read_text(encoding='utf-8') print(f"๐Ÿ“„ Read test content ({len(content)} characters)") # Test 1: Plugin system initialization print("\n1๏ธโƒฃ Initializing plugin system...") plugin_manager = PluginManager() rendering_manager = RenderingEngineManager(plugin_manager) print(" โœ… Plugin system initialized") # Test 2: Engine selection logic (same as CLI) engine_name = None edit_mode = True # Default engine selection (copied from CLI logic) if engine_name is None: if edit_mode: engine_name = 'testdrive-jsui' # Default to testdrive-jsui for interactive modes else: engine_name = 'standard' # Use standard CleanDocumentManager for non-interactive print(f" ๐ŸŽฏ Selected engine: {engine_name}") # Test 3: Engine loading print(f"\n2๏ธโƒฃ Loading rendering engine '{engine_name}'...") rendering_engine = rendering_manager.get_engine(engine_name) if rendering_engine is None: print(f" โŒ Rendering engine '{engine_name}' not found") return False print(f" โœ… Engine loaded: {rendering_engine.metadata.name}") print(f" ๐Ÿ“ Description: {rendering_engine.metadata.description}") print(f" ๐ŸŽฏ Supported modes: {rendering_engine.get_supported_modes()}") # Test 4: Mode validation current_mode = 'edit' if not rendering_engine.validate_mode(current_mode): print(f" โŒ Engine doesn't support mode '{current_mode}'") return False print(f" โœ… Mode '{current_mode}' is supported") # Test 5: Rendering configuration print(f"\n3๏ธโƒฃ Setting up rendering configuration...") render_config = RenderingConfig( asset_base_url="_markitect", development_mode=False, # Production deployment for CLI usage output_directory=Path(output_file).parent ) print(f" โœ… Configuration created") print(f" ๐Ÿ“ Output directory: {render_config.output_directory}") print(f" ๐Ÿ”— Asset base URL: {render_config.asset_base_url}") # Test 6: Document rendering print(f"\n4๏ธโƒฃ Rendering document...") html_content = rendering_engine.render_document(content, current_mode, render_config) print(f" โœ… Document rendered ({len(html_content):,} characters)") # Test 7: Output writing print(f"\n5๏ธโƒฃ Writing output file...") Path(output_file).write_text(html_content, encoding='utf-8') output_size = Path(output_file).stat().st_size print(f" โœ… Output written: {output_file} ({output_size:,} bytes)") # Test 8: Verification print(f"\n6๏ธโƒฃ Verifying output...") if Path(output_file).exists() and output_size > 0: print(f" โœ… Output file exists and has content") print(f" ๐ŸŒ Open in browser: file://{Path(output_file).absolute()}") else: print(f" โŒ Output file missing or empty") return False print(f"\n๐ŸŽ‰ CLI integration test completed successfully!") print(f"\n๐Ÿ“Š Summary:") print(f" Engine: {engine_name}") print(f" Mode: {current_mode}") print(f" Input: {input_file} ({len(content)} chars)") print(f" Output: {output_file} ({output_size:,} bytes)") return True except Exception as e: print(f"โŒ CLI integration test failed: {e}") import traceback traceback.print_exc() return False if __name__ == "__main__": success = test_cli_integration() sys.exit(0 if success else 1)