You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Return checked values from Assert.IsNotNull - #12219
Replace both Assert.IsNotNull(object?, ...) overloads with unconstrained generic overloads that return the checked T. Preserve reference identity, input/return nullability annotations, lazy interpolated messages, telemetry, caller expressions, and soft assertion scopes. Nullable structs retain their original type; they are not unwrapped.
Intentional MSTest 5 breaking change: the old void overloads are removed, rather than retained as compatibility shims, following the issue's agreed major-release direction. Untyped C# null/default calls need an explicit type, old void delegate bindings must be adapted, and F# statement calls may need |> ignore. IsNull is unchanged.
Three scoped review passes covered API/compatibility, tests/integration, and the final revised diff. The integration pass found and reproduced an unquoted consumer-build path (MSB1008 on both target frameworks). Both language consumers now build from their explicit working directory, with spaces permanently included in their asset paths. No further code findings remained after the final pass. Current main was integrated without rewriting commits; its unrelated API removals were preserved.
Demonstration
This is a nonvisual library API change; screenshots and rendered-surface checks are not applicable. The checked expression can now be used directly:
The real packed F# console consumer checked reference identity, single evaluation, string/value/nullable-value returns, and null rejection, then printed the following deterministic output on each target framework (generated asset prefix redacted):
The equivalent .NET 11 case printed its net11.0 assembly path. The acceptance tests assert this complete output exactly and the process exit is 0. The loaded DLLs and each isolated NuGet cache were hash-checked against the freshly packed MSTest.TestFramework.5.0.0-dev.nupkg (SHA-256 25106BFD07654C9E3486BC8F514D980AA2A35892DD4F4D5F0F00D520B2B43868).
Validation and regression proof
Reviewed head:13fac566b11e8de037ece87887a83a1df5ae01c2, based on 6876cf113dce6e1db55092779e73840697a0af73. Local runs built that base plus code/test patch SHA-256 ADA786C6210A00CE218BDADFCC938C016AD38E019DF4E653EBE98A5069E482E9; the committed code was verified byte-for-byte against that tested patch. Repository-pinned SDK: 12.0.100-alpha.1.26509.101, Windows x64.
The full Windows Release build/pack passed with 0 warnings and 0 errors, including the complete package-content gate. All 61 focused cases passed, with 0 skips: 42 framework cases (14 each on .NET Framework 4.8, .NET 10, and .NET 11), 11 analyzer cases, and eight packed acceptance cases.
Executed from the repository root, with the repo-local toolchain and Windows PowerShell available to child processes (artifact paths shown repository-root relative):
Each command above exited 0. The repository execution verifier reconciled all eight planned acceptance identities with a fresh TRX. Configured TRX/JUnit reports were parsed; raw reports, binlogs, and provenance manifests remain local rather than being publicly uploaded.
Requirement / risk
Executed evidence
Typed return, identity, and single evaluation
IsNotNull_WithReferenceType_ReturnsSameInstance, IsNotNull_WithNullableTypeArgument_ReturnsNonNullableValue, both value-type cases, and IsNotNull_EvaluatesArgumentOnce.
Null rejection, lazy messages, and scoped continuation
Existing exact-message checks, IsNotNull_WithNullNullableValueType_ShouldFail, and both Scope_AssertIsNotNull_* cases.
Source/language compatibility and actual package consumption
PublicAssertCallShapes_CompileWithCSharp12 and IsNotNullCallShapes_CompileAndRunWithFSharp, each on .NET 10/.NET 11 with isolated caches and paths containing spaces.
Existing packaged F# execution
RunsNamedNestedExplicitAndCustomModulesAlongsideExistingClass, on both TFMs through MTP and VSTest; each child asserts six distinct names/outcomes.
Safe analyzer fixes for value-returning calls
All 11 selected WhenAssertIsNotNull* cases, including five value-use contexts where no invalid Assert.Fail replacement may be offered.
Unit scheduling remains sequential under TestContainer; analyzer/acceptance scheduling remained method-parallel (32 workers). No new locks or serialization were added. Linux/macOS execution and CI are not claimed by this local evidence.
Test-value evidence
A pristine old-API run cannot compile the new return-value calls, so the feature proof uses a buildable wrong-return mutation, not a compiler failure presented as red. In an isolated checkout of base 6876cf113dce6e1db55092779e73840697a0af73, retain the API and exact tests, and return default instead of non-null inputs. Retained unit/API/test patch SHA-256: 98BF6C9FD3E7316AFC73B274140B3328CFD468C6CDA22933D31EA5C59B9A3583; behavior-only mutation patch SHA-256: 08373505424D107614A964D4EC0D3DA0F27F5B51027AA46A599475D7F353A8E6.
The same /*/*/AssertTests/*IsNotNull* selector executed all 14 cases in both rebuilt states:
State
Executed result
Wrong returns, API/tests retained
8 intended value/identity assertion failures, 6 passes, 0 skips; exit 2. Example: IsNotNull_WithNonNullableValueType_ReturnsValue reported Expected result to be 42, but found 0 (difference of -42).
Correct implementation restored
14 passes, 0 failures, 0 skips; exit 0. Source/test identities were rechecked after restoration.
Both states used the repo-pinned toolchain and separate comparison outputs. The mutated package was not used for consumer/package claims; those checks used only the correct freshly packed shipping variant. The path-space MSB1008 repro was separately classified as a test-harness finding and is not counted as behavioral product red-phase evidence.
The comparison checkout and generated consumer assets were removed after retaining patch identities, reports, and provenance evidence. No maintainer approval or CI success is implied by these three local review passes.
Compared merge base 6876cf113dce6e1db55092779e73840697a0af73 with head 13fac566b11e8de037ece87887a83a1df5ae01c2. Evidence applies to this head, not every intermediate commit.
Test-value evidence
Static read-only assessment; no tests were executed here. The PR description claims a local wrong-return mutation run (8 failing, 6 passing, then 14 passing). Its records are not accessible, so it is not counted as executed evidence.
| Contract | Decisive test / assertion | Counterfactual (static prediction) | | --- | --- | --- | | Returns the original instance (all overloads) | `IsNotNull_WithReferenceType_ReturnsSameInstance`, `result.Should().BeSameAs(value)` | Returning `default` or a copy would fail. Likely killed (inferred). | | Value types, nullable struct and nullable type argument return the value | `IsNotNull_WithNonNullableValueType_ReturnsValue`, `IsNotNull_WithNullableValueType_ReturnsValue`, `IsNotNull_WithNullableTypeArgument_ReturnsNonNullableValue` (`Should().Be(...)`) | Returning `default` would fail. Likely killed (inferred). | | Argument evaluated once | `IsNotNull_EvaluatesArgumentOnce`, evaluation counts 1, 2 and 3 | Re-evaluating `value` would fail. Likely killed (inferred). | | Null still fails, including `int?` | `IsNotNull_WithNullNullableValueType_ShouldFail`, `IsNotNull_PassNull_ShouldFail` and the existing exact-message tests | Dropping the failure report would fail. Likely killed (inferred). | | Soft failure inside `AssertScope` returns null and continues, with a lazy message | `Scope_AssertIsNotNull_IsSoftFailure`, `Scope_AssertIsNotNull_InterpolatedString_IsSoftFailure` | Throwing in scope would fail. Likely killed (inferred). | | Source compatibility (C# 12) and F# consumption of the packed package | `PublicAssertCallShapes_CompileWithCSharp12`, `IsNotNullCallShapes_CompileAndRunWithFSharp` (exact output plus exit code 0) | Build and exit-code outcomes. Execution is unverified here. | | Analyzer: no `Assert.Fail` code fix when the result is used | `WhenAssertIsNotNullResultIsUsed_DiagnosticWithoutCodeFix` (5 data rows) | Offering a fix would fail the code-fix verification. Likely killed (inferred). | | Doc, public API and F# call-site edits | Not applicable (non-behavioral) | The `|> ignore` edits are covered by the F# module acceptance test. |
Evidence gap: no accessible paired red/green execution records for this exact head.
🧵 Parallel safety
Status: CLEAN, with findings Critical 0, High 0, Warning 0, Info 0.
Assembly
Scope
MSTest.Acceptance.IntegrationTests
Method-level parallelism (per repo guidance). The new F# test uses a unique TestAsset directory, a per-asset NUGET_PACKAGES path and its own DotnetMuxer. No shared mutable state.
MSTest.Analyzers.UnitTests
Stateless additions.
TestFramework.UnitTests
Stateless additions.
Coverage was read-only and no analyzers were run.
Per-test assessment
Pseudo-mutation evidence is static prediction only, not executed mutation results. No inline findings qualified for publication. Existing PR reviews: none.
<table>
<thead>
<tr><th>Result</th><th>Quality</th><th>Test</th><th>Notes</th><th>How to improve</th></tr>
</thead>
<tbody>
<tr><td>Pass</td><td>A (90–100)</td><td>new <code>AssertTests.<br>IsNotNull_<br>EvaluatesArgumentOnce</code></td><td>Verifies identity and exact evaluation count per overload.</td><td>None</td></tr>
<tr><td>Pass</td><td>A (90–100)</td><td>new <code>AssertTests.<br>IsNotNull_<br>WithReferenceType_<br>ReturnsSameInstance</code></td><td>BeSameAs covers all three overloads.</td><td>None</td></tr>
<tr><td>Pass</td><td>A (90–100)</td><td>new <code>AssertTests.<br>IsNotNull_<br>WithNullNullableValueType_<br>ShouldFail</code></td><td>Exact structured failure message asserted.</td><td>None</td></tr>
<tr><td>Pass</td><td>B (80–89)</td><td>new <code>AssertTests.<br>IsNotNull_<br>WithNullableTypeArgument_<br>ReturnsNonNullableValue</code></td><td>Value equality on a string; contract is value return.</td><td>None</td></tr>
<tr><td>Pass</td><td>B (80–89)</td><td>new <code>AssertTests.<br>IsNotNull_<br>WithNonNullableValueType_<br>ReturnsValue</code></td><td>Exact value checked across three overloads.</td><td>None</td></tr>
<tr><td>Pass</td><td>B (80–89)</td><td>new <code>AssertTests.<br>IsNotNull_<br>WithNullableValueType_<br>ReturnsValue</code></td><td>Exact value checked across three overloads.</td><td>None</td></tr>
<tr><td>Pass</td><td>A (90–100)</td><td>new <code>AssertTests.<br>Scope_<br>AssertIsNotNull_<br>InterpolatedString_<br>IsSoftFailure</code></td><td>Exact messages, null result and lazy-message use asserted.</td><td>None</td></tr>
<tr><td>Pass</td><td>A (90–100)</td><td>new <code>PreferAssertFailOverAlwaysFalseConditionsAnalyzerTests.<br>WhenAssertIsNotNullResultIsUsed_<br>DiagnosticWithoutCodeFix</code></td><td>Five value-use shapes each expect a diagnostic and no fix.</td><td>None</td></tr>
<tr><td>Pass</td><td>B (80–89)</td><td>new <code>AssertSourceCompatibilityTests.<br>IsNotNullCallShapes_<br>CompileAndRunWithFSharp</code></td><td>Real packed F# consumer with exact output and exit code.</td><td>None</td></tr>
<tr><td>Pass</td><td>B (80–89)</td><td>mod <code>AssertTests.<br>IsNotNull_<br>WhenNonNullNullableValue*</code> (3 tests)</td><td>Added BeSameAs on the returned value; the NRE-free check is retained.</td><td>None</td></tr>
<tr><td>Pass</td><td>B (80–89)</td><td>mod <code>AssertTests.<br>Scope_<br>AssertIsNotNull_<br>IsSoftFailure</code></td><td>Also asserts the result stays null after a soft failure.</td><td>None</td></tr>
<tr><td>Pass</td><td>B (80–89)</td><td>mod <code>AssertTests.<br>IsNotNull_<br>PassNull_ShouldFail</code>, <code>IsNotNull_<br>StringMessage_PassNonNull_ShouldFail</code>, <code>IsNotNull_<br>InterpolatedString_PassNonNull_ShouldFail</code>, analyzer <code>WhenAssertIsNotNull*</code></td><td>Retargeted to <code>IsNotNull(object)(null)</code>; existing exact assertions are unchanged.</td><td>None</td></tr>
<tr><td>Pass</td><td>B (80–89)</td><td>mod <code>AssertSourceCompatibilityTests.<br>PublicAssertCallShapes_<br>CompileWithCSharp12</code></td><td>New IsNotNull call shapes added to the compile-only consumer.</td><td>None</td></tr>
</tbody>
</table>
<sub>This advisory review is heuristic and non-blocking.
Re-run the combined review with /review-tests, or only the parallel-safety specialist with /parallel-audit.</sub>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The MSTEST0037 code fix discards required type arguments when generating IsNotNull calls, causing valid target-typed new() arguments to fail compilation with CS0411.
This PR makes MSTest’s Assert.IsNotNull return the checked value, enabling direct use in expressions while preserving its type, identity, and existing assertion behavior. Removing the old void overloads is an intentional MSTest 5 breaking change.
Changes:
Replace both overloads with generic, value-returning APIs and update API tracking.
Add return-value, soft-scope, analyzer, and packed C#/F# consumer coverage.
Document compatibility decisions and revision-bound validation.
Test-value evidence: For head 13fac566b11e8de037ece87887a83a1df5ae01c2, the PR reports 61 passing focused cases and a buildable wrong-return mutation detected by eight assertions. Execution artifacts were not independently inspected; no builds or tests were run during this review.
Retain explicit type arguments when the consumer has generic IsNotNull overloads, without changing the nongeneric MSTest 4 fix. Cover target-typed new, default, collection and conditional expressions, message preservation, and legacy API compatibility.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The fixer can generate Assert.IsNotNull calls that fail with CS0411 when rewriting IsTrue/IsFalse comparisons involving default or null, requiring preservation of the operand’s contextual type and regression coverage.
Preserving existing generic arguments does not cover MSTEST0037's IsTrue/IsFalse rewrites: Assert.IsFalse(default == (object)null) becomes Assert.IsNotNull(default), and Assert.IsFalse(null == null) becomes Assert.IsNotNull(null). Both generated calls now fail with CS0411 because the generic-only API cannot infer T. Preserve the extracted operand's contextual type with an explicit type argument or cast, and add simple-mode regression cases while retaining MSTest 4 compatibility.
Final test-triage resolution — Azure Pipelines build 1666049
Result: inconclusive, likely an environmental one-off. No issue created.
Affected leg:Windows Debug, task Test (unit tests only), net462 only.
Failing tests:SystemWrappersTests.Environment_ExitAndFailFastAreConfinedToOwnedChild for the "fail-fast" and "fail-fast-exception" cases.
Signature: both cases failed with System.TimeoutException: The operation has timed out. after about 30 s. The "exit" case passed.
Other legs: Linux and the other Windows TFMs show no failures for these tests.
Retries and flakiness: I found no CTRF retry metadata showing a fail-then-pass recovery for these tests, so I am not calling them flaky.
History: the bounded history from recent main builds shows these tests passing. Their historical durations range from sub-second to about 12 s, so the 30 s timeout is far outside the usual range. No prior timeouts were found in the history that was collected.
Likely cause: the tests launch child processes that call Environment.Exit or FailFast. A timeout in a child-process rendezvous on a loaded Windows agent fits the evidence better than the PR change, which is about Assert.IsNotNull return values. I did not find a code link between the two.
Crash/hang evidence: the crash-dump directory was empty and no diagnostic files were collected, so there is nothing to inspect.
Confidence: low to medium. The evidence is marked incomplete: one artifact download failed, so I cannot claim the tests are otherwise clean.
Issue threshold: not met. This is a single occurrence tied to this PR, with no recurrence across builds or commits.
Next step: re-run the Windows Debug leg. If the net462 timeout recurs on unrelated commits, it would then meet the threshold for a flaky-test issue.
🤖 Automated content by GitHub Copilot. Generated by the Pipeline Test Triage workflow. · copilot · auto · ~37 AIC · ⌖ ~1 AIC · ⊞ 10K
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
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.
Pull request
Summary
Fixes #10918.
Replace both
Assert.IsNotNull(object?, ...)overloads with unconstrained generic overloads that return the checkedT. Preserve reference identity, input/return nullability annotations, lazy interpolated messages, telemetry, caller expressions, and soft assertion scopes. Nullable structs retain their original type; they are not unwrapped.Intentional MSTest 5 breaking change: the old
voidoverloads are removed, rather than retained as compatibility shims, following the issue's agreed major-release direction. Untyped C#null/defaultcalls need an explicit type, old void delegate bindings must be adapted, and F# statement calls may need|> ignore.IsNullis unchanged.Design and decision record
Research, decisions, compatibility matrix, and revision-bound evidence.
Three scoped review passes covered API/compatibility, tests/integration, and the final revised diff. The integration pass found and reproduced an unquoted consumer-build path (
MSB1008on both target frameworks). Both language consumers now build from their explicit working directory, with spaces permanently included in their asset paths. No further code findings remained after the final pass. Currentmainwas integrated without rewriting commits; its unrelated API removals were preserved.Demonstration
This is a nonvisual library API change; screenshots and rendered-surface checks are not applicable. The checked expression can now be used directly:
The real packed F# console consumer checked reference identity, single evaluation, string/value/nullable-value returns, and null rejection, then printed the following deterministic output on each target framework (generated asset prefix redacted):
The equivalent .NET 11 case printed its
net11.0assembly path. The acceptance tests assert this complete output exactly and the process exit is 0. The loaded DLLs and each isolated NuGet cache were hash-checked against the freshly packedMSTest.TestFramework.5.0.0-dev.nupkg(SHA-25625106BFD07654C9E3486BC8F514D980AA2A35892DD4F4D5F0F00D520B2B43868).Validation and regression proof
Reviewed head:
13fac566b11e8de037ece87887a83a1df5ae01c2, based on6876cf113dce6e1db55092779e73840697a0af73. Local runs built that base plus code/test patch SHA-256ADA786C6210A00CE218BDADFCC938C016AD38E019DF4E653EBE98A5069E482E9; the committed code was verified byte-for-byte against that tested patch. Repository-pinned SDK:12.0.100-alpha.1.26509.101, Windows x64.The full Windows Release build/pack passed with 0 warnings and 0 errors, including the complete package-content gate. All 61 focused cases passed, with 0 skips: 42 framework cases (14 each on .NET Framework 4.8, .NET 10, and .NET 11), 11 analyzer cases, and eight packed acceptance cases.
Executed from the repository root, with the repo-local toolchain and Windows PowerShell available to child processes (artifact paths shown repository-root relative):
Each command above exited 0. The repository execution verifier reconciled all eight planned acceptance identities with a fresh TRX. Configured TRX/JUnit reports were parsed; raw reports, binlogs, and provenance manifests remain local rather than being publicly uploaded.
IsNotNull_WithReferenceType_ReturnsSameInstance,IsNotNull_WithNullableTypeArgument_ReturnsNonNullableValue, both value-type cases, andIsNotNull_EvaluatesArgumentOnce.IsNotNull_WithNullNullableValueType_ShouldFail, and bothScope_AssertIsNotNull_*cases.PublicAssertCallShapes_CompileWithCSharp12andIsNotNullCallShapes_CompileAndRunWithFSharp, each on .NET 10/.NET 11 with isolated caches and paths containing spaces.RunsNamedNestedExplicitAndCustomModulesAlongsideExistingClass, on both TFMs through MTP and VSTest; each child asserts six distinct names/outcomes.WhenAssertIsNotNull*cases, including five value-use contexts where no invalidAssert.Failreplacement may be offered.Unit scheduling remains sequential under
TestContainer; analyzer/acceptance scheduling remained method-parallel (32 workers). No new locks or serialization were added. Linux/macOS execution and CI are not claimed by this local evidence.Test-value evidence
A pristine old-API run cannot compile the new return-value calls, so the feature proof uses a buildable wrong-return mutation, not a compiler failure presented as red. In an isolated checkout of base
6876cf113dce6e1db55092779e73840697a0af73, retain the API and exact tests, and returndefaultinstead of non-null inputs. Retained unit/API/test patch SHA-256:98BF6C9FD3E7316AFC73B274140B3328CFD468C6CDA22933D31EA5C59B9A3583; behavior-only mutation patch SHA-256:08373505424D107614A964D4EC0D3DA0F27F5B51027AA46A599475D7F353A8E6.The same
/*/*/AssertTests/*IsNotNull*selector executed all 14 cases in both rebuilt states:IsNotNull_WithNonNullableValueType_ReturnsValuereportedExpected result to be 42, but found 0 (difference of -42).Both states used the repo-pinned toolchain and separate comparison outputs. The mutated package was not used for consumer/package claims; those checks used only the correct freshly packed shipping variant. The path-space
MSB1008repro was separately classified as a test-harness finding and is not counted as behavioral product red-phase evidence.The comparison checkout and generated consumer assets were removed after retaining patch identities, reports, and provenance evidence. No maintainer approval or CI success is implied by these three local review passes.