Files
loyal_companion/verify_gateway.py
latte dde2649876
All checks were successful
Enterprise AI Code Review / ai-review (pull_request) Successful in 35s
phase 1
2026-01-31 18:44:29 +01:00

219 lines
6.3 KiB
Python

"""Simple verification script for Conversation Gateway implementation.
This script verifies that the gateway can be imported and basic functionality works.
Run with: python3 verify_gateway.py
"""
import sys
def verify_imports():
"""Verify all required imports work."""
print("✓ Verifying imports...")
try:
from loyal_companion.models.platform import (
ConversationContext,
ConversationRequest,
ConversationResponse,
IntimacyLevel,
MoodInfo,
Platform,
RelationshipInfo,
)
print(" ✓ Platform models imported successfully")
except ImportError as e:
print(f" ✗ Failed to import platform models: {e}")
return False
try:
from loyal_companion.services import ConversationGateway
print(" ✓ ConversationGateway imported successfully")
except ImportError as e:
print(f" ✗ Failed to import ConversationGateway: {e}")
return False
return True
def verify_enums():
"""Verify enum values are correct."""
print("\n✓ Verifying enums...")
from loyal_companion.models.platform import IntimacyLevel, Platform
# Verify Platform enum
assert Platform.DISCORD == "discord"
assert Platform.WEB == "web"
assert Platform.CLI == "cli"
print(" ✓ Platform enum values correct")
# Verify IntimacyLevel enum
assert IntimacyLevel.LOW == "low"
assert IntimacyLevel.MEDIUM == "medium"
assert IntimacyLevel.HIGH == "high"
print(" ✓ IntimacyLevel enum values correct")
return True
def verify_request_creation():
"""Verify ConversationRequest can be created."""
print("\n✓ Verifying ConversationRequest creation...")
from loyal_companion.models.platform import (
ConversationContext,
ConversationRequest,
IntimacyLevel,
Platform,
)
context = ConversationContext(
is_public=False,
intimacy_level=IntimacyLevel.MEDIUM,
guild_id="12345",
channel_id="channel-1",
user_display_name="TestUser",
)
request = ConversationRequest(
user_id="user123",
platform=Platform.DISCORD,
session_id="session-1",
message="Hello there!",
context=context,
)
assert request.user_id == "user123"
assert request.platform == Platform.DISCORD
assert request.message == "Hello there!"
assert request.context.intimacy_level == IntimacyLevel.MEDIUM
print(" ✓ ConversationRequest created successfully")
print(f" - Platform: {request.platform.value}")
print(f" - Intimacy: {request.context.intimacy_level.value}")
print(f" - Message: {request.message}")
return True
def verify_gateway_initialization():
"""Verify ConversationGateway can be initialized."""
print("\n✓ Verifying ConversationGateway initialization...")
from loyal_companion.services import ConversationGateway
gateway = ConversationGateway()
assert gateway is not None
assert gateway.ai_service is not None
print(" ✓ ConversationGateway initialized successfully")
return True
def verify_intimacy_modifiers():
"""Verify intimacy level modifiers work."""
print("\n✓ Verifying intimacy modifiers...")
from loyal_companion.models.platform import IntimacyLevel, Platform
from loyal_companion.services import ConversationGateway
gateway = ConversationGateway()
# Test LOW intimacy
low_modifier = gateway._get_intimacy_modifier(Platform.DISCORD, IntimacyLevel.LOW)
assert "PUBLIC, SOCIAL" in low_modifier
assert "brief and light" in low_modifier
print(" ✓ LOW intimacy modifier correct")
# Test MEDIUM intimacy
medium_modifier = gateway._get_intimacy_modifier(Platform.DISCORD, IntimacyLevel.MEDIUM)
assert "SEMI-PRIVATE" in medium_modifier
assert "Balanced warmth" in medium_modifier
print(" ✓ MEDIUM intimacy modifier correct")
# Test HIGH intimacy
high_modifier = gateway._get_intimacy_modifier(Platform.WEB, IntimacyLevel.HIGH)
assert "PRIVATE, INTENTIONAL" in high_modifier
assert "Deeper reflection" in high_modifier
assert "CRITICAL SAFETY BOUNDARIES" in high_modifier
print(" ✓ HIGH intimacy modifier correct")
return True
def verify_sentiment_estimation():
"""Verify sentiment estimation works."""
print("\n✓ Verifying sentiment estimation...")
from loyal_companion.services import ConversationGateway
gateway = ConversationGateway()
# Positive sentiment
positive = gateway._estimate_sentiment("Thanks! This is awesome and amazing!")
assert positive > 0.3, f"Expected positive sentiment, got {positive}"
print(f" ✓ Positive sentiment: {positive:.2f}")
# Negative sentiment
negative = gateway._estimate_sentiment("This is terrible and awful")
assert negative < 0, f"Expected negative sentiment, got {negative}"
print(f" ✓ Negative sentiment: {negative:.2f}")
# Neutral sentiment
neutral = gateway._estimate_sentiment("The weather is cloudy")
assert -0.3 < neutral < 0.3, f"Expected neutral sentiment, got {neutral}"
print(f" ✓ Neutral sentiment: {neutral:.2f}")
return True
def main():
"""Run all verification checks."""
print("=" * 60)
print("Conversation Gateway Verification")
print("=" * 60)
checks = [
verify_imports,
verify_enums,
verify_request_creation,
verify_gateway_initialization,
verify_intimacy_modifiers,
verify_sentiment_estimation,
]
all_passed = True
for check in checks:
try:
if not check():
all_passed = False
except Exception as e:
print(f"\n✗ Check failed with error: {e}")
import traceback
traceback.print_exc()
all_passed = False
print("\n" + "=" * 60)
if all_passed:
print("✓ All verification checks passed!")
print("=" * 60)
print("\nConversation Gateway is ready for use.")
print("\nNext steps:")
print(" 1. Refactor Discord cog to use gateway (Phase 2)")
print(" 2. Add Web platform (Phase 3)")
print(" 3. Add CLI client (Phase 4)")
return 0
else:
print("✗ Some verification checks failed!")
print("=" * 60)
return 1
if __name__ == "__main__":
sys.exit(main())