Repository navigation
Reject negative timeout values during command-line validation - #8496
Merged
Amaury Levé (Evangelink) merged 5 commits intoMay 23, 2026
Merged
Conversation
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix negative duration handling in --timeout option
Reject negative timeout values during command-line validation
May 22, 2026
Amaury Levé (Evangelink)
marked this pull request as ready for review
May 22, 2026 12:50
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens --timeout command-line validation in Microsoft.Testing.Platform so invalid timeout values (notably negative durations) are rejected during validation rather than reaching CancellationTokenSource.CancelAfter and causing a startup-time exception.
Changes:
- Extend
--timeoutvalidation to reject negative, NaN, and Infinity float values. - Add unit test coverage for negative timeout arguments in
PlatformCommandLineProvidervalidation. - Add an acceptance test asserting
--timeout -1sexits withInvalidCommandLine.
Show a summary per file
| File | Description |
|---|---|
src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs |
Strengthens --timeout argument validation to reject negative and non-finite values. |
test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs |
Adds unit coverage for negative timeout arguments being invalid. |
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs |
Adds acceptance coverage for --timeout -1s returning InvalidCommandLine. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 5
- 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>
'--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>
Contributor
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (1)
src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx:630
- The
PlatformCommandLineTimeoutOptionDescriptionhelp text still says the timeout value is afloat, but validation now also rejects NaN/Infinity, negative numbers, and values that overflowTimeSpan. Consider updating the option description to match the new constraints (and then update the--help/--infoacceptance expectations that assert this description).
<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</value>
</data>
<data name="PlatformCommandLineTimeoutOptionDescription" xml:space="preserve">
<value>A global test execution timeout.
Takes one argument as string in the format <value>[h|m|s] where 'value' is float.</value>
- Files reviewed: 19/19 changed files
- Comments generated: 0 new
This was referenced May 23, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--timeoutaccepted negative durations because validation only checked format. Those values later reachedCancelAfter, causing startup failure instead of the normal invalid command-line path.PlatformCommandLineProvidervalidation.--timeout -1sreturningInvalidCommandLine.