Skip to content

Commit 8fddfa1

Browse files
Copilothalter73
andcommitted
Replace LF read tests with CRLF read tests, skipped on non-Windows
Per review feedback, the LF read tests were redundant since we now always emit LF. Replace them with CRLF acceptance tests that validate backward compatibility with \r\n-delimited messages, skipped on non-Windows platforms. Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
1 parent 4216490 commit 8fddfa1

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

tests/ModelContextProtocol.Tests/Transport/StdioServerTransportTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,10 @@ public async Task SendMessageAsync_Should_Use_LF_Not_CRLF()
249249
Assert.NotEqual((byte)'\r', bytes[^2]);
250250
}
251251

252-
[Fact]
253-
public async Task ReadMessagesAsync_Should_Accept_LF_Delimited_Messages()
252+
public static bool IsWindows => PlatformDetection.IsWindows;
253+
254+
[Fact(Skip = "Non-Windows platform", SkipUnless = nameof(IsWindows))]
255+
public async Task ReadMessagesAsync_Should_Accept_CRLF_Delimited_Messages()
254256
{
255257
var message = new JsonRpcRequest { Method = "test", Id = new RequestId(44) };
256258
var json = JsonSerializer.Serialize(message, McpJsonUtilities.DefaultOptions);
@@ -263,12 +265,12 @@ public async Task ReadMessagesAsync_Should_Accept_LF_Delimited_Messages()
263265
Stream.Null,
264266
loggerFactory: LoggerFactory);
265267

266-
// Write the message with \n line ending (not \r\n)
267-
await pipe.Writer.WriteAsync(Encoding.UTF8.GetBytes($"{json}\n"), TestContext.Current.CancellationToken);
268+
// Write the message with \r\n line ending
269+
await pipe.Writer.WriteAsync(Encoding.UTF8.GetBytes($"{json}\r\n"), TestContext.Current.CancellationToken);
268270

269271
var canRead = await transport.MessageReader.WaitToReadAsync(TestContext.Current.CancellationToken);
270272

271-
Assert.True(canRead, "Should be able to read a \\n-delimited message");
273+
Assert.True(canRead, "Should be able to read a \\r\\n-delimited message");
272274
Assert.True(transport.MessageReader.TryPeek(out var readMessage));
273275
Assert.NotNull(readMessage);
274276
Assert.IsType<JsonRpcRequest>(readMessage);

tests/ModelContextProtocol.Tests/Transport/StreamClientTransportTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace ModelContextProtocol.Tests.Transport;
88

99
public class StreamClientTransportTests(ITestOutputHelper testOutputHelper) : LoggedTest(testOutputHelper)
1010
{
11+
public static bool IsWindows => PlatformDetection.IsWindows;
12+
1113
[Fact]
1214
public async Task SendMessageAsync_Should_Use_LF_Not_CRLF()
1315
{
@@ -34,8 +36,8 @@ public async Task SendMessageAsync_Should_Use_LF_Not_CRLF()
3436
Assert.Equal(expected, json);
3537
}
3638

37-
[Fact]
38-
public async Task ReadMessagesAsync_Should_Accept_LF_Delimited_Messages()
39+
[Fact(Skip = "Non-Windows platform", SkipUnless = nameof(IsWindows))]
40+
public async Task ReadMessagesAsync_Should_Accept_CRLF_Delimited_Messages()
3941
{
4042
Pipe serverInputPipe = new();
4143
Pipe serverOutputPipe = new();
@@ -46,12 +48,12 @@ public async Task ReadMessagesAsync_Should_Accept_LF_Delimited_Messages()
4648
var message = new JsonRpcRequest { Method = "test", Id = new RequestId(44) };
4749
var json = JsonSerializer.Serialize(message, McpJsonUtilities.DefaultOptions);
4850

49-
// Write a \n-delimited message to the server's output (which the client reads)
50-
await serverOutputPipe.Writer.WriteAsync(Encoding.UTF8.GetBytes($"{json}\n"), TestContext.Current.CancellationToken);
51+
// Write a \r\n-delimited message to the server's output (which the client reads)
52+
await serverOutputPipe.Writer.WriteAsync(Encoding.UTF8.GetBytes($"{json}\r\n"), TestContext.Current.CancellationToken);
5153

5254
var canRead = await sessionTransport.MessageReader.WaitToReadAsync(TestContext.Current.CancellationToken);
5355

54-
Assert.True(canRead, "Should be able to read a \\n-delimited message");
56+
Assert.True(canRead, "Should be able to read a \\r\\n-delimited message");
5557
Assert.True(sessionTransport.MessageReader.TryPeek(out var readMessage));
5658
Assert.NotNull(readMessage);
5759
Assert.IsType<JsonRpcRequest>(readMessage);

0 commit comments

Comments
 (0)