Skip to content

Simplify GitHubActionsAnnotationReporter: extract testName and DisplayAnnotationLineAsync helper#9678

Merged
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/simplify-github-actions-annotation-repor
Jul 7, 2026
Merged

Simplify GitHubActionsAnnotationReporter: extract testName and DisplayAnnotationLineAsync helper#9678
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/simplify-github-actions-annotation-repor

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes #9658

Two small, purely mechanical simplifications to GitHubActionsAnnotationReporter.cs.

Improvements

  1. Eliminated duplicate GetTestName call in ConsumeAsyncGetTestName(nodeUpdateMessage.TestNode) was called in both the skipped and failure branches. It's now computed once into a testName local before the branch.

  2. Extracted shared DisplayAnnotationLineAsync helperWriteAnnotationAsync and WriteSkippedAnnotationAsync both ended with an identical _outputDisplay.DisplayAsync(this, new FormattedTextOutputDeviceData($"\n{line}"), ...) call plus a comment explaining why a leading newline is required. This is now centralized in one method (returning Task directly), consolidating the explanation in a single place. Callers still apply .ConfigureAwait(false) to the returned Task.

Testing

  • Microsoft.Testing.Extensions.GitHubActionsReport builds with 0 warnings / 0 errors across all target frameworks
  • ✅ All 8 GitHubActionsAnnotationReporterTests pass unchanged
  • No functional changes — behaviour is identical.

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

…yAnnotationLineAsync helper

Fixes #9658

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 7, 2026 04:32
@Evangelink Evangelink added the state/needs-review Awaiting review from the team. label Jul 7, 2026
@Evangelink
Evangelink enabled auto-merge (squash) July 7, 2026 04:33
@Evangelink

Copy link
Copy Markdown
Member Author

/backport to rel/4.3

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Started backporting to rel/4.3: https://github.com/microsoft/testfx/actions/runs/28841770334

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR applies two small, mechanical simplifications to GitHubActionsAnnotationReporter.cs (the MTP extension that emits GitHub Actions ::error/::warning workflow-command annotations for failing and skipped tests). It follows up on the reporter introduced in #9641 and is tracked by #9658. The observable output is unchanged.

Changes:

  • Hoists GetTestName(...) into a single testName local in ConsumeAsync instead of calling it in each branch.
  • Extracts the identical trailing _outputDisplay.DisplayAsync(..., $"\n{line}") call (plus its explanatory comment) from WriteAnnotationAsync and WriteSkippedAnnotationAsync into a shared DisplayAnnotationLineAsync helper that returns Task directly.
Show a summary per file
File Description
src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/GitHubActionsAnnotationReporter.cs Deduplicates the GetTestName call into a testName local and consolidates the shared annotation-writing logic/comment into DisplayAnnotationLineAsync.

The DisplayAnnotationLineAsync extraction is correct and semantically equivalent — the non-async method returns the DisplayAsync task directly and callers keep .ConfigureAwait(false), so no synchronization context is captured. One minor trade-off: computing testName before the early return now evaluates it for every message (including passing tests), which I flagged as an optional nit since this reporter only needs the name when it writes an annotation.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Medium

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

🤖 Automated review by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

✅ 22/22 dimensions clean — no findings.

Clean mechanical refactoring: hoisting testName eliminates a duplicate call, and DisplayAnnotationLineAsync consolidates identical display logic with an improved unified comment. The slightly broader scope of GetTestName (now called for all node states) is negligible in this CI-only reporter and safely caught by the existing try/catch.

Evangelink added a commit that referenced this pull request Jul 7, 2026
…yAnnotationLineAsync helper by @Evangelink in #9678 (backport to rel/4.3) (#9679)

Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The two GetTestName calls were in mutually exclusive branches (never a
runtime duplicate), so hoisting them evaluated the name for every message
including passing tests on the consumer hot path. Keep the calls in the
skip/failure branches; retain the DisplayAnnotationLineAsync helper.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Evangelink
Evangelink disabled auto-merge July 7, 2026 07:59
@Evangelink
Evangelink enabled auto-merge (squash) July 7, 2026 07:59
@Evangelink
Evangelink merged commit abbe33e into main Jul 7, 2026
39 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/simplify-github-actions-annotation-repor branch July 7, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[code-simplifier] simplify: extract testName variable and DisplayAnnotationLineAsync helper in GitHubActionsAnnotationReporter

3 participants