Skip to content

Fix CA1416 build failure in FileLoggerTests - #9844

Merged
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/literate-eureka
Jul 11, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/literate-eureka

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Problem

The CI build fails on all legs (Linux/macOS/Windows, Debug/Release) — as seen on the darc dependency PR #9839, but the root cause is on main. The failing step is the main Build task, which errors with:

FileLoggerTests.cs(465,16): error CA1416: This call site is reachable on all platforms.
  'ITask.RunLongRunning(Func<Task>, string, CancellationToken)' is unsupported on: 'browser'.
FileLoggerTests.cs(490,16): error CA1416: ... (same)

(CA1416 is treated as an error, which is why the build fails and no test results are produced — the subsequent "Publish Test Results" / "Copy binlogs" failures are just downstream symptoms.)

Root cause

The ITask.RunLongRunning interface member is annotated [UnsupportedOSPlatform("browser")], and so is the SystemTask implementation. The two ITask test doubles in FileLoggerTests — RecordingTask and NeverCompletingTask — implement RunLongRunning without that annotation and delegate to a real SystemTask. Their call sites into _inner.RunLongRunning(...) are therefore "reachable on all platforms" while calling a browser-unsupported API, tripping CA1416 on net8.0/net9.0.

Fix

Annotate both test-double RunLongRunning overrides with [UnsupportedOSPlatform("browser")] to match the interface member, matching the convention already used across this test project (e.g. IPCTests, TestHostBuilderTests). Only browser is used (not wasi) to avoid CA1418 on the Windows-only net462 target where wasi is not a known platform name.

Verification

Built Microsoft.Testing.Platform.UnitTests across all TFMs (net8.0, net9.0, net462) locally: 0 warnings, 0 errors.

Annotate the RunLongRunning overrides in the RecordingTask and
NeverCompletingTask test doubles with [UnsupportedOSPlatform("browser")]
to match the ITask interface member. Without it, their call sites into
SystemTask.RunLongRunning were reachable on all platforms and triggered
CA1416 (treated as error) on net8.0/net9.0, failing the build on all legs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 321a8057-828d-43c4-ae07-203293449e0a
Copilot AI review requested due to automatic review settings July 11, 2026 12:02

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 fixes a CA1416 analyzer error (treated as build-breaking) in Microsoft.Testing.Platform.UnitTests by aligning the platform support annotations on ITask.RunLongRunning test-double implementations with the underlying API they delegate to.

Changes:

  • Added [UnsupportedOSPlatform("browser")] to RecordingTask.RunLongRunning.
  • Added [UnsupportedOSPlatform("browser")] to NeverCompletingTask.RunLongRunning.
Show a summary per file
File Description
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/FileLoggerTests.cs Adds browser platform annotations to ITask test doubles’ RunLongRunning methods to prevent CA1416 at the delegate call sites.

Review details

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

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test quality grade — PR #9844

No new or modified test methods were identified in the changed regions of this PR. The only changed test file (FileLoggerTests.cs) had [UnsupportedOSPlatform("browser")] added to RunLongRunning helper methods inside private fixture classes (SynchronousTask and NeverCompletingTask) — these are infrastructure helpers, not test methods. Nothing to grade.

Re-run with /grade-tests.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · 21.7 AIC · ⌖ 6.55 AIC · ⊞ 9.5K · [◷]( · ◷)

@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.

Expert Review — PR #9844: Fix CA1416 build failure in FileLoggerTests

Summary

Clean, minimal fix. No issues found.

Correctness ✅

The [UnsupportedOSPlatform("browser")] annotation is correctly applied to both RecordingTask.RunLongRunning and NeverCompletingTask.RunLongRunning to match the ITask interface member and SystemTask implementation. This resolves the CA1416 diagnostic.

Consistency ✅

The pattern matches existing usage across the test project (IPCTests, TestHostBuilderTests, ServerTests, DotnetTestDataConsumerTests, etc.) — all use [UnsupportedOSPlatform("browser")] on method overrides that delegate to browser-unsupported APIs.

Scope ✅

Surgical two-line change, no unrelated modifications.

Design note

The PR description correctly explains why only "browser" is used (not "wasi") — adding "wasi" would trigger CA1418 on the net462 target. This is consistent with the rest of the codebase.

Verdict: Looks good. No changes requested.

@Evangelink
Amaury Levé (Evangelink) merged commit 6d11d21 into main Jul 11, 2026
28 of 35 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/literate-eureka branch July 11, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants