fix: Validate max value in ProgressTask to ensure it is zero or greater - #2170
Open
Rain6435 wants to merge 1 commit into
Open
fix: Validate max value in ProgressTask to ensure it is zero or greater#2170Rain6435 wants to merge 1 commit into
Rain6435 wants to merge 1 commit into
Conversation
Author
|
@microsoft-github-policy-service agree |
Contributor
|
Thanks for your contribution! A question: Wouldn't having a max value of -1 and a min value of -10 be a valid configuration? |
Author
|
@patriksvensson Good question. In ProgressTask we don’t have a MinValue concept, only Value and MaxValue, so a configuration like max=-1/min=-10 is outside the current model. Indeterminate progress is represented explicitly via IsIndeterminate, and completion is Value >= MaxValue, which means max=-1 would mark a new task as finished immediately. That’s why this change enforces MaxValue >= 0 and keeps indeterminate behavior on the dedicated IsIndeterminate path. Also, this is intuitive way of usage of the ProgressTask. |
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.
Fixes #2167
Changes
This change puts maxValue validation in ProgressTask at the exact points where invalid values can enter task state, so the invariant is enforced centrally instead of at call sites.
Constructor guard in ProgressTask.cs:142: validates initial maxValue when a task is created. This covers all AddTask overloads because they all flow into ProgressTask construction through ProgressContext internals.
Update-path guard in ProgressTask.cs:231: validates later changes via task.MaxValue setter, which routes through Update(maxValue: ...). This prevents a task from becoming invalid after successful creation.
Regression tests in ProgressTests.cs:142 and ProgressTests.cs:167: one test verifies creation-time rejection (ctx.AddTask(..., maxValue: -1)), and one verifies mutation-time rejection (task.MaxValue = -1), so both entry points are locked down.
Putting validation in these two locations ensures consistent runtime behavior for every API path without duplicating checks across ProgressContext overloads or user call sites.
Please upvote 👍 this pull request if you are interested in it.