forked from BeehiveInnovations/pal-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_integration_tests.ps1
More file actions
201 lines (174 loc) · 5.94 KB
/
run_integration_tests.ps1
File metadata and controls
201 lines (174 loc) · 5.94 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env pwsh
#Requires -Version 5.1
[CmdletBinding()]
param(
[switch]$WithSimulator,
[switch]$VerboseOutput
)
# Set error action preference
$ErrorActionPreference = "Stop"
# Colors for output
function Write-ColorText {
param(
[Parameter(Mandatory)]
[string]$Text,
[string]$Color = "White",
[switch]$NoNewline
)
if ($NoNewline) {
Write-Host $Text -ForegroundColor $Color -NoNewline
} else {
Write-Host $Text -ForegroundColor $Color
}
}
function Write-Emoji {
param(
[Parameter(Mandatory)]
[string]$Emoji,
[Parameter(Mandatory)]
[string]$Text,
[string]$Color = "White"
)
Write-Host "$Emoji " -NoNewline
Write-ColorText $Text -Color $Color
}
Write-Emoji "🧪" "Running Integration Tests for Zen MCP Server" -Color Cyan
Write-ColorText "==============================================" -Color Cyan
Write-ColorText "These tests use real API calls with your configured keys"
Write-Host ""
# Check for virtual environment
$venvPath = ".zen_venv"
$activateScript = if ($IsWindows -or $env:OS -eq "Windows_NT") {
"$venvPath\Scripts\Activate.ps1"
} else {
"$venvPath/bin/activate"
}
if (Test-Path $venvPath) {
Write-Emoji "✅" "Virtual environment found" -Color Green
# Activate virtual environment (for PowerShell on Windows)
if ($IsWindows -or $env:OS -eq "Windows_NT") {
if (Test-Path "$venvPath\Scripts\Activate.ps1") {
& "$venvPath\Scripts\Activate.ps1"
} elseif (Test-Path "$venvPath\Scripts\activate.bat") {
# Use Python directly from venv
$env:PATH = "$PWD\$venvPath\Scripts;$env:PATH"
}
}
} else {
Write-Emoji "❌" "No virtual environment found!" -Color Red
Write-ColorText "Please run: .\run-server.ps1 first" -Color Yellow
exit 1
}
# Check for .env file
if (!(Test-Path ".env")) {
Write-Emoji "⚠️" "Warning: No .env file found. Integration tests may fail without API keys." -Color Yellow
Write-Host ""
}
Write-Emoji "🔑" "Checking API key availability:" -Color Cyan
Write-ColorText "---------------------------------" -Color Cyan
# Function to check if API key is configured
function Test-ApiKey {
param(
[string]$KeyName
)
# Check environment variable
$envValue = [Environment]::GetEnvironmentVariable($KeyName)
if (![string]::IsNullOrWhiteSpace($envValue)) {
return $true
}
# Check .env file
if (Test-Path ".env") {
$envContent = Get-Content ".env" -ErrorAction SilentlyContinue
$found = $envContent | Where-Object { $_ -match "^$KeyName\s*=" -and $_ -notmatch "^$KeyName\s*=\s*$" }
return $found.Count -gt 0
}
return $false
}
# Check API keys
$apiKeys = @(
"GEMINI_API_KEY",
"OPENAI_API_KEY",
"XAI_API_KEY",
"OPENROUTER_API_KEY",
"CUSTOM_API_URL"
)
foreach ($key in $apiKeys) {
if (Test-ApiKey $key) {
if ($key -eq "CUSTOM_API_URL") {
Write-Emoji "✅" "$key configured (local models)" -Color Green
} else {
Write-Emoji "✅" "$key configured" -Color Green
}
} else {
Write-Emoji "❌" "$key not found" -Color Red
}
}
Write-Host ""
# Load environment variables from .env if it exists
if (Test-Path ".env") {
Get-Content ".env" | ForEach-Object {
if ($_ -match '^([^#][^=]*?)=(.*)$') {
$name = $matches[1].Trim()
$value = $matches[2].Trim()
# Remove quotes if present
$value = $value -replace '^["'']|["'']$', ''
[Environment]::SetEnvironmentVariable($name, $value, "Process")
}
}
}
# Run integration tests
Write-Emoji "🏃" "Running integration tests..." -Color Cyan
Write-ColorText "------------------------------" -Color Cyan
try {
# Build pytest command
$pytestArgs = @("tests/", "-v", "-m", "integration", "--tb=short")
if ($VerboseOutput) {
$pytestArgs += "--verbose"
}
# Run pytest
python -m pytest @pytestArgs
if ($LASTEXITCODE -ne 0) {
throw "Integration tests failed"
}
Write-Host ""
Write-Emoji "✅" "Integration tests completed!" -Color Green
} catch {
Write-Host ""
Write-Emoji "❌" "Integration tests failed!" -Color Red
Write-ColorText "Error: $_" -Color Red
exit 1
}
# Run simulator tests if requested
if ($WithSimulator) {
Write-Host ""
Write-Emoji "🤖" "Running simulator tests..." -Color Cyan
Write-ColorText "----------------------------" -Color Cyan
try {
if ($VerboseOutput) {
python communication_simulator_test.py --verbose
} else {
python communication_simulator_test.py
}
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Emoji "❌" "Simulator tests failed!" -Color Red
Write-ColorText "This may be due to a known issue in communication_simulator_test.py" -Color Yellow
Write-ColorText "Integration tests completed successfully - you can proceed." -Color Green
} else {
Write-Host ""
Write-Emoji "✅" "Simulator tests completed!" -Color Green
}
} catch {
Write-Host ""
Write-Emoji "❌" "Simulator tests failed!" -Color Red
Write-ColorText "Error: $_" -Color Red
Write-ColorText "This may be due to a known issue in communication_simulator_test.py" -Color Yellow
Write-ColorText "Integration tests completed successfully - you can proceed." -Color Green
}
}
Write-Host ""
Write-Emoji "💡" "Tips:" -Color Yellow
Write-ColorText "- Run '.\run_integration_tests.ps1' for integration tests only" -Color White
Write-ColorText "- Run '.\run_integration_tests.ps1 -WithSimulator' to also run simulator tests" -Color White
Write-ColorText "- Run '.\code_quality_checks.ps1' for unit tests and linting" -Color White
Write-ColorText "- Check logs in logs\mcp_server.log if tests fail" -Color White