Repository navigation
[code-simplifier] Simplify nested ternary in CtrfReportEngine.ResolveRunId - #11836
Conversation
Replace the nested ternary expression with an explicit if/else chain for improved readability, per project guidance to avoid nested ternary operators. No behavioral change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
Review outcome: No actionable findings — this is a clean, behavior-preserving refactor.
Change classification
- Microsoft.Testing.Extensions.CtrfReport:
CtrfReportEngine.ResolveRunId()unrolls a nested ternary into an early-returnifplus an extractedexecutionIdlocal. No functional change.
Confidence at a glance
🟢 Correctness & design — verified equivalent across all branches
- Why it applies: The only change is control-flow restructuring of a private helper; must confirm no behavior drift.
- Evidence: Traced all three reachable paths against the original nested ternary: (1)
runIdnon-empty → returnsrunIdin both versions; (2)runIdempty,TESTINGPLATFORM_DOTNETTEST_EXECUTIONIDnon-empty → both returnnull; (3) both empty → both returnGuid.NewGuid().ToString("D"). The newexecutionIdlocal is read exactly once, matching the original single-evaluation semantics (no risk of the env var being read twice with a different value). - Gap or disposition: None. The method is
private, so noPublicAPI.Unshipped.txtentry is needed, and no caller contract changes. - Action: None.
⚪ Not applicable: Concurrency & lifecycle, Security & protocol, API & compatibility, Performance, Localization, Tests, Analyzers, Build/dependencies/scripts (no behavioral, API, security, performance, localization, test, analyzer, or build-file changes in this diff).
There was a problem hiding this comment.
🟢 Approval recommended
The refactor is behaviorally equivalent, covered by existing tests, and retains the required file encoding.
0 open findings
What changed in this PR
Simplifies ResolveRunId while preserving environment-variable precedence and GUID generation behavior.
Changes:
- Replaces the nested ternary with an early return and named execution ID.
- Preserves existing run ID behavior.
| File | Description |
|---|---|
CtrfReportEngine.JsonSerializer.cs |
Simplifies ResolveRunId control flow. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
Replace the nested ternary expression with an explicit if/else chain for improved readability, per project guidance to avoid nested ternary operators. No behavioral change.
Fixes #11833