-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconftest.py
More file actions
159 lines (116 loc) · 4.71 KB
/
Copy pathconftest.py
File metadata and controls
159 lines (116 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python3
"""Shared fixtures and utilities for agent end-to-end tests.
This module provides a common setup for testing LiveKit Agents with Yandex STT,
including room management, participant simulation, and Russian audio processing.
"""
import logging
import os
from pathlib import Path
from typing import TYPE_CHECKING, AsyncGenerator, Dict, List
if TYPE_CHECKING:
from .infrastructure import AgentDeployment, RoomManager
from .validation_utils import AudioSimulator
import pytest
import pytest_asyncio
from livekit.plugins.yandex import STT
from tests import FIXTURES_DIR
# Configure logging for tests
logger = logging.getLogger("agent-e2e-tests")
@pytest.fixture(scope="session")
def agent_credentials() -> Dict[str, str]:
"""Get required credentials for agent mode testing."""
yandex_api_key = os.environ.get("YANDEX_API_KEY")
yandex_folder_id = os.environ.get("YANDEX_FOLDER_ID")
livekit_api_key = os.environ.get("LIVEKIT_API_KEY")
livekit_api_secret = os.environ.get("LIVEKIT_API_SECRET")
livekit_ws_url = os.environ.get("LIVEKIT_WS_URL")
if not all(
[yandex_api_key, yandex_folder_id, livekit_api_key, livekit_api_secret, livekit_ws_url]
):
pytest.skip("Required credentials not available for agent mode testing")
# Type assertions since we've checked all values are not None
assert (
yandex_api_key
and yandex_folder_id
and livekit_api_key
and livekit_api_secret
and livekit_ws_url
)
return {
"yandex_api_key": yandex_api_key,
"yandex_folder_id": yandex_folder_id,
"livekit_api_key": livekit_api_key,
"livekit_api_secret": livekit_api_secret,
"livekit_ws_url": livekit_ws_url,
}
@pytest.fixture
def russian_audio_files() -> List[Path]:
"""Get available Russian audio test files."""
if not FIXTURES_DIR.exists():
pytest.skip("Audio fixtures directory not found - run 'make fixtures'")
# Find Russian audio files
russian_files = list(FIXTURES_DIR.glob("russian_*.wav"))
if not russian_files:
pytest.skip("No Russian audio files found - run 'make fixtures'")
logger.info(f"Found {len(russian_files)} Russian audio files")
for file in russian_files:
logger.info(f" - {file.name}")
return russian_files
@pytest.fixture
def russian_greeting_audio() -> Path:
"""Get the Russian greeting audio file specifically."""
greeting_file = FIXTURES_DIR / "russian_greeting.wav"
assert greeting_file.exists()
assert greeting_file.is_file()
return greeting_file
@pytest.fixture
def russian_weather_audio() -> Path:
"""Get the Russian weather audio file specifically."""
weather_file = FIXTURES_DIR / "russian_weather.wav"
if not weather_file.exists():
pytest.skip("Russian weather audio file not found - run 'make fixtures'")
return weather_file
@pytest.fixture
def russian_stt_agent(agent_credentials: Dict[str, str]) -> STT:
"""Create a Yandex STT instance configured for the Russian language."""
return STT(
api_key=agent_credentials["yandex_api_key"],
folder_id=agent_credentials["yandex_folder_id"],
language="ru-RU", # Russian language for all agent tests
interim_results=True, # Essential for real-time agent experience
sample_rate=16000,
)
@pytest.fixture
def audio_simulator() -> "AudioSimulator":
"""Create an audio simulator for participant speech simulation."""
from .validation_utils import AudioSimulator
return AudioSimulator()
# LiveKit Infrastructure Fixtures
@pytest_asyncio.fixture
async def room_manager(agent_credentials: Dict[str, str]) -> AsyncGenerator["RoomManager", None]:
"""Create a room manager for LiveKit operations."""
from .infrastructure import RoomManager
manager = RoomManager(
api_key=agent_credentials["livekit_api_key"],
api_secret=agent_credentials["livekit_api_secret"],
ws_url=agent_credentials["livekit_ws_url"],
)
yield manager
# Clean up all rooms
await manager.cleanup_all_rooms()
@pytest_asyncio.fixture
async def agent_deployment(
agent_credentials: Dict[str, str],
) -> AsyncGenerator["AgentDeployment", None]:
"""Create an agent deployment manager."""
from .infrastructure import AgentDeployment
deployment = AgentDeployment(
yandex_api_key=agent_credentials["yandex_api_key"],
yandex_folder_id=agent_credentials["yandex_folder_id"],
livekit_api_key=agent_credentials["livekit_api_key"],
livekit_api_secret=agent_credentials["livekit_api_secret"],
livekit_ws_url=agent_credentials["livekit_ws_url"],
)
yield deployment
# Clean up all agents
await deployment.cleanup_all_agents()