@@ -251,6 +251,7 @@ jobs:
251251
252252 - name : Test Named Pipe communication
253253 shell : pwsh
254+ timeout-minutes : 2
254255 run : |
255256 $ErrorActionPreference = "Stop"
256257
@@ -260,7 +261,7 @@ jobs:
260261 Write-Host "Starting background pwsh with PowerShell.MCP..."
261262 $bgPsi = [System.Diagnostics.ProcessStartInfo]::new()
262263 $bgPsi.FileName = "pwsh"
263- $bgPsi.Arguments = "-NoProfile -NoExit -Command `"Import-Module PowerShell.MCP`""
264+ $bgPsi.Arguments = "-NoProfile -NoExit -Command `"Import-Module PowerShell.MCP -Verbose `""
264265 $bgPsi.UseShellExecute = $false
265266 $bgPsi.CreateNoWindow = $true
266267 $bgPsi.RedirectStandardInput = $true
@@ -276,6 +277,17 @@ jobs:
276277 $pipeReady = $false
277278 for ($i = 0; $i -lt 30; $i++) {
278279 Start-Sleep -Milliseconds 500
280+
281+ # Check if process is still running
282+ if ($bgProcess.HasExited) {
283+ Write-Host "ERROR: Background pwsh exited with code $($bgProcess.ExitCode)" -ForegroundColor Red
284+ Write-Host "=== stdout ===" -ForegroundColor Yellow
285+ Write-Host $bgProcess.StandardOutput.ReadToEnd()
286+ Write-Host "=== stderr ===" -ForegroundColor Yellow
287+ Write-Host $bgProcess.StandardError.ReadToEnd()
288+ throw "Background pwsh process exited unexpectedly"
289+ }
290+
279291 if ($IsWindows) {
280292 $pipeReady = Test-Path "\\.\pipe\$pipeName"
281293 } else {
@@ -285,10 +297,29 @@ jobs:
285297 Write-Host "Named Pipe ready after $($i * 500)ms"
286298 break
287299 }
300+
301+ # Show progress every 5 seconds
302+ if ($i % 10 -eq 9) {
303+ Write-Host "Still waiting... ($($i * 500)ms elapsed)"
304+ }
288305 }
289306
290307 if (-not $pipeReady) {
291- $bgProcess.Kill()
308+ Write-Host "=== Named Pipe not found, checking process state ===" -ForegroundColor Red
309+ Write-Host "Process running: $(-not $bgProcess.HasExited)"
310+ if (-not $bgProcess.HasExited) {
311+ Write-Host "=== Available stdout ===" -ForegroundColor Yellow
312+ while ($bgProcess.StandardOutput.Peek() -ge 0) {
313+ Write-Host ([char]$bgProcess.StandardOutput.Read()) -NoNewline
314+ }
315+ Write-Host ""
316+ Write-Host "=== Available stderr ===" -ForegroundColor Yellow
317+ while ($bgProcess.StandardError.Peek() -ge 0) {
318+ Write-Host ([char]$bgProcess.StandardError.Read()) -NoNewline
319+ }
320+ Write-Host ""
321+ $bgProcess.Kill()
322+ }
292323 throw "Named Pipe server did not start within 15 seconds"
293324 }
294325
@@ -305,50 +336,42 @@ jobs:
305336
306337 $process = [System.Diagnostics.Process]::Start($psi)
307338
339+ # Use async reading with timeout
308340 function Send-JsonRpc {
309- param([string]$Json, [int]$WaitMs = 2000)
341+ param([string]$Json, [int]$TimeoutMs = 5000)
342+ Write-Host "Sending: $Json"
310343 $process.StandardInput.WriteLine($Json)
311344 $process.StandardInput.Flush()
312- Start-Sleep -Milliseconds $WaitMs
313345
314- $output = ""
315- while ($process.StandardOutput.Peek() -ge 0) {
316- $output += [char]$process.StandardOutput.Read()
346+ $task = $process.StandardOutput.ReadLineAsync()
347+ if ($task.Wait($TimeoutMs)) {
348+ return $task.Result
349+ } else {
350+ throw "Timeout waiting for response"
317351 }
318- return $output
319352 }
320353
321354 try {
322355 # Initialize
323356 $initRequest = '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
324- $null = Send-JsonRpc $initRequest
357+ $response = Send-JsonRpc $initRequest
358+ Write-Host "Init response: $response"
359+
325360 $process.StandardInput.WriteLine('{"jsonrpc":"2.0","method":"notifications/initialized"}')
326361 $process.StandardInput.Flush()
327362 Start-Sleep -Milliseconds 200
328363
329364 # Test: invoke_expression with Get-Date
330365 Write-Host "`n=== Test: invoke_expression (Get-Date) ===" -ForegroundColor Yellow
331366 $invokeRequest = '{"jsonrpc":"2.0","id":10,"method":"tools/call","params":{"name":"invoke_expression","arguments":{"pipeline":"Get-Date -Format yyyy-MM-dd"}}}'
332- $response = Send-JsonRpc $invokeRequest 3000
367+ $response = Send-JsonRpc $invokeRequest 10000
333368 Write-Host "Response: $response"
334369
335370 $today = Get-Date -Format "yyyy-MM-dd"
336371 if ($response -match $today) {
337- Write-Host "invoke_expression (Get-Date): PASSED - Got today's date " -ForegroundColor Green
372+ Write-Host "invoke_expression (Get-Date): PASSED" -ForegroundColor Green
338373 } else {
339- throw "invoke_expression failed - expected date $today not found in response"
340- }
341-
342- # Test: get_current_location
343- Write-Host "`n=== Test: get_current_location ===" -ForegroundColor Yellow
344- $locRequest = '{"jsonrpc":"2.0","id":11,"method":"tools/call","params":{"name":"get_current_location","arguments":{}}}'
345- $response = Send-JsonRpc $locRequest 3000
346- Write-Host "Response: $response"
347-
348- if ($response -match '"current_location"' -or $response -match '"system"') {
349- Write-Host "get_current_location: PASSED" -ForegroundColor Green
350- } else {
351- throw "get_current_location failed - no location info in response"
374+ throw "invoke_expression failed - expected date $today not found"
352375 }
353376
354377 Write-Host "`n=== All Named Pipe tests passed ===" -ForegroundColor Green
@@ -359,3 +382,4 @@ jobs:
359382 if (-not $bgProcess.HasExited) { $bgProcess.Kill() }
360383 $bgProcess.Dispose()
361384 }
385+
0 commit comments