feat: warn when setup hooks pass the test execution token - #6883
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThis change adds TUnit0075 for setup-hook calls that pass the hook’s ChangesSetup Hook Cancellation Token Warning
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Feature Suggested reviewers: Merge Risk: ⚪ Minimal · up to The new setup-hook warning appears mergeable after normal checks. No concrete issue requiring a pre-merge change was identified. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change is limited to a narrowly scoped warning, but that warning can interrupt builds configured to reject warnings. No new runtime security exposure was identified; the evidence does not fully establish the upstream source of the hook’s timeout token. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 5 files. (2 skipped: 2 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit checks each setup call, Comment |
Review: TUnit0075 — warn on setup hooks passing the test execution tokenReviewed the analyzer implementation, docs, and tests. No prior substantive review comments exist on this PR to reconcile against (only CodeRabbit's automated "in progress" placeholder). SummaryThis is a well-scoped, correctly-implemented diagnostic. The core detection logic in
Minor gaps (not blocking, already implicitly scoped-out)
Verification
Overall: solid, narrowly-scoped analyzer addition with good test coverage and consistent doc/release-tracking updates. No blocking issues found. |
|
Review: TUnit0075 — warn on setup hooks passing the test execution tokenRe-reviewed against the previous CodeRabbit/greptile/github-actions review comments on this PR. Both previously-raised findings have since been fixed:
DesignThe core matching strategy is solid: anchoring on the Extending the existing Suggestions (non-blocking)
Verification
No blocking issues. Good, narrowly-scoped diagnostic with strong test coverage; the two suggestions above are minor polish, not correctness concerns. |
|
Thanks! |
Description
A setup hook can pass
context.Execution.CancellationTokento an awaited operation and silently bypass its own timeout. The hook's injectedCancellationTokenincludes that timeout; the test execution token does not. A runtime probe with[Timeout(100)]confirmed that the hook token is cancelled while the execution token remains uncancelled. We found this mistake in 37 setup hooks in a downstream application.Add warning TUnit0075 for the direct property chain from a
[Before(Test)]or[BeforeEvery(Test)]hook'sTestContextparameter, when passed as a cancellation argument to an operation the hook awaits or returns. The rule includesConfigureAwait, expression-bodied and conditional returns, and overrides of virtual setup hooks without repeated attributes. It also applies when the default hook timeout is used. Documentation explains which token to pass and that cancellation remains cooperative.Related Issue
Related to #4789, but does not attempt to resolve its broader timeout/lifecycle design. This PR detects a concrete incorrect-token use; it does not detach timed-out hooks, alter initialization or cleanup, or change runtime APIs.
Type of Change
Scope and compatibility
The diagnostic checks actual TUnit symbols and a
CancellationTokenparameter. It does not inspect cleanup-only methods, ordinary tests/helpers, cancellation-state reads, nested lambdas/local functions, or other contexts. It follows the actual override chain rather than matching method names, sonewmethods do not inherit a setup role. It deliberately does not follow aliases or add an automatic code fix. This introduces a new compiler warning, which will surface as an error in projects that treat all warnings as errors.This is a proposed diagnostic; there is no prior maintainer agreement on the new warning. Feedback on whether this narrow scope belongs in the existing analyzer is welcome.
Validation
Checklist
Summary by CodeRabbit