Skip to content

Commit c3b5b32

Browse files
yotsudaclaude
andcommitted
Fix Named Pipe test to use length-prefixed binary protocol
The Named Pipe server uses 4-byte little-endian length prefix framing, not newline-delimited text. Updated Send-PipeCommand accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9d27279 commit c3b5b32

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

.github/workflows/macos-terminal-test.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,34 @@ jobs:
102102
# Import module for NamedPipeClient
103103
Import-Module PowerShell.MCP
104104
105-
# Helper to send command via Named Pipe
105+
# Helper to send command via Named Pipe (4-byte length-prefixed binary protocol)
106106
function Send-PipeCommand {
107107
param([string]$Pipeline, [int]$TimeoutSec = 30)
108108
$client = [System.IO.Pipes.NamedPipeClientStream]::new('.', $pipeName)
109109
$client.Connect($TimeoutSec * 1000)
110-
$writer = [System.IO.StreamWriter]::new($client)
111-
$reader = [System.IO.StreamReader]::new($client)
112110
113111
$json = @{ name = "invoke_expression"; pipeline = $Pipeline } | ConvertTo-Json -Compress
114-
$writer.WriteLine($json)
115-
$writer.Flush()
116-
117-
$response = $reader.ReadLine()
112+
$msgBytes = [System.Text.Encoding]::UTF8.GetBytes($json)
113+
$lenBytes = [BitConverter]::GetBytes([int]$msgBytes.Length)
114+
115+
# Send: 4-byte length prefix + message body
116+
$client.Write($lenBytes, 0, 4)
117+
$client.Write($msgBytes, 0, $msgBytes.Length)
118+
$client.Flush()
119+
120+
# Receive: 4-byte length prefix + message body
121+
$respLenBytes = [byte[]]::new(4)
122+
$client.Read($respLenBytes, 0, 4) | Out-Null
123+
$respLen = [BitConverter]::ToInt32($respLenBytes, 0)
124+
$respBytes = [byte[]]::new($respLen)
125+
$totalRead = 0
126+
while ($totalRead -lt $respLen) {
127+
$read = $client.Read($respBytes, $totalRead, $respLen - $totalRead)
128+
if ($read -eq 0) { break }
129+
$totalRead += $read
130+
}
118131
$client.Dispose()
119-
return $response
132+
return [System.Text.Encoding]::UTF8.GetString($respBytes, 0, $totalRead)
120133
}
121134
122135
# Test 1: Quick command

0 commit comments

Comments
 (0)