From 99529cff748a03a9a0e5198e3d53888025210e2b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 22 May 2026 12:21:09 +0000 Subject: [PATCH 1/5] Initial plan From a4f6870cc391b82056a06bc33960ce73b83a92a6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 22 May 2026 12:35:09 +0000 Subject: [PATCH 2/5] Validate non-negative timeout arguments Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../CommandLine/PlatformCommandLineProvider.cs | 6 +++++- .../TimeoutTests.cs | 11 +++++++++++ .../CommandLine/PlatformCommandLineProviderTests.cs | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs index ddfaab74d2d..a80b0bf6821 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs @@ -127,7 +127,11 @@ public Task ValidateOptionArgumentsAsync(CommandLineOption com { string arg = arguments[0]; int size = arg.Length; - if ((char.ToLowerInvariant(arg[size - 1]) != 'h' && char.ToLowerInvariant(arg[size - 1]) != 'm' && char.ToLowerInvariant(arg[size - 1]) != 's') || !float.TryParse(arg[..(size - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float _)) + if ((char.ToLowerInvariant(arg[size - 1]) != 'h' && char.ToLowerInvariant(arg[size - 1]) != 'm' && char.ToLowerInvariant(arg[size - 1]) != 's') + || !float.TryParse(arg[..(size - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float value) + || float.IsNaN(value) + || float.IsInfinity(value) + || value < 0) { return ValidationResult.InvalidTask(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage); } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs index 5bc3d61ad01..075bcc4f2e2 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs @@ -39,6 +39,17 @@ public async Task TimeoutWithInvalidArg_WithInvalidFormat_OutputInvalidMessage(s testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); } + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] + public async Task TimeoutWithInvalidArg_WithNegativeValue_OutputInvalidMessage(string tfm) + { + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout -1s", cancellationToken: TestContext.CancellationToken); + + testHostResult.AssertExitCodeIs(ExitCode.InvalidCommandLine); + testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); + } + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] [TestMethod] public async Task TimeoutWithValidArg_WithTestTimeOut_OutputContainsCancelingMessage(string tfm) diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs index e43463a544e..bec51e4e9de 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs @@ -250,6 +250,7 @@ public async Task IsNotValid_If_ExitOnProcess_Not_Running() [DataRow("1.5s")] [DataRow("2.0m")] [DataRow("0.5h")] + [DataRow("0s")] [DataRow("10s")] [DataRow("30m")] [DataRow("1h")] @@ -283,6 +284,8 @@ public async Task IsValid_If_Timeout_Has_CorrectFormat_InvariantCulture(string t [DataRow("invalid")] [DataRow("1.5")] // Missing unit [DataRow("abc.5s")] + [DataRow("-1s")] + [DataRow("-0.5m")] public async Task IsInvalid_If_Timeout_Has_IncorrectFormat(string timeout) { var provider = new PlatformCommandLineProvider(); From f7c60097fde0fe4ccd1fc666554197f24d9f3ae3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 22 May 2026 12:36:10 +0000 Subject: [PATCH 3/5] Address timeout test review feedback Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../CommandLine/PlatformCommandLineProviderTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs index bec51e4e9de..a902d0d2aea 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs @@ -250,7 +250,6 @@ public async Task IsNotValid_If_ExitOnProcess_Not_Running() [DataRow("1.5s")] [DataRow("2.0m")] [DataRow("0.5h")] - [DataRow("0s")] [DataRow("10s")] [DataRow("30m")] [DataRow("1h")] From 8dbec18ab881be33cc4fa638a54f19e313457aa5 Mon Sep 17 00:00:00 2001 From: Evangelink <11340282+Evangelink@users.noreply.github.com> Date: Fri, 22 May 2026 17:41:45 +0200 Subject: [PATCH 4/5] Address review feedback on timeout validation - Guard against empty/short arguments to avoid IndexOutOfRangeException. - Extract TryParseTimeoutArgument helper used by both validator and host. - Reject TimeSpan overflow (e.g. '1e30h') during validation. - Update error message to mention finite, non-negative requirement. - Split unit tests by intent and add NaN/Infinity/overflow coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../PlatformCommandLineProvider.cs | 56 +++++++++++++++---- .../Hosts/TestHostBuilder.CommonServices.cs | 12 +--- .../Resources/PlatformResources.resx | 2 +- .../Resources/xlf/PlatformResources.cs.xlf | 4 +- .../Resources/xlf/PlatformResources.de.xlf | 4 +- .../Resources/xlf/PlatformResources.es.xlf | 4 +- .../Resources/xlf/PlatformResources.fr.xlf | 4 +- .../Resources/xlf/PlatformResources.it.xlf | 4 +- .../Resources/xlf/PlatformResources.ja.xlf | 4 +- .../Resources/xlf/PlatformResources.ko.xlf | 4 +- .../Resources/xlf/PlatformResources.pl.xlf | 4 +- .../Resources/xlf/PlatformResources.pt-BR.xlf | 4 +- .../Resources/xlf/PlatformResources.ru.xlf | 4 +- .../Resources/xlf/PlatformResources.tr.xlf | 4 +- .../xlf/PlatformResources.zh-Hans.xlf | 4 +- .../xlf/PlatformResources.zh-Hant.xlf | 4 +- .../TimeoutTests.cs | 8 +-- .../TimeoutTests.cs | 10 ++-- .../PlatformCommandLineProviderTests.cs | 21 ++++++- 19 files changed, 101 insertions(+), 60 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs index a80b0bf6821..3c2e68ef0bd 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs @@ -123,18 +123,10 @@ public Task ValidateOptionArgumentsAsync(CommandLineOption com return ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, PlatformResources.PlatformCommandLineExitOnProcessExitSingleArgument, ExitOnProcessExitOptionKey)); } - if (commandOption.Name == TimeoutOptionKey) + if (commandOption.Name == TimeoutOptionKey + && !TryParseTimeoutArgument(arguments[0], out _)) { - string arg = arguments[0]; - int size = arg.Length; - if ((char.ToLowerInvariant(arg[size - 1]) != 'h' && char.ToLowerInvariant(arg[size - 1]) != 'm' && char.ToLowerInvariant(arg[size - 1]) != 's') - || !float.TryParse(arg[..(size - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float value) - || float.IsNaN(value) - || float.IsInfinity(value) - || value < 0) - { - return ValidationResult.InvalidTask(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage); - } + return ValidationResult.InvalidTask(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage); } if (commandOption.Name == ConfigFileOptionKey) @@ -183,6 +175,48 @@ private static Task IsMinimumExpectedTestsOptionValidAsync(Com ? ValidationResult.InvalidTask(PlatformResources.PlatformCommandLineMinimumExpectedTestsOptionSingleArgument) : ValidationResult.ValidTask; + internal static bool TryParseTimeoutArgument(string arg, out TimeSpan timeout) + { + timeout = TimeSpan.Zero; + + // We need at least one digit plus a unit suffix (e.g. "1s"). + if (arg is null || arg.Length < 2) + { + return false; + } + + char unit = char.ToLowerInvariant(arg[arg.Length - 1]); + if (unit is not 'h' and not 'm' and not 's') + { + return false; + } + + if (!float.TryParse(arg[..(arg.Length - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float value) + || float.IsNaN(value) + || float.IsInfinity(value) + || value < 0) + { + return false; + } + + try + { + timeout = unit switch + { + 'h' => TimeSpan.FromHours(value), + 'm' => TimeSpan.FromMinutes(value), + 's' => TimeSpan.FromSeconds(value), + _ => throw ApplicationStateGuard.Unreachable(), + }; + } + catch (OverflowException) + { + return false; + } + + return true; + } + public Task ValidateCommandLineOptionsAsync(ICommandLineOptions commandLineOptions) { if (!commandLineOptions.IsOptionSet(DiagnosticOptionKey)) diff --git a/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.CommonServices.cs b/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.CommonServices.cs index 35a796577d2..b17a16627dc 100644 --- a/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.CommonServices.cs +++ b/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.CommonServices.cs @@ -197,21 +197,11 @@ private async Task SetupCommonServicesAsync( if (commandLineOptions.IsOptionSet(PlatformCommandLineProvider.TimeoutOptionKey) && commandLineOptions.TryGetOptionArgumentList(PlatformCommandLineProvider.TimeoutOptionKey, out string[]? args)) { - string arg = args[0]; - int size = arg.Length; - if (!float.TryParse(arg[..(size - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float value)) + if (!PlatformCommandLineProvider.TryParseTimeoutArgument(args[0], out TimeSpan timeout)) { throw ApplicationStateGuard.Unreachable(); } - TimeSpan timeout = char.ToLowerInvariant(arg[size - 1]) switch - { - 'h' => TimeSpan.FromHours(value), - 'm' => TimeSpan.FromMinutes(value), - 's' => TimeSpan.FromSeconds(value), - _ => throw ApplicationStateGuard.Unreachable(), - }; - context.TestApplicationCancellationTokenSource.CancelAfter(timeout); } diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index 475c56ea180..33265d55c92 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -623,7 +623,7 @@ Valid values are 'All', 'Failed', 'None'. Default is 'All'. --show-stdout and --show-stderr expect a single parameter with value 'All', 'Failed', or 'None'. - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration A global test execution timeout. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf index dc67ce0c918..dc2c3456ade 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf @@ -654,8 +654,8 @@ Výchozí hodnota je TestResults v adresáři, který obsahuje testovací aplika - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - Možnost timeout by měla mít jeden argument jako řetězec ve formátu <value>[h|m|s], kde value je hodnota datového typu float. + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + Možnost timeout by měla mít jeden argument jako řetězec ve formátu <value>[h|m|s], kde value je hodnota datového typu float. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf index ba194e66e2a..bb05487a4a7 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf @@ -654,8 +654,8 @@ Der Standardwert ist "TestResults" im Verzeichnis, das die Testanwendung enthäl - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - Die Option "timeout" muss ein Argument als Zeichenfolge im Format <value>[h|m|s] aufweisen, wobei "value" auf "float" festgelegt ist. + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + Die Option "timeout" muss ein Argument als Zeichenfolge im Format <value>[h|m|s] aufweisen, wobei "value" auf "float" festgelegt ist. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf index bd4c3c92146..d3b089e34e4 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf @@ -654,8 +654,8 @@ El valor predeterminado es TestResults en el directorio que contiene la aplicaci - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - La opción 'timeout' debe tener un argumento como cadena con el formato <value>[h|m|s] donde 'value' es float + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + La opción 'timeout' debe tener un argumento como cadena con el formato <value>[h|m|s] donde 'value' es float diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf index b43db09ffa2..62613162aea 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf @@ -654,8 +654,8 @@ La valeur par défaut est TestResults dans le répertoire qui contient l’appli - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - L’option « timeout » doit avoir un argument sous forme de chaîne au format <value>[h|m|s] où « value » est float + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + L’option « timeout » doit avoir un argument sous forme de chaîne au format <value>[h|m|s] où « value » est float diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf index bdfe056496d..aa8507e0215 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf @@ -654,8 +654,8 @@ L’impostazione predefinita è TestResults nella directory che contiene l'appli - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - L'opzione 'timeout' deve contenere un argomento come stringa nel formato <value>[h|m|s] dove 'value' è float + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + L'opzione 'timeout' deve contenere un argomento come stringa nel formato <value>[h|m|s] dove 'value' è float diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf index 97edfe78785..2ea47b47135 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf @@ -655,8 +655,8 @@ The default is TestResults in the directory that contains the test application.< - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - 'timeout' オプションには、1 つの引数を文字列として <value>[h|m|s] の形式で指定する必要があります。この場合、'value' は float です + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + 'timeout' オプションには、1 つの引数を文字列として <value>[h|m|s] の形式で指定する必要があります。この場合、'value' は float です diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf index 3d791db0293..a8d7073019e 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf @@ -654,8 +654,8 @@ The default is TestResults in the directory that contains the test application.< - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - 'timeout' 옵션에는 'value'가 float인 <value>[h|m|s] 형식의 문자열로 인수가 하나 있어야 합니다. + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + 'timeout' 옵션에는 'value'가 float인 <value>[h|m|s] 형식의 문자열로 인수가 하나 있어야 합니다. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf index 70985a304e3..e90641a1b4d 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf @@ -654,8 +654,8 @@ Wartość domyślna to TestResults w katalogu zawierającym aplikację testową. - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - Opcja „timeout” powinna mieć jeden argument jako ciąg w formacie <value>[h|m|s], gdzie element „value” ma wartość zmiennoprzecinkową + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + Opcja „timeout” powinna mieć jeden argument jako ciąg w formacie <value>[h|m|s], gdzie element „value” ma wartość zmiennoprzecinkową diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf index aa46d0ef8da..d4389c7dc04 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf @@ -654,8 +654,8 @@ O padrão é TestResults no diretório que contém o aplicativo de teste. - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - A opção 'timeout' deve ter um argumento como cadeia de caracteres no formato <value>[h|m|s] onde 'value' é float + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + A opção 'timeout' deve ter um argumento como cadeia de caracteres no formato <value>[h|m|s] onde 'value' é float diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf index 4f5c785313c..0abf840d111 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf @@ -654,8 +654,8 @@ The default is TestResults in the directory that contains the test application.< - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - Параметр "timeout" должен иметь один аргумент в виде строки в формате <value>[h|m|s], где "value" — число с плавающей точкой + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + Параметр "timeout" должен иметь один аргумент в виде строки в формате <value>[h|m|s], где "value" — число с плавающей точкой diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf index 906259438c5..4e771ba79a3 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf @@ -654,8 +654,8 @@ Varsayılan değer, test uygulamasını içeren dizindeki TestResults'dır. - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - 'timeout' seçeneği, 'value' değerinin kayan olduğu <value>[h|m|s] biçiminde dize olarak bir bağımsız değişkene sahip olmalıdır + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + 'timeout' seçeneği, 'value' değerinin kayan olduğu <value>[h|m|s] biçiminde dize olarak bir bağımsız değişkene sahip olmalıdır diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf index 41afc5ebc9c..41c25dc363f 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf @@ -654,8 +654,8 @@ The default is TestResults in the directory that contains the test application.< - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - "timeout" 选项应有一个字符串形式的参数,格式为 <value>[h|m|s],其中 "value" 为浮点型 + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + "timeout" 选项应有一个字符串形式的参数,格式为 <value>[h|m|s],其中 "value" 为浮点型 diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf index b179a83eaba..aa8ce1eb1ff 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf @@ -654,8 +654,8 @@ The default is TestResults in the directory that contains the test application.< - 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is float - 'timeout' 選項應該有一個引數作為字串,格式為 <value>[h|m|s],其中 'value' 為 float + 'timeout' option should have one argument as string in the format <value>[h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration + 'timeout' 選項應該有一個引數作為字串,格式為 <value>[h|m|s],其中 'value' 為 float diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TimeoutTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TimeoutTests.cs index 5f59c7e7dbf..df34df2327f 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TimeoutTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TimeoutTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.Testing.Platform.Acceptance.IntegrationTests; @@ -18,7 +18,7 @@ public async Task TimeoutWithInvalidArg_WithoutLetterSuffix_OutputInvalidMessage TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5", cancellationToken: TestContext.CancellationToken); testHostResult.AssertExitCodeIs(ExitCode.InvalidCommandLine); - testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); + testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration"); } [TestMethod] @@ -29,7 +29,7 @@ public async Task TimeoutWithInvalidArg_WithInvalidLetterSuffix_OutputInvalidMes TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5y", cancellationToken: TestContext.CancellationToken); testHostResult.AssertExitCodeIs(ExitCode.InvalidCommandLine); - testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); + testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration"); } [TestMethod] @@ -40,7 +40,7 @@ public async Task TimeoutWithInvalidArg_WithInvalidFormat_OutputInvalidMessage(s TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5h6m", cancellationToken: TestContext.CancellationToken); testHostResult.AssertExitCodeIs(ExitCode.InvalidCommandLine); - testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); + testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration"); } [TestMethod] diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs index 075bcc4f2e2..b06970c7bf8 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; @@ -14,7 +14,7 @@ public async Task TimeoutWithInvalidArg_WithoutLetterSuffix_OutputInvalidMessage TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5", cancellationToken: TestContext.CancellationToken); testHostResult.AssertExitCodeIs(ExitCode.InvalidCommandLine); - testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); + testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration"); } [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] @@ -25,7 +25,7 @@ public async Task TimeoutWithInvalidArg_WithInvalidLetterSuffix_OutputInvalidMes TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5y", cancellationToken: TestContext.CancellationToken); testHostResult.AssertExitCodeIs(ExitCode.InvalidCommandLine); - testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); + testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration"); } [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] @@ -36,7 +36,7 @@ public async Task TimeoutWithInvalidArg_WithInvalidFormat_OutputInvalidMessage(s TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5h6m", cancellationToken: TestContext.CancellationToken); testHostResult.AssertExitCodeIs(ExitCode.InvalidCommandLine); - testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); + testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration"); } [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] @@ -47,7 +47,7 @@ public async Task TimeoutWithInvalidArg_WithNegativeValue_OutputInvalidMessage(s TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout -1s", cancellationToken: TestContext.CancellationToken); testHostResult.AssertExitCodeIs(ExitCode.InvalidCommandLine); - testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); + testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration"); } [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs index a902d0d2aea..77627040905 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs @@ -283,8 +283,8 @@ public async Task IsValid_If_Timeout_Has_CorrectFormat_InvariantCulture(string t [DataRow("invalid")] [DataRow("1.5")] // Missing unit [DataRow("abc.5s")] - [DataRow("-1s")] - [DataRow("-0.5m")] + [DataRow("")] // Empty value + [DataRow("s")] // Missing numeric value public async Task IsInvalid_If_Timeout_Has_IncorrectFormat(string timeout) { var provider = new PlatformCommandLineProvider(); @@ -295,6 +295,23 @@ public async Task IsInvalid_If_Timeout_Has_IncorrectFormat(string timeout) Assert.AreEqual(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage, validateOptionsResult.ErrorMessage); } + [TestMethod] + [DataRow("-1s")] // Negative + [DataRow("-0.5m")] // Negative fractional + [DataRow("NaNs")] // Not a number + [DataRow("Infinitys")] // Positive infinity + [DataRow("-Infinitys")] // Negative infinity + [DataRow("1e30h")] // Overflows TimeSpan + public async Task IsInvalid_If_Timeout_Has_NonFiniteOrOutOfRangeValue(string timeout) + { + var provider = new PlatformCommandLineProvider(); + CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == PlatformCommandLineProvider.TimeoutOptionKey); + + ValidationResult validateOptionsResult = await provider.ValidateOptionArgumentsAsync(option, [timeout]); + Assert.IsFalse(validateOptionsResult.IsValid); + Assert.AreEqual(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage, validateOptionsResult.ErrorMessage); + } + [TestMethod] public async Task Timeout_Parsing_Uses_InvariantCulture_NotCurrentCulture() { From 209b64df0c5ab511628bb71de943d665f492d7ae Mon Sep 17 00:00:00 2001 From: Amaury Leveugle <11340282+Evangelink@users.noreply.github.com> Date: Sat, 23 May 2026 17:13:13 +0200 Subject: [PATCH 5/5] Use '=' delimiter so negative timeout isn't parsed as an option '--timeout -1s' was being parsed as the unknown option '--1s' because the CLI parser strips leading dashes from any token that starts with a hyphen. Pass the negative value with the '=' delimiter so the validator can actually reject it. Addresses CI failure on PR #8496. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../TimeoutTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs index b06970c7bf8..8321283851c 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs @@ -44,7 +44,8 @@ public async Task TimeoutWithInvalidArg_WithInvalidFormat_OutputInvalidMessage(s public async Task TimeoutWithInvalidArg_WithNegativeValue_OutputInvalidMessage(string tfm) { var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); - TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout -1s", cancellationToken: TestContext.CancellationToken); + // Use the '=' delimiter so the negative value is not parsed as a short option. + TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout=-1s", cancellationToken: TestContext.CancellationToken); testHostResult.AssertExitCodeIs(ExitCode.InvalidCommandLine); testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is a finite, non-negative number that does not exceed the maximum supported duration");