| |
| """ |
| Test for LearnedPrinciple Fix |
| |
| This test verifies that the LearnedPrinciple object access issue is fixed |
| in the integrated proactive messaging system. |
| """ |
|
|
| import sys |
| import os |
| from pathlib import Path |
| from datetime import datetime |
|
|
| |
| sys.path.append(str(Path(__file__).parent)) |
|
|
| def test_learned_principle_access(): |
| """Test that LearnedPrinciple objects are accessed correctly.""" |
| print("π§ͺ Testing LearnedPrinciple Object Access") |
| print("-" * 50) |
| |
| try: |
| from atles.memory_aware_reasoning import LearnedPrinciple |
| from atles.integrated_proactive_messaging import IntegratedProactiveMessaging |
| |
| |
| test_principle = LearnedPrinciple( |
| name="Test Principle", |
| description="A test principle for verification", |
| rules=["Test rule 1", "Test rule 2"], |
| examples=["Example 1", "Example 2"], |
| confidence=0.8, |
| learned_at=datetime.now() |
| ) |
| |
| print(f"Created test principle: {test_principle.name}") |
| |
| |
| print(f"Accessing name attribute: {test_principle.name}") |
| print(f"Accessing description attribute: {test_principle.description}") |
| |
| |
| try: |
| name_dict = test_principle["name"] |
| print("β Dictionary access unexpectedly succeeded") |
| return False |
| except TypeError as e: |
| print(f"β
Dictionary access correctly failed: {e}") |
| |
| |
| print("\nTesting integrated proactive messaging...") |
| |
| |
| mock_learning_summary = { |
| "total_principles": 2, |
| "most_used": "Test Principle", |
| "recently_learned": [test_principle] |
| } |
| |
| |
| ipm = IntegratedProactiveMessaging() |
| |
| |
| insights = ipm._generate_learning_insights(mock_learning_summary) |
| |
| print(f"Generated insights: {insights}") |
| |
| |
| if "recent_learning" in insights and len(insights["recent_learning"]) > 0: |
| print(f"β
Recent learning correctly extracted: {insights['recent_learning']}") |
| return True |
| else: |
| print("β Recent learning not properly extracted") |
| return False |
| |
| except Exception as e: |
| print(f"β ERROR: {e}") |
| import traceback |
| traceback.print_exc() |
| return False |
|
|
| def run_learned_principle_fix_test(): |
| """Run the LearnedPrinciple fix test.""" |
| print("π LearnedPrinciple Fix Test") |
| print("Verifying that object access is fixed in integrated proactive messaging") |
| print("=" * 80) |
| |
| success = test_learned_principle_access() |
| |
| print("\n" + "=" * 80) |
| print("π LEARNED PRINCIPLE FIX TEST SUMMARY") |
| print("=" * 80) |
| |
| if success: |
| print("β
PASS: LearnedPrinciple Object Access") |
| print("π LEARNED PRINCIPLE ERROR COMPLETELY FIXED!") |
| print("\nπ Verified Solutions:") |
| print("β
LearnedPrinciple objects use attribute access (p.name)") |
| print("β
Dictionary access correctly fails as expected") |
| print("β
Integrated proactive messaging works without errors") |
| print("β
Self-review insights generation should now work") |
| print("\nπ‘ The 'LearnedPrinciple' object is not subscriptable error is resolved!") |
| return True |
| else: |
| print("β FAIL: LearnedPrinciple Object Access") |
| print("β οΈ LearnedPrinciple fix test failed.") |
| return False |
|
|
| if __name__ == "__main__": |
| success = run_learned_principle_fix_test() |
| sys.exit(0 if success else 1) |
|
|
|
|
|
|