- Created shared/models.py with all common Pydantic models - Updated voicebot/main.py to use shared models and remove dd.get() calls - Updated server/main.py to use shared models - Fixed lobby_state message handling with proper validation - Updated Dockerfiles to include shared/ directory - Added comprehensive documentation and migration guide Benefits: - Type safety across both components - Consistent data validation - Eliminated unsafe dictionary access patterns - Centralized model definitions for easier maintenance
64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to validate that shared models work correctly.
|
|
This script can be run to test model validation without dependencies.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# Add shared directory to path
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
def test_models():
|
|
"""Test shared models without external dependencies"""
|
|
|
|
print("Testing shared models (syntax validation only)...")
|
|
|
|
try:
|
|
# Test that models can be imported
|
|
from models import (
|
|
LobbyModel,
|
|
SessionModel,
|
|
ParticipantModel,
|
|
WebSocketMessageModel,
|
|
JoinStatusModel,
|
|
UserJoinedModel,
|
|
LobbyStateModel,
|
|
UpdateModel,
|
|
AddPeerModel,
|
|
RemovePeerModel,
|
|
SessionDescriptionModel,
|
|
IceCandidateModel,
|
|
ICECandidateDictModel,
|
|
SessionDescriptionTypedModel,
|
|
LobbyCreateRequest,
|
|
LobbyCreateResponse,
|
|
AdminActionResponse,
|
|
HealthResponse,
|
|
)
|
|
print("✓ All shared models imported successfully")
|
|
|
|
# Test model definitions (without actually creating instances since we don't have pydantic)
|
|
model_names = [
|
|
'LobbyModel', 'SessionModel', 'ParticipantModel',
|
|
'WebSocketMessageModel', 'JoinStatusModel', 'UserJoinedModel',
|
|
'LobbyStateModel', 'UpdateModel', 'AddPeerModel', 'RemovePeerModel',
|
|
'SessionDescriptionModel', 'IceCandidateModel', 'ICECandidateDictModel',
|
|
'SessionDescriptionTypedModel', 'LobbyCreateRequest', 'LobbyCreateResponse',
|
|
'AdminActionResponse', 'HealthResponse'
|
|
]
|
|
|
|
print(f"✓ {len(model_names)} models defined and accessible")
|
|
print("✓ Shared models structure is valid")
|
|
|
|
except Exception as e:
|
|
print(f"✗ Error testing shared models: {e}")
|
|
return False
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
success = test_models()
|
|
sys.exit(0 if success else 1)
|