migrate-xunit-to-mstest: forbid CancellationToken.None replacement explicitly#758
Conversation
…plicitly The TestContext.Current.CancellationToken guidance already forbids replacing it with a fresh CancellationTokenSource, but real-world agent migrations have been observed substituting CancellationToken.None instead, which silently drops the test host's cancellation linkage. Call CancellationToken.None out explicitly so both common shortcuts are covered. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the migrate-xunit-to-mstest skill documentation to more explicitly forbid a common incorrect migration pattern where TestContext.Current.CancellationToken is replaced with CancellationToken.None, which drops the test-host cancellation linkage (similar to using a new CancellationTokenSource).
Changes:
- Expand the “REQUIRED for CancellationToken” callout to explicitly forbid
CancellationToken.Nonein addition to freshly-constructedCancellationTokenSource.
Show a summary per file
| File | Description |
|---|---|
| plugins/dotnet-test/skills/migrate-xunit-to-mstest/SKILL.md | Strengthens migration guidance to preserve cancellation behavior under timeouts by forbidding CancellationToken.None substitutions. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Per Copilot review on PR dotnet#758: the section above notes that projects pinned to MSTest < 3.6 must use property injection. Reword the CancellationToken callout to cover both constructor and property injection so the guidance stays correct in that supported scenario. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/evaluate |
Skill Validation Results
[1] Model: claude-opus-4.6 | Judge: claude-opus-4.6 🔍 Full Results - additional metrics and failure investigation steps
▶ Sessions Visualisation -- interactive replay of all evaluation sessions |
Why
The
TestContext.Current.CancellationTokenguidance inmigrate-xunit-to-mstestalready forbids replacing it with a freshly-constructedCancellationTokenSource, but real-world agent migrations have been observed substitutingCancellationToken.Noneinstead, which silently drops the test host's cancellation linkage in the same way.What
Update the REQUIRED for CancellationToken callout to call out both shortcuts explicitly:
Source
Observed during the dotnet/sdk xUnit→MSTest migration: see e.g. dotnet/sdk#54725 (BrowserRefresh.Tests) and dotnet/sdk#54731 (HotReload.Client.Tests), where the migration agent rewrote
TestContext.Current.CancellationTokenasCancellationToken.Nonein everyWriteAsync/FlushAsynccall. Restoring the original behavior required addingpublic TestContext TestContext { get; set; }to the test class and usingTestContext.CancellationToken.