Add comprehensive unit tests for BuddAI functionality

- Introduced 16 additional coverage tests in `test_additional_coverage.py` to enhance overall test coverage.
- Added 15 extended feature tests in `test_extended_features.py` to validate new functionalities.
- Implemented 27 final coverage tests in `test_final_coverage.py` to achieve a total of 100 tests.
- Created 2 fallback logic tests in `test_fallback_logic.py` to ensure proper fallback behavior based on confidence scores.
- Each test suite covers various aspects of the BuddAI system, including command handling, database interactions, and hardware detection.
This commit is contained in:
JamesTheGiblet 2026-01-07 19:48:24 +00:00
parent f9fd27d228
commit 27601aa2ba
34 changed files with 5022 additions and 2921 deletions

View file

@ -1,105 +1,67 @@
import sys
import os
import unittest
from pathlib import Path
import json
from datetime import datetime
from unittest.mock import patch
# Add parent directory to path so we can import buddai modules
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from buddai_executive import BuddAI
def test_personality_loading():
print("🧪 Testing Personality Loading...")
# Initialize BuddAI (mocking server_mode to avoid input loops)
try:
ai = BuddAI(user_id="test_user", server_mode=True)
# 1. Check Identity & Meta
print("\n👤 Verifying Identity & Meta...")
user_name = ai.get_personality_value("identity.user_name")
ai_name = ai.get_personality_value("identity.ai_name")
version = ai.get_personality_value("meta.version")
if user_name == "James" and ai_name == "BuddAI":
print(f"✅ Identity Loaded: {ai_name} v{version} is ready to assist {user_name}")
else:
print(f"❌ Identity Mismatch. Got User: {user_name}, AI: {ai_name}")
# 2. Check Communication & Phrases
print("\n💬 Verifying Communication Style...")
welcome = ai.get_personality_value("communication.welcome_message")
phrases = ai.get_personality_value("identity.signature_phrases")
if welcome and "{rule_count}" in welcome:
print(f"✅ Welcome Message Template Loaded")
else:
print(f"❌ Welcome Message Issue: {welcome}")
if phrases and len(phrases) > 0:
print(f"✅ Loaded {len(phrases)} signature phrases (e.g., '{phrases[0]}')")
else:
print("❌ No signature phrases found")
class TestPersonality(unittest.TestCase):
def setUp(self):
# Suppress prints
self.print_patcher = patch("builtins.print")
self.print_patcher.start()
self.ai = BuddAI(user_id="test_user", server_mode=True)
# 3. Test Schedule Logic & Work Cycles
print("\n⏰ Testing Schedule & Work Cycles...")
status = ai.get_user_status()
current_time = datetime.now().strftime('%H:%M')
print(f" Current Time: {current_time}")
print(f" Detected Status: {status}")
def tearDown(self):
self.print_patcher.stop()
def test_identity_meta(self):
"""Verify Identity & Meta"""
user_name = self.ai.personality_manager.get_value("identity.user_name")
ai_name = self.ai.personality_manager.get_value("identity.ai_name")
self.assertEqual(user_name, "James")
self.assertEqual(ai_name, "BuddAI")
def test_communication_style(self):
"""Verify Communication & Phrases"""
welcome = self.ai.personality_manager.get_value("communication.welcome_message")
phrases = self.ai.personality_manager.get_value("identity.signature_phrases")
self.assertIn("{rule_count}", welcome)
self.assertGreater(len(phrases), 0)
def test_schedule_logic(self):
"""Test Schedule & Work Cycles"""
morning_mode = self.ai.personality_manager.get_value(["work_cycles", "schedule", "weekdays", "0-4", "5.5-6.5", "mode"])
self.assertEqual(morning_mode, "morning_build_peak")
def test_forge_theory(self):
"""Verify Forge Theory Configuration"""
forge_enabled = self.ai.personality_manager.get_value("forge_theory.enabled")
k_balanced = self.ai.personality_manager.get_value("forge_theory.constants.balanced.value")
self.assertTrue(forge_enabled)
self.assertEqual(k_balanced, 0.1)
def test_technical_preferences(self):
"""Verify Technical Preferences"""
baud = self.ai.personality_manager.get_value("technical_preferences.james_patterns.serial_baud")
self.assertIn("115200", str(baud))
def test_interaction_modes(self):
"""Verify Interaction Modes"""
modes = self.ai.personality_manager.get_value("interaction_modes")
self.assertIn("morning_build", modes)
self.assertIn("evening_build", modes)
def test_advanced_features(self):
"""Verify Deep Key Access"""
shadow_enabled = self.ai.personality_manager.get_value("advanced_features.shadow_suggestions.enabled")
self.assertTrue(shadow_enabled)
# Verify specific schedule slots exist
morning_mode = ai.get_personality_value(["work_cycles", "schedule", "weekdays", "0-4", "5.5-6.5", "mode"])
if morning_mode == "morning_build_peak":
print("✅ Morning Build Peak schedule slot verified")
else:
print(f"❌ Morning schedule slot missing or incorrect: {morning_mode}")
# 4. Verify Forge Theory Configuration
print("\n⚡ Verifying Forge Theory...")
forge_enabled = ai.get_personality_value("forge_theory.enabled")
k_balanced = ai.get_personality_value("forge_theory.constants.balanced.value")
formula = ai.get_personality_value("forge_theory.formula")
if forge_enabled and k_balanced == 0.1:
print(f"✅ Forge Theory Active (Balanced k={k_balanced})")
print(f" Formula: {formula}")
else:
print(f"❌ Forge Theory configuration mismatch")
# 5. Verify Technical Preferences
print("\n🛠️ Verifying Technical Preferences...")
baud = ai.get_personality_value("technical_preferences.james_patterns.serial_baud")
safety = ai.get_personality_value("technical_preferences.james_patterns.safety_first")
if "115200" in str(baud) and "5000ms" in str(safety):
print(f"✅ Technical Patterns Loaded: Baud {baud}, Safety {safety}")
else:
print(f"❌ Technical preferences mismatch")
# 6. Verify Interaction Modes
print("\n🔄 Verifying Interaction Modes...")
modes = ai.get_personality_value("interaction_modes")
if modes and "morning_build" in modes and "evening_build" in modes:
print(f"✅ Interaction Modes Loaded: {', '.join(modes.keys())}")
else:
print("❌ Interaction modes missing")
# 7. Verify Deep Key Access (Advanced Features)
print("\n🔑 Verifying Advanced Features...")
shadow_enabled = ai.get_personality_value("advanced_features.shadow_suggestions.enabled")
auto_fix = ai.get_personality_value("advanced_features.self_correction.enabled")
if shadow_enabled and auto_fix:
print("✅ Advanced features (Shadow Suggestions, Self Correction) enabled")
else:
print("❌ Advanced features configuration issue")
except Exception as e:
print(f"❌ Error during test: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
test_personality_loading()
unittest.main()