diff --git a/src/Cli/dotnet/Commands/CliCommandStrings.resx b/src/Cli/dotnet/Commands/CliCommandStrings.resx index afdb84f78d4e..0f0c8283f41b 100644 --- a/src/Cli/dotnet/Commands/CliCommandStrings.resx +++ b/src/Cli/dotnet/Commands/CliCommandStrings.resx @@ -2663,4 +2663,7 @@ Proceed? Error disposing 'NamedPipeServer', and no handshake was found. - \ No newline at end of file + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + diff --git a/src/Cli/dotnet/Commands/Test/CliConstants.cs b/src/Cli/dotnet/Commands/Test/CliConstants.cs index c8d411bdc202..8f8735bad471 100644 --- a/src/Cli/dotnet/Commands/Test/CliConstants.cs +++ b/src/Cli/dotnet/Commands/Test/CliConstants.cs @@ -65,7 +65,10 @@ internal static class HandshakeMessagePropertyNames internal static class ProtocolConstants { - internal const string Version = "1.0.0"; + /// + /// The protocol versions that are supported by the current SDK. Multiple versions can be present and be semicolon separated. + /// + internal const string SupportedVersions = "1.0.0"; } internal static class ProjectProperties diff --git a/src/Cli/dotnet/Commands/Test/CustomEventArgs.cs b/src/Cli/dotnet/Commands/Test/CustomEventArgs.cs index 4592599c0234..0f7e7f77ab32 100644 --- a/src/Cli/dotnet/Commands/Test/CustomEventArgs.cs +++ b/src/Cli/dotnet/Commands/Test/CustomEventArgs.cs @@ -5,19 +5,20 @@ namespace Microsoft.DotNet.Cli.Commands.Test; -internal class HandshakeArgs : EventArgs +internal sealed class HandshakeArgs : EventArgs { public Handshake Handshake { get; set; } + public bool GotSupportedVersion { get; set; } } -internal class HelpEventArgs : EventArgs +internal sealed class HelpEventArgs : EventArgs { public string ModulePath { get; set; } public CommandLineOption[] CommandLineOptions { get; set; } } -internal class DiscoveredTestEventArgs : EventArgs +internal sealed class DiscoveredTestEventArgs : EventArgs { public string ExecutionId { get; set; } @@ -26,7 +27,7 @@ internal class DiscoveredTestEventArgs : EventArgs public DiscoveredTest[] DiscoveredTests { get; set; } } -internal class TestResultEventArgs : EventArgs +internal sealed class TestResultEventArgs : EventArgs { public string ExecutionId { get; set; } @@ -37,7 +38,7 @@ internal class TestResultEventArgs : EventArgs public FailedTestResult[] FailedTestResults { get; set; } } -internal class FileArtifactEventArgs : EventArgs +internal sealed class FileArtifactEventArgs : EventArgs { public string ExecutionId { get; set; } @@ -46,25 +47,19 @@ internal class FileArtifactEventArgs : EventArgs public FileArtifact[] FileArtifacts { get; set; } } -internal class SessionEventArgs : EventArgs +internal sealed class SessionEventArgs : EventArgs { public TestSession SessionEvent { get; set; } } -internal class ErrorEventArgs : EventArgs +internal sealed class ErrorEventArgs : EventArgs { public string ErrorMessage { get; set; } } -internal class TestProcessExitEventArgs : EventArgs +internal sealed class TestProcessExitEventArgs : EventArgs { public List OutputData { get; set; } public List ErrorData { get; set; } public int ExitCode { get; set; } } - -internal class ExecutionEventArgs : EventArgs -{ - public string ModulePath { get; set; } - public string ExecutionId { get; set; } -} diff --git a/src/Cli/dotnet/Commands/Test/IPC/NamedPipeServer.cs b/src/Cli/dotnet/Commands/Test/IPC/NamedPipeServer.cs index 1130e77b7500..1a15a1401bf2 100644 --- a/src/Cli/dotnet/Commands/Test/IPC/NamedPipeServer.cs +++ b/src/Cli/dotnet/Commands/Test/IPC/NamedPipeServer.cs @@ -30,7 +30,7 @@ public NamedPipeServer( CancellationToken cancellationToken, bool skipUnknownMessages) { - _namedPipeServerStream = new((PipeName = pipeNameDescription).Name, PipeDirection.InOut, maxNumberOfServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); + _namedPipeServerStream = new((PipeName = pipeNameDescription).Name, PipeDirection.InOut, maxNumberOfServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly); _callback = callback; _cancellationToken = cancellationToken; _skipUnknownMessages = skipUnknownMessages; diff --git a/src/Cli/dotnet/Commands/Test/TestApplication.cs b/src/Cli/dotnet/Commands/Test/TestApplication.cs index f32f8e9660fd..a643f32f83d7 100644 --- a/src/Cli/dotnet/Commands/Test/TestApplication.cs +++ b/src/Cli/dotnet/Commands/Test/TestApplication.cs @@ -184,8 +184,9 @@ private Task OnRequest(NamedPipeServer server, IRequest request) { case HandshakeMessage handshakeMessage: _handshakes.Add(server, handshakeMessage); - OnHandshakeMessage(handshakeMessage); - return Task.FromResult((IResponse)CreateHandshakeMessage(GetSupportedProtocolVersion(handshakeMessage))); + string negotiatedVersion = GetSupportedProtocolVersion(handshakeMessage); + OnHandshakeMessage(handshakeMessage, negotiatedVersion.Length > 0); + return Task.FromResult((IResponse)CreateHandshakeMessage(negotiatedVersion)); case CommandLineOptionMessages commandLineOptionMessages: OnCommandLineOptionMessages(commandLineOptionMessages); @@ -235,15 +236,26 @@ private Task OnRequest(NamedPipeServer server, IRequest request) private static string GetSupportedProtocolVersion(HandshakeMessage handshakeMessage) { - handshakeMessage.Properties.TryGetValue(HandshakeMessagePropertyNames.SupportedProtocolVersions, out string protocolVersions); + if (!handshakeMessage.Properties.TryGetValue(HandshakeMessagePropertyNames.SupportedProtocolVersions, out string protocolVersions) || + protocolVersions is null) + { + // It's not expected we hit this. + // TODO: Maybe we should fail more hard? + return string.Empty; + } - string version = string.Empty; - if (protocolVersions is not null && protocolVersions.Split(";").Contains(ProtocolConstants.Version)) + // NOTE: Today, ProtocolConstants.Version is only 1.0.0 (i.e, SDK supports only a single version). + // Whenever we support multiple versions in SDK, we should do intersection + // between protocolVersions given by MTP, and the versions supported by SDK. + // Then we return the "highest" version from the intersection. + // The current logic **assumes** that ProtocolConstants.SupportedVersions is a single version. + if (protocolVersions.Split(";").Contains(ProtocolConstants.SupportedVersions)) { - version = ProtocolConstants.Version; + return ProtocolConstants.SupportedVersions; } - return version; + // The version given by MTP is not supported by SDK. + return string.Empty; } private static HandshakeMessage CreateHandshakeMessage(string version) => @@ -304,9 +316,9 @@ private bool ModulePathExists() return true; } - public void OnHandshakeMessage(HandshakeMessage handshakeMessage) + public void OnHandshakeMessage(HandshakeMessage handshakeMessage, bool gotSupportedVersion) { - HandshakeReceived?.Invoke(this, new HandshakeArgs { Handshake = new Handshake(handshakeMessage.Properties) }); + HandshakeReceived?.Invoke(this, new HandshakeArgs { Handshake = new Handshake(handshakeMessage.Properties), GotSupportedVersion = gotSupportedVersion }); } public void OnCommandLineOptionMessages(CommandLineOptionMessages commandLineOptionMessages) diff --git a/src/Cli/dotnet/Commands/Test/TestApplicationEventHandlers.cs b/src/Cli/dotnet/Commands/Test/TestApplicationEventHandlers.cs index cf0729f661fc..4ed892008237 100644 --- a/src/Cli/dotnet/Commands/Test/TestApplicationEventHandlers.cs +++ b/src/Cli/dotnet/Commands/Test/TestApplicationEventHandlers.cs @@ -18,12 +18,17 @@ internal sealed class TestApplicationsEventHandlers(TerminalTestReporter output) public void OnHandshakeReceived(object sender, HandshakeArgs args) { var testApplication = (TestApplication)sender; - // Today, it's 1.0.0 in MTP. - // https://github.com/microsoft/testfx/blob/516eebb3c9b7e81eb2677c00b3d0b7867d8acb33/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Constants.cs#L40 - var supportedProtocolVersions = args.Handshake.Properties[HandshakeMessagePropertyNames.SupportedProtocolVersions]; - if (supportedProtocolVersions != "1.0.0" && !supportedProtocolVersions.Split(';').Contains("1.0.0")) + if (!args.GotSupportedVersion) { - _output.HandshakeFailure(testApplication.Module.TargetPath, string.Empty, ExitCode.GenericFailure, $"Supported protocol versions '{supportedProtocolVersions}' doesn't include '1.0.0' which is not supported by the current .NET SDK.", string.Empty); + _output.HandshakeFailure( + testApplication.Module.TargetPath, + string.Empty, + ExitCode.GenericFailure, + string.Format( + CliCommandStrings.DotnetTestIncompatibleHandshakeVersion, + args.Handshake.Properties[HandshakeMessagePropertyNames.SupportedProtocolVersions], + ProtocolConstants.SupportedVersions), + string.Empty); } var hostType = args.Handshake.Properties[HandshakeMessagePropertyNames.HostType]; diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf index 272957153c14..c29b4866ff65 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. Testovací příkaz .NET + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf index 8ac73bef322e..6913c9cda6ce 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. Testbefehl .NET + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf index 62b42de329ad..4e0221d5c06f 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. Comando de prueba de .NET + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf index 18246376179b..2d160f7bba44 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. Commande de test .NET + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf index f853ab45bf3a..aae329f5e2c3 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. Comando di test .NET + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf index 4b7595d0de9d..5f56fb642500 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. .NET Test コマンド + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf index 40e8f2a9e7b8..6baf79650098 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. .NET 테스트 명령 + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf index b785e150bc76..12a489c5e6f9 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. Polecenie testowe platformy .NET + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf index 62ba2c077037..3a1d114e1f80 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. Comando de Teste do .NET + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf index fa2d7008a874..ac581d9af78f 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. Команда .NET Test + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf index 280ded10ba66..5aafa116a7fb 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. .NET Test Komutu + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf index 448d208ed368..3a2a80912a93 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. .NET 测试命令 + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf index b8b754e717df..0a0b46938dca 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf @@ -1163,6 +1163,11 @@ dotnet.config is a name don't translate. .NET 測試命令 + + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + Supported protocol versions sent by Microsoft.Testing.Platform are '{0}'. The SDK supports '{1}', which is incompatible. + + Error disposing 'NamedPipeServer' corresponding to handshake: Error disposing 'NamedPipeServer' corresponding to handshake: