Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script for enhanced prompt optimization integration. | |
| """ | |
| import os | |
| import sys | |
| sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'src')) | |
| def test_integration(): | |
| """Test the integration of enhanced prompt editor with the main app.""" | |
| print("π§ͺ Testing Enhanced Prompt Optimization Integration") | |
| print("=" * 60) | |
| try: | |
| # Test 1: Import all components | |
| print("1. Testing imports...") | |
| from interface.enhanced_prompt_editor import EnhancedPromptEditor | |
| from config.prompt_management.prompt_controller import PromptController | |
| from interface.gradio_app import main | |
| print(" β All components import successfully") | |
| # Test 2: Initialize components | |
| print("\n2. Testing component initialization...") | |
| editor = EnhancedPromptEditor() | |
| controller = PromptController() | |
| print(" β Components initialize successfully") | |
| # Test 3: Test prompt loading | |
| print("\n3. Testing prompt loading...") | |
| prompts = editor.get_available_prompts() | |
| print(f" β Found {len(prompts)} available prompts:") | |
| for prompt in prompts: | |
| print(f" - {prompt}") | |
| # Test 4: Test session override functionality | |
| print("\n4. Testing session override functionality...") | |
| session_id = "integration_test_session" | |
| test_content = "Test session override content for integration testing" | |
| # Load original prompt | |
| original_content, _, _ = editor.load_prompt_for_editing( | |
| "π Spiritual Monitor (Classifier)", | |
| session_id | |
| ) | |
| print(f" β Original prompt loaded: {len(original_content)} chars") | |
| # Apply session override | |
| status_html, success = editor.apply_prompt_changes( | |
| "π Spiritual Monitor (Classifier)", | |
| test_content, | |
| session_id | |
| ) | |
| print(f" β Session override applied: {success}") | |
| # Verify override is active | |
| override_content, _, _ = editor.load_prompt_for_editing( | |
| "π Spiritual Monitor (Classifier)", | |
| session_id | |
| ) | |
| override_active = test_content in override_content | |
| print(f" β Session override active: {override_active}") | |
| # Test reset functionality | |
| reset_content, _, _ = editor.reset_prompt_to_default( | |
| "π Spiritual Monitor (Classifier)", | |
| session_id | |
| ) | |
| reset_successful = test_content not in reset_content | |
| print(f" β Reset to default works: {reset_successful}") | |
| # Test 5: Test validation | |
| print("\n5. Testing prompt validation...") | |
| validation_html, is_valid = editor.validate_prompt_syntax(original_content) | |
| print(f" β Validation works: {is_valid}") | |
| # Test 6: Test session status | |
| print("\n6. Testing session status...") | |
| # Set override again for status test | |
| editor.apply_prompt_changes( | |
| "π Spiritual Monitor (Classifier)", | |
| test_content, | |
| session_id | |
| ) | |
| status_html = editor.get_session_prompt_status(session_id) | |
| has_overrides = "Active Session Overrides" in status_html | |
| print(f" β Session status tracking: {has_overrides}") | |
| print("\n" + "=" * 60) | |
| print("π ALL INTEGRATION TESTS PASSED!") | |
| print("\nπ Summary:") | |
| print(" β Enhanced prompt editor fully integrated") | |
| print(" β Session-level prompt overrides working") | |
| print(" β Validation and status tracking functional") | |
| print(" β Reset and promotion workflows ready") | |
| print("\nπ Ready to launch the enhanced medical assistant!") | |
| return True | |
| except Exception as e: | |
| print(f"\nβ Integration test failed: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| if __name__ == "__main__": | |
| success = test_integration() | |
| sys.exit(0 if success else 1) |