Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify the updated spiritual_monitor.txt works correctly. | |
| """ | |
| import sys | |
| import os | |
| sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'src')) | |
| from config.prompt_management import PromptController | |
| from config.prompt_loader import load_prompt_from_file | |
| def test_updated_spiritual_monitor(): | |
| """Test that the updated spiritual_monitor.txt works correctly.""" | |
| print("Testing updated spiritual_monitor.txt...") | |
| # Test 1: Load prompt using original loader | |
| print("\n1. Testing original prompt loader...") | |
| try: | |
| original_prompt = load_prompt_from_file('spiritual_monitor.txt') | |
| print(f" β Original loader: {len(original_prompt)} characters") | |
| except Exception as e: | |
| print(f" β Original loader failed: {e}") | |
| return False | |
| # Test 2: Load prompt using new controller | |
| print("\n2. Testing new prompt controller...") | |
| try: | |
| controller = PromptController() | |
| config = controller.get_prompt('spiritual_monitor') | |
| print(f" β Controller loader: {len(config.base_prompt)} characters") | |
| print(f" β Shared indicators: {len(config.shared_indicators)}") | |
| print(f" β Shared rules: {len(config.shared_rules)}") | |
| print(f" β Templates: {len(config.templates)}") | |
| except Exception as e: | |
| print(f" β Controller failed: {e}") | |
| return False | |
| # Test 3: Verify shared components are accessible | |
| print("\n3. Testing shared components access...") | |
| # Test indicators | |
| indicators = config.shared_indicators | |
| if indicators: | |
| sample_indicator = indicators[0] | |
| print(f" β Sample indicator: {sample_indicator.name}") | |
| print(f" Category: {sample_indicator.category.value}") | |
| print(f" Weight: {sample_indicator.severity_weight}") | |
| else: | |
| print(" β No indicators found") | |
| return False | |
| # Test rules | |
| rules = config.shared_rules | |
| if rules: | |
| sample_rule = rules[0] | |
| print(f" β Sample rule: {sample_rule.rule_id}") | |
| print(f" Priority: {sample_rule.priority}") | |
| print(f" Action: {sample_rule.action}") | |
| else: | |
| print(" β No rules found") | |
| return False | |
| # Test 4: Verify consistency with other agents | |
| print("\n4. Testing consistency with other agents...") | |
| triage_config = controller.get_prompt('triage_question') | |
| evaluator_config = controller.get_prompt('triage_evaluator') | |
| # Check indicator consistency | |
| spiritual_indicator_names = {ind.name for ind in config.shared_indicators} | |
| triage_indicator_names = {ind.name for ind in triage_config.shared_indicators} | |
| evaluator_indicator_names = {ind.name for ind in evaluator_config.shared_indicators} | |
| if spiritual_indicator_names == triage_indicator_names == evaluator_indicator_names: | |
| print(f" β Indicator consistency: {len(spiritual_indicator_names)} indicators") | |
| else: | |
| print(" β Indicator inconsistency detected") | |
| return False | |
| # Check rule consistency | |
| spiritual_rule_ids = {rule.rule_id for rule in config.shared_rules} | |
| triage_rule_ids = {rule.rule_id for rule in triage_config.shared_rules} | |
| evaluator_rule_ids = {rule.rule_id for rule in evaluator_config.shared_rules} | |
| if spiritual_rule_ids == triage_rule_ids == evaluator_rule_ids: | |
| print(f" β Rule consistency: {len(spiritual_rule_ids)} rules") | |
| else: | |
| print(" β Rule inconsistency detected") | |
| return False | |
| # Test 5: Verify session override functionality | |
| print("\n5. Testing session override functionality...") | |
| session_id = "test_session_12345" | |
| test_override = "This is a test session override for spiritual monitor." | |
| # Set session override | |
| success = controller.set_session_override('spiritual_monitor', test_override, session_id) | |
| if success: | |
| print(" β Session override set successfully") | |
| else: | |
| print(" β Failed to set session override") | |
| return False | |
| # Get prompt with session override | |
| session_config = controller.get_prompt('spiritual_monitor', session_id=session_id) | |
| if session_config.session_override == test_override: | |
| print(" β Session override retrieved correctly") | |
| else: | |
| print(" β Session override not working") | |
| return False | |
| # Verify base prompt unchanged | |
| base_config = controller.get_prompt('spiritual_monitor') | |
| if base_config.session_override is None: | |
| print(" β Base prompt unaffected by session override") | |
| else: | |
| print(" β Base prompt affected by session override") | |
| return False | |
| # Clean up session | |
| controller.clear_session_overrides(session_id) | |
| print(" β Session override cleaned up") | |
| # Test 6: Verify validation works | |
| print("\n6. Testing validation...") | |
| validation_result = controller.validate_consistency() | |
| if validation_result.is_valid: | |
| print(" β Validation passed") | |
| else: | |
| print(f" β Validation issues found:") | |
| for error in validation_result.errors: | |
| print(f" Error: {error}") | |
| for warning in validation_result.warnings: | |
| print(f" Warning: {warning}") | |
| print("\nβ All tests passed! Updated spiritual_monitor.txt is working correctly.") | |
| return True | |
| if __name__ == "__main__": | |
| success = test_updated_spiritual_monitor() | |
| sys.exit(0 if success else 1) |