Files
PowerToys/.github/skills/ui-tests-local-vm/templates/vm/Stop-LocalVm.ps1
Gleb Khmyznikov d0c27dd512 [UITests] Add UITest.Next suites (Image Resizer, Peek, File Explorer add‑ons, File Locksmith) + local‑VM tooling and CI test‑signing (#49671)
## Summary

Adds end‑to‑end UI tests on the `Microsoft.PowerToys.UITest.Next`
(winappcli) framework for three
modules, grows the shared `.Next` test framework with the helpers those
suites needed, and adds the
CI plumbing that lets shell‑extension tests exercise the **real**
Windows 11 modern context menu.
Also ships two agent skills that document how to write and run these
tests.

Product runtime behavior is **unchanged** — the only product edits are
test‑observability hooks in Peek
and a unit‑test project exclude.

Closes: https://github.com/microsoft/PowerToys/issues/40660
https://github.com/microsoft/PowerToys/issues/49424
https://github.com/microsoft/PowerToys/issues/40661

## What's added

### New UI test suites
- **Image Resizer** —
`src/modules/imageresizer/tests/ImageResizer.UITests`: context‑menu
enable/disable
tracking, the resize dialog, custom presets, every fit mode, every unit,
filename format, keep‑date,
  shrink‑only, replace‑in‑place, and orientation.
- **Peek** — `src/modules/peek/Peek.UITests.Next`: file‑preview coverage
across image/text/archive/
  markdown types with per‑arch visual baselines.
- **File Explorer add‑ons** —
`src/modules/previewpane/PreviewPane.UITests`: Preview Pane handlers and
  thumbnail providers.

### `UITestAutomation.Next` framework
- New helpers: `ExplorerShell` (Shell selection/view‑mode interop),
`WaitHelper` (structured stable
waits), `WindowControl` (foreground/context‑menu/process control),
`VisualAssert` (image compare),
  `WindowHelper`.
- Updates to `Session`, `UITestBase`, `SettingsConfigHelper`,
`WinappCli`.
- New `UITestAutomation.Next.UnitTests` project covering the new
wait/settings/CLI helpers.

### CI — sign sparse MSIX so the modern menu registers
- **`.pipelines/signSparsePackages.ps1`** — self‑signs each sparse
context‑menu MSIX with a
publisher‑matching test certificate and force‑trusts it (machine
stores), so
`AddPackageByUriAsync` succeeds on otherwise‑unsigned PR builds. Robust
`signtool` discovery with a
  NuGet fallback; test‑only trust that asserts no security.
- Wired into **`.pipelines/v2/templates/job-test-project.yml`** as a
best‑effort step covering the
run‑in‑place, machine‑install, and per‑user‑install locations. Signs
nothing it can't (skips
  already‑signed packages) and never fails the job.

### Product changes (test observability only)
- **Peek `FilePreview.xaml` / `.xaml.cs`** — a named `LoadingIndicator`
and a hidden automation peer
that exposes the current preview state as text, so tests can read load
state deterministically. No
  runtime behavior change.
- **`ImageResizer.UnitTests.csproj`** — exclude the sibling
`ImageResizer.UITests\**` folder from the
  unit‑test compilation.

### Agent skills & docs
- **New `ui-tests-local-vm` skill** — run `.Next` suites in persistent
dockur/windows VMs: setup,
agentic loop, image customization, troubleshooting, the shell‑extension
**signing** reference, plus
  controller/guest scripts and VM templates.
- **Updated `ui-tests-migration` skill** — WinAppDriver/Selenium →
`.Next` porting guidance
(CI stability, Explorer/shell‑extension test design, patterns &
pitfalls).
- **`doc/devdocs/development/ui-tests.md`** — updated for the `.Next`
workflow.

## Testing
- All three suites pass locally and in CI across **x64 Win10**, **x64
Win11**, and **arm64** (machine
  and per‑user install legs).

## Reviewer notes
- No product runtime behavior changes; product edits are limited to the
Peek test hooks above.
- The CI signing step is a **test‑only** trust anchor (self‑signed,
scoped to the agent) and is
best‑effort, so it can only add modern‑menu coverage and never regress
the job.
2026-08-11 12:07:52 +08:00

85 lines
2.8 KiB
PowerShell

# Copyright (c) Microsoft Corporation
# The Microsoft Corporation licenses this file to you under the MIT license.
# See the LICENSE file in the project root for more information.
<#
.SYNOPSIS
Stops the persistent Hyper-V UI-test guest while preserving its disk and checkpoints.
.EXAMPLE
pwsh ./Stop-LocalVm.ps1
#>
[CmdletBinding()]
param(
[string]$ConfigPath = (Join-Path $PSScriptRoot 'vm.config.psd1'),
[string]$CredentialPath = (Join-Path $env:LOCALAPPDATA 'PowerToysUiTestVm\admin.credential.xml'),
# Saves the running state instead of shutting the guest down, so the next start resumes instantly.
[switch]$Save,
[switch]$TurnOff
)
$ErrorActionPreference = 'Stop'
if (-not (Test-Path $ConfigPath -PathType Leaf)) {
throw "Configuration was not found: $ConfigPath"
}
$configuration = Import-PowerShellDataFile $ConfigPath
try {
Import-Module Hyper-V -ErrorAction Stop
Get-VMHost -ErrorAction Stop | Out-Null
}
catch {
throw 'BLOCKED: Hyper-V is not accessible from this shell. Run from an elevated PowerShell 7 terminal, or add this account to the local "Hyper-V Administrators" group.'
}
$vm = Get-VM -Name $configuration.VmName -ErrorAction SilentlyContinue
if ($null -eq $vm) {
throw "Virtual machine '$($configuration.VmName)' does not exist."
}
if ($vm.State -eq 'Running') {
if (-not $Save -and -not $TurnOff) {
if (-not (Test-Path $CredentialPath -PathType Leaf)) {
throw "DPAPI credential file was not found: $CredentialPath"
}
$credential = Import-Clixml $CredentialPath
$session = New-PSSession -VMName $vm.Name -Credential $credential
try {
# Validate the protected guest-local credential; repair it only when it no longer authenticates.
$autoLogonScript = Join-Path $PSScriptRoot 'oem\Set-UiTestAutoLogon.ps1'
if (-not (Test-Path $autoLogonScript -PathType Leaf)) {
$autoLogonScript = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\oem\Set-UiTestAutoLogon.ps1'))
}
if (-not (Test-Path $autoLogonScript -PathType Leaf)) {
throw "Auto-logon persistence helper was not found: $autoLogonScript"
}
Invoke-Command `
-Session $session `
-FilePath $autoLogonScript `
-ArgumentList ([string]$configuration.StandardUser) | Out-Null
}
finally {
Remove-PSSession $session -ErrorAction SilentlyContinue
}
}
if ($Save) {
Save-VM -Name $vm.Name
}
elseif ($TurnOff) {
Stop-VM -Name $vm.Name -TurnOff -Force
}
else {
Stop-VM -Name $vm.Name -Force
}
}
$vm = Get-VM -Name $configuration.VmName
[pscustomobject]@{
VmName = $vm.Name
State = [string]$vm.State
} | ConvertTo-Json