Skip to content

Relocate VSTest logger/sink bridges to the adapter (Phase 6e-2)#9623

Draft
Evangelink wants to merge 1 commit into
dev/amauryleve/vstest-decoupling-bridgesfrom
dev/amauryleve/vstest-decoupling-bridges2
Draft

Relocate VSTest logger/sink bridges to the adapter (Phase 6e-2)#9623
Evangelink wants to merge 1 commit into
dev/amauryleve/vstest-decoupling-bridgesfrom
dev/amauryleve/vstest-decoupling-bridges2

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Phase 6e-2 — Relocate the VSTest logger/sink bridges to the adapter

Part of the initiative to make MSTestAdapter.PlatformServices platform-agnostic by removing its dependency on the VSTest object model (Microsoft.TestPlatform.ObjectModel). VSTest coupling moves up into MSTest.TestAdapter; the platform-services engine becomes neutral.

What this does

Moves the three remaining VSTest-object-model bridge helpers out of MSTestAdapter.PlatformServices/Services/ and into MSTest.TestAdapter/Services/:

  • AdapterMessageLoggerExtensions.csIMessageLoggerIAdapterMessageLogger
  • MessageLevel.cs — the MessageLevelTestMessageLevel mapping (ToTestMessageLevel)
  • UnitTestElementSinkExtensions.csITestCaseDiscoverySinkIUnitTestElementSink

These were the last code references to Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging / ITestCaseDiscoverySink in PlatformServices. After this change, the only mentions of the VSTest logger/sink types in PlatformServices are <c>…</c> doc-comment references on the neutral interfaces (IAdapterMessageLogger, IUnitTestElementSink).

The files keep their logical namespace (…MSTestAdapter.PlatformServices), so the adapter-boundary callers (MSTestExecutor/MSTestDiscoverer/MSTestBridgedTestFramework) and the integration-test harness are source-unaffected — they already reach these via [InternalsVisibleTo].

Test-double adjustment

MSTestAdapter.PlatformServices.UnitTests calls the ToAdapterMessageLogger bridge in ~150 places (to wrap a Moq IMessageLogger when exercising the neutral MSTestSettings.GetSettings(…, IAdapterMessageLogger) surface). Now that the bridge lives in MSTest.TestAdapter, the first such call loads that module, which runs its [ModuleInitializer] (MSTestExecutor.SetPlatformLogger) and assigns PlatformServiceProvider.Instance.AdapterTraceLogger. The TestablePlatformServiceProvider double previously threw from that setter as a guard, which turned the initializer into a hard fault cascading across the suite.

Since the real PlatformServiceProvider.AdapterTraceLogger is a normal settable property, the double's setter is now a no-op (the getter still returns the mock so trace-logging verifications are unchanged). No test assigns AdapterTraceLogger directly, so this only affects tolerance of the production module initializer.

Verification

  • Full build.cmd -c Debug green across all TFMs (net462/net8.0/net9.0/UWP/WinUI).
  • MSTestAdapter.PlatformServices.UnitTests: 897 (net8.0) / 935 (net462), 0 failed.
  • MSTestAdapter.UnitTests: 21, 0 failed.
  • MSTest.IntegrationTests: 48 total, 0 failed, 1 skipped (OutputIsNotMixedWhenTestsRunInParallel, pre-existing known flaky).
  • Grep-confirmed: no VSTest ObjectModel.Logging / IMessageLogger / TestMessageLevel / ITestCaseDiscoverySink code references remain in PlatformServices (doc comments only).

Stacking

Stacked chain onto dev/amauryleve/vstest-decoupling-base:
6c2 #95906d-1 #95916d-2 #96216e-1 #96226e-2 (this).
Base for this PR is the 6e-1 branch (dev/amauryleve/vstest-decoupling-bridges). Review/merge after the predecessors reach the base. Do not rebase/reset the base.

Move the three remaining VSTest-object-model bridge helpers out of
MSTestAdapter.PlatformServices and into MSTest.TestAdapter:
AdapterMessageLoggerExtensions, MessageLevel (ToTestMessageLevel), and
UnitTestElementSinkExtensions. These are the last code references to
Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging /
ITestCaseDiscoverySink in PlatformServices; only doc comments now mention
the VSTest types. The logical namespace is unchanged so callers at the
adapter boundary and the integration harness are unaffected.

PlatformServices.UnitTests calls the ToAdapterMessageLogger bridge, which
now lives in MSTest.TestAdapter; touching that module runs its
[ModuleInitializer] (MSTestExecutor.SetPlatformLogger), which assigns
PlatformServiceProvider.Instance.AdapterTraceLogger. Make the test double's
setter tolerate the assignment (as the real PlatformServiceProvider does)
instead of throwing.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

1 participant