-
Notifications
You must be signed in to change notification settings - Fork 6
385 lines (321 loc) · 14.9 KB
/
cross-platform-test.yml
File metadata and controls
385 lines (321 loc) · 14.9 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
name: Cross-Platform Test
on:
workflow_dispatch: # Manual trigger
push:
branches: [ main ]
paths:
- 'PowerShell.MCP/**'
- 'PowerShell.MCP.Proxy/**'
- 'Staging/**'
permissions:
contents: read
jobs:
test:
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
rid: win-x64
exe: PowerShell.MCP.Proxy.exe
- os: ubuntu-latest
rid: linux-x64
exe: PowerShell.MCP.Proxy
- os: macos-14
rid: osx-arm64
exe: PowerShell.MCP.Proxy
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Install PowerShell 7.5 (Windows)
if: runner.os == 'Windows'
run: |
# GitHub Actions has PowerShell 7.4 which uses .NET 8
# PowerShell.MCP requires .NET 9, so we need PowerShell 7.5+
# Use ZIP package to avoid MSI installation issues
$ErrorActionPreference = "Stop"
$url = "https://github.com/PowerShell/PowerShell/releases/download/v7.5.4/PowerShell-7.5.4-win-x64.zip"
$zipPath = "$env:TEMP\PowerShell-7.5.4-win-x64.zip"
$installPath = "C:\pwsh75"
Write-Host "Downloading PowerShell 7.5.4 ZIP..."
Invoke-WebRequest -Uri $url -OutFile $zipPath -UseBasicParsing
Write-Host "Downloaded: $((Get-Item $zipPath).Length) bytes"
Write-Host "Extracting to $installPath..."
Expand-Archive -Path $zipPath -DestinationPath $installPath -Force
Write-Host "Verifying installation..."
& "$installPath\pwsh.exe" --version
# Add to PATH for subsequent steps
echo "$installPath" | Out-File -FilePath $env:GITHUB_PATH -Append
shell: pwsh
- name: Install PowerShell (macOS)
if: runner.os == 'macOS'
run: |
brew install powershell/tap/powershell
- name: Install PowerShell (Linux)
if: runner.os == 'Linux'
run: |
# Install PowerShell on Ubuntu
sudo apt-get update
sudo apt-get install -y wget apt-transport-https software-properties-common
source /etc/os-release
wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y powershell
- name: Verify PowerShell
shell: pwsh
run: |
Write-Host "PowerShell Version: $($PSVersionTable.PSVersion)"
Write-Host "PowerShell Path: $((Get-Process -Id $PID).Path)"
Write-Host "OS: $($PSVersionTable.OS)"
# On Windows, verify we're using 7.5+
if ($IsWindows -and $PSVersionTable.PSVersion.Major -eq 7 -and $PSVersionTable.PSVersion.Minor -lt 5) {
throw "Expected PowerShell 7.5+, got $($PSVersionTable.PSVersion)"
}
- name: Build PowerShell.MCP module
run: |
dotnet build PowerShell.MCP -c Release --no-incremental
- name: Build Proxy
run: |
dotnet publish PowerShell.MCP.Proxy -c Release -r ${{ matrix.rid }} --self-contained
- name: Setup module directory (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$modulePath = "$env:USERPROFILE\Documents\PowerShell\Modules\PowerShell.MCP"
New-Item -Path "$modulePath\bin\${{ matrix.rid }}" -ItemType Directory -Force | Out-Null
Copy-Item "PowerShell.MCP\bin\Release\net9.0\PowerShell.MCP.dll" -Destination $modulePath
Copy-Item "PowerShell.MCP\bin\Release\net9.0\Ude.NetStandard.dll" -Destination $modulePath
Copy-Item "Staging\PowerShell.MCP.psd1" -Destination $modulePath
Copy-Item "Staging\PowerShell.MCP.psm1" -Destination $modulePath
Copy-Item "PowerShell.MCP.Proxy\bin\Release\net9.0\${{ matrix.rid }}\publish\${{ matrix.exe }}" -Destination "$modulePath\bin\${{ matrix.rid }}"
Write-Host "Module files:"
Get-ChildItem $modulePath -Recurse | Select-Object FullName
- name: Setup module directory (Linux/macOS)
if: runner.os != 'Windows'
run: |
MODULE_PATH="$HOME/.local/share/powershell/Modules/PowerShell.MCP"
mkdir -p "$MODULE_PATH/bin/${{ matrix.rid }}"
cp PowerShell.MCP/bin/Release/net9.0/PowerShell.MCP.dll "$MODULE_PATH/"
cp PowerShell.MCP/bin/Release/net9.0/Ude.NetStandard.dll "$MODULE_PATH/"
cp Staging/PowerShell.MCP.psd1 "$MODULE_PATH/"
cp Staging/PowerShell.MCP.psm1 "$MODULE_PATH/"
cp "PowerShell.MCP.Proxy/bin/Release/net9.0/${{ matrix.rid }}/publish/${{ matrix.exe }}" "$MODULE_PATH/bin/${{ matrix.rid }}/"
chmod +x "$MODULE_PATH/bin/${{ matrix.rid }}/${{ matrix.exe }}"
echo "Module files:"
ls -laR "$MODULE_PATH/"
- name: Test module import
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
Write-Host "=== Importing module ===" -ForegroundColor Cyan
Import-Module PowerShell.MCP -Verbose
Write-Host "`n=== Module info ===" -ForegroundColor Cyan
Get-Module PowerShell.MCP | Format-List Name, Version, ModuleBase
Write-Host "`n=== Get-MCPProxyPath ===" -ForegroundColor Cyan
$proxyPath = Get-MCPProxyPath
Write-Host "Proxy path: $proxyPath"
if (-not (Test-Path $proxyPath)) { throw "Proxy not found at $proxyPath" }
Write-Host "`n=== Get-MCPProxyPath -Escape ===" -ForegroundColor Cyan
$escapedPath = Get-MCPProxyPath -Escape
Write-Host "Escaped path: $escapedPath"
Write-Host "`n=== PSReadLine status ===" -ForegroundColor Cyan
$psrl = Get-Module PSReadLine
if ($IsWindows) {
if ($psrl) {
Write-Host "PSReadLine is loaded (expected on Windows)" -ForegroundColor Green
} else {
Write-Host "PSReadLine is NOT loaded (unexpected on Windows)" -ForegroundColor Yellow
}
} else {
if ($psrl) {
Write-Host "PSReadLine is loaded (unexpected on Linux/macOS)" -ForegroundColor Yellow
} else {
Write-Host "PSReadLine is NOT loaded (expected on Linux/macOS)" -ForegroundColor Green
}
}
Write-Host "`n=== All tests passed ===" -ForegroundColor Green
- name: Test Proxy JSON-RPC communication
shell: pwsh
timeout-minutes: 2
run: |
$ErrorActionPreference = "Stop"
Write-Host "=== Testing Proxy JSON-RPC ===" -ForegroundColor Cyan
$proxyPath = Get-MCPProxyPath
Write-Host "Proxy path: $proxyPath"
# Start Proxy process with redirected stdin/stdout
$psi = [System.Diagnostics.ProcessStartInfo]::new()
$psi.FileName = $proxyPath
$psi.RedirectStandardInput = $true
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.UseShellExecute = $false
$psi.CreateNoWindow = $true
$process = [System.Diagnostics.Process]::Start($psi)
Write-Host "Proxy started with PID: $($process.Id)"
# Use async reading with timeout
function Send-JsonRpc {
param([string]$Json, [int]$TimeoutMs = 5000)
Write-Host "Sending: $Json"
$process.StandardInput.WriteLine($Json)
$process.StandardInput.Flush()
# Read response line with timeout
$task = $process.StandardOutput.ReadLineAsync()
if ($task.Wait($TimeoutMs)) {
return $task.Result
} else {
throw "Timeout waiting for response"
}
}
try {
# Test 1: Initialize
Write-Host "`n=== Test 1: Initialize ===" -ForegroundColor Yellow
$initRequest = '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
$response = Send-JsonRpc $initRequest
Write-Host "Response: $response"
if ($response -match '"protocolVersion"') {
Write-Host "Initialize: PASSED" -ForegroundColor Green
} else {
throw "Initialize failed - no protocolVersion in response"
}
# Send initialized notification (no response expected)
Write-Host "`nSending initialized notification..."
$process.StandardInput.WriteLine('{"jsonrpc":"2.0","method":"notifications/initialized"}')
$process.StandardInput.Flush()
Start-Sleep -Milliseconds 200
# Test 2: List tools
Write-Host "`n=== Test 2: List Tools ===" -ForegroundColor Yellow
$listRequest = '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'
$response = Send-JsonRpc $listRequest
Write-Host "Response: $response"
if ($response -match '"get_current_location"' -and $response -match '"invoke_expression"') {
Write-Host "List Tools: PASSED" -ForegroundColor Green
} else {
throw "List Tools failed - expected tools not found"
}
Write-Host "`n=== All JSON-RPC tests passed ===" -ForegroundColor Green
} finally {
if (-not $process.HasExited) { $process.Kill() }
$process.Dispose()
}
- name: Test Named Pipe communication
shell: pwsh
timeout-minutes: 2
run: |
$ErrorActionPreference = "Stop"
Write-Host "=== Testing Named Pipe Communication ===" -ForegroundColor Cyan
# Start a background pwsh process with PowerShell.MCP imported
Write-Host "Starting background pwsh with PowerShell.MCP..."
$bgPsi = [System.Diagnostics.ProcessStartInfo]::new()
$bgPsi.FileName = "pwsh"
$bgPsi.Arguments = "-NoProfile -NoExit -Command `"Import-Module PowerShell.MCP -Verbose`""
$bgPsi.UseShellExecute = $false
$bgPsi.CreateNoWindow = $true
$bgPsi.RedirectStandardInput = $true
$bgPsi.RedirectStandardOutput = $true
$bgPsi.RedirectStandardError = $true
$bgProcess = [System.Diagnostics.Process]::Start($bgPsi)
Write-Host "Background pwsh PID: $($bgProcess.Id)"
# Wait for Named Pipe server to be ready
Write-Host "Waiting for Named Pipe server..."
$pipeName = "PowerShell.MCP.Communication"
$pipeReady = $false
for ($i = 0; $i -lt 30; $i++) {
Start-Sleep -Milliseconds 500
# Check if process is still running
if ($bgProcess.HasExited) {
Write-Host "ERROR: Background pwsh exited with code $($bgProcess.ExitCode)" -ForegroundColor Red
Write-Host "=== stdout ===" -ForegroundColor Yellow
Write-Host $bgProcess.StandardOutput.ReadToEnd()
Write-Host "=== stderr ===" -ForegroundColor Yellow
Write-Host $bgProcess.StandardError.ReadToEnd()
throw "Background pwsh process exited unexpectedly"
}
if ($IsWindows) {
$pipeReady = Test-Path "\\.\pipe\$pipeName"
} else {
$pipeReady = Test-Path "/tmp/CoreFxPipe_$pipeName"
}
if ($pipeReady) {
Write-Host "Named Pipe ready after $($i * 500)ms"
break
}
# Show progress every 5 seconds
if ($i % 10 -eq 9) {
Write-Host "Still waiting... ($($i * 500)ms elapsed)"
}
}
if (-not $pipeReady) {
Write-Host "=== Named Pipe not found, checking process state ===" -ForegroundColor Red
Write-Host "Process running: $(-not $bgProcess.HasExited)"
if (-not $bgProcess.HasExited) {
Write-Host "=== Available stdout ===" -ForegroundColor Yellow
while ($bgProcess.StandardOutput.Peek() -ge 0) {
Write-Host ([char]$bgProcess.StandardOutput.Read()) -NoNewline
}
Write-Host ""
Write-Host "=== Available stderr ===" -ForegroundColor Yellow
while ($bgProcess.StandardError.Peek() -ge 0) {
Write-Host ([char]$bgProcess.StandardError.Read()) -NoNewline
}
Write-Host ""
$bgProcess.Kill()
}
throw "Named Pipe server did not start within 15 seconds"
}
# Start Proxy
Write-Host "Starting Proxy..."
$proxyPath = Get-MCPProxyPath
$psi = [System.Diagnostics.ProcessStartInfo]::new()
$psi.FileName = $proxyPath
$psi.RedirectStandardInput = $true
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.UseShellExecute = $false
$psi.CreateNoWindow = $true
$process = [System.Diagnostics.Process]::Start($psi)
# Use async reading with timeout
function Send-JsonRpc {
param([string]$Json, [int]$TimeoutMs = 5000)
Write-Host "Sending: $Json"
$process.StandardInput.WriteLine($Json)
$process.StandardInput.Flush()
$task = $process.StandardOutput.ReadLineAsync()
if ($task.Wait($TimeoutMs)) {
return $task.Result
} else {
throw "Timeout waiting for response"
}
}
try {
# Initialize
$initRequest = '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
$response = Send-JsonRpc $initRequest
Write-Host "Init response: $response"
$process.StandardInput.WriteLine('{"jsonrpc":"2.0","method":"notifications/initialized"}')
$process.StandardInput.Flush()
Start-Sleep -Milliseconds 200
# Test: invoke_expression with Get-Date
Write-Host "`n=== Test: invoke_expression (Get-Date) ===" -ForegroundColor Yellow
$invokeRequest = '{"jsonrpc":"2.0","id":10,"method":"tools/call","params":{"name":"invoke_expression","arguments":{"pipeline":"Get-Date -Format yyyy-MM-dd"}}}'
$response = Send-JsonRpc $invokeRequest 10000
Write-Host "Response: $response"
$today = Get-Date -Format "yyyy-MM-dd"
if ($response -match $today) {
Write-Host "invoke_expression (Get-Date): PASSED" -ForegroundColor Green
} else {
throw "invoke_expression failed - expected date $today not found"
}
Write-Host "`n=== All Named Pipe tests passed ===" -ForegroundColor Green
} finally {
if (-not $process.HasExited) { $process.Kill() }
$process.Dispose()
if (-not $bgProcess.HasExited) { $bgProcess.Kill() }
$bgProcess.Dispose()
}