Skip to content

Reject negative timeout values during command-line validation - #8496

Merged
Amaury Levé (Evangelink) merged 5 commits into
mainfrom
copilot/fix-negative-timeout-crash
May 23, 2026
Merged

Amaury Levé (Evangelink) merged 5 commits into
mainfrom
copilot/fix-negative-timeout-crash

Conversation

Copilot AI commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

--timeout accepted negative durations because validation only checked format. Those values later reached CancelAfter, causing startup failure instead of the normal invalid command-line path.

  • Validation
    • Reject negative timeout values during PlatformCommandLineProvider validation.
    • Also reject non-finite parsed values before timeout construction.
|| !float.TryParse(..., out float value)
|| float.IsNaN(value)
|| float.IsInfinity(value)
|| value < 0
  • Coverage
    • Added unit coverage for negative timeout arguments.
    • Added acceptance coverage for --timeout -1s returning InvalidCommandLine.

Copilot AI self-assigned this May 22, 2026
Copilot AI review requested due to automatic review settings May 22, 2026 12:21
Copilot AI removed the request for review from Copilot May 22, 2026 12:21
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 22, 2026 12:35
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 22, 2026 12:36
Copilot AI changed the title [WIP] Fix negative duration handling in --timeout option Reject negative timeout values during command-line validation May 22, 2026
@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review May 22, 2026 12:50
Copilot AI review requested due to automatic review settings May 22, 2026 12:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --timeout validation to reject negative, NaN, and Infinity float values.
  • Add unit test coverage for negative timeout arguments in PlatformCommandLineProvider validation.
  • Add an acceptance test asserting --timeout -1s exits with InvalidCommandLine.
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

Amaury Levé (Evangelink) and others added 2 commits May 22, 2026 17:41
- 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>
Copilot AI review requested due to automatic review settings May 23, 2026 15:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

Comments suppressed due to low confidence (1)

src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx:630

  • The PlatformCommandLineTimeoutOptionDescription help text still says the timeout value is a float, but validation now also rejects NaN/Infinity, negative numbers, and values that overflow TimeSpan. Consider updating the option description to match the new constraints (and then update the --help/--info acceptance expectations that assert this description).
    <value>'timeout' option should have one argument as string in the format &lt;value&gt;[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 &lt;value&gt;[h|m|s] where 'value' is float.</value>
  • Files reviewed: 19/19 changed files
  • Comments generated: 0 new

@Evangelink
Amaury Levé (Evangelink) merged commit d6f82b3 into main May 23, 2026
24 of 26 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the copilot/fix-negative-timeout-crash branch May 23, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MTP Core Analysis] --timeout accepts negative durations and crashes during startup

3 participants