Skip to content

Support testing unpackaged WinUI apps under Microsoft.Testing.Platform - #10330

Merged
Amaury Levé (Evangelink) merged 15 commits into
mainfrom
dev/amauryleve/fuzzy-train
Jul 30, 2026
Merged

Amaury Levé (Evangelink) merged 15 commits into
mainfrom
dev/amauryleve/fuzzy-train

Conversation

@Evangelink

@Evangelink Amaury Levé (Evangelink) commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Addresses the unpackaged half of #2784 for Microsoft.Testing.Platform (MTP). VSTest is explicitly out of scope — see "Scope" below.

Why

Two separate things stood between an unpackaged WinUI app and a working test run under MTP.

1. The PackagedApp launcher was always on. PackagedAppTestHostLauncher.IsEnabledAsync() returned OperatingSystem.IsWindows() unconditionally, and TestHostControllersManager sets requireProcessRestart = true whenever any launcher is enabled. So merely referencing Microsoft.Testing.Extensions.PackagedApp — directly, or transitively through a shared Directory.Packages.props — forced an unpackaged app onto the out-of-process controller model and copied its entire build output into %TEMP%\MTPPackagedAppDeployment\<guid> on every run. That is the right trade for a packaged (MSIX) app, which genuinely cannot be started in place, and pure overhead for an app that just needs Process.Start.

2. UITestMethodAttribute could hang the whole run. InitializeApplication had an empty catch { }, so a failure while bringing the application up left the TaskCompletionSource incomplete and tsc.Task.Wait() blocked forever, with no diagnostic at all. That is exactly what an unpackaged app hits when the Windows App SDK runtime cannot be resolved (COMException / REGDB_E_CLASSNOTREG).

What changed

The launcher now decides per layout

Situation Enabled?
Not Windows no
Packaged layout (an AppxManifest.xml that describes this app) yes
Anything else — unpackaged WinUI, ordinary console test apps no

TESTINGPLATFORM_PACKAGEDAPP_LAUNCHER = auto (default) / always / never overrides the probe. An env var rather than a CLI option, because enablement is decided before options are read and a CLI option would surface in --help for every consumer.

How a manifest is attributed. The manifest sitting in the app's own directory is accepted without parsing, which keeps the common case and its cost unchanged. An ancestor manifest is walked up to without a depth limit, but is accepted only when one of its applications declares an executable that resolves back to the app directory — or to the requested executable on the launch path. That preserves arbitrarily deep, legal package-relative executable paths while still ensuring a stray AppxManifest.xml in a shared build root or CI staging directory cannot classify an unrelated console test app as packaged and hijack its run. Malformed or unreadable ancestor manifests are ignored rather than failing enablement, and package-relative paths that escape the layout (rooted, drive-qualified, or ..-traversing) are rejected.

The hang is fixed

Failures now propagate instead of being swallowed. That alone was not sufficient: thread dumps of a hung host showed the "UI Thread for Tests" was gone entirely — XAML tears the thread down for some native startup failures without ever raising a managed exception, so no catch can fire. The fix therefore also treats the UI thread dying as a failure, and bounds the wait with an overall timeout for the case where Application.Start blocks without invoking its callback. Additionally: startup is serialized (Application.Start can only run once per process), the statics are volatile, the reflection wrapper is unwrapped so the reported message is the real cause rather than "Exception has been thrown by the target of an invocation", and the failure is remembered so later [UITestMethod]s report the same root cause instead of a generic message.

Samples and docs

  • New samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged — WindowsPackageType=None, no Package.appxmanifest, no logo assets. This is what was asked for on the issue.
  • Both WinUI samples now assign Environment.ExitCode = await app.RunAsync(). The WinUI-generated entry point is void, so without this a test app always exits 0 and failing tests never fail the build. Verified: exit code is now 9 instead of 0 on a failing run.
  • New docs/winui-testing.md: packaged vs unpackaged, self-hosted vs WinUITestTarget wiring (using WinUITestTarget in a self-hosted app starts a second application), how the Windows App SDK bootstrapper is initialized, and the known MrtCore PRI257/PRI263 warning.

Scope

VSTest is not addressed. Its UwpTestHostRuntimeProvider unconditionally reads an AppxManifest.xml from the build output and throws FileNotFoundException when there is none — that provider ships in Visual Studio, not in this repository. Under MTP the WinUI app is the test host, so no appx provider is involved.

Verification

Suite Result
WinUI acceptance (2 new) 3/3
PackagedApp acceptance 7/7
Microsoft.Testing.Extensions.UnitTests 822
TestFramework.UnitTests 1490
Help/info acceptance 30/30
Unpackaged sample, run directly 3/3, exit 0

Beyond the suites passing, the behaviour claims were proven directly rather than asserted:

  • The hang is real and the test catches it. With the fix reverted the test host hung until a 5-minute timeout killed it; with the fix it completes in ~0.5s reporting the actual exception. The new acceptance test is bounded by an explicit timeout so a regression fails CI instead of stalling it.
  • The launcher no longer costs unpackaged apps anything. PackagedAppDeployment_WithNonPackagedLayoutAndNoOptIn_RunsInPlace asserts the app runs from its own output directory; the timing is the tell — 1.98s in place vs 8.5s for the deploy path.
  • The manifest-attribution regression test earns its keep. IsEnabledAsync_WithTrailingSeparatorOnAppDirectory_IsEnabled fails without the accompanying normalization fix.

The new acceptance tests build real Microsoft.WindowsAppSDK apps with dotnet build, so they run on every Windows CI leg rather than being skipped.

Notes for reviewers

  • No public API added; the new internal members are tracked in InternalAPI.Unshipped.txt. No CLI options added, so no --help/--info expectations changed (the 30 help/info acceptance tests confirm this).
  • Resource strings were edited in .resx and the .xlf files regenerated with /t:UpdateXlf.
  • PackagedAppDeploymentTests gained [DoNotParallelize]: it now has two methods sharing one generated asset, and one of them deploys that directory while the other writes into it.
  • The MrtCore PRI warning cannot be silenced with NoWarn or MSBuildWarningsAsMessages (the PRI… code is in the message text, not the MSBuild warning code), so the asset build opts out of -warnaserror; this is documented for users too.

Addresses the unpackaged half of #2784 for Microsoft.Testing.Platform.

Make the PackagedApp launcher layout-aware. Its ITestHostLauncher was
enabled for every Windows run, and an enabled launcher forces the platform
onto the out-of-process test host controller model and copies the whole
build output into a temp deployment directory. That is right for a packaged
(MSIX) app, which cannot be started in place, but pure overhead for an
unpackaged one. It now enables only when the layout really is packaged, so
referencing the package from an unpackaged app costs nothing.
TESTINGPLATFORM_PACKAGEDAPP_LAUNCHER (auto|always|never) overrides the
probe, and the manifest search is bounded so an unrelated ancestor manifest
cannot misclassify an app.

Fix a deadlock in UITestMethodAttribute. An empty catch swallowed failures
while bringing the application up, leaving the TaskCompletionSource
incomplete so the blocking wait never returned: the run hung forever with
no diagnostic. This is what an unpackaged app hits when the Windows App SDK
runtime cannot be resolved. Failures now propagate, the UI thread dying
counts as a failure (XAML tears that thread down for some native failures
without any managed exception), an overall timeout bounds the wait, and the
reflection wrapper is unwrapped so the reported message is the real cause.
Startup is serialized, since Application.Start can only run once per
process, and the failure is remembered so later tests report the same cause.

Add an unpackaged sample and end-to-end acceptance tests that build real
Windows App SDK apps, plus docs covering packaged versus unpackaged, the
self-hosted versus WinUITestTarget wiring, and how the bootstrapper is
initialized.

Also publish the run's exit code from the samples: the WinUI-generated
entry point is void, so without assigning Environment.ExitCode a test app
always exits 0 and failing tests never fail the build.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
Copilot AI review requested due to automatic review settings July 29, 2026 18:06

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

Adds MTP support for unpackaged WinUI test apps while preserving packaged MSIX activation.

Changes:

  • Enables the PackagedApp launcher only for detected packaged layouts or explicit opt-in.
  • Bounds and reports WinUI application startup failures.
  • Adds acceptance coverage, an unpackaged sample, localization resources, and documentation.
Show a summary per file
File Description
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/PackagedAppTestHostLauncherTests.cs Tests launcher detection and overrides.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WinUITests.cs Marks the lightweight fixture unpackaged.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/UnpackagedWinUITests.cs Adds unpackaged WinUI acceptance coverage.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/PackagedAppDeploymentTests.cs Tests opt-in deployment and in-place execution.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.zh-Hant.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.zh-Hans.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.tr.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ru.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.pt-BR.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.pl.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ko.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ja.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.it.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.fr.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.es.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.de.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.cs.xlf Adds startup diagnostics localization entries.
src/TestFramework/TestFramework.Extensions/Resources/FrameworkExtensionsMessages.resx Defines WinUI startup failure messages.
src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs Serializes and bounds WinUI initialization.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/TestingPlatformBuilderHook.cs Updates launcher registration documentation.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.zh-Hant.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.zh-Hans.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.tr.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.ru.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.pt-BR.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.pl.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.ko.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.ja.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.it.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.fr.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.es.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.de.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.cs.xlf Updates localized extension description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/ExtensionResources.resx Documents conditional launcher behavior.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/PackagedAppTestHostLauncher.cs Implements layout-aware launcher enablement.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/PackagedAppExtensions.cs Documents automatic and override behavior.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/PACKAGE.md Updates package usage guidance.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Microsoft.Testing.Extensions.PackagedApp.csproj Updates NuGet package description.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/InternalAPI/InternalAPI.Unshipped.txt Tracks new internal APIs.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs Bounds ancestor manifest discovery.
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/UnitTests.cs Demonstrates plain and UI tests.
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/UnitTestAppWindow.xaml.cs Defines the sample window.
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/UnitTestAppWindow.xaml Defines the sample window UI.
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/UnitTestApp.xaml.cs Self-hosts MTP in WinUI.
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/UnitTestApp.xaml Defines sample application resources.
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/Properties/launchSettings.json Adds unpackaged launch profile.
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged.csproj Configures the unpackaged sample.
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/app.manifest Declares desktop process compatibility.
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged.slnx Adds the sample solution.
samples/public/mstest-runner/MSTestRunnerWinUI/MSTestRunnerWinUI/UnitTestApp.xaml.cs Propagates packaged sample exit codes.
samples/public/mstest-runner/MSTestRunnerWinUI/MSTestRunnerWinUI/MSTestRunnerWinUI.csproj Clarifies packaged activation behavior.
docs/winui-testing.md Adds comprehensive WinUI testing guidance.
docs/README.md Links the new guide.
docs/glossary.md Updates the PackagedApp definition.

Review details

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

@github-actions

This comment has been minimized.

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

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 59.3 AIC · ⌖ 4.33 AIC · ⊞ 11.8K · ◷

@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) July 29, 2026 18:40
@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jul 29, 2026
The sample's first test asserted `0 == 0`, which no production change can
ever break and which needed an MSTEST0032 suppression. Assert the property
that actually defines this sample instead: the app runs with no MSIX
package identity, so `Package.Current` throws.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
Copilot AI review requested due to automatic review settings July 29, 2026 18:46

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.

Review details

Comments suppressed due to low confidence (3)

src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:107

  • The fixed two-level cap rejects valid packaged layouts whose Application/@Executable is nested more deeply (the manifest schema permits arbitrary relative subdirectories up to its path-length limit). In auto mode that makes IsEnabledAsync return false, so MTP falls back to Process.Start for an MSIX app that cannot be started that way. Please preserve support for all valid executable paths; if false-positive manifests are the concern, validate that a candidate manifest declares the current executable instead of assuming a maximum depth.
        for (int depth = 0; directory is not null && depth <= MaxManifestSearchDepth; directory = directory.Parent, depth++)

docs/winui-testing.md:110

  • Directory.Packages.props centralizes package versions but does not add a package reference, so a project cannot reference this extension “transitively” through that file. Remove this example or name a shared Directory.Build.props that actually contributes the PackageReference.
So an **unpackaged** WinUI app that references `Microsoft.Testing.Extensions.PackagedApp` (directly, or transitively through a shared `Directory.Packages.props`) pays nothing for it: no extra process, and no copy of the build output into a deployment directory.

docs/winui-testing.md:10

  • This statement is incorrect for the packaged flavor: MTP still needs Microsoft.Testing.Extensions.PackagedApp to register and AUMID-activate the app, as this guide explains later. Qualify the no-deployment/no-activation claim as unpackaged-only so readers do not omit the required packaged-app launcher.

This issue also appears on line 110 of the same file.

Both flavors are supported when you run on [Microsoft.Testing.Platform](https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-intro) (MTP), which you enable with `<EnableMSTestRunner>true</EnableMSTestRunner>`. Under MTP the WinUI app **is** the test host: it hosts the platform in-process, so no external test host provider has to deploy or activate anything.
  • Files reviewed: 54/54 changed files
  • Comments generated: 0 new
  • 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.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 69.4 AIC · ⌖ 4.08 AIC · ⊞ 11.8K · ◷

The bounded upward search for AppxManifest.xml traded one problem for
another: it stopped a stray manifest in a shared build root from
misclassifying an unrelated test app, but it also misclassified a valid
packaged layout whose Application/@eXecutable is nested deeper than the
cap. In that case the launcher stayed disabled in auto mode, and even the
explicit `always` opt-in could not recover because the launch path shared
the same bounded lookup and treated the layout as loose.

Replace the cap with attribution. The manifest sitting in the app's own
directory is still accepted without parsing, which keeps the common case
and its cost unchanged. An ancestor manifest is now accepted only when one
of its applications declares an executable that resolves back to the app
directory (or, on the launch path, to the requested executable), so a
manifest that has nothing to do with this app no longer enables the
launcher no matter where it sits. Malformed or unreadable ancestor
manifests are ignored rather than failing enablement, and package-relative
executable paths that escape the layout are rejected.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
Copilot AI review requested due to automatic review settings July 29, 2026 19:09
The unrecognized-mode test expected false against a loose layout, which is
the same result the loose-layout baseline already produces, so a change
that short-circuited any unknown mode straight to disabled would have gone
unnoticed. Assert the packaged layout instead, which only returns true if
the probe really ran, and keep the loose-layout case as its own test so
both directions stay covered.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057

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.

Review details

Comments suppressed due to low confidence (2)

src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:117

  • The PR description still says this search is bounded by MaxManifestSearchDepth = 2, but the current implementation deliberately walks to the root and attributes ancestor manifests by executable path. Please update the description so reviewers and release notes reflect the implemented design and the resolution of the prior depth-limit feedback.
        while (directory is not null)

src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:113

  • The default launcher passes AppContext.BaseDirectory, which has a trailing directory separator. Path.GetFullPath preserves that separator, but Path.GetDirectoryName(applicationExecutablePath) at line 164 does not, so a valid ancestor manifest is never attributed to a deeply nested app during enablement. Normalize the ending separator here (and cover a trailing-separator input) so the production path behaves like the current tests' separator-free paths.
        string fullStartDirectory = Path.GetFullPath(startDirectory);
  • Files reviewed: 55/55 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

Copilot AI review requested due to automatic review settings July 29, 2026 19:16

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.

Review details

Comments suppressed due to low confidence (7)

docs/winui-testing.md:107

  • The table currently implies that any ancestor AppxManifest.xml enables the launcher. The implementation deliberately rejects an ancestor unless an Application/@Executable resolves to this app directory (and ignores malformed or unattributable manifests), so document that condition to avoid misleading users whose manifest omits Executable.
| Packaged layout (`AppxManifest.xml` found at or above the app directory) | yes | The layout is registered and activated by AUMID. |

samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/app.manifest:13

  • This blank line contains trailing spaces, which violates the repository-wide trim_trailing_whitespace = true rule in .editorconfig:9.
    docs/winui-testing.md:10
  • This says neither flavor needs activation, but the packaged path documented below explicitly requires Microsoft.Testing.Extensions.PackagedApp to register and activate the app by AUMID. Clarify that only unpackaged apps start directly; packaged apps still self-host MTP after the launcher activates them.

This issue also appears on line 107 of the same file.

Both flavors are supported when you run on [Microsoft.Testing.Platform](https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-intro) (MTP), which you enable with `<EnableMSTestRunner>true</EnableMSTestRunner>`. Under MTP the WinUI app **is** the test host: it hosts the platform in-process, so no external test host provider has to deploy or activate anything.

src/Platform/Microsoft.Testing.Extensions.PackagedApp/PACKAGE.md:20

  • This table implies that any ancestor AppxManifest.xml enables the launcher, but the implementation only accepts an ancestor whose Application/@Executable resolves to the app directory. State that attribution requirement so package consumers are not told that ancestor manifests without Executable are auto-detected.
| Packaged layout (`AppxManifest.xml` at or above the app directory) | yes |

src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:117

  • The PR description still says the ancestor search is bounded by MaxManifestSearchDepth = 2, but this implementation now walks to the root and filters candidates by executable attribution. Update the PR description so reviewers and release notes do not document a limit that no longer exists.
        while (directory is not null)

samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/app.manifest:7

  • This new line has trailing whitespace, which violates the repository-wide trim_trailing_whitespace = true rule in .editorconfig:9.

This issue also appears on line 13 of the same file.

      <!-- The ID below informs the system that this application is compatible with OS features first introduced in Windows 10. 

docs/glossary.md:378

  • “At or above” is broader than the implemented auto-detection: an ancestor manifest is accepted only when an Application/@Executable resolves to this app directory. Document that condition here as well, especially because ancestor manifests without Executable are intentionally ignored.
An experimental MTP extension (`Microsoft.Testing.Extensions.PackagedApp`, `[Experimental("TPEXP")]`, ships as `1.0.0-alpha`) that enables testing packaged Windows apps (full-trust MSIX desktop, e.g. packaged WinUI) by registering the layout with the `PackageManager` and activating it by AUMID through the [ITestHostLauncher](#itesthostlauncher) extension point, rather than a plain `Process.Start`. Register via `builder.AddPackagedAppDeployment()`, or simply by referencing the package (its MSBuild props register the hook). The launcher only enables itself when the test application is a packaged layout — an `AppxManifest.xml` at or above the app directory — so referencing it from an **unpackaged** app does not force the test host controller process model or copy the build output; `TESTINGPLATFORM_PACKAGEDAPP_LAUNCHER` (`auto`/`always`/`never`) overrides that decision. Introduced in [PR #9454](https://github.com/microsoft/testfx/pull/9454); AUMID activation added in [PR #9970](https://github.com/microsoft/testfx/pull/9970). See also [ITestHostLauncher](#itesthostlauncher) and [docs/winui-testing.md](winui-testing.md).
  • Files reviewed: 55/55 changed files
  • Comments generated: 2
  • Review effort level: Medium

The launcher passes AppContext.BaseDirectory, which ends with a directory
separator, while Path.GetDirectoryName never returns one. Comparing the two
unnormalized meant the equality check could not match, so a valid ancestor
manifest was never attributed during enablement and a deeply nested
packaged layout stayed unrecognized in production.

The existing tests missed it because they build their paths with
Path.Combine and so never carry a trailing separator. Normalize both sides
of the comparison and add a regression test that passes a trailing
separator the way the launcher does; that test fails without this change.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
Copilot AI review requested due to automatic review settings July 29, 2026 19:27

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.

Review details

Comments suppressed due to low confidence (2)

src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:169

  • When the manifest declares a different executable in the same directory as the requested host, the exact-path overload still accepts it via this directory fallback. LaunchTestHostAsync then treats the layout as packaged, and a single-application manifest is resolved without checking the filename, so the launcher can activate the wrong AUMID. Use directory matching only for the directory-only enablement probe; when executablePath is supplied, require an exact resolved-path match.
            if (executablePath is not null
                && string.Equals(applicationExecutablePath, executablePath, StringComparison.OrdinalIgnoreCase))
            {
                return true;
            }

            string? applicationDirectory = Path.GetDirectoryName(applicationExecutablePath);
            if (applicationDirectory is not null
                && string.Equals(NormalizeDirectory(applicationDirectory), appDirectory, StringComparison.OrdinalIgnoreCase))

src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs:275

  • The new acceptance test exercises only the callback's managed-exception path (the application constructor throws). It does not execute this dead-thread fallback—the branch added for the native startup failure described by the PR—or the live-thread timeout below it, so regressions in the two mechanisms that make the fix robust would still pass CI. Add deterministic coverage by isolating/injecting the startup thread and timeout behavior, then test both “thread exits without completing initialization” and “thread remains alive without completing initialization.”
  • Files reviewed: 55/55 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

The launch path is handed the exact executable it must start, but the
ancestor-manifest check also accepted any application that merely resolved
into the same directory. A package declaring a different application beside
the requested host therefore matched, and because ResolveApplication returns
a lone application unconditionally, the launcher would have activated the
wrong Application User Model ID.

Require the full executable path to match whenever the caller supplies one.
Enablement has no launch context and so still attributes on the app
directory, which is the weakest signal that can work there.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
Copilot AI review requested due to automatic review settings July 29, 2026 19:34
@github-actions

This comment has been minimized.

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

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 80.5 AIC · ⌖ 4.31 AIC · ⊞ 11.7K · ◷

Three findings from review, all in the startup path added for issue #2784.

The timeout said Application.Start "never invoked its initialization callback",
but the wait is only completed after the callback constructs the application, so
the timeout also fires when the callback was invoked and then blocked. Saying the
callback never ran is false in that case and misdirects diagnosis, so say that
initialization did not complete instead.

The liveness and timeout guards are what keep a startup problem a test failure
rather than a hung run, yet neither was covered: the acceptance case exercises
the managed catch, and neither guard is reproducible on demand from a test host.
Separate the wait decision from the thread it observes so both branches can be
driven directly, and cover them. Verified by mutation: making each guard stop
reporting fails exactly its own test.

Also trim the trailing whitespace the sample manifest inherited from the project
template, which the repository-wide .editorconfig rule forbids.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
Copilot AI review requested due to automatic review settings July 30, 2026 10:58
@Evangelink

Copy link
Copy Markdown
Member Author

Acted on all four suppressed low-confidence findings from the latest review in c9a2277.

FrameworkExtensionsMessages.resx:133 (timeout wording) -- accepted. Correct: the wait is only completed after the callback returns from Activator.CreateInstance, so the timeout also fires when the callback was invoked and then blocked. The message now says "Application.Start was called but its initialization did not complete", which is true for both a callback that never ran and one that stalled. XLF regenerated via /t:UpdateXlf (13 files).

WinUI_UITestMethodAttribute.cs:277 (untested guards) -- accepted. Fair: the acceptance case only exercises the managed catch, and neither guard is reproducible on demand from a test host. Extracted the wait decision into WaitForApplicationStartup, which observes the UI thread through a Func<TimeSpan, bool> instead of owning it, so both branches can be driven deterministically. Added four tests in MSTestAdapter.PlatformServices.UnitTests (which already builds $(WinUiMinimum) with WIN_UI and has InternalsVisibleTo). Verified by mutation: making each guard stop reporting fails exactly its own test and nothing else.

app.manifest:7 and :13 (trailing whitespace) -- accepted. Real, and inherited from the project template. The trim_trailing_whitespace = unset override only applies to xlf,resx, so [*] governs .manifest. Both lines trimmed.

Validation: PlatformServices unit tests 975/975 on the WinUI TFM and 1039/1039 on net9.0; the two WinUI acceptance tests still pass against a real XAML application (33s), covering both the success path and the failure path through the extracted helper; sample still builds. Assertions use the resource strings rather than English fragments so they stay culture-independent.

A non-null dispatcher only showed that the control has one, not that the test
body was running on that thread, which is what the test name claims. Assert
thread access as well.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057

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.

Review details

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

Copilot AI review requested due to automatic review settings July 30, 2026 11: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.

Review details

Comments suppressed due to low confidence (3)

src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs:302

  • TestFramework.Extensions.csproj includes the per-TFM InternalAPI files as analyzer inputs (lines 101-112), but this new internal member is absent from InternalAPI/net8.0-windows10.0.18362.0/InternalAPI.Unshipped.txt. The WinUI build will therefore report RS0016. Add the generated signature for WaitForApplicationStartup<T> to that file.
    src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:379
  • A syntactically valid manifest can still contain an invalid or overlong Executable path. Path.GetFullPath then throws here, outside the parse exception handler in IsAncestorManifestForApp, so probing a malformed ancestor manifest can fail the entire run despite the documented behavior of ignoring it. Treat path-normalization failures as a non-match.
        string fullManifestDirectory = Path.GetFullPath(manifestDirectory);
        string[] pathSegments = packageRelativePath.Split(['\\', '/'], StringSplitOptions.RemoveEmptyEntries);
        string resolvedPath = Path.GetFullPath(Path.Combine([fullManifestDirectory, .. pathSegments]));
        string relativePath = Path.GetRelativePath(fullManifestDirectory, resolvedPath);

docs/winui-testing.md:71

  • This recommended async void hosting pattern only closes the window and exits after a successful run. If builder creation, build, or RunAsync throws, control never reaches these lines and the WinUI message loop can keep the process alive. Match the sample implementation by putting shutdown in finally.
    // The WinUI-generated entry point is 'void', so publish the exit code yourself.
    Environment.ExitCode = await app.RunAsync();
    _window.Close();
    Exit();
  • Files reviewed: 56/56 changed files
  • Comments generated: 0 new
  • 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.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 133.1 AIC · ⌖ 4.06 AIC · ⊞ 11.8K · ◷

The test checked only the exception type, so a message that stopped naming the
requested and declared executables would have survived it - even though naming
both is what makes the failure actionable, and the neighbouring ambiguity test
already asserts its message.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
Copilot AI review requested due to automatic review settings July 30, 2026 11:20
A non-empty string only showed that the call returned something. Parsing it as a
version shows the bootstrapper resolved an actual runtime, which is the point of
covering a Windows App SDK WinRT type from a plain test method.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
@Evangelink

Copy link
Copy Markdown
Member Author

Both grading items are addressed.

UITestMethodCreatesWinUIControlsOnTheUIThread got HasThreadAccess in 7d7ae38, so the test now asserts the body really is running on the dispatcher's thread rather than just that a dispatcher exists.

WindowsAppSdkWinRTIsUsableFromAPlainTestMethod is addressed in 0305901. I checked the actual value before changing the assertion rather than assuming the suggested pattern matched: RuntimeInfo.AsString returns 8000.921.1539.0, so ^\d+\.\d+ would indeed have matched. I asserted Version.TryParse instead, which validates the whole string rather than a prefix and states the intent directly: a parseable version shows the bootstrapper resolved a real runtime, which is what the test is there to demonstrate.

Sample rebuilt and run: 3/3 pass, exit code 0.

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.

Review details

Comments suppressed due to low confidence (2)

src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs:283

  • No test exercises the remembered-failure behavior: the acceptance asset has only one failing [UITestMethod], and the unit tests call only WaitForApplicationStartup, so removing this assignment or the later replay branch would leave every current test passing. Add a second UI test to the failing-startup asset and verify it reports WinUIApplicationInitializationAlreadyFailed while preserving the original constructor message.
    src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:378
  • The new package-relative path boundary is not covered by any regression test: the current tests exercise valid nested and mismatched paths, but none uses a rooted, drive-qualified, or ..-traversing Executable. These checks prevent an ancestor manifest from being attributed outside its layout, so a regression could re-enable the wrong launcher/AUMID path unnoticed. Add cases through FindManifestPath for each rejected form and assert the ancestor manifest is ignored.
        return relativePath == ".."
            || relativePath.StartsWith($"..{Path.DirectorySeparatorChar}", StringComparison.Ordinal)
            || relativePath.StartsWith($"..{Path.AltDirectorySeparatorChar}", StringComparison.Ordinal)
            || Path.IsPathRooted(relativePath)
            ? null
  • Files reviewed: 56/56 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

Copilot AI review requested due to automatic review settings July 30, 2026 11:25

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.

Review details

  • Files reviewed: 56/56 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test quality grade — PR #10330

GradeTestMutationNotesHow to improve
A (90–100) new UnitTest1.
AppRunsWithout
PackageIdentity
N/A ThrowsExactly verifies both throw and exact exception type; single behavior, one line. —
A (90–100) new UnitTest1.
UITestMethod
CreatesWinUI
ControlsOnThe
UIThread
N/A IsNotNull guard plus IsTrue(HasThreadAccess) directly verifies the UITestMethod thread claim. —
A (90–100) new UnitTest1.
WindowsAppSdk
WinRTIsUsable
FromAPlain
TestMethod
N/A IsNotNull plus IsTrue(Version.TryParse) guards both null and non-version returns; well-commented. —

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Re-run with
/grade-tests.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 68 AIC · ⌖ 4.22 AIC · ⊞ 11.8K · [◷]( · ◷)

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.

3 participants