Compare commits

..

71 Commits

Author SHA1 Message Date
Copilot CLI
11d1d941e2 Fix DesktopGrass.Native.Tests source/include paths for the module layout
The test project references the app's sources and headers; upstream they sit at
../../src/DesktopGrass.Native (tests/ vs src/ layout). In the PowerToys module the
app and tests are siblings under src/modules/DesktopGrass/, so the references are
now ../DesktopGrass.Native. Verified: builds in-tree and passes all 305 Catch2 cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-09 09:09:22 -07:00
Copilot CLI
94d4d556a0 Integrate DesktopGrass.Native as a PowerToys module
- Add src/modules/DesktopGrass/DesktopGrass.Native (Win32 + Direct2D/DirectComposition,
  /MT static CRT, no external runtime dependencies) plus its Catch2 unit-test project.
- Redirect the native exe output to the repo build root (x64/Release) so the installer's
  root file sweep (generateAllFileComponents.ps1 -> BaseApplicationsComponentGroup) harvests it.
- Opt this self-contained leaf module out of the repo-wide precompiled-header default and
  CppCoreCheck-as-errors (cf. FileLocksmithCLI) so it builds within PowerToys.
- Add installer DesktopGrass.wxs (uninstall marker component group), register it in
  PowerToysInstallerVNext.wixproj and reference it from Product.wxs CoreFeature.
- Register both projects in PowerToys.slnx.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-09 05:00:13 -07:00
Niels Laute
87fa204fd6 Disable Shortcut Guide by default on clean installs (#48383)
## Summary

Flips the default for the `Shortcut Guide` entry in `enabledModules`
from `true` to `false`. New PowerToys installs (no prior
`settings.json`) will start with Shortcut Guide disabled, matching how
other newer modules (PowerToys Run, MouseJump, AdvancedPaste,
MouseWithoutBorders, CropAndLock, QuickAccent, TextExtractor,
MousePointerCrosshairs, KeyboardManager) already ship off-by-default in
`EnabledModules.cs`.

## Why

Shortcut Guide has been on-by-default since the early days, but it is an
opt-in style utility (overlay launched on hotkey). It should not be
active for users who never asked for it on a fresh install.

## Changes

- `src/settings-ui/Settings.UI.Library/EnabledModules.cs` -- flip
`shortcutGuide` backing field from `= true` to bare declaration with the
file's `// defaulting to off` comment convention.
- `src/settings-ui/Settings.UI.UnitTests/ViewModelTests/General.cs` --
update the corresponding `AllModulesAreEnabledByDefault` assertion.

## Compatibility

Existing installs are unaffected: their `settings.json` already persists
the user's prior value (`true`), so anyone who has it on today keeps it
on. Only freshly created `EnabledModules` instances pick up the new
default.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-09 17:06:40 +08:00
Niels Laute
6ebfac8eab [Shortcut Guide] Settings footer icon clip fix and vector nav icons (#48390)
## Summary of the Pull Request

Visual polish for the Shortcut Guide UI, follow-up to #48383 and #48384.

- Fixes the Settings footer icon being clipped in the rail at startup.
Root cause: the icon `RowDefinition` in `CustomNavigationViewStyle.xaml`
was `*`, so the rail's `MinHeight` constraint compressed the 20px icon
down. Changing it to `Auto` lets the row size to its content. This also
removes the need for the `FakeSettingsButton` workaround.
- Replaces the laptop `FontIcon` used for the `Windows` nav entry with a
4-square Windows logo rendered as a `PathIcon`.
- Replaces the bitmap PowerToys app icon with a theme-aware vector
`PathIcon` (rounded square frame + menu bar + three dots) so it matches
the rest of the icons.
- Path data for both icons lives as `x:String` resources in `App.xaml`.
- Tunes the rail item `Row 0` height so the icon vertically aligns with
the selection pill center.

<img width="681" height="1405" alt="image"
src="https://github.com/user-attachments/assets/10787087-e32f-4018-b004-3f824648b962"
/>

## PR Checklist

- [x] **Closes:** part of the Shortcut Guide 0.100 polish set
- [x] **Communication:** internal only
- [x] **Tests:** manual verification
- [x] **Localization:** no new strings
- [x] **Dev docs:** N/A

## Validation Steps Performed

- Built locally and verified the Settings footer icon is no longer
clipped on first show.
- Verified the Windows nav entry now uses the Windows logo PathIcon and
renders correctly in light and dark.
- Verified the PowerToys entry now renders as a vector and follows the
theme foreground.
- Verified the selection pill aligns vertically with the icon center.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-09 17:06:17 +08:00
Jessica Dene Earley-Cha
582f3eb5c3 Move from testing to final for telemetry PR detection workflow (#47993)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

Transitions the telemetry PR detection workflow from testing phase to
ready status. All components are now fully functional and automatically
triggered on every new PR.

- Skips checks on draft PRs to avoid noise
- Prevents multiple concurrent runs per PR
- Safely requests `@chatasweetie` as reviewer on telemetry changes
- update commit messages

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

---------

Co-authored-by: Carlos Zamora <carlos.zamora@microsoft.com>
2026-06-08 22:56:09 +02:00
Mike Griese
4f14070a1a cmdpal: blindly try to fix dock usage data (#48283)
We have no idea why this event isn't flowing in 0.99. We fixed the other
"new" event, `CmdPal_ExtensionInvoked`, when we merged #47121. But this
event didn't show up.

So, as a blind experiment, we're removing the potentially long payload.
Just to see if something happens.
2026-06-05 11:31:00 +08:00
Shinpache Shimura
76eb6eaac5 Add copy monitor diagnostics button to Power Display (#48209)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #47572 
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

In the powerdisplay tool, Added a new button, that allows to copy the
current display configuration, to allow to share for troubleshooting, or
just sharing.

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
2026-06-05 01:14:09 +08:00
Jessica Dene Earley-Cha
97f2868481 Fix: Narrator announces checkbox labels in CmdPal Extensions > Installed Apps page (#48135)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

Fixes labels not associated with controls in Installed Apps pane.
Narrator only announces "space, checkbox, checked/unchecked" for
Extensions > Installed Apps page checkboxes instead of reading the label
too.

this is an a11y internal bug

The Adaptive Cards renderer (`AdaptiveCards.Rendering.WinUI3` v2.x)
renders `Input.Toggle` as a CheckBox whose `Content` is a TextBlock
containing just `" "`. Without an AutomationProperties.Name`, Narrator
reads the CheckBox.Content (a space character), making the settings
inaccessible to screen reader users.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

---------

Co-authored-by: Michael Jolley <mike@baldbeardedbuilder.com>
2026-06-03 07:50:35 +02:00
Pranshu Namdeo
f3d3abc552 Fix Performance Monitor settings file path collision (#48251)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Fixes #48224

The Performance Monitor extension was still storing its settings in the
shared settings.json file. Since Command Palette built-in extensions now
use extension-specific sibling settings files, the extension's settings
could be overwritten when Command Palette personalization settings were
saved.

This change updates SettingsJsonPath() to store Performance Monitor
settings in an extension-specific settings file
(performanceMonitor.settings.json), ensuring the network speed unit
setting persists correctly.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #48224 
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

The Performance Monitor extension had not been migrated to the newer
extension-specific settings file architecture. As a result, its settings
were stored in the shared settings.json file and could be lost when the
Command Palette host rewrote its configuration.

Following @zadjii-msft's guidance in the issue, this PR updates
SettingsManager.cs to store Performance Monitor settings in an
extension-specific settings file:

performanceMonitor.settings.json

instead of the shared:

settings.json

This aligns the extension with the current Command Palette settings
architecture and prevents the network speed unit setting from being
overwritten.


<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

* Changed Network Speed Unit to "Binary bytes per second" in Performance
Monitor settings.
* Verified the setting was successfully saved to the newly created
`performanceMonitor.settings.json` file.
* Modified core Command Palette personalization settings.
* Verified the Performance Monitor setting was preserved and not
overwritten.
* Restarted PowerToys and verified the setting persisted correctly.

**Note to reviewers:** I left the "Tests" box unchecked because this is
a single-line file path configuration change. I did not add an automated
test, but I have thoroughly verified the fix manually as described in
the Validation steps above.
2026-06-02 16:33:17 +00:00
Michael Jolley
0a64561ed5 CmdPal: Allow connecting to arbitrary hostnames in Remote Desktop list page (#48069)
## Summary of the Pull Request

Fixes #48053 — Remote Desktop extension now allows connecting to
arbitrary hostnames when navigated into the extension's list page.

Previously, `RemoteDesktopListPage` only displayed previously saved
connections. This converts it from `ListPage` to `DynamicListPage`,
adding search-driven behavior:

- Typing a valid hostname/IP that **doesn't** match an existing saved
connection shows a **"Connect to {hostname}"** item at the top of the
list
- Typing something that **exactly matches** a saved connection shows
only the normal results (no duplicate arbitrary-host item)
- Typing an invalid string (not a valid hostname/IP) shows no
arbitrary-host item

The hostname validation reuses the same logic as
`FallbackRemoteDesktopItem`: strip the port suffix (e.g. `myhost:3389` →
`myhost`), then check `Uri.CheckHostName` against `IPv4`, `IPv6`, `Dns`.

## PR Checklist
- [x] Closes: #48053
- [ ] **Communication:** I've discussed this with core contributors
already.
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized

---------

Co-authored-by: root <root@io.bbq>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-02 10:47:25 -05:00
Niels Laute
7f19817182 Rework Power Display warning dialog (#48249)
## Summary of the Pull Request

Rework the confirmation dialog shown when enabling Power Display (and
its potentially-destructive sub-features) so it is shorter, friendlier,
and consistent across all entry points. The five separate prefix-driven
variants are now a single `PowerDisplayWarningDialog` user control
selected via an enum, sharing the title, learn-more link, and
Enable/Cancel buttons. The previous hand-rolled red warning text is
replaced with a Fluent `InfoBar Severity=""Warning""`.

## PR Checklist

- [ ] Closes: #xxx
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places

## Detailed Description of the Pull Request / Additional comments

### Before
- `DangerousFeatureWarningDialog` took a resource-key prefix string and
probed up to five optional keys per variant (`_WarningHeader`,
`_WarningConfirm`, `_WarningList_Item1/2`, etc.).
- Each of the five flows (EnableModule, ColorTemperature, PowerState,
InputSource, MaxCompatibility) had a slightly different title (some
questions, some statements, mixed `Warning:` prefixes) and a hand-rolled
red `TextBlock` warning header with a `⚠️` emoji and
`SystemFillColorCriticalBrush`.
- ~30 fragmented `PowerDisplay_*_Warning*` resw keys.

### After
- New `PowerDisplayWarningDialog` selected via `PowerDisplayWarningKind`
enum (`EnableModule`, `ColorTemperature`, `PowerState`, `InputSource`,
`MaxCompatibility`).
- Shared chrome lives in the control:
  - Single title `Before you continue` for every variant.
  - `InfoBar Severity=""Warning""` replaces the hand-rolled red header.
- Learn-more `HyperlinkButton` pointing at
`aka.ms/powerToysOverview_PowerDisplay_Note` (URL is a `private const`
so translators don't see it).
  - Consistent Enable / Cancel buttons.
- Per-variant content collapses to one InfoBar message + one body
paragraph in resw (12 keys total, down from ~30). Bullets are inlined as
`• ` + newlines with `xml:space=""preserve""`.
- `PowerDisplayViewModel.ConfirmDangerousFeatureAsync` and
`TryCommitDangerousChangeAsync` now take the enum instead of a magic
string.

### Files
- **Added:** `ViewModels/PowerDisplayWarningKind.cs`,
`SettingsXAML/Views/PowerDisplayWarningDialog.xaml{,.cs}`
- **Removed:**
`SettingsXAML/Views/DangerousFeatureWarningDialog.xaml{,.cs}`
- **Updated:** `Strings/en-us/Resources.resw`,
`ViewModels/PowerDisplayViewModel.cs`,
`SettingsXAML/Views/PowerDisplayPage.xaml.cs`

## Validation Steps Performed

- Built `PowerToys.Settings.csproj` (Debug arm64) — clean.
- Manually exercised the EnableModule and MaxCompatibility flows;
verified the new title, InfoBar, body paragraph, learn-more link, and
Enable/Cancel button behavior.
- Verified `aka.ms/powerToysOverview_PowerDisplay_Note` opens in the
default browser.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-02 14:57:43 +08:00
Niels Laute
a33fd3c474 [KBM] Enable new editor by default (#48245)
## Summary

Make the new WinUI 3 Keyboard Manager editor the default by flipping
`useNewEditor` from `false` to `true` everywhere a default is supplied.

## Behavior

- **New installs / new `settings.json`** → new editor enabled
- **Upgrades from a version before the `useNewEditor` key existed** →
new editor enabled (the key is missing, so the default kicks in)
- **Users who have explicitly toggled the setting** → unchanged (we only
change the default, not stored values)
- The "Go back to classic" button in the KBM settings page is untouched

## Changes

- `src/settings-ui/Settings.UI.Library/KeyboardManagerProperties.cs` —
`UseNewEditor` property initializer now `true`
- `src/modules/keyboardmanager/dll/dllmain.cpp` — `m_useNewEditor`
member init + `GetNamedBoolean` fallback now `true`; warn-log message
updated to match
-
`src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Modules/KeyboardManagerModuleCommandProvider.cs`
— both fallback paths in `IsUseNewEditorEnabled` (file missing /
unreadable) now return `true`, so the "Open New Editor" CmdPal command
surfaces by default

## Validation

Built locally on ARM64 Debug (exit code 0):
- `src/modules/keyboardmanager/dll`
- `src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys`
- `src/settings-ui/Settings.UI.Library`

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-02 14:57:02 +08:00
Niels Laute
b712fa4d85 Reword Shortcut Guide module and OOBE descriptions (#48248)
## Summary of the Pull Request

Reword the Shortcut Guide module description and OOBE description so
they describe the feature without referring to `your apps`. The module
description now reads as a single sentence covering Windows and the
active app; the OOBE description is shortened to one paragraph and
refers to `various applications` instead of enumerating the bundled
apps.

## PR Checklist

- [ ] Closes: #xxx
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places

## Detailed Description of the Pull Request / Additional comments

Two strings in
`src/settings-ui/Settings.UI/Strings/en-us/Resources.resw` changed:

- `ShortcutGuide.ModuleDescription` — now: `Shows an on-screen overlay
of keyboard shortcuts for Windows and the active application.`
- `Oobe_ShortcutGuide.Description` — collapsed to one sentence
describing Windows + various applications, no longer enumerating bundled
apps or mentioning future additions.

No code or behavioral changes.

## Validation Steps Performed

- Built Settings.UI (Debug arm64) – clean.
- Verified the Shortcut Guide module card in Settings UI shows the new
description and the OOBE Shortcut Guide page shows the new paragraph.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-06-02 14:39:52 +08:00
Michael Jolley
b66b044210 CmdPal: Synchronize fallback title/subtitle format for consistent scoring (#48085)
## Summary

Fixes #46055 — Standardizes built-in fallback title/subtitle format so
scoring is consistent across all action fallbacks.

## Problem

`MainListPage.cs` scores fallback items by fuzzy-matching the query
against both Title and Subtitle, but with different weights:
- `nameScore = FuzzyScore(query, Title)`
- `descriptionScore = (FuzzyScore(query, Subtitle) - 4) / 2`

Fallbacks that embedded the raw query in Title got artificially higher
scores than those using Subtitle. This made ranking unpredictable.

## Fix

All "action" fallbacks now follow a consistent pattern:
- **Title** = static action description (no query text)
- **Subtitle** = raw query string (unquoted)

"Result" fallbacks (that found a specific matched item) are left
unchanged — they correctly show the matched item name in Title.

## Full Fallback Audit (example query: `notepad`)

| Fallback | Title | Subtitle | Status |
|---|---|---|---|
| WebSearch: Search | "Search the web with Edge" | `Search for notepad`
| **Changed** — was `Search for "notepad"` in subtitle |
| WebSearch: Open URL | "Open in Microsoft Edge" | `Open notepad.com` |
**Changed** — was `Open "notepad.com"` in title |
| Shell: Run | "Run" | `notepad` | Unchanged — already correct |
| Calculator | "3" (result) | `1+2` (query) | Unchanged — intentional
exception |
| Indexer: single result | "notepad.exe" | `C:\Windows\notepad.exe` |
Unchanged — result fallback |
| Indexer: multiple results | "File search" | `Search for notepad in
files` | **Changed** — was `Search for "notepad" in files` in title |
| Windows Settings: single | "Notepad settings" | `Settings > Apps` |
Unchanged — result fallback |
| Windows Settings: multiple | "Search Windows settings..." | `Search
for notepad` | **Changed** — was `Search for "notepad" in Windows
settings` in title |
| Remote Desktop: exact match | "MyPC" (connection) | "Connect to MyPC"
| Unchanged — result fallback |
| Remote Desktop: arbitrary host | "Remote Desktop" | `Connect to
notepad-host` | **Changed** — was `Connect to notepad-host` in title |
| TimeDate | "Monday, May 23" (result) | "Current date" | Unchanged —
result fallback |
| System | "Shut down" (result) | "Shuts down the computer" | Unchanged
— result fallback |
| PowerToys | "Color Picker" (static) | "Pick a color..." | Unchanged —
result fallback |

## Changes

- `FallbackExecuteSearchItem.cs` — Subtitle uses raw query instead of
`"Search for \"{query}\""` format
- `FallbackOpenURLItem.cs` — Title shows browser name (was query),
Subtitle shows raw query (was browser)
- `FallbackOpenFileItem.cs` — Multi-result: Title is static display
name, Subtitle is raw query
- `FallbackWindowsSettingsItem.cs` — Multi-result: Title is static
description, Subtitle is raw query
- `FallbackRemoteDesktopItem.cs` — Arbitrary host: Title is static
"Remote Desktop", Subtitle is raw query

---------

Co-authored-by: root <root@io.bbq>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-01 16:57:30 -05:00
Michael Jolley
18919eaa40 CmdPal: Fix dock subtitle visibility in compact mode after async update (#48088)
## Summary

When an extension updates its `Subtitle` property asynchronously after
initial render, the `TextVisibilityStates` visual state group
transitions from `TitleOnly` → `TextVisible`. This transition sets
`SubtitleText.Visibility = Visible`, overriding the `CompactStates`
setter that had hidden it.

## Fix

Added `control.UpdateCompactState()` to `OnTextPropertyChanged` in
`DockItemControl.xaml.cs`. This re-applies the compact state after any
text property change. When `IsCompact` is `false`, `UpdateCompactState`
is a no-op — no behavior change for the non-compact path.

Fixes #47980

Co-authored-by: root <root@io.bbq>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-01 16:56:33 -05:00
Michael Jolley
e0854fbaf3 CmdPal: Reorder dock network stats to match Task Manager order (#48098)
## Summary

Fixes #47939

The Performance Monitor dock band displayed network stats as Receive →
Send, but Task Manager shows Send → Receive. This swaps the order to
match Task Manager.

## Changes

- `PerformanceWidgetsPage.cs`: Swap `_networkUpItem` (Send) before
`_networkDownItem` (Receive) in the band items array.

Co-authored-by: root <root@io.bbq>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-01 16:55:41 -05:00
Michael Jolley
ba20da1611 CmdPal: Fix hotkey navigation when palette is showing transient dock page (#48089)
## Summary

When a keyboard shortcut opens CmdPal to an extension while the palette
is already showing a dock-launched transient page, `GoHome(false)`
cannot restore the root page — the frame's back stack is empty because
the transient dock page was never pushed on top of root. The user ends
up with only the hotkey-target page in the frame with no way to navigate
back to the main list.

## Root Cause

In `ShellPage.SummonOnUiThread()`, the hotkey-to-page branch called
`GoHome(false)` before sending `ShowWindowMessage`. But when the active
page is a transient dock page, `_currentlyTransient` is still `true` and
the frame back stack is empty, so `GoHome` can't re-establish the root
page as the frame base.

## Fix

Added `ResetToHome()` to `ShellViewModel`, mirroring the pattern already
used in `WindowHiddenMessage` handling:
1. Clears `_currentlyTransient`
2. Calls `_rootPageService.GoHome()` to reset extension state
3. Sends `PerformCommandMessage` for `_rootPage` — navigating
MainListPage into the frame as the base

In `ShellPage.SummonOnUiThread()`, the `GoHome(false)` call in the
`isPage` branch is replaced with `ViewModel.ResetToHome()`. The root
page is then cleanly in the frame before the hotkey target's
`PerformCommandMessage` navigates on top of it.

Fixes #47994

Co-authored-by: root <root@io.bbq>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-01 16:29:53 -05:00
Niels Laute
35f2ed839e CmdPal: Reorder Pin to Dock dialog so controls precede the preview (#48250)
## Summary of the Pull Request

Reorder the Pin to Dock dialog content so the configuration controls
(monitor selector, dock section, label options) appear at the top and
the live preview is shown below them. The user now configures the pin
first and sees the resulting preview directly underneath, instead of
staring at the preview and having to scan past it to find the controls.

<img width="515" height="440" alt="image"
src="https://github.com/user-attachments/assets/0d1d0543-2b30-48f5-a1aa-676a165870f5"
/>

## PR Checklist

- [ ] Closes: #xxx
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places

## Detailed Description of the Pull Request / Additional comments

XAML-only change to
`src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/PinToDockDialogContent.xaml`.
The new visual order inside the `ScrollViewer`/`StackPanel` is:

1. Monitor selector (still `Visibility=""Collapsed""` by default; shown
when more than one monitor is available)
2. Dock section `Segmented` (Start / Center / End)
3. Label options (`Show title` / `Show subtitle` checkboxes)
4. Divider `Rectangle`
5. Preview `Border`

No logic, bindings, `x:Name` identifiers, event handlers, or `x:Uid`
keys are changed.

## Validation Steps Performed

- Built `Microsoft.CmdPal.UI` (Debug arm64) — clean.
- Verified the Pin to Dock dialog renders with controls on top and the
preview underneath; segmented selection, label-option checkboxes, and
the multi-monitor combo still behave as before.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-01 15:43:46 -05:00
Michael Jolley
e20b5b9c51 CmdPal: Fix GPU index out of range crash in PerfMon widget (#48103)
## Summary

Fixes #47821

The GPU Performance Monitor widget crashes with
`IndexOutOfRangeException` on systems where GPU performance counters
fail to enumerate (common on Intel Arc and hybrid GPU configurations).
The dock band shows `???` and opening the flyout causes an error.

## Root Cause

`GPUStats.CreateGPUImageUrl()` accessed `_stats[index]` without bounds
checking. When `GetGPUPerfCounters()` finds no matching counter
instances, `_stats` remains empty but callers still pass index 0.

`GetGPUName()`, `GetGPUUsage()`, and `GetGPUTemperature()` already have
proper guards (`if (_stats.Count <= index) return ...`) — this fix adds
the same pattern to the one remaining unguarded method.

## Changes

- `GPUStats.cs`: Add bounds check to `CreateGPUImageUrl()` — return
empty string if index out of range

Co-authored-by: root <root@io.bbq>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-01 20:59:57 +02:00
Mike Griese
c6a9ad2ad0 cmdpal: fix the dock window border being visible, redux (#48180)
Addenda to #47187

that fix only works if the _hwnd is already set. Actually it's crazy it
ever worked.

Tested by disconnecting and reconnecting RDP a couple times, which
pretty consistently reproduces the problem.
2026-06-01 11:33:17 +00:00
Muyuan Li
a67fc2d9b7 Fix ShortcutGuide v2 crash when Manifests directory is missing (#48171)
## Summary

Fixes #48170 — ShortcutGuide v2 crashes on launch when the bundled
`Manifests` directory is absent from the install path.

### Root Cause

The `Assets\ShortcutGuide\Manifests\*.yml` files were never reaching the
build output directory during the CI solution-level build (`msbuild
PowerToys.slnx /t:Build -graph`). The `CopyToOutputDirectory` metadata
on `<Content>` items does not reliably copy files to a shared
`OutputPath` in this build configuration. As a result, the WiX installer
generator found no yml files to package, and the installed product was
missing the Manifests directory entirely.

At runtime, `PowerToysShortcutsPopulator.Populate()` threw an unhandled
`FileNotFoundException` causing a crash loop.

### Fix (3 layers)

1. **Code resilience** (`Program.cs`, `PowerToysShortcutsPopulator.cs`):
- Wrap `Populate()` in try/catch so a missing manifest degrades
gracefully instead of crashing
   - Add `File.Exists` guard before `File.ReadAllText`

2. **Build output** (`ShortcutGuide.Ui.csproj`):
- Add explicit `CopyManifestsToOutputDir` MSBuild target
(`AfterTargets="Build"`) that copies yml files to
`$(OutDir)Assets\ShortcutGuide\Manifests\` — same pattern as the
existing `CopyPRIFileToOutputDir` target
- Keep `<Content Include>` with `CopyToOutputDirectory` as a fallback
for publish scenarios

3. **Installer packaging** (`generateAllFileComponents.ps1`,
`ShortcutGuide.wxs`):
   - Add `*.yml` to the file inclusion list
- Add `Generate-FileList` / `Generate-FileComponents` calls for
`ShortcutGuideManifestsFiles`
- Add WiX directory definition and `RemoveFolder` component for the
Manifests directory

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-01 16:28:08 +08:00
Jessica Dene Earley-Cha
c78f6e52a0 [CmdPal] Toggle "Show details" / "Hide details" with icon in context menu (#48140)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

Converts the "Show details" context menu command into a toggle that
switches between "Show details" and "Hide details" with appropriate
icons, and fixes the icon not rendering in the context menu.

Address internal a11y bug.



<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
2026-06-01 13:19:38 +08:00
thetsaw
9a55209d13 Add DiskAnalyzer to third-party Run plugins list (#48106)
## Summary of the Pull Request

Adds **DiskAnalyzer** to the General plugins table in
`doc/thirdPartyRunPlugins.md`.

- **Plugin:**
[Community.PowerToys.Run.Plugin.DiskAnalyzer](https://github.com/thetsaw/PowerToys.Plugin)
- - **Author:** thetsaw
- - **Keyword:** `ds`
- - **License:** MIT
- - **Platforms:** x64 and ARM64
### What it does
Scan any folder or drive to find the largest files and subfolders, view
drive usage with visual progress bars, and navigate your filesystem all
from PowerToys Run.

## PR Checklist

- [x] Plugin has been publicly available
- [ ] - [x] MIT licensed
- [ ] - [x] Releases include x64 and ARM64 zips
- [ ] - [x] plugin.json is correctly formatted
- [ ] - [x] README includes install instructions
## Detailed Description

This is a documentation-only change adding one row to the third-party
plugins table. No source code, binaries, or build files are modified.
2026-05-28 17:46:23 +00:00
Copilot
0cb6fe250b Rename Settings UI label from “Shortcut Guide V2” to “Shortcut Guide” (#48151)
## Summary of the Pull Request

This updates PowerToys Settings to remove the obsolete “V2” suffix from
the Shortcut Guide module name. The UI now consistently shows **Shortcut
Guide**.

## PR Checklist

- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

## Detailed Description of the Pull Request / Additional comments

- **Settings navigation label**
  - Updated `Shell_ShortcutGuide.Content` to `Shortcut Guide`.
- **Module title**
  - Updated `ShortcutGuide.ModuleTitle` to `Shortcut Guide`.
- **OOBE title**
  - Updated `Oobe_ShortcutGuide.Title` to `Shortcut Guide`.

```xml
<data name="Shell_ShortcutGuide.Content" xml:space="preserve">
  <value>Shortcut Guide</value>
</data>
```

## Validation Steps Performed

- N/A for behavior-level validation in this description (change is
limited to localized display strings).

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-05-28 17:46:17 +08:00
moooyo
c0cb9417ad Remove "NEW" tag from Power Display and Grab and Move (#48174)
## Summary of the Pull Request
Both Power Display and Grab and Move have matured beyond their initial
release phase. This removes the "NEW" `InfoBadge` from their navigation
items in Settings, the two parent navigation groups (Windowing &
Layouts, Input / Output) that surfaced the badge when collapsed, and
clears the `IsNew` flag for Power Display in the OOBE shell.

<img width="1867" height="973" alt="image"
src="https://github.com/user-attachments/assets/533f271c-c70f-414f-a76a-43fd9ffbbd44"
/>
<img width="497" height="575" alt="image"
src="https://github.com/user-attachments/assets/fe1e97c3-c806-4f42-a836-76e042630d61"
/>
<img width="1619" height="1027" alt="image"
src="https://github.com/user-attachments/assets/f5db715b-bc69-4505-803a-18a9b2716280"
/>


## PR Checklist

- [x] Closes: #48153
- [x] **Communication:** Tracked by the linked issue
- [x] **Tests:** Markup-only change; Settings.UI builds clean with WinUI
markup compiler (no XAML errors)
- [x] **Localization:** No end-user-facing strings changed
- [ ] **Dev docs:** N/A
- [ ] **New binaries:** N/A
- [ ] **Documentation updated:** N/A

## Detailed Description of the Pull Request / Additional comments
Files touched:
- `src/settings-ui/Settings.UI/SettingsXAML/Views/ShellPage.xaml` —
removed four `<InfoBadge Style="{StaticResource NewInfoBadge}" />`
blocks on `GrabAndMoveNavigationItem`, `PowerDisplayNavigationItem`, and
on the two parent group headers `WindowingAndLayoutsNavigationItem` and
`InputOutputNavigationItem` (the parent badges existed only to surface a
NEW child when the group was collapsed; with no NEW children left in
those groups, the parent badges are now stale).
- `src/settings-ui/Settings.UI/OOBE/ViewModel/OobeShellViewModel.cs` —
flipped `(PowerToysModules.PowerDisplay, true)` to
`(PowerToysModules.PowerDisplay, false)`. Grab and Move was already
`false`.

No other modules or strings affected.

## Validation Steps Performed
- Built `src\settings-ui\Settings.UI\PowerToys.Settings.csproj`
(Release|x64) with MSBuild from VS 18 Enterprise;
`PowerToys.Settings.dll` produced with 0 errors related to this change.
WinUI markup compiler would have aborted before producing the DLL if the
XAML had syntax issues.
- Diff inspected: only the five intended deletions/edits, no collateral
changes.
- Visual run-time verification of the Settings navigation pane is
recommended before merge.

Co-authored-by: Yu Leng <yuleng@microsoft.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 09:28:31 +00:00
moooyo
cd5027fa1a [PowerDisplay] Fix false-positive crash detection on cooperative shutdown (#48173)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

Cooperative shutdowns of `PowerDisplay.exe` — Runner's `TerminateApp`
NamedPipe message, the `Terminate` named event, tray-quit, Runner-exit
detection, and PowerToys upgrades — all call `Environment.Exit(0)`
immediately. If DDC/CI discovery is mid-flight, that path skips the
`try/finally` that owns `CrashDetectionScope`, leaving `discovery.lock`
on disk. Phase 0 at the next `PowerDisplay.exe` startup then treats this
orphan as evidence of a real crash and auto-disables the module,
surfacing the "PowerDisplay has crashed" InfoBar in Settings UI.

This PR adds an `AppDomain.ProcessExit` safety-net inside
`CrashDetectionScope`. ProcessExit fires for `Environment.Exit` but
**not** for `FailFast` / BSOD / external `TerminateProcess` — exactly
the partition we need: cooperative exit → best-effort delete the lock;
involuntary kill → leave the lock for Phase 0 to detect (original design
intent preserved).

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #48169
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
<!-- no user-facing strings changed -->
- [x] **Dev docs:** Added/updated <!-- inline XML doc on
CrashDetectionScope explains the ProcessExit partition -->
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

### Root cause

`CrashDetectionScope.Begin()` writes `discovery.lock` before DDC/CI
capability fetch and `Dispose()` deletes it when the `using` block
exits. The lock is intentionally designed to survive any code path that
cannot run user-mode cleanup (BSOD, kernel OOM, `TerminateProcess`), so
that the next `PowerDisplay.exe` start can see it and run Phase 0 (write
`crash_detected.flag`, set `enabled.PowerDisplay=false` in global
`settings.json`, signal `AutoDisablePowerDisplayEvent`).

The bug is that several **cooperative** shutdown paths route to
`Environment.Exit(0)` immediately:

| Path | Code |
|---|---|
| Runner's `TerminateApp` NamedPipe | `App.xaml.cs::OnNamedPipeMessage`
→ `Shutdown()` → `Environment.Exit(0)` |
| `Terminate` named event | `App.xaml.cs::OnLaunched` →
`RegisterEvent(..., () => Environment.Exit(0), "Terminate")` |
| Tray-quit | `TrayIconService` callback → `Environment.Exit(0)` |
| Runner-exit detection | `RunnerHelper.WaitForPowerToysRunner` callback
→ `Environment.Exit(0)` |

`Environment.Exit` calls `ExitProcess` under the hood, which terminates
all threads abruptly. Background `Task.WhenAll` doing DDC capability
fetch is killed mid-flight; the `finally` block that calls
`scope.Dispose()` never runs; `discovery.lock` orphans; Phase 0 next
time false-positives.

Concrete repro from logs:
- `15:08:42.510` lock written
- `15:08:42.79` probe monitor #1
- `15:08:46.92` probe monitor #2 (started, not finished — typical probe
takes ~5s)
- `15:08:49.03` `TerminateApp` received → `Environment.Exit(0)` → no
`Dispose` log line
- `15:10:10.03` next startup: Phase 0 sees orphan lock with `pid:17712,
startedAt:2026-05-28T07:08:42Z` → writes `crash_detected.flag` →
auto-disables

### Fix

`CrashDetectionScope.Begin()` now also subscribes to
`AppDomain.CurrentDomain.ProcessExit`. The handler does a best-effort
`File.Delete(_lockPath)` (swallowing exceptions, as required for
ProcessExit handlers). `Dispose()` unsubscribes before deleting. An
`Interlocked.Exchange` guards the race between Dispose and ProcessExit
so only one of the two performs the delete.

ProcessExit's semantics match the cooperative/involuntary partition
exactly:

| Shutdown path | ProcessExit fires? | Behavior after this PR |
|---|---|---|
| `Environment.Exit(code)` (all 4 paths above) | yes | lock deleted by
handler |
| `Environment.FailFast` | no | lock survives → Phase 0 catches it
(correct: explicit FailFast = real failure) |
| BSOD / external `TerminateProcess` / kernel OOM | no | lock survives →
Phase 0 catches it (correct: original design) |
| Discovery completes normally / throws | n/a | `try/finally` calls
`Dispose()` as before; handler unsubscribed first |

### Testability

A new `IProcessExitHook` interface abstracts the subscription so unit
tests can simulate ProcessExit without terminating the test runner.
Production code uses the default `AppDomainProcessExitHook` singleton;
tests inject a fake whose `RaiseExit()` invokes subscribed handlers
synchronously.

### Files touched

-
`src/modules/powerdisplay/PowerDisplay.Lib/Services/IProcessExitHook.cs`
*(new)* — interface + production singleton
-
`src/modules/powerdisplay/PowerDisplay.Lib/Services/CrashDetectionScope.cs`
— subscribe in `Begin`, unsubscribe in `Dispose`, add `OnProcessExit`
handler, expanded class doc
-
`src/modules/powerdisplay/PowerDisplay.Lib.UnitTests/CrashDetectionScopeTests.cs`
*(new)* — 10 unit tests

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

### Automated

10 new unit tests in `CrashDetectionScopeTests`, all passing:

```
Passed Begin_WritesLockFileAtomically
Passed Begin_SubscribesToProcessExit
Passed Dispose_UnsubscribesFromProcessExit
Passed Dispose_DeletesLockFile
Passed ProcessExitFired_BeforeDispose_DeletesLock      (core scenario)
Passed ProcessExitFired_AfterDispose_DoesNothing
Passed Dispose_AfterProcessExit_DoesNotThrow
Passed ProcessExitFired_LockFileMissing_DoesNotThrow
Passed Dispose_IsIdempotent
Passed MultipleScopes_DoNotShareState
```

Full `PowerDisplay.Lib.UnitTests` suite: **129 / 132 passing**. The 3
failures (`DetectOrphanAndDisable_RunsFullSequenceWhenOrphanPresent`,
`DetectOrphanAndDisable_HandlesUnknownVersionAsOrphan`,
`DetectOrphanAndDisable_LeavesLockIntactOnSignalFailure`) are
**pre-existing on `main`** — they fail with `REGDB_E_CLASSNOTREG` from
`Constants.AutoDisablePowerDisplayEvent()` (WinRT activation factory not
COM-registered in the test environment). Verified by stashing this PR's
changes and re-running the same 3 tests on baseline `main` — same
failures, same cause, unrelated to this change.

### Manual

1. Reproduced the original false-positive on `main`:
- Enable PowerDisplay → open Settings UI → quickly toggle PowerDisplay
off
- Observe `discovery.lock` left in
`%LOCALAPPDATA%\Microsoft\PowerToys\PowerDisplay\`
- Re-enable PowerDisplay → Phase 0 writes `crash_detected.flag` →
InfoBar appears
2. Repeated the same steps with this branch:
- Toggling PowerDisplay off cleanly deletes `discovery.lock`
(ProcessExit handler ran)
- Re-enabling PowerDisplay shows no InfoBar, no `crash_detected.flag`
created
3. BSOD path is unchanged (verified by inspecting the conditional logic
— `AppDomain.ProcessExit` does not fire for involuntary terminations;
the lock survives just as before).

---------

Co-authored-by: Yu Leng <yuleng@microsoft.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 09:02:14 +00:00
Copilot
7da62cdb0a Rename OOBE overview Learn link label to “Documentation” (#48155)
## Summary of the Pull Request

Renames the OOBE welcome/overview hyperlink label from **“Documentation
on Microsoft Learn”** to **“Documentation”** for brevity and
consistency.
Scope is limited to the localized string resource used by the OOBE
overview page.

## PR Checklist

- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

## Detailed Description of the Pull Request / Additional comments

- **Resource update (OOBE Overview)**
- Updated `Oobe_Overview_DescriptionLinkText.Text` in
`src/settings-ui/Settings.UI/Strings/en-us/Resources.resw`.

```xml
<data name="Oobe_Overview_DescriptionLinkText.Text" xml:space="preserve">
  <value>Documentation</value>
</data>
```

## Validation Steps Performed

- Confirmed the OOBE overview string key now resolves to
**“Documentation”**.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-05-28 15:26:02 +08:00
Eymard Silva
c46083dd8d Handle complex calculator results (#47506)
## Summary of the Pull Request

Return a friendly calculator error when Mages evaluates an expression to
a complex number instead of letting decimal conversion throw.

This fixes the PowerToys Run Calculator result for expressions such as
`sqrt(-1)` by detecting `System.Numerics.Complex` results before decimal
conversion and showing a localized error message instead.

Fixes #43937

## PR Checklist

- [x] Closes: #43937
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [x] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [x] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [x] **Documentation updated:** Not required for this bug fix.

## Detailed Description of the Pull Request / Additional comments

The Calculator plugin previously passed complex results from Mages into
`Convert.ToDecimal`, which caused an exception for expressions like
`sqrt(-1)`.

This PR updates the calculator result transformation logic to detect
`System.Numerics.Complex` and return a localized user-facing error
message: `Complex numbers are not supported`.

It also updates calculator query tests to cover both direct keyword and
global query behavior.

## Validation Steps Performed

- Added unit test coverage for `=sqrt(-1)` returning `Complex numbers
are not supported`.
- Added unit test coverage for global query `sqrt(-1)` returning no
result instead of surfacing an unhandled exception.
- Ran `git diff --check`.
- Attempted local build/test with the PowerToys build scripts, but local
validation was blocked by Visual Studio/VC tooling configuration issues
unrelated to this change: `PlatformToolsetVersion` resolves to an empty
value during restore/build.
2026-05-28 15:06:22 +08:00
Mike Griese
65112a7b05 Move CmdPal API spec back to cmdpal/ directory (#48160)
Reverts 0819a62 / #46926

The cmdpal API is literally generated from this spec document. It needs
to live with the rest of the code to work correctly.

Docs for authoring cmdpal extensions are on
https://learn.microsoft.com/en-us/windows/powertoys/command-palette/extension-development,
and we should direct docs commentary there.
2026-05-28 00:05:12 +02:00
Dustin L. Howett
109c63ba33 Remove our dependency on expected-lite (#48159)
This removes our last git submodule dependency!

We were using `expected-lite` in one place, which was being compiled out
_anyway_ in favor of using `std::expected`.
2026-05-27 14:58:27 -07:00
🄂ʏᴇᴅ 🄰ʙᴅᴜʟ 🄰ᴍᴀ🄝 ✧
6be6509c46 Fix project template settings heading (#48148)
## Summary
- Fix a grammar typo in the PowerToy project template README heading.
- Change "Settings Informations" to "Settings Information".

## Validation
- Ran `git diff --check`.
2026-05-27 17:31:03 +00:00
Boliang Zhang
8a7933c0b2 Migrate spdlog from submodule to vcpkg (#48039)
## Summary

Migrate `deps/spdlog` from a git submodule to **vcpkg manifest mode**
with an overlay port pinned to the **exact same commit**
(`gabime/spdlog@616866fc`). Replaces the polyfill shim added in #47910
with a proper port-level patch.

This is the follow-up to PR #47928, which I closed after @zadjii-msft /
@DHowett clarified that the intended direction was a single combined
"move to vcpkg **and** apply a patch file" (one change, not two stepping
stones).

## Guidance honored

Per @zadjii-msft (offline):
-  Convert each submodule to vcpkg **one at a time** — this PR is
**spdlog only**. `deps/expected-lite` stays a submodule (separate PR
next).
-  Atomic commit per dep (multiple commits on the branch for review
traceability; squash on merge gives the requested single commit).
-  **Don't bump the version.** Only variable changed: submodule →
vcpkg. Same commit (`616866fc`, v1.8.5 + 38) the submodule pointed at.

Per @DHowett
([review](https://github.com/microsoft/PowerToys/pull/48039#pullrequestreview-4338835150)):
-  No vcpkg submodule — vswhere-first detection via a Terminal-style
`steps-install-vcpkg.yml` template; three-tier `VcpkgRoot` fallback (env
var → VS-shipped → runtime clone pinned to manifest baseline).

## Design

- **Repo-root manifest**: `vcpkg.json` declares only `spdlog`, with
`builtin-baseline` pinned. `vcpkg-configuration.json` registers
`deps/vcpkg-overlays/` as overlay-ports.
- **Overlay port** `deps/vcpkg-overlays/spdlog/`: `vcpkg_from_github(REF
616866fc...)` with bundled fmt preserved (`-DSPDLOG_FMT_EXTERNAL=OFF`);
the MSVC 14.51 fix from #47910 carried as a proper vcpkg patch on
`include/spdlog/fmt/bundled/format.h`.
- **vcpkg integration is global** (set in `Cpp.Build.props`, imported
via `ForceImportBeforeCppProps` for every `.vcxproj`). An earlier
attempt to make vcpkg per-project-opt-in via `deps/spdlog.props` failed
because ~85 PowerToys `.vcxproj` files import `spdlog.props` AFTER
`Microsoft.Cpp.targets`, by which point `vcpkg.props`' `ClCompile` hook
is dead-on-arrival. The trade-off (every C++ project invokes `vcpkg
install` once at build time, ~0.5 s on cache hits, manifest declares
only spdlog so install set is fixed) is documented in the expanded
`Cpp.Build.props` comment.
- **`deps/spdlog.props`** is now a thin shim that only sets the
historical `SPDLOG_*` preprocessor defines for source-compat.
- **`Cpp.Build.targets`** is a new file imported via
`ForceImportAfterCppTargets` to load `vcpkg.targets` after
`Microsoft.Cpp.targets`. A fail-fast `<Target>` errors with a clear
message if `vcpkg.props` can't be found at the resolved `VcpkgRoot`.
- **Removes** `deps/spdlog-msvc-fix/` polyfill, in-tree wrapper
`src/logging/`, spdlog submodule, the single `<ProjectReference>` in
`logger.vcxproj`, plus 3 `.slnf` refs and 2 `.slnx` refs
(`PowerToys.slnx` + `installer/PowerToysSetup.slnx`), plus 3 hard-coded
`..\deps\spdlog\include` entries in `<AdditionalIncludeDirectories>`.
- **CI**: new reusable `.pipelines/v2/templates/steps-install-vcpkg.yml`
(vswhere-first, manifest-baseline-pinned fallback clone, respects
`useVSPreview`). Gated `Cache@2` for `%LOCALAPPDATA%\vcpkg\archives`
keyed on overlay-port contents. Same vcpkg detection added to
`tools\build\build-essentials.ps1` for local devs.

## Verification

Local build matrix (all 4 configs of `logger.vcxproj` and a
representative late-import consumer):

| Config | Result | Notes |
|--------|--------|-------|
| Release \| x64    |  | vcpkg install ~21 s, `logger.lib` produced |
| Debug \| x64 |  | **Validates patch fixes the actual MSVC 14.51 bug**
(`_ITERATOR_DEBUG_LEVEL > 0` → `_SECURE_SCL`) |
| Release \| ARM64 |  | vcpkg cross-installs `arm64-windows-static`
spdlog in ~16 s |
| Debug \| ARM64 |  | **Previously DISABLED for the in-tree spdlog**
(per `<Build Solution="Debug\|ARM64" Project="false" />` in
`PowerToysSetup.slnx`); this migration FIXES that latent gap |
| FancyZonesLib (Release \| x64) |  | Late-import-pattern consumer;
previously broke in v2 |

Full PowerToys CI (x64 + arm64 + CmdPal SDK + all GitHub Actions checks)
green.

**Consumer audit**: 72 `.vcxproj` files reference `logger.vcxproj`; all
72 also import `deps/spdlog.props`. No transitive-link breakage.

## Out of scope (intentional)

- `deps/expected-lite` migration — next PR per "one-at-a-time" rule.
- Remote vcpkg binary cache (Azure Artifacts NuGet feed). Local pipeline
`Cache@2` works for now, but a remote feed survives across pipelines and
is the long-term answer. Happy to split this into a follow-up.

## Notes for review

- Patch in the overlay port is identical content to PR #47928's patch
but regenerated with LF line endings (vcpkg's `vcpkg_apply_patches` is
strict; no `--ignore-whitespace`).
- Once PowerToys eventually bumps spdlog past v1.14 (which ships fmt
10.2 and drops the affected code path), the overlay port can be deleted
and we can use upstream vcpkg's `spdlog` directly.
- Re. official-release pipelines and terrapin / less-restricted network
isolation: VS-shipped vcpkg is the primary path (no network); the
fallback clone is only exercised when VS doesn't ship vcpkg. Happy to
wire terrapin into the fallback as a follow-up if the official build
template needs it.

Closes the work tracked in #47928 (which was closed unmerged).

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Dustin L. Howett <dustin@howett.net>
2026-05-27 15:45:24 +08:00
Jeremy Sinclair
6f5ea3bb95 [Deps] Upgrade .NET Runtime package versions to 10.0.8 (#48010)
## Summary of the Pull Request

Updates .NET 10 Runtime / Library packages to the latest 10.0.8
servicing release for security fixes.

## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

## Detailed Description of the Pull Request / Additional comments

Updates the runtime-related package versions in
`Directory.Packages.props` from `10.0.7` to `10.0.8`.

## Validation Steps Performed

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
2026-05-26 14:57:35 +08:00
Michael Clayton
fe985e7eea Ready To Review - [MouseWithoutBorders] - incremental code cleanup / refactor (#44553)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

Some focussed refactoring / simplifying / cleanup / delinting on the
Mouse Without Borders codebase (see [#44508 - [Mouse Without Borders] -
de-linting
codebase](https://github.com/microsoft/PowerToys/issues/44508)) now that
the Common class has been broken down.

This PR does some cleaning up on the ```Logger``` class:

* Uplifting coding style (string interpolation, pattern matching,
```var```, etc)
* Rationalising and simplifying code
* Relocating e.g. IO and UI side effects (writing to disk, displaying
dialog boxes) outside of Logger class
* Removing dead code, tightening visibility of existing code
* Added / updated tests to try to cover as much of the refactoring as
possible to prevent regressions

I've split the changes into lots of small commits - it might be easier
to review the individual commits rather than the whole PR in one go.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

### Run manual tests from [Test Checklist
Template](5bc7201ae2/doc/releases/tests-checklist-template.md (mouse-without-borders)):

* Install PowerToys on two PCs in the same local network:
   - [x]     Verify that PowerToys is properly installed on both PCs.
   - [x]     Configure Windows Firewall Rules
- ```netsh advfirewall firewall add rule
name="PowerToys.MouseWithoutBorders - mc" dir=in action=allow
program="C:\src\mc\PowerToys\x64\Debug\PowerToys.exe" enable=yes
remoteip=any profile=any protocol=tcp```
   
 * Setup Connection:
- [x] Open MWB's settings on the first PC and click the "New Key"
button. Verify that a new security key is generated.
- [x] Copy the generated security key and paste it in the corresponding
input field in the settings of MWB on the second PC. Also enter the name
of the first PC in the required field.
- [x] Press "Connect" and verify that the machine layout now includes
two PC tiles, each displaying their respective PC names.
   
 * Verify Connection Status:
- [x] Ensure that the border of the remote PC turns green, indicating a
successful connection.
- [x] Enter an incorrect security key and verify that the border of the
remote PC turns red, indicating a failed connection.
   
 * Test Remote Mouse/Keyboard Control:
- [x] With the PCs connected, test the mouse/keyboard control from one
PC to another. Verify that the mouse/keyboard inputs are correctly
registered on the other PC.
- [ ] Test remote mouse/keyboard control across all four PCs, if
available. Verify that inputs are correctly registered on each connected
PC when the mouse is active there.
     - unable to test - only 2 machines available
   
 * Test Remote Control with Elevated Apps:
- note - the main PowerToys.exe must be running as a **non**-admin for
these tests
- [x] Open an elevated app on one of the PCs. Verify that without "Use
Service" enabled, PowerToys does not control the elevated app.
- [x] Enable "Use Service" in MWB's settings (need to run PowerToys.exe
as admin to enable "Use Service", then restart PowerToys.exe as
non-admin). Verify that PowerToys can now control the elevated app
remotely. Verify that MWB processes are running as LocalSystem, while
the MWB helper process is running non-elevated.
- ```get-process -Name "PowerToys.MouseWithoutBorders*" -IncludeUserName
| format-table Id, ProcessName, UserName```
- [x] Process: ```PowerToys.MouseWithoutBorders.exe``` - running as
```SYSTEM```
- [x] Process: ```PowerToys.MouseWithoutBorders.Helper.exe``` - running
as current user
- ```get-service -Name "PowerToys.*" | ft Status, Name, UserName;
get-ciminstance -Class "Win32_Service" -Filter "Name like 'PowerToys%'"
| ft ProcessId, Name```
- [ ] Service: ```PowerToys.MWB.Service``` - running as ```Local
System```
- [x] Toggle "Use Service" again, verify that each time you do that, the
MWB processes are restarted.
- [ ] Run PowerToys elevated on one of the machines, verify that you can
control elevated apps remotely now on that machine.

* Test Module Enable Status:
- [ ] For all combinations of "Use Service"/"Run PowerToys as admin",
try enabling/disabling MWB module and verify that it's indeed being
toggled using task manager.
   
 * Test Disconnection/Reconnection:
- [ ] Disconnect one of the PCs from network. Verify that the machine
layout updates to reflect the disconnection.
   - [ ]     Do the same, but now by exiting PowerToys.
   - [ ]     Start PowerToys again, verify that the PCs are reconnected.
  
 * Test Various Local Network Conditions:
- [ ] Test MWB performance under various network conditions (e.g., low
bandwidth, high latency). Verify that the tool maintains a stable
connection and functions correctly.

 * Clipboard Sharing:
- [ ] Copy some text on one PC and verify that the same text can be
pasted on another PC.
- [ ] Use the screenshot key and Win+Shift+S to take a screenshot on one
PC and verify that the screenshot can be pasted on another PC.
- [ ] Copy a file in Windows Explorer and verify that the file can be
pasted on another PC. Make sure the file size is below 100MB.
- [ ] Try to copy multiple files and directories and verify that it's
not possible (only the first selected file is being copied).
 
 * Drag and Drop:
- [ ] Drag a file from Windows Explorer on one PC, cross the screen
border onto another PC, and release it there. Verify that the file is
copied to the other PC. Make sure the file size is below 100MB.
- [ ] While dragging the file, verify that a corresponding icon is
displayed under the mouse cursor.
- [ ] Without moving the mouse from one PC to the target PC, press
CTRL+ALT+F1/2/3/4 hotkey to switch to the target PC directly and verify
that file sharing/dropping is not working.

 * Lock and Unlock with "Use Service" Enabled:
   - [ ]     Enable "Use Service" in MWB's settings.
- [ ] Lock a remote PC using Win+L, move the mouse to it remotely, and
try to unlock it. Verify that you can unlock the remote PC.
- [ ] Disable "Use Service" in MWB's settings, lock the remote PC, move
the mouse to it remotely, and try to unlock it. Verify that you can't
unlock the remote PC.

 * Test Settings:
- [ ] Change the rest of available settings on MWB page and verify that
each setting works as described.

### Group Policy Tests

See https://learn.microsoft.com/en-us/windows/powertoys/grouppolicy

- [ ] Install *.admx / *.adml and check settings behave as expected
  - [ ] I'll expand the list of settings here when I get this far :-)
- [ ] HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys
  - [x]     ConfigureEnabledUtilityMouseWithoutBorders
- [x] ```[missing]``` - "Activation -> Enable Mouse Without Borders"
enabled, with GPO warning hidden
- ```reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v
ConfigureEnabledUtilityMouseWithoutBorders /f```
- [x] ```0``` - "Activation -> Enable Mouse Without Borders" set to
"off" and disabled, with GPO warning visible
- ```reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v
ConfigureEnabledUtilityMouseWithoutBorders /t REG_DWORD /d 0 /f```
- [x] ```1``` - "Activation -> Enable Mouse Without Borders" set to "on"
and disabled, with GPO warning visible
- ```reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v
ConfigureEnabledUtilityMouseWithoutBorders /t REG_DWORD /d 1 /f```
  - [ ] MwbClipboardSharingEnabled
  - [ ] MwbFileTransferEnabled
  - [ ] MwbUseOriginalUserInterface
  - [ ] MwbDisallowBlockingScreensaver
  - [ ] MwbSameSubnetOnly
  - [ ] MwbValidateRemoteIp
  - [x]     MwbDisableUserDefinedIpMappingRules
- [x] ```[missing]``` - "Advanced Settings -> IP address mapping"
enabled, with GPO warning hidden
- ```reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v
MwbDisableUserDefinedIpMappingRules /f```
- [x] ```0``` - "Advanced Settings -> IP address mapping" enabled, with
GPO warning hidden
- ```reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v
MwbDisableUserDefinedIpMappingRules /t REG_DWORD /d 0 /f```
- [x] ```1``` - "Advanced Settings -> IP address mapping" disabled, with
GPO warning visible
- ```reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v
MwbDisableUserDefinedIpMappingRules /t REG_DWORD /d 1 /f```
  - [x]     MwbPolicyDefinedIpMappingRules
- [x] ```[missing]``` - "Advanced Settings -> IP address mapping"
enabled, with GPO warning and GPO values hidden
- ```reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v
MwbPolicyDefinedIpMappingRules /f```
- [x] ```[empty value]``` - "Advanced Settings -> IP address mapping"
enabled, with GPO warning hidden and GPO values hidden
- ```reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v
MwbPolicyDefinedIpMappingRules /t REG_MULTI_SZ /d "" /f```
- [x] ```[non-empty value]``` - "Advanced Settings -> IP address
mapping" enabled, with GPO warning visible and GPO values visible
- ```reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\PowerToys /v
MwbPolicyDefinedIpMappingRules /t REG_MULTI_SZ /d "aaa 10.0.0.1\0bbb
10.0.0.2" /f```
2026-05-26 14:54:15 +08:00
Niels Laute
b3bf154fa5 [General] Update issue tracker's duplicate resolution message (#47981)
Reopens the change from #46743 (which appears to be broken) on a fresh
branch.

Original author: @daverayment

## Summary

GitHub newcomers can be confused by the current duplicate resolution
message, as it doesn't clearly point to the original referenced issue -
see
https://github.com/microsoft/PowerToys/issues/46347#issuecomment-4103681050.
They may not realise that the #12345 in the duplicate comment is the
relevant link.

This small wording update to the duplicate resolution message tightens
up wording slightly and includes reference to the prior `/dup #nnn`
comment so newcomers don't miss it.

### Before
> Hi! We've identified this issue as a duplicate of another one that
already exists on this Issue Tracker. This specific instance is being
closed in favor of tracking the concern over on the referenced thread.
Thanks for your report!

### After
> We've identified this issue as a duplicate of an existing one and are
closing this thread so discussion stays in one place.<br/><br/>Please
see the comment above for the link to the original tracking issue, and
feel free to subscribe there for updates.

## Validation Steps Performed
N/A - bot reply text change only.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-26 13:44:34 +08:00
Niels Laute
ab553f9930 [CmdPal][PerfMon] Use distinct up/down arrow icons for network Send/Receive (#48118)
## Summary of the Pull Request

On the Command Palette Performance Monitor extension's Network widget
page, the **Send** and **Receive** list items both used the generic
`NetworkIcon` (`\uEC05`), making them visually indistinguishable at a
glance.

This PR gives each direction its own glyph:
- Send → up arrow `\uE74A`
- Receive → down arrow `\uE74B`

The redundant `↑`/`↓` characters are removed from the Send/Receive
subtitles since the icons now carry that meaning.

Before vs after:

<img width="918" height="122" alt="image"
src="https://github.com/user-attachments/assets/4af3a2fc-d5a7-4fb5-98c6-f1889c7e80f2"
/>


## PR Checklist

- [x] **Closes:** N/A (no existing issue found)
- [x] **Communication:** I've discussed this with collaborators
- [x] **Tests:** Manually verified
- [x] **Localization:** Updated en-US resw (other locales still contain
the arrow characters and can be translated/updated by the loc pipeline)

## Detailed Description of the Pull Request / Additional comments

Files changed:
- `Icons.cs` – added `NetworkUpIcon` and `NetworkDownIcon`
- `PerformanceWidgetsPage.cs` – set `Icon` on `_networkUpItem` and
`_networkDownItem`
- `Strings/en-US/Resources.resw` – `Send ↑` → `Send`, `Receive ↓` →
`Receive`

## Validation Steps Performed

Local visual verification in Command Palette.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-26 06:29:00 +02:00
Gordon Lam
85b9191b7c [AdvancedPaste] Harden ToJsonFromXmlOrCsvAsync against clipboard read failures (#48124)
## Summary

`ToJsonFromXmlOrCsvAsync` in `AdvancedPaste/Helpers/JsonHelper.cs`
documents that it never throws and returns an empty string on any
failure. The clipboard read at the top of the method
(`clipboardData.GetTextAsync()`) was not wrapped, so a transient
clipboard failure could surface as an exception to callers, contrary to
the documented contract.

This PR:

- Wraps `GetTextAsync()` in a try/catch and returns `string.Empty` on
failure, matching the pattern already used by the JSON/XML/CSV parsing
branches further down in the same method.
- Updates the matching unit test to decode input bytes as UTF-8
(`Encoding.UTF8.GetString(input)`) and consume the awaited task via
`GetAwaiter().GetResult()`, for consistency with sibling tests elsewhere
in the solution.

## Validation

- Local build of `AdvancedPaste.sln`. (Note: my machine has a
pre-existing NuGet SDK resolver issue unrelated to this change — the
same baseline fails on `main` for me. CI should be the source of truth.)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-26 10:59:24 +08:00
Marcello Morena
cb174210cb Add CmdPal debugging information (#48108)
## Summary of the Pull Request
Adding information about using the Command Palette Visual Studio
solution filter based on
https://github.com/microsoft/PowerToys/issues/47997#issuecomment-4524045763.

## PR Checklist

- [ ] Closes: #47997 

## Detailed Description of the Pull Request / Additional comments
I found this really useful and couldn't see a reference to it anywhere
else in the devdocs. Not sure if this is the best way to describe the
process, but I think adding this information somewhere in the debugging
doc would really help newcomers to CmdPal development!
2026-05-25 17:32:57 +00:00
moooyo
f175a9c96a [PowerDisplay] Confirm before enabling module; log EdidId in Phase 0 (#48111)
## Summary of the Pull Request

Two crash-correlation aids for the kernel-side DDC/CI BSOD mitigated by
#47734:

1. Log EDID hardware ID (manufacturer + product code, e.g. `DELD1A8`)
during Phase 0 monitor classification, before any DDC/CI capability
fetch enters the BSOD risk window.
2. Show a confirmation dialog before turning the Power Display module on
from the Settings page, so the user understands the BSOD risk before the
first capability fetch runs.

## PR Checklist

- [ ] Closes: #xxx
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

## Detailed Description of the Pull Request / Additional comments

### 1. Phase 0 EdidId logging

`MonitorIdentity.EdidIdFromDevicePath` parses the EDID hardware ID
segment from a DevicePath of the form
``\?\DISPLAY#DELD1A8#5&abc&0&UID12345#{guid}`` and returns ``DELD1A8``.
The 3-letter PNP manufacturer code + 4-hex product code is identical for
every physical unit of the same model, so it identifies the *model*
without leaking per-unit identifiers.

`MonitorManager` logs the EdidId on the existing Phase 0 classification
line. Phase 0 uses `QueryDisplayConfig`, which reads OS-cached EDID and
cannot BSOD, so this line is guaranteed on disk before the crash-prone
Phase 2 capability fetch starts. If a machine crashes during
enumeration, the recovered log identifies every attached model
(including same-model duplicates), which makes it possible to correlate
crash reports to specific monitor models even when the user can't tell
us which monitor caused the crash.

### 2. Enable-module confirmation dialog

`PowerDisplayViewModel.IsEnabled` setter is refactored to follow the
same two-phase pattern already used by `MaxCompatibilityMode`:

- `false → true` does not commit immediately; it kicks off
`ConfirmAndEnableModuleAsync`, which awaits the existing
`DangerousFeatureWarningDialog` (resource prefix
`PowerDisplay_EnableModule`) and either commits or reverts the
ToggleSwitch via `OnPropertyChanged`.
- `true → false` commits unconditionally — we never block a user who
wants to turn the module off.
- App-startup loads via `InitializeEnabledValue()` /
`RefreshEnabledState()` assign the `_isEnabled` field directly,
bypassing the setter, so the dialog never fires on settings restore or
GPO refresh.
- GPO-configured state still short-circuits before any dialog logic.

The dialog reuses the existing `DangerousFeatureWarningDialog` injected
by `PowerDisplayPage.xaml.cs`. The 5 new `PowerDisplay_EnableModule_*`
strings explain that the BSOD is in Windows (not Power Display), that
Power Display will auto-disable itself after a detected crash, and that
the user has to re-enable + dismiss the warning each time.

## Validation Steps Performed

- Built `src/settings-ui` and `src/modules/powerdisplay` locally.
- Unit tests: added `EdidIdFromDevicePath_*` cases to
`MonitorIdentityTests`, all green.
- Settings UI manual: toggling Power Display ON now shows the warning
dialog. Pressing Cancel reverts the ToggleSwitch visually; pressing
Enable commits and the module starts. Toggling OFF does not prompt.
Restarting Settings UI with PowerDisplay enabled does not prompt.
GPO-disabled state still locks the toggle.
- Log inspection: `MonitorManager` Phase 0 log now shows `EdidId=...`
for each path before any capability fetch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 09:08:26 +00:00
moooyo
273d735a8b [PowerDisplay] Confirm before enabling module; log EdidId in Phase 0 (#48111)
## Summary of the Pull Request

Two crash-correlation aids for the kernel-side DDC/CI BSOD mitigated by
#47734:

1. Log EDID hardware ID (manufacturer + product code, e.g. `DELD1A8`)
during Phase 0 monitor classification, before any DDC/CI capability
fetch enters the BSOD risk window.
2. Show a confirmation dialog before turning the Power Display module on
from the Settings page, so the user understands the BSOD risk before the
first capability fetch runs.

## PR Checklist

- [ ] Closes: #xxx
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

## Detailed Description of the Pull Request / Additional comments

### 1. Phase 0 EdidId logging

`MonitorIdentity.EdidIdFromDevicePath` parses the EDID hardware ID
segment from a DevicePath of the form
``\?\DISPLAY#DELD1A8#5&abc&0&UID12345#{guid}`` and returns ``DELD1A8``.
The 3-letter PNP manufacturer code + 4-hex product code is identical for
every physical unit of the same model, so it identifies the *model*
without leaking per-unit identifiers.

`MonitorManager` logs the EdidId on the existing Phase 0 classification
line. Phase 0 uses `QueryDisplayConfig`, which reads OS-cached EDID and
cannot BSOD, so this line is guaranteed on disk before the crash-prone
Phase 2 capability fetch starts. If a machine crashes during
enumeration, the recovered log identifies every attached model
(including same-model duplicates), which makes it possible to correlate
crash reports to specific monitor models even when the user can't tell
us which monitor caused the crash.

### 2. Enable-module confirmation dialog

`PowerDisplayViewModel.IsEnabled` setter is refactored to follow the
same two-phase pattern already used by `MaxCompatibilityMode`:

- `false → true` does not commit immediately; it kicks off
`ConfirmAndEnableModuleAsync`, which awaits the existing
`DangerousFeatureWarningDialog` (resource prefix
`PowerDisplay_EnableModule`) and either commits or reverts the
ToggleSwitch via `OnPropertyChanged`.
- `true → false` commits unconditionally — we never block a user who
wants to turn the module off.
- App-startup loads via `InitializeEnabledValue()` /
`RefreshEnabledState()` assign the `_isEnabled` field directly,
bypassing the setter, so the dialog never fires on settings restore or
GPO refresh.
- GPO-configured state still short-circuits before any dialog logic.

The dialog reuses the existing `DangerousFeatureWarningDialog` injected
by `PowerDisplayPage.xaml.cs`. The 5 new `PowerDisplay_EnableModule_*`
strings explain that the BSOD is in Windows (not Power Display), that
Power Display will auto-disable itself after a detected crash, and that
the user has to re-enable + dismiss the warning each time.

## Validation Steps Performed

- Built `src/settings-ui` and `src/modules/powerdisplay` locally.
- Unit tests: added `EdidIdFromDevicePath_*` cases to
`MonitorIdentityTests`, all green.
- Settings UI manual: toggling Power Display ON now shows the warning
dialog. Pressing Cancel reverts the ToggleSwitch visually; pressing
Enable commits and the module starts. Toggling OFF does not prompt.
Restarting Settings UI with PowerDisplay enabled does not prompt.
GPO-disabled state still locks the toggle.
- Log inspection: `MonitorManager` Phase 0 log now shows `EdidId=...`
for each path before any capability fetch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 09:08:06 +00:00
Copilot
bcf0b685ac [File Locksmith] Fix IPC text-mode file I/O corrupting Unicode paths (#47361)
## Summary of the Pull Request

The File Locksmith IPC layer reads and writes raw UTF-16 (WCHAR) bytes
to `last-run.log`, but all three stream opens were using the default
text mode. On Windows, the CRT translates `0x0A` bytes to `0x0D 0x0A` on
write and collapses `0x0D 0x0A` back to `0x0A` on read. Because each
WCHAR is 2 bytes, any code unit whose little-endian byte pair contains
`0x0A` in the low position (e.g. `U+010A`, `U+0A0D`) is silently
corrupted. The fix opens all three streams in binary mode and adds an
explicit open-failure guard.

```cpp
// IPC.cpp — Writer::start()
// Before
m_stream = std::ofstream(path);
// After
m_stream = std::ofstream(path, std::ios::binary);
// + is_open() guard returning E_FAIL on failure

// NativeMethods.cpp — StartAsElevated() writer
// Before
std::ofstream stream(paths_file());
// After
std::ofstream stream(paths_file(), std::ios::binary);

// NativeMethods.cpp — ReadPathsFromFile() reader
// Before
std::ifstream stream(paths_file());
// After
std::ifstream stream(paths_file(), std::ios::binary);
```

## PR Checklist

- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

## Detailed Description of the Pull Request / Additional comments

Three targeted changes across two files:

1. **`FileLocksmithLib/IPC.cpp` — `Writer::start()`**: switched
`std::ofstream` from text to binary mode and added an `is_open()` check
that returns `E_FAIL` immediately when the file cannot be opened
(previously the try/catch did not catch a silent open failure because
`std::ofstream` does not throw by default).

2. **`FileLocksmithLibInterop/NativeMethods.cpp` —
`StartAsElevated()`**: switched `std::ofstream` from text to binary
mode. This is the elevated-restart writer path; without this fix,
Unicode corruption persisted when File Locksmith relaunched as
administrator.

3. **`FileLocksmithLibInterop/NativeMethods.cpp` —
`ReadPathsFromFile()`**: switched `std::ifstream` from text to binary
mode. This is the symmetric reader-side bug — even with both writers
corrected, the CRT text-mode reader could collapse a `0x0D 0x0A` byte
pair (a valid UTF-16 LE code unit, e.g. U+0A0D GURMUKHI EK ONKAR) into a
single byte, desynchronising the 2-bytes-at-a-time read loop and
corrupting all subsequent path data.

No behaviour change for purely ASCII paths. Paths containing Unicode
code points whose little-endian UTF-16 byte pair spans `0x0D 0x0A` were
silently corrupted in all three code paths before this fix.

## Validation Steps Performed

- Code review: no issues flagged.
- Full diff reviewed: all three stream opens (`ofstream` writer in
`IPC.cpp`, `ofstream` writer in `NativeMethods.cpp`, `ifstream` reader
in `NativeMethods.cpp`) now use `std::ios::binary`, making write and
read paths byte-exact and symmetric.
- Mechanically correct: `std::ios::binary` suppresses Windows CRT
`\n`↔`\r\n` translation; the delimiter `L'\n'` (LE bytes `0x0A 0x00`) is
unambiguous in binary mode and is handled correctly by the existing read
loop.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
Co-authored-by: Muyuan Li (from Dev Box) <muyuanli@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-25 16:30:15 +08:00
Boliang Zhang
6a5e320749 [CI] Prune orphan tokens from check-spelling expect.txt (#48110)
## Problem

Since #47119 (`Refresh check-spelling 0.0.26`, merged 2026-04-23)
refreshed the check-spelling tooling and rewrote
`.github/actions/spell-check/expect.txt` (938 lines / 633 deletions),
the check-spelling bot has been leaving a noisy advisory comment on
**every PR**:

> #### These words are not needed and should be removed
> ABlocked AClient AColumn ACR ADate ADifferent AHybrid ALarger
AModifier ANull AOklab APeriod ARandom ARemapped ASingle ASUS bck …

The same ~150-word list is appended verbatim to every PR the bot looks
at (verified against #48058, #48102, #48104 — the list is identical).
These tokens are residual orphans in `expect.txt` from before the 0.0.26
refresh and no longer match anything in source.

## Fix

Removes exactly the 147 orphan tokens that the bot has consistently
flagged as `now absent` from `.github/actions/spell-check/expect.txt`.
The removed tokens are exclusively the ones the bot itself identified.

All uppercase Win32 / DirectWrite identifiers that are still used in
source (`DWRITE`, `LWIN`, `VCENTER`, `VREDRAW`, etc.) are **preserved**.

## Verification

- Diff is a single file, deletions only: `expect.txt` shrinks from 2343
→ 2196 lines.
- Each of the 4 uppercase Win32 tokens (`DWRITE` line 514, `LWIN` 1074,
`VCENTER` 2105, `VREDRAW` 2144 in the original) remains in the file.
- The check-spelling job on this PR should now post a clean report (no
`should be removed` block).

## Background — which PR introduced the drift

| PR | Date | What it changed |
|----|------|-----------------|
| **#47119** | 2026-04-23 | Refreshed check-spelling to 0.0.26; rewrote
`expect.txt` with 938 line-changes (633 deletions, 305 additions). The
duplicated lowercase/uppercase entries and many obsolete tokens
originate here. |

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <Copilot@users.noreply.github.com>
2026-05-25 16:29:42 +08:00
Michael Jolley
83285e929a CmdPal: Enable entrance animation for End dock bands (#48099)
## Summary

Fixes #46767

Items pinned to the End section of the dock did not animate on startup,
while Start and Center items did. The EndListView had an explicit empty
`ItemContainerTransitions` collection that suppressed all container
transitions. Removing it allows the default WinUI entrance animations to
play, matching Start and Center behavior.

## Changes

- `DockControl.xaml`: Remove empty `TransitionCollection` override from
EndListView

---------

Co-authored-by: root <root@io.bbq>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-25 08:31:09 +02:00
Boliang Zhang
26108ff04b [CI] Sign PowerAccent.Common.dll (new managed library from #47211) (#48058)
## Summary

Fixes the **stable** signed release pipeline failure (Dart build
[`147621162`](https://microsoft.visualstudio.com/Dart/_build/results?buildId=147621162))
at the *"Verify all binaries are signed and versioned"* task:

```
Not Signed: + …\extractedMachineMsi\File\BaseApplicationsFiles_File_PowerAccent.Common.dll
```

## Root cause

PR #47211 (*"[Quick Accent] Move language data to PowerAccent.Common
library, refactor"*) introduced the new managed library:

- `src/modules/poweraccent/PowerAccent.Common/PowerAccent.Common.csproj`

`PowerAccent.Common.dll` is referenced by both `PowerAccent.Core` (ships
in the installer root) and `PowerToys.Settings` (ships in WinUI3Apps;
deduplicated against root by `generateAllFileComponents.ps1`). The DLL
is harvested into the MSI's `BaseApplicationsFiles` component group, but
the PR did not update `.pipelines/ESRPSigning_core.json`, so ESRP never
signs it and `versionAndSignCheck.ps1` correctly fails the build.

This is the same kind of omission that PR #48050 fixed for
`YamlDotNet.dll` introduced by #40834 — a new managed library shipping
in the MSI without a matching signing config entry.

## Fix

One additive line in `.pipelines/ESRPSigning_core.json`, placing
`"PowerAccent.Common.dll"` inside the existing alphabetized PowerAccent
block (next to `PowerAccent.Core.dll`).

```diff
             "PowerAccent.Core.dll",
+            "PowerAccent.Common.dll",
             "PowerToys.PowerAccent.dll",
```

## Validation

- `git diff` shows exactly one additive line.
- File still parses as valid JSON (`ConvertFrom-Json` round-trip OK).
- Audited the full file list of PR #47211: `PowerAccent.Common.dll` is
the only new shippable assembly it added (the other new project,
`PowerAccent.Common.UnitTests`, is a test project and is not included in
the installer).
- Dedup logic in
`installer/PowerToysSetupVNext/generateAllFileComponents.ps1` keeps only
the root copy when WinUI3Apps and root copies are byte-identical, so a
single root-level entry is sufficient.

## Follow-up

After merge to `main`, cherry-pick / merge into `stable` to unblock the
0.100 release pipeline. This is the third (and hopefully final) PR in
the 0.100 release-pipeline unblock sequence, after #48050 (sign
`YamlDotNet.dll`) and #48054 (remove duplicate
`QuickAccent_SelectedLanguage_Greek_Polytonic` resource).

Co-authored-by: Copilot <Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-25 11:43:17 +08:00
Noraa Junker
fed9e81fdc [Shortcut Guide V2] Fixes (#48043)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

* Fix wrong Shortcut for Shortcut Guide V2 (previously always showed
default)
* Fix outdated OOBE description
* Fix process not stopping when exiting via ESC or close button
* Fixed some missing modules
* Removed regex capability and was able to improve the start up time
through this

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-05-24 18:08:54 +08:00
Mike Griese
f998c38ac8 cmdpal: fix an AOT-only crash loading the extension page (#48065)
Okay I'll admit this is a clanker fix. 

There's currently a crash when you navigate to an individual extension
page, that only repro's in Release/AOT. And because of
release&trimming&AOT reasons, that's very very difficult to diagnose.
But the clanker added a shitload of logging, and was able to figure out
that:

We were binding to this `Screenshots` collection. Problem is that we
can't safely bind to an `IReadOnlyList` in trimmed scenarios. C#/AOT is
a wonderful world of horrors.

Fixing this is as simple as swapping it for a `ObservableCollection`.
2026-05-23 05:56:14 -05:00
Mike Griese
11083c9fb2 CmdPal: Successfully open when opened on other displays (#48061)
When we were docked on a screen other than the primary display, then
clicking on a dock item that was a `IPage` would result in the palette
window just not showing up at all.

The fix is to make sure that we use the actual position of the current
monitor in the calculation of the final position of the palette HWND.
2026-05-23 05:55:51 -05:00
Boliang Zhang
809601a33c [CmdPal] Add stable AutomationIds across XAML for UI testing (#48033)
## Summary

Adds **77 explicit `AutomationProperties.AutomationId`** declarations (4
→ 81, ~20x) to Command Palette XAML so UI-testing tools (WinAppDriver,
FlaUI, winappCli, Appium) can address controls deterministically instead
of falling back to runtime slugs that change every session. Also covers
the `DataTemplate`-generated long tail (search results, file results,
every extension item, every monitor in Dock settings) by binding
`AutomationId` to existing stable model identifiers via `{x:Bind}`.

Headline: a one-line addition to the four CmdPal `ListItem`
`DataTemplate`s now exposes each instance's underlying `Command.Id`
(e.g. `com.microsoft.cmdpal.builtin.calculator`) as its `AutomationId`.
This is the same pattern as web's `<li data-testid={item.id}>`.

## Why

CmdPal today ships with only **4** explicit
`AutomationProperties.AutomationId` declarations across **44** XAML
files (~303 interactive controls). UI tests are forced to fall back to:

- runtime-generated slugs like `itm-12-9dda` that change every CmdPal
restart, or
- regex-parsing the text output of `winappCli ui inspect`, or
- walking the UIA tree client-side and matching by `Name` (localized,
ambiguous when several controls share a label).

## What changed

### Source changes
- **`Microsoft.CmdPal.UI/ExtViews/ListItemsView.xaml`** — bind
`AutomationProperties.AutomationId="{x:Bind Command.Id, Mode=OneWay}"`
on the root of all 4 `ListItem` `DataTemplate`s (single-row, small-grid,
medium-grid, gallery). Covers **every** runtime list item across all
built-in and third-party providers.
- **`Microsoft.CmdPal.UI/Settings/GeneralPage.xaml`** — 14 IDs on
activation hotkey controls, auto-go-home combo, behaviour toggles,
about-section hyperlinks.
- **`Microsoft.CmdPal.UI/Settings/AppearancePage.xaml`** — 19 IDs on
theme/backdrop/colorization, background image controls, 5 sliders,
behaviour toggles.
- **`Microsoft.CmdPal.UI/Settings/DockSettingsPage.xaml`** — 14 IDs on
enable toggle, theme/colorization/backdrop, background image controls,
plus per-monitor data-bound ID using `DisplayName`.
- **`Microsoft.CmdPal.UI/Settings/ExtensionsPage.xaml`** — 4 IDs on
banner/store hyperlinks plus the per-provider `SettingsCard` (data-bound
to the provider's `Id`, e.g. `com.microsoft.cmdpal.builtin.calculator`).
- **`Microsoft.CmdPal.UI/Settings/ExtensionPage.xaml`** — 5 IDs on
provider enable toggle, alias text/activation, fallback rank link.
- **`Microsoft.CmdPal.UI/Settings/ExtensionGalleryItemPage.xaml`** — 5
IDs on install/cancel/copy-command buttons and author/repo/uninstall
links.
- **`Microsoft.CmdPal.UI/Settings/InternalPage.xaml`** — 7 IDs on the
dev-only "Throw exception" and folder/log-opening buttons.
- **`Microsoft.CmdPal.UI/Pages/ShellPage.xaml`** — 1 data-bound ID on
the `CommandTemplate` button (binds to `CommandViewModel.Id`).
- **`Microsoft.CmdPal.UI.ViewModels/ProviderSettingsViewModel.cs`** —
single-line addition exposing the underlying `CommandProviderWrapper.Id`
so the ExtensionsPage template can bind to it.

### Naming convention applied

`CmdPal_<Page>_<Semantic>` PascalCase, with the existing well-known IDs
left untouched to avoid breaking the `modules/cmdpal/*` checklist tests
already referencing them. `Id` / `TestId` suffixes deliberately omitted
(the attribute is already `AutomationId`); control-type suffixes
(`Toggle` / `Button` / `ComboBox`) omitted because the type lives on the
UIA `type` field already.

### Files NOT touched (deferred)

About 5–7 secondary files (`SettingsWindow.xaml`,
`ExtensionGalleryPage.xaml`, `DockControl.xaml`, `DevRibbon.xaml`, deep
style/viewer XAML) — their interactive controls already carry `x:Name`,
which WinUI auto-promotes to `AutomationId` at runtime, so practical
testability is mostly already there. Can be tightened up in a follow-up
PR.

## Risk

-  Zero runtime cost (`AutomationProperties.AutomationId` is metadata
only)
-  Does not affect localization (`AutomationId` is non-localized by
design)
-  Does not affect user-facing accessibility (screen readers consume
`Name` / `AutomationProperties.Name`, untouched)
-  Does not rename any existing ID; `modules/cmdpal/*` tests
referencing `MainSearchBox` / `PrimaryCommandButton` / `ItemsList` /
etc. remain valid
-  All 51 CmdPal XAML files parse as valid XML (PowerShell `[xml]`
round-trip)
-  All `x:Bind` paths verified against the relevant ViewModel types
(`CommandViewModel.Id`, `DockMonitorConfigViewModel.DisplayName`,
`ProviderSettingsViewModel.Id`)

## Validation requested before merge

XAML compilation was attempted locally but blocked by a missing native
NuGet package (`Microsoft.Windows.ImplementationLibrary`) — needs
`tools\build\build-essentials.cmd` to fully restore first. **Reviewer
please run a clean local build of `Microsoft.CmdPal.UI` (or rely on CI)
to confirm the XAML compiler is happy.**

Once built, a quick smoke check:

```powershell
# After CmdPal restart with the new bits installed:
winapp ui search 'CmdPal_'           -w <hwnd> --json  # should list all the new IDs
winapp ui invoke 'CmdPal_AppearancePage_OpenCommandPalette' -w <hwnd>
winapp ui invoke 'com.microsoft.cmdpal.builtin.calculator' -w <hwnd>   # ListItem template binding
```

## Why this matters beyond our tools

This is the same pattern Microsoft's accessibility and WinUI teams
already recommend for any XAML app intended to be automated. It's the
WinUI equivalent of adding `data-testid` in a web app — universally
accepted as low-risk, high-leverage. WinAppDriver, FlaUI, Appium and any
future automation framework all benefit from the same change.
2026-05-22 21:42:19 -05:00
Mike Griese
2c9481e69a cmdpal: update template project to 0.11 SDK (#48066)
title
2026-05-22 21:09:06 -05:00
Boliang Zhang
1d0917d06f [CI] Sign YamlDotNet.dll (ShortcutGuide V2 dependency) (#48050)
## Summary

Fixes the **stable** signed release pipeline failure (Dart build
[`147590319`](https://microsoft.visualstudio.com/Dart/_build/results?buildId=147590319))
at the *"Verify all binaries are signed and versioned"* task on both
`Build Release_x64` and `Build Release_arm64`:

```
Not Signed: + …\extractedMachineMsi\File\WinUI3ApplicationsFiles_File_YamlDotNet.dll
```

## Root cause

PR #40834 (*Shortcut Guide V2*) added a `YamlDotNet` `PackageReference`
to:

- `src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuide.Ui.csproj`
-
`src/modules/ShortcutGuide/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator.csproj`

Both projects publish into `WinUI3Apps\`, so `YamlDotNet.dll` is
harvested into the MSI by
`installer/PowerToysSetupVNext/generateAllFileComponents.ps1`. The PR
updated `ESRPSigning_core.json` for its own new binaries but missed this
3rd-party transitive dependency, so ESRP never signs it and
`.pipelines/versionAndSignCheck.ps1` correctly fails the build.

## Fix

One additive line to `.pipelines/ESRPSigning_core.json`, placing
`WinUI3Apps\YamlDotNet.dll` next to the other 3rd-party `WinUI3Apps\`
entries (`Google.Apis.*`, `Google.GenAI.dll`, `ReverseMarkdown.dll`,
`SharpCompress.dll`, …).

## Validation

- `git diff` shows exactly one additive line.
- File still parses as valid JSON (`ConvertFrom-Json` round-trip OK).
- Both ShortcutGuide csprojs target
`$(Platform)\$(Configuration)\WinUI3Apps`, so a single
`WinUI3Apps\YamlDotNet.dll` entry covers all uses.

## Follow-up

After merge to `main`, cherry-pick / merge into `stable` so build
`147590319` can be re-queued and the 0.100 release pipeline can proceed.

Co-authored-by: Copilot <Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-22 15:43:42 +00:00
moooyo
4edfcee87e [Power Display] Built-in monitor blacklist to mitigate DDC/CI BSOD (#47556, #47968) (#48051)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

Adds a built-in monitor blacklist that skips known-bad monitor models at
the DDC/CI discovery stage — before PowerDisplay sends any capabilities
request to the firmware. Matches by EdidId (the PnP manufacturer +
product code from EDID). Two entries pre-populated from existing crash
reports:

| EdidId | Reported in | Notes |

|-----------|-------------|------------------------------------------------------------------------|
| `LTM2C02` | #47556 | Counterfeit-EDID LG 27MR400 (PnP claims Litemax
40" 2011, actual hw is LG 27" 2024) |
| `GSM7714` | #47968 | LG UltraWide HDR WFHD |

Also logs `[EdidId=…] [FriendlyName=…] [DevicePath=…]` immediately
before each `GetCapabilitiesString*` syscall in `DdcCiController`. If
the kernel call BSODs (`win32kfull` stack-cookie overrun), that is the
last log line that survives — adding a new blacklist entry then takes
one PR to `BuiltInMonitorBlacklist.json` instead of a memory-dump
triage.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Mitigates: #47556
- [x] Mitigates: #47968
- [x] **Communication:** This is the "Add blacklist and prevent the API
call on broken monitor" mitigation outlined in [#47556
(comment)](https://github.com/microsoft/PowerToys/issues/47556#issuecomment-4505498427).
The underlying `win32kfull!DdcciGetCapabilitiesStringFromMonitor` stack
overrun is tracked separately by the Windows team.
- [x] **Tests:** 6 new MSTest unit tests under
`PowerDisplay.Lib.UnitTests`. All 120 PowerDisplay tests pass on x64
Debug.
- [ ] **Localization:** N/A — this PR ships no end-user-facing strings
(no UI surface).
- [ ] **Dev docs:** N/A.
- [ ] **New binaries:** N/A. Data ships as an `<EmbeddedResource>`
inside the existing `PowerDisplay.Models.dll`; no new .dll, no installer
change.
- [ ] **Documentation updated:** N/A.

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

### Threat model

Some retail monitor firmwares ship non-conformant DDC/CI capabilities
strings — typically oversized, not NUL-terminated, or otherwise
malformed. When PowerDisplay calls `GetCapabilitiesStringLength` /
`CapabilitiesRequestAndCapabilitiesReply` on these monitors, the request
flows into
`win32kfull!CPhysicalMonitorHandle::DdcciGetCapabilitiesStringFromMonitor`,
which copies the reply into a stack buffer without bounding the length.
The kernel detects its own stack cookie corruption on the epilogue check
and `__fastfail`s with `BUGCHECK 0x139 / 2
(STACK_COOKIE_CHECK_FAILURE)`.

The kernel-side overrun is a Windows defect, not PowerDisplay's, but
PowerDisplay is currently the most widely deployed consumer of this API
on hot-plug. Until the Windows team fixes the kernel, the only safe
mitigation in user space is to **never call** the capabilities API on
monitor models known to trigger it.

### Architecture

| File | Role |
|---|---|
| `PowerDisplay.Models/MonitorBlacklistEntry.cs` | POCO: `{ edidId,
comments }` |
| `PowerDisplay.Models/BuiltInMonitorBlacklist.json` | Data file
(embedded resource) |
| `PowerDisplay.Models/BuiltInMonitorBlacklist.cs` | Lazy-loaded reader,
AOT-safe (source-gen `JsonSerializerContext`); silent fallback to empty
list on any IO/parse failure |
| `PowerDisplay.Lib/Services/MonitorBlacklistService.cs` |
`IsBlocked(monitorId)` — extracts EdidId via
`MonitorIdentity.EdidIdFromMonitorId`, checks a `HashSet<string>` with
`OrdinalIgnoreCase` |
| `PowerDisplay/Helpers/MonitorManager.cs` | Filters QueryDisplayConfig
inventory by EdidId **before** any controller (DDC/CI or WMI) is
dispatched; logs each skip with `[MonitorBlacklist] Skipping ...` |
| `PowerDisplay.Lib/Drivers/DDC/DdcCiController.cs` | Logs EdidId +
FriendlyName + DevicePath immediately before the first capabilities
syscall per-monitor |

Matching is **model-level granularity** (EdidId, e.g. `GSM7714`) rather
than device-level (full DevicePath). One entry covers every physical
port and every machine with the same monitor model.

### Adding new entries

Once the kernel overrun is fixed this list can shrink. Until then, when
a new BSOD surfaces:

1. User reports BSOD, attaches PowerDisplay log
2. The last line before the crash now reads `DDC: probing capabilities
[EdidId=XXXXXX] [FriendlyName='...'] [DevicePath=...]`
3. Add `{ "edidId": "XXXXXX", "comments": "See #issue" }` to
`BuiltInMonitorBlacklist.json`
4. Submit PR, ship in next release

### Scoped out (deliberate)

A user-customized blacklist surface (Settings UI dialog) was prototyped
and hit multiple WinUI 3 dialog parse / measure crashes inside a
`ContentDialog`. The custom-list code path was reverted in favor of
"built-in only" for v1 reliability. UI can be re-added later on top of
this foundation if needed — the data model and service already support
it.

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

1. **Unit tests:** `dotnet test` on `PowerDisplay.Lib.UnitTests` →
**120/120 pass** (including 6 new tests for loader + service: built-in
JSON loads, EdidIds are normalized to upper-case, no blank entries,
`Lazy<>` cache returns same instance, `IsBlocked` returns `false` for
empty built-in list and for unidentifiable monitor IDs).
2. **Clean x64 Debug build** via `tools\build\build-essentials.cmd` +
per-project `tools\build\build.cmd`:
   - `PowerDisplay.Models` — 0 warning, 0 error
   - `PowerDisplay.Lib` — 0 warning, 0 error
   - `PowerDisplay` (app) — 0 warning, 0 error
3. **Smoke test (manual):** launched PowerDisplay, confirmed every
connected monitor produces a `DDC: probing capabilities [EdidId=…]
[FriendlyName=…] [DevicePath=…]` log line right before its caps request.
4. **Empty-list case:** `BuiltInMonitorBlacklist.json` with no entries →
`IsBlocked` returns `false` for any input (verified via unit test).
5. **Non-empty case (manual):** temporarily added a connected monitor's
EdidId to the built-in JSON → that monitor disappears from
`MonitorManager.Monitors` and `[MonitorBlacklist] Skipping ...` log line
appears; removed the entry → monitor reappears, all per-monitor settings
intact.

---------

Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
2026-05-22 23:18:13 +08:00
Boliang Zhang
33cf6995fc [Settings UI] Remove duplicate QuickAccent_SelectedLanguage_Greek_Polytonic resource (#48054)
## Summary

Fixes the **"Build PowerToys main project"** failure on every PR/CI
build off current `main` (e.g. Dart build
[`147597426`](https://microsoft.visualstudio.com/Dart/_build/results?buildId=147597426)):

```
WINAPPSDKGENERATEPROJECTPRIFILE: Error PRI175: Processing Resources failed with error: Duplicate Entry.
WINAPPSDKGENERATEPROJECTPRIFILE: Error PRI277: Conflicting values for resource
                                  'Resources/QuickAccent_SelectedLanguage_Greek_Polytonic'
```

## Root cause

`src/settings-ui/Settings.UI/Strings/en-us/Resources.resw` contained two
`<data name="QuickAccent_SelectedLanguage_Greek_Polytonic">` entries:

- Line 3597 — original, added by #47021 (*"[PowerAccent] adding greek
polytonic"*), placed in the alphabetized QuickAccent block.
- Line 6175 — duplicate, appended at the file tail by #47211 (*"[Quick
Accent] Move language data to PowerAccent.Common library, refactor"*).

The two entries are byte-identical (same value `Greek Polytonic`, same
`xml:space="preserve"`). The WinAppSDK PRI generator (`MakePri`) rejects
duplicates, so every build off current `main` fails before reaching the
compile step.

## Fix

Remove the tail duplicate (3-line block right before `</root>`). Keeps
the original entry in its alphabetized location.

## Validation

- `git diff` shows exactly 3 deleted lines.
- `[xml](Get-Content … -Raw)` round-trip succeeds — file is still
well-formed XML.
- `Select-String` count of
`QuickAccent_SelectedLanguage_Greek_Polytonic` in the file is now **1**
(was 2).
- Only `en-us` has this key (other localized `.resw` files are populated
later via Touchdown), so no other file needs touching.

## Note

Discovered while investigating a CI failure unrelated to my other PR
#48050 (signing of `WinUI3Apps\YamlDotNet.dll`). Both fixes are needed
for the 0.100 release pipeline; this PR unblocks PR builds off `main`,
and #48050 unblocks the signed release pipeline once both are merged to
`main` and the next `main → stable` sync happens.

Co-authored-by: Copilot <Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-22 15:42:56 +02:00
Dave Rayment
81e251c2de [Quick Accent] Move language data to PowerAccent.Common library, refactor (#47211)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Language data for Quick Accent was previously defined in
**PowerAccent.Core/Languages.cs**, internal to the Quick Accent
application itself. The Settings application had no access to the list
and had to maintain a parallel, manually-synchronised list of the
language names and groups, and there was no single place to look up the
complete set of languages.

This PR resolves this and extracts the language data into a new
**PowerAccent.Common** project with no external or UI dependencies,
making it the single source of truth for both the character popup and
Settings UI.

The implicit and non-obvious ordering of the old **Languages.cs** has
been replaced with explicit ordering of the language groups and
languages list.

A new unit test project for the application has also been added.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #47159
- [x] Closes: #30000
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

The following changes and additions have been made:

New project **PowerAccent.Common** contains:

- **Language.cs** - an enum of Quick Accent's pseudo-ISO identifiers for
each of the supported languages
- **LetterKey.cs** - mirrors the LetterKey enum defined in the
KeyboardListener.idl, and must be kept in sync with that. This exposes
the VK_* data to the Settings UI without it having to reference the
PowerAccentKeyboardService project
- **LanguageGroup.cs** - classifies languages as `Language` (for spoken
languages), `Special` (for sets like Currency and International Phonetic
Alphabet), or `UserDefined` (reserved for future work)
- **LanguageInfo.cs** - a record which combines a language's identity,
group, resource identifier, and character mappings
- **CharacterMappings.cs** - a new version of the old **Languages.cs**,
providing:
    - `All` - the canonical registry of every `LanguageInfo` entry
- `DisplayOrder` - the explicit within-group ordering for languages, for
the default popup ordering, i.e. when the user has not got
frequency-based ordering enabled. This is a culturally-neutral
alphabetical ordering by our pseudo-ISO language IDs, and close to the
previous order, minimising any impact to users' muscle memory
- `GroupDisplayOrder` - the explicit ordering of language groups for
both the popup and the Settings UI
- `LanguageLookup` - new _O(1)_ `Language` to `LanguageInfo` dictionary
- `GetCharacters(LetterKey, Language[])` - a deduplicating character
collector and sorter

A significant improvement over the old **Languages.cs** is that language
ordering is now explicit and in one place. Previously, popup ordering
was an implicit side-effect of a large Union chain across all language
mappings, with the enum, the language mapping declarations and the union
all carrying different orderings. This was a source of confusion and
made adding new languages fragile.

The original **Languages.cs** has been deleted. There's now a thin
`CharacterMappings` adapter that casts the `LetterKey` to the managed
equivalent by numeric value. This is another effort to decouple the
Settings UI and Quick Accent and only share the required elements.

In Settings, the `PowerAccentViewModel` class has been updated. It now
derives the language list directly from `CharacterMappings.All`; the
`InitializeLanguages()` call handles localisation, sorting and grouping
in a single place using `GroupDisplayOrder`.

A new unit test project covers `CharacterMappings`, the `LetterKey`
IDL-to-managed code bridge and general language declaration checks. The
application is now much more robust against changes which alter the
declared order, introduce empty/null elements, and so on. It is now
impossible to add a new language and forget a constituent part (the enum
entry, its place in the display order, the character mappings
themselves) without a test failing.

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

See new unit test project for comprehensive tests.

Manually confirmed:

- Triggering Quick Accent with no language selected does not report an
error
- Language order is consistent in the popup, no matter what order the
languages are selected in Settings
- The order of languages in Settings is consistent, alphabetically by
localised name
- All declared languages are present in Settings and no resource IDs
were missed

---------

Co-authored-by: Muyuan Li (from Dev Box) <muyuanli@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-22 15:24:26 +08:00
Clint Rutkas
f02b66c88d Fix auto-update relaunch, add config backup, enable auto-download by default (#46889)
## Summary

Addresses three critical issues with the PowerToys update experience
that cause user fragmentation across old versions.

### Changes

**1. Fix relaunch after update (Fixes #42004, #43011, #44071)**
- Stage 1 now passes the PowerToys install directory to Stage 2 as an
argument
- After successful install, Stage 2 relaunches `PowerToys.exe` with
`-report_update_success`
- Users will see a 'successfully updated' toast and PT resumes
automatically

**2. Config backup/restore (Fixes #46179)**
- `BackupConfigFiles()` snapshots all JSON configs to `ConfigBackup/`
before update begins
- `RestoreCorruptedConfigs()` checks for null-byte corruption after
install and auto-restores
- Protects Workspaces, FancyZones, Keyboard Manager, and all other
module settings

**3. Enable auto-download by default**
- New installations default `AutoDownloadUpdates` to `true` (was
`false`)
- Existing users' preferences are preserved — this only affects
first-run defaults
- The runner already defaulted to `true`; this aligns the C# settings
model

### Why this matters

The current updater kills all PowerToys processes, runs the installer,
then **exits without relaunching**. Users lose keyboard remappings,
FancyZones layouts, and Awake settings with no indication why. Combined
with auto-download being off by default, most users are multiple
versions behind.

### Testing

- Verified update flow: Stage 1 → Stage 2 → PT relaunches with success
toast
- Config backup creates mirror of all JSON settings before update
- Corruption detection catches null-byte pattern from #46179
- Graceful fallback: if install dir not provided (old Stage 1), logs
warning but doesn't crash

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Muyuan Li (from Dev Box) <muyuanli@microsoft.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
2026-05-22 14:01:56 +08:00
Copilot
386fdcb1e9 [Shortcut Guide] Render key names instead of raw numeric key codes (#48037)
## Summary of the Pull Request

Shortcut Guide was rendering raw numeric key codes in key visuals for
some shortcuts (notably generated PowerToys shortcuts), showing numbers
where key characters/names were expected. This change normalizes numeric
key handling so display output matches actual key labels.

## PR Checklist

- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

## Detailed Description of the Pull Request / Additional comments

- **Scope**
- Updated `ShortcutDescriptionToKeysConverter` in `ShortcutGuide.Ui`
only.

- **Behavior change**
- Numeric key codes are no longer passed through as raw integers by
default.
- Arrow keys (`37/38/39/40`) remain numeric to preserve existing glyph
rendering behavior.
- All other numeric key codes are converted to display names via
`Helper.GetKeyName(...)`.

- **Result**
- Shortcut Guide key caps now show expected characters/key names instead
of numeric values for manifest-provided numeric keys.

```csharp
if (int.TryParse(key, out int keyCode))
{
    switch (keyCode)
    {
        case 38:
        case 40:
        case 37:
        case 39:
            shortcutList.Add(keyCode); // keep glyph path
            break;
        default:
            shortcutList.Add(Helper.GetKeyName((uint)keyCode)); // show key label
            break;
    }
}
```

## Validation Steps Performed

No additional validation details are included in this description.

> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `o3svsblobprodcus318.vsblob.vsassets.io`
> - Triggering command: `/usr/bin/dotnet dotnet build
/home/REDACTED/work/PowerToys/PowerToys/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuide.Ui.csproj
-v minimal` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/microsoft/PowerToys/settings/copilot/coding_agent)
(admins only)
>
> </details>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
Co-authored-by: Noraa Junker <noraa.junker@outlook.com>
2026-05-22 11:08:32 +08:00
Niels Laute
8af6a99136 Settings UX tweaks (#48024)
This PR:

- Adds a MaxWidth to the SCOOBE and OOBE pages, inline with Fluent
design guidance
- Updates the imagery for PowerToys
- Tweaks some small nits in the General settings page: re-ordering,
adding icons, replacing a ToggleSwitch with a CheckBox

<img width="1774" height="1325" alt="image"
src="https://github.com/user-attachments/assets/d825047a-27be-4e8b-a6ce-7f1a71f39dfe"
/>
2026-05-21 17:28:40 +02:00
Noraa Junker
9699d8a802 Shortcut Guide V2 (#40834)
## Summary of the Pull Request


https://github.com/user-attachments/assets/f4afdaf8-2830-4993-82ea-1ee9a6978e4c


<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: Status: #890 #15405 #179 #129 #22419 #31289 #47297 #47464
#44816
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [x] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [x] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here:
https://github.com/MicrosoftDocs/windows-dev-docs/pull/5717

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

Work for future PRs:

- [ ] Localization of built-in shortcut files
- [ ] Further customization (we can wait on user feedback for that)
- [ ] Reimplement holding windows key
- [ ] Search bar

<details>
<summary>Images</summary>


https://github.com/user-attachments/assets/f923daa4-d713-463b-ba33-ede72b986c12

<img width="726" height="1388" alt="image"
src="https://github.com/user-attachments/assets/781eff9a-2863-44be-bbe2-25371ef8838e"
/>
<img width="624" height="351" alt="image"
src="https://github.com/user-attachments/assets/ec8a44db-afbc-4e28-8285-ba2a9e345fb9"
/>
<img width="712" height="1086" alt="image"
src="https://github.com/user-attachments/assets/5a3775fc-36e9-4971-8d3f-491e8f8da45a"
/>
<img width="726" height="134" alt="image"
src="https://github.com/user-attachments/assets/7d0a8b1f-d10e-4466-820c-b3efdc5f3c84"
/>


</details>




<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

---------

Co-authored-by: Gordon Lam (SH) <yeelam@microsoft.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Muyuan Li <116717757+MuyuanMS@users.noreply.github.com>
Co-authored-by: Muyuan Li (from Dev Box) <muyuanli@microsoft.com>
2026-05-21 17:27:52 +02:00
moooyo
5b16a8c945 fix(PowerDisplay): close window on Escape key (#48016) (#48026)
The PowerDisplay flyout had no keyboard close path: pressing Tab kept
focus inside the window so it never deactivated, and there was no
KeyDown / KeyboardAccelerator wired up. Handle Escape on RootGrid to
hide the window, matching the behavior of other PowerToys flyouts.

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #48016
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 12:59:07 +02:00
Muyuan Li
fa2b7f6e5f Fix VALID_LABELS mismatches in auto-label-issues workflow (#48027)
## Summary

Corrects four label names in the \VALID_LABELS\ allow-list of the
\uto-label-issues.yml\ workflow to match existing repository labels
exactly.

## Root Cause

The GitHub Actions \ddLabels\ API creates a brand-new label when the
name doesn't exactly match an existing one. The hardcoded list had
typos/mismatches:

| Workflow had | Repo actually has |
|---|---|
| \Product-Power Display\ | \Product-PowerDisplay\ |
| \Product-ColorPicker\ | \Product-Color Picker\ |
| \Product-Command Not Found\ | \Product-CommandNotFound\ |
| \Product-Hosts\ | \Product-Hosts File Editor\ |

## Changes

- Fixed all 4 label strings in \VALID_LABELS\ array
- Deleted the spurious \Product-Power Display\ label that was created by
the mismatch

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-21 12:58:46 +02:00
moooyo
f117bfc64e feat(PowerDisplay): migrate legacy "{Source}_{EdidId}_{N}" Ids to new stable ID (#47977)
Carry per-monitor user preferences from the pre-#47712 Id format onto
the current DevicePath-based Ids by matching on EdidId. Without this,
every upgrade silently resets Enable* toggles (input source, color
temperature, power state) for monitors users had already opted in on,
because the direct-Id lookup in ApplyPreservedUserSettings can never
match the old "DDC_DELD1A8_1" / "WMI_BOE0900_2" keys.

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

---------

Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 14:21:20 +08:00
Niels Laute
52bf042df2 [Workspaces] Move to WPF Fluent and tweak overall UX (#46172)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

This PR includes the following changes:
- Remove the dependency of ControlzEx and ModernWpf, and instead uses
the default WPF Fluent theming. No more third-party packages.
- A lot of UI design refinements: using the proper fontweights, spacing,
Mica background, and default Fluent styles.
- Usability improvements: action buttons are at the top, full width
scrolling.

Related: #46220

<img width="1209" height="879" alt="image"
src="https://github.com/user-attachments/assets/132cdb9a-aa73-4aa2-88b0-c36031b4aea3"
/>


<img width="1060" height="980" alt="image"
src="https://github.com/user-attachments/assets/a04f83d4-74d3-466c-9d5c-f193f436337b"
/>



<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

---------

Co-authored-by: Jay <65828559+Jay-o-Way@users.noreply.github.com>
Co-authored-by: Muyuan Li (from Dev Box) <muyuanli@microsoft.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
2026-05-21 07:54:19 +02:00
Mike Griese
2fc27b13b6 CmdPal: Fix opening a IPage from a context menu on a dock item (#47991)
Currently, if the user clicks on a dock item which is a Page command,
then we'll attempt to show the cmdpal where the user clicked on a dock
item. This works great. However, if the user right-clicks a dock item to
invoke the context menu, then from that menu clicks on a Page command,
then nothing happens - we don't show the cmdpal window.

Similarly - IInvokableCommand's that return a CommandResult.Confirm - we
never show the cmdpal window so that the confirmation ContentDialog is
shown to the user.

Yes in the long run, these will make more sense to have a better UI for
the "dock flyout" (see #45861). But until then, this fixes these
scenarios.

Closes #45963

very relevant for #47989
2026-05-20 16:03:07 -05:00
Dave Rayment
94b7e3eea2 [Image Resizer] Automatically reload settings changes (#45266)
## Summary of the Pull Request

This PR introduces real-time settings synchronisation for Image Resizer.
External changes to `settings.json` (via the Settings application or
manual edits to the file) are detected and reloaded immediately without
requiring a restart.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #36943
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

### Reload updates
The reload detection is via an `IFileSystemWatcher` (as file system
operations are abstracted in Image Resizer), which monitors the
`settings.json` file for creation and changes. There is a half second
debounce for changes, as the settings file can rapidly change when the
user is editing the preset name field.

Hot reloading of the properties required refactoring `ReloadCore`, which
replaces the `Sizes` preset collection and updates the Custom and AI
presets, in addition to the application-wide properties like compression
options and the fallback encoder choice.

I changed the combo box data binding from the `SelectedSize` object to
the int `SelectedSizeIndex`. This was required to resolve a specific WPF
issue where reloading the `Sizes` collection would cause issues with
restoring the current combo box selection to the prior value. Binding to
the index decouples the selection state from the object lifecycle during
the reload process.

Selection preservation is based on the preset ID (for user presets) and
preset type (for Custom and AI presets). This ensures that matches are
robust even if the user is in the process of renaming an entry in the
Settings application. If the preset cannot be matched (for example, if
the user deletes the item or changes the ID manually in the file), the
Custom preset is selected.

Selection range checks are maintained from the old code, and additional
checks have been added to ensure that Custom and AI presets will be
present even if they're deleted from the settings file.

The AI preset check from before has been inlined; this guarantees that
the AI resize option will not display if the facility is unavailable on
the current PC, even if it's present in the settings file.

The reload routine is dispatched to the UI thread, as changes involve
updates to the combo box.

### ID recovery
Preset IDs are key to preserving the combo box selection between
reloads, and a couple of changes were necessary to ensure round-tripping
changes were robust.

1. IDs are not reused. The old code could reuse IDs under certain
circumstances, for example if a preset was deleted and re-added via
Settings.
2. The ID Recovery Helper routine sorted the supplied presets by ID
before performing duplicate conflict resolution. This is not required
and it is more natural to assume that the order in the settings file and
the client UI is the source of truth.

New ID assignment is now based on a monotonically increasing ID (seeded
at application start) rather than `Current Maximum ID + 1`. This means
that IDs cannot be reused in the same Settings application session. This
makes the matching process in the client application more reliable.

A small update was made to the ID Recovery Helper to use `HashSet.Add()`
instead of splitting up the check and addition steps (`Add` will return
false if the value already exists), which saves a massive one line of
code.

There were comments about the ID Recovery Helper resolving "empty" or
"invalid" entries; this was inaccurate, as IDs are ints, which must by
definition always have a valid value. The routine only guards against
duplicates, so the comments have been updated to reflect this.

### Miscellaneous
The `Default` Settings property getter previously called `Reload` every
time it was accessed. This is fine when the file is only read at
application startup, but I changed this to lazily instantiate and call
`Reload` a single time.

I refactored duplicate code related to settings file/folder strings, and
also the creation of the Custom and AI size instances.

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

Manual testing:
1. Add new preset in the Settings application. The new entry is
reflected in the client application as it is running.
2. Delete new preset. The entry is removed in the client application
list.
3. Edit an existing preset. The property change is reflected in the
client application.
4. Add new preset in the Settings application. Select the new preset in
the client application. Edit the properties of the new preset in the
Settings application and confirm that the updates appear in the client
application.
5. Add new preset in the Settings application. Select the new preset in
the client application. Delete the new preset in Settings. Confirm that
the current preset is removed and the selection changes to the default
in the client application.
6. Change one or more application-wide properties in the settings file
which are represented in the client application, too, e.g. "Make
pictures smaller but not larger" (`imageresizer_shrinkOnly`) or
"Overwrite files" (`imageresizer_replace`). Upon saving, confirm the
checkbox changes immediately in the client application.
7. Edit the `settings.json` file manually by e.g. adding a new Size
preset or editing the width or height property of an existing preset.
Upon saving, the change(s) should be reflected in the client
application.
8. Make a change to an existing or new preset which affects the resize
operation itself, e.g. the dimensions or the "Make pictures smaller but
not larger" setting. Proceed with the resize operation and confirm that
the new changes have been applied.

14 new unit tests have been added to `SetingsTests.cs` to exercise the
`Settings` and `IDRecoveryHelper` functionality.

---------

Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 12:18:12 +00:00
Gordon Lam
c334f1d997 [CI] Sign Google.Apis.* and Google.GenAI DLLs (AdvancedPaste Gemini deps) (#48001)
## Summary

Adds the four Google.* DLLs shipped by AdvancedPaste (via
`Microsoft.SemanticKernel.Connectors.Google` for Gemini support) to the
ESRP sign list.

## Problem

The `Verify all binaries are signed and versioned` pipeline step
(`.pipelines/versionAndSignCheck.ps1`) was failing with:

```
Not Signed:  + ...\extractedMachineMsi\File\WinUI3ApplicationsFiles_File_Google.Apis.Auth.dll
Not Signed:  + ...\extractedMachineMsi\File\WinUI3ApplicationsFiles_File_Google.Apis.Core.dll
Not Signed:  + ...\extractedMachineMsi\File\WinUI3ApplicationsFiles_File_Google.Apis.dll
Not Signed:  + ...\extractedMachineMsi\File\WinUI3ApplicationsFiles_File_Google.GenAI.dll
```

These DLLs are transitive NuGet dependencies of
`Microsoft.SemanticKernel.Connectors.Google` (referenced by
`src/modules/AdvancedPaste/AdvancedPaste/AdvancedPaste.csproj`) and
deploy to `WinUI3Apps\`, but were never added to
`.pipelines/ESRPSigning_core.json`.

## Fix

Added the four DLLs to the second `SignBatch` (`CP-231522`, the
third-party / OSS-library identity) — same batch used for other
connector DLLs like `OpenAI.dll`, `OllamaSharp.dll` and
`Microsoft.SemanticKernel.Connectors.Ollama.dll`.

## Validation

- `ConvertFrom-Json` on the modified file confirms valid JSON.
- Sign-list entries match the actual deploy paths flagged by
`versionAndSignCheck.ps1`.
- The next ESRP signing run will pick them up; the verify step should
pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-20 17:45:56 +08:00
moooyo
8e74eb2ba8 [PowerDisplay] Auto-disable on detected DDC/CI capability fetch crash (#47556) (#47734)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary

Mitigation for issue #47556 — `KERNEL_SECURITY_CHECK_FAILURE` BSOD
originating in `win32kfull!DdcciGetCapabilitiesStringFromMonitor` when
PowerDisplay calls DDC/CI capability APIs against monitors with
malformed capability strings.

After a detected crash, PowerDisplay auto-disables itself via
`settings.json`, shows an error InfoBar at the top of the PowerDisplay
settings page (page is locked except the Ignore button), so users can
avoid getting stuck in an infinite reboot loop after a crash. And the
user must explicitly dismiss the warning before re-enabling the module.

The actual kernel-side fix is the Windows team's responsibility — this
PR only prevents users from BSOD-ing repeatedly on the same monitor
without warning.

settings page:
<img width="1743" height="1475" alt="image"
src="https://github.com/user-attachments/assets/8cf1b72f-c51a-4955-82d7-213cae49fd4e"
/>


## Mechanism

1. `CrashDetectionScope` IDisposable wraps Phase 2 capability fetch in
`DdcCiController.DiscoverMonitorsAsync`, writing `discovery.lock`
(`WriteThrough` + `Flush(flushToDisk: true)`) before, deleting it on
Dispose.
2. If the process is killed externally (BSOD, FailFast), the lock
survives.
3. On next PowerDisplay.exe startup (Phase 0), `CrashRecovery` detects
the orphan lock and runs a strict fail-fast sequence: write
`crash_detected.flag` → set `enabled.PowerDisplay=false` in global
`settings.json` → signal the new `POWER_DISPLAY_AUTO_DISABLE_EVENT` →
delete the lock (commit point).
4. The runner-loaded `PowerDisplayModuleInterface.dll` runs a one-shot
listener thread that wakes on the event and calls `disable()` to sync
`m_enabled`.
5. `PowerDisplayViewModel` reads the flag at construction and binds
`IsCrashLockActive` to lock the page.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #47556 
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

---------

Co-authored-by: Yu Leng <yuleng@microsoft.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 16:13:16 +08:00
Mike Griese
da9a08aa92 CmdPal: Add support for drag-drop bookmarking to the dock (#47989)
This allows users to drag files & URLS to the dock, to immediately
create a bookmark, and pin that bookmark to the dock.

It also updates the bookmark provider's dock bands. If you bookmark a
folder, then pin that to the dock, when you click it on the dock, we'll
default to the "browse" experience, which will open the list of files in
cmdpal, rather than open in explorer.

Had to make miscellaneous changes to make this all a bit faster:
* DirectoryPage didn't load icons smartly, like we do for bookmarks
* I added a different "observable" collection for dock top-level items,
because it caused a flippin CollectionChanged cascade any time a single
provider had more than one item pinned in the dock. Each item from each
provider would cause us to recreate all the dock view models (???) crazy
* I alas had to make `IBookmarksManager` public, so that the UI could
use it. I hate it, but I couldn't figure out a better way. Bookmarks are
a pretty built-in part, so it's _fine i guess_

re: #45584
2026-05-19 16:49:33 -05:00
Jessica Dene Earley-Cha
b893d633d9 [TEST Version] Event PR Check (#47889)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

This PR checks if future PRs has added or refines telemetry events, if
so, the bot will add a message to the PR about the needed steps
depending on the PR.

**NOTE**: This PR is submitting a test version, which is only manually
triggered, once tested and confirmed then will move to it being
automatic


<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
2026-05-19 17:28:57 +00:00
Dave Rayment
a7bc09a87a [QuickAccent] Fix UI glitches, DPI-related issues, selection bugs, and add hardware shift key state fallback (#46593)
## Summary of the Pull Request
This PR fixes several issues around the popup selection window's size
and position, selection-related issues which result in flashing or
glitching, and includes more reliable detection of the Shift key.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #44332
- [x] Closes: #44980
- [x] Closes: #35094 
- [x] Closes: #40498
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

This PR includes fixes for the Quick Accent's selection window position,
its width measurement, and letter selection-related issues. In addition,
glitches such as the window flashing the selection colour and the window
appearing blank should be reduced or eliminated entirely.

### Popup width bug

When opening Quick Accent from a letter with many mappings, it would
appear too wide for the display. Even though letters could be selected,
they may be entirely off-screen:

<img width="1578" height="134" alt="image"
src="https://github.com/user-attachments/assets/cfcb2ddb-3cf3-47d5-9386-133a2fc70550"
/>

This was because of this flaw in `GetDisplayMaxWidth`, which is used
directly by the popup to set the maximum width of the characters area:

```csharp
    // In Selector.xaml.cs
    private void SetWindowsSize()
    {
        this.characters.MaxWidth = _powerAccent.GetDisplayMaxWidth();
    }

...
    // In PowerAccent.cs
    public double GetDisplayMaxWidth()
    {
        return WindowsFunctions.GetActiveDisplay().Size.Width - ScreenMinPadding;
    }
```

`GetActiveDisplay` uses the `GetMonitorInfo` API, which exposes the
working area of the display. It returns its values in _raw unscaled
pixel_ values:

```csharp
    public static (Point Location, Size Size, double Dpi) GetActiveDisplay()
    {
        ...
        var res = PInvoke.MonitorFromWindow(guiInfo.hwndActive, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
        MONITORINFO monitorInfo = default;
        monitorInfo.cbSize = (uint)Marshal.SizeOf(monitorInfo);
        PInvoke.GetMonitorInfo(res, ref monitorInfo);

        ...

        return (location, monitorInfo.rcWork.Size, dpi);
    }
```

However, the `MaxWidth` property must be a _pre-scaled_ value, i.e. in
logical WPF units not physical pixels. The fix is straightforward:

```csharp
    public double GetDisplayMaxWidth()
    {
        var activeDisplay = WindowsFunctions.GetActiveDisplay();
        return (activeDisplay.Size.Width / activeDisplay.Dpi) - ScreenMinPadding;
    }
```

### Popup positioning bug

This is related to a subtle DPI issue in `GetActiveDisplay()`:

```csharp
    public static (Point Location, Size Size, double Dpi) GetActiveDisplay()
    {
        GUITHREADINFO guiInfo = default;
        guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);
        PInvoke.GetGUIThreadInfo(0, ref guiInfo);
        var res = PInvoke.MonitorFromWindow(guiInfo.hwndActive, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);

        MONITORINFO monitorInfo = default;
        monitorInfo.cbSize = (uint)Marshal.SizeOf(monitorInfo);
        PInvoke.GetMonitorInfo(res, ref monitorInfo);

        double dpi = PInvoke.GetDpiForWindow(guiInfo.hwndActive) / 96d;
        var location = new Point(monitorInfo.rcWork.left, monitorInfo.rcWork.top);
        return (location, monitorInfo.rcWork.Size, dpi);
    }
```

Here, the application window's DPI is returned. Unfortunately, the
window may report a value which is different from the monitor's own DPI
value. This will consistently happen if the application is not
Per-Monitor DPI-Aware, and the monitor is not at 100% Scale. The effects
are that the Quick Accent popup can appear misaligned or even off-screen
entirely. Quick Accent can still be used, but the user may not be able
to see what they are selecting.

As Quick Accent is using monitor coordinates for setting its location,
the solution is to use the monitor's own DPI value. The fix is to add
this in place of the `GetDpiForWindow` line:

```csharp
        uint dpiRaw = 96; // Safe default
        if (PInvoke.GetDpiForMonitor(res, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out uint dpiX, out _) == 0)
        {
            dpiRaw = dpiX;
        }

        double dpi = dpiRaw / 96d;
```

### Selection bugs

After dismissing the Quick Accent window, the `_selectedIndex` state was
not properly reset. The next time the window opened, it could attempt to
scroll to or highlight an index that was out-of-bounds for the new
character set. This could result in glitching, such as the window
flashing the selection colour or the initial selection being incorrect.
In this fix, I:

1. Explicitly set `_selectedIndex` to `-1` when the UI hides.
2. Reset the `SelectedIndex` inside Selector.xaml.cs before updating the
`ItemsSource`.

### Shift key activation

In certain cases, a quick press of Shift could fail to move back through
the character list. In this fix, I:

1. Added a native fallback usign GetAsyncKeyState(VK_SHIFT).
2. Updated `ProcessNextChar()` to evaluate `shiftPressed ||
WindowsFunctions.IsShiftState()`.
3. Updated the multiple `if`s in `ProcessNextChar` to be an if/else
structure, to prevent bugs when more than one trigger key is pressed.

### Support added for multi-codepoint graphemes

The current code loops through each `char` of a mapping, calling
`SendInput` multiple times for multi-char sequences. This will fail for
multi-codepoint graphemes, i.e. where the mapping 'letter' is more than
one UTF-16 codepoint. Those characters may appear as `[]`. The amended
`Insert()` in `WindowsFunctions` appends all characters before calling
`SendInput`.

### Miscelleneous

- Added an `OnDpiChanged` handler for the Selector control, so changing
the DPI of the screen should be picked up automatically. (It's
questionable whether this is essential, as the DPI would have to change
while the control was displayed, but it's worth having for robustness.)
- Now using `SetWindowPos` instead of setting the `Left` and `Top` of
the popup control. Also now initialising the popup offscreen to attempt
to reduce flicker and the occurrence of blank window flashes.
- Changed the `Focusable` property of the characters `ListBox` to
`False`, to attempt to reduce flicker and the window flashing the
selector colour.
- Removed `Width` and added `MinWidth` to the letter control in
Selector.xaml. This allows for wider letters or longer multi-letter
mappings.
- Changed the `VirtualizingStackPanel` to a regular `StackPanel`. We do
not have mappings with enough entries for a virtual control to be
necessary, and using StackPanel seemed to have a positive effect on the
appearance of blank window glitches.
- Added `TextTrimming`, `TextWrapping` and `MaxHeight` to the unicode
description `TextBlock`. This helps support extremely long unicode
descriptions. Again, this will enable us to support longer
multi-character mappings in the future.
- Added CsWin32 to the PowerAccent.UI project, to support the
`SetWindowPos` call.

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

See separate doc for full test details:


https://docs.google.com/document/d/19uClcUiv7RUDRlbFhazG-Cmu46oNmrAVoJf9bHSjSJU/edit?usp=sharing

---------

Co-authored-by: Muyuan Li (from Dev Box) <muyuanli@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
2026-05-20 00:20:03 +08:00
Marco Guido
6e9b3b1536 [PowerAccent] adding greek polytonic (#47021)
Adds Greek Polytonic characters set to power accent, based on
https://github.com/microsoft/PowerToys/pull/29709
### PR Checklist

- [x]  Closes #46941
- [x] Communication: I've discussed this with core contributors already.
- [ ] Tests: Not sure if there are specific tests for this
- [ ] Documentation updated: Power accent docs

### Detailed Description of the Pull Request / Additional comments
Added all greek polytonic letters to their corresponding english letter
(some duplicated)
(if you wondered about GRC -> ISO 639-3)

### Validation Steps Performed
Compiled and Observed Power Accent

---------

Co-authored-by: Niels Laute <niels.laute@live.nl>
Co-authored-by: Dave Rayment <dave.rayment@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-20 00:19:06 +08:00
Gordon Lam
d973bcbcaa Update Microsoft.SemanticKernel packages from 1.66.0 to 1.71.0 (#47819)
## Summary

Updates the `Microsoft.SemanticKernel` package family from 1.66.0 to
1.71.0 to pick up upstream improvements and bug fixes from the Semantic
Kernel project.

> Note: the `Connectors.AzureAIInference` (`-beta`), `Connectors.Google`
/ `Connectors.MistralAI` / `Connectors.Ollama` (`-alpha`) packages have
no stable upstream release yet, but are required to keep the existing
Advanced Paste AI provider options working.


## Packages updated

**SemanticKernel family:**

| Package | From | To |
|---------|------|----|
| `Microsoft.SemanticKernel` | 1.66.0 | 1.71.0 |
| `Microsoft.SemanticKernel.Connectors.OpenAI` | 1.66.0 | 1.71.0 |
| `Microsoft.SemanticKernel.Connectors.AzureAIInference` | 1.66.0-beta |
1.71.0-beta |
| `Microsoft.SemanticKernel.Connectors.Google` | 1.66.0-alpha |
1.71.0-alpha |
| `Microsoft.SemanticKernel.Connectors.MistralAI` | 1.66.0-alpha |
1.71.0-alpha |
| `Microsoft.SemanticKernel.Connectors.Ollama` | 1.66.0-alpha |
1.71.0-alpha |

**Transitive dependencies bumped to satisfy SK 1.71's resolution
constraints:**

| Package | From | To |
|---------|------|----|
| `Microsoft.Extensions.AI` | 9.9.1 | 10.2.0 |
| `Microsoft.Extensions.AI.OpenAI` | 9.9.1-preview.1.25474.6 |
10.0.1-preview.1.25571.5 |
| `System.Numerics.Tensors` | 9.0.11 | 10.0.2 |
| `Newtonsoft.Json` | 13.0.3 | 13.0.4 |
| `OpenAI` | 2.5.0 | 2.7.0 |
| `System.ClientModel` | 1.7.0 | 1.8.0 |

These transitive bumps were required to avoid `NU1109` package-downgrade
errors after the SK upgrade.

## Scope

- `Directory.Packages.props` only  central package version bumps.
- No source-code changes.

## Consumers

- AdvancedPaste uses the SK `Kernel` / `IChatCompletionService` /
connector surfaces unchanged.
- `LanguageModelProvider` and `FoundryLocalPasteProvider` use the stable
`Microsoft.Extensions.AI` `IChatClient` / `ChatMessage` / `ChatRole` /
`ChatResponse` / `AsIChatClient()` types unchanged across 9.x to 10.x.

## Validation

- Static API-surface review of all SK / `Microsoft.Extensions.AI` call
sites only stable types in use.
- CI build pipeline will provide the full restore + compile verification
across the solution.

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

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-19 10:25:41 +02:00
Niels Laute
02fbb916a7 [Quick Accent] Remove wpfui (#46604)
## Summary of the Pull Request

<img
src="https://github.com/user-attachments/assets/8756671f-642a-4bbd-a174-eb13b02cfe59">

This PR removes the dependency on the WpfUI library and uses plain WPF.

## PR Checklist

- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

## Detailed Description of the Pull Request / Additional comments

- Replaced `ui:FluentWindow` with a standard WPF `Window` and removed
the `xmlns:ui` WpfUI namespace
- Replaced `<Rectangle.Fill><SolidColorBrush /></Rectangle.Fill>` with
an inline `Fill=` attribute on the selection indicator rectangle
- Simplified `App.xaml` by removing WpfUI theme/controls resource
dictionaries and using `ThemeMode="System"` instead
- Fixed XAML formatting: converted empty `<Application>` to a
self-closing tag, removed extra blank lines in `Window.Resources` and
inside `ControlTemplate`

## Validation Steps Performed

- Manually verified the Quick Accent overlay renders correctly with
accent character selection and character name display

<!-- START COPILOT CODING AGENT TIPS -->
---

 Let Copilot coding agent [set things up for
you](https://github.com/microsoft/PowerToys/issues/new?title=+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-19 08:13:00 +00:00
536 changed files with 71946 additions and 8221 deletions

View File

@@ -51,6 +51,7 @@ resw
resx
srt
Stereolithography
taskmgr
terabyte
UYVY
xbf
@@ -336,6 +337,10 @@ MRUCMPPROC
MRUINFO
REGSTR
#Xaml
NVI
Storyboards
# Misc Win32 APIs and PInvokes
DEFAULTTONEAREST
INVOKEIDLIST
@@ -360,7 +365,10 @@ FILESYSONLY
URLIS
WAITTIMEOUT
DEFAULTTONEAREST
DWRITE
LWIN
VCENTER
VREDRAW
# COM/WinRT interface prefixes and type fragments
BAlt

View File

@@ -105,7 +105,9 @@
^src/common/ManagedCommon/ColorFormatHelper\.cs$
^src/common/notifications/BackgroundActivatorDLL/cpp\.hint$
^src/common/sysinternals/Eula/
^doc/devdocs/modules/cmdpal/initial-sdk-spec/list-elements-mock-002\.pdn$
^src/modules/cmdpal/Tests/Microsoft\.CommandPalette\.Extensions\.Toolkit\.UnitTests/FuzzyMatcherComparisonTests.cs$
^src/modules/cmdpal/Tests/Microsoft\.CommandPalette\.Extensions\.Toolkit\.UnitTests/FuzzyMatcherDiacriticsTests.cs$
^src/modules/cmdpal/doc/initial-sdk-spec/list-elements-mock-002\.pdn$
^src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleMarkdownImagesPage\.cs$
^src/modules/cmdpal/Microsoft\.CmdPal\.UI/Settings/InternalPage\.SampleData\.cs$
^src/modules/cmdpal/Tests/Microsoft\.CmdPal\.Common\.UnitTests/.*\.TestData\.cs$

View File

@@ -25,6 +25,7 @@ advapi
advfirewall
AFeature
affordances
afterfx
AFX
agentskills
AGGREGATABLE
@@ -62,6 +63,7 @@ APPEXECLINK
appext
apphost
APPLICATIONFRAMEHOST
Applocal
appmanifest
APPMODEL
APPNAME
@@ -80,6 +82,7 @@ ARPPRODUCTICON
ARRAYSIZE
ARROWKEYS
arrowshape
artboard
ARTIFACTSTAGINGDIRECTORY
asf
Ashcraft
@@ -117,7 +120,6 @@ Badmode
Badparam
bbwe
BCIE
bck
BESTEFFORT
bezelled
bhid
@@ -156,6 +158,7 @@ breadcrumb
Browsable
BROWSEINFO
bsd
BSOD
bthprops
bti
BTNFACE
@@ -163,6 +166,7 @@ bugreport
bugreportfile
BUILDARCH
BUILDNUMBER
buildsystems
buildtransitive
builttoroam
BUNDLEINFO
@@ -200,6 +204,7 @@ checkmarks
CHILDACTIVATE
CHILDWINDOW
CHOOSEFONT
chu
CIBUILD
cidl
CIELCh
@@ -222,6 +227,7 @@ CLIPSIBLINGS
closesocket
clp
CLSCTX
CLSIDs
clsids
Clusion
cmder
@@ -332,6 +338,7 @@ dacl
DAffine
DAFFINETRANSFORM
datareader
Datasheet
datatracker
Dayof
dbcc
@@ -368,6 +375,7 @@ DEFPUSHBUTTON
deinitialization
DELA
DELD
deld
DELETEDKEYIMAGE
DELETESCANS
DEMOTYPE
@@ -392,6 +400,7 @@ DEVMODE
DEVMODEW
DEVNODES
devpal
devpackages
DEVTYP
dfx
DIALOGEX
@@ -435,9 +444,9 @@ drawingcolor
dreamsofameaningfullife
drivedetectionwarning
DROPFILES
DSPDLOG
DSTINVERT
DString
DSVG
dto
DUMMYUNIONNAME
dumpbin
@@ -501,7 +510,6 @@ ETDT
etl
etw
eula
eurochange
eventvwr
evt
EWXFORCE
@@ -542,6 +550,7 @@ FFFF
fffffffzzz
FFh
Figma
figma
FILEEXPLORER
fileexploreraddons
fileexplorerpreview
@@ -631,9 +640,11 @@ gpu
grabandmove
GRABANDMOVEMODULEINTERFACE
gradians
GRC
grctlext
GRGX
Gridcustomlayout
gridlines
GSM
gtm
guiddata
@@ -720,6 +731,7 @@ hotkeys
hotlight
hotspot
HPAINTBUFFER
HPS
HRAWINPUT
HREDRAW
hres
@@ -783,6 +795,7 @@ imgflip
inapp
inbox
INCONTACT
indesign
Indo
inetcpl
Infobar
@@ -793,6 +806,7 @@ INITDIALOG
INITGUID
initialfile
INITTOLOGFONTSTRUCT
inkscape
INLINEPREFIX
inlines
Inno
@@ -836,6 +850,7 @@ issecret
ISSEPARATOR
issuecomment
istep
Italicise
ith
IUI
IUWP
@@ -843,6 +858,7 @@ IWIC
jeli
jfif
jgeosdfsdsgmkedfgdfgdfgbkmhcgcflmi
JIDEA
jjw
jobject
JOBOBJECT
@@ -854,6 +870,7 @@ Jsons
jsonval
jxr
Kantai
KBSC
keybd
KEYBDDATA
KEYBDINPUT
@@ -871,6 +888,7 @@ keynum
keyremaps
keyring
keyvault
kfull
KILLFOCUS
killrunner
kmph
@@ -974,6 +992,7 @@ lstrcmpi
lstrcpyn
lstrlen
LTEXT
LTM
LTRREADING
luid
lusrmgr
@@ -1029,6 +1048,7 @@ Mgmt
Microwaved
middleclickaction
midl
midtones
mii
MIIM
mikeclayton
@@ -1042,7 +1062,7 @@ MINMAXINFO
minwindef
Mip
Miracast
MIRACAST
miracast
mkdn
mlcfg
mmc
@@ -1073,6 +1093,7 @@ MOVESIZEEND
MOVESIZESTART
MRM
mru
msaccess
MSAL
msc
mscorlib
@@ -1081,8 +1102,6 @@ msdata
msdia
MSDL
MSGFLT
MSHCTX
MSHLFLAGS
msiexec
MSIFASTINSTALL
MSIHANDLE
@@ -1092,13 +1111,16 @@ msixbundle
MSIXCA
MSLLHOOKSTRUCT
Mso
mspub
msrc
msstore
mstsc
msvcp
mswhql
MT
MTND
multimonitor
Multiplayer
MULTIPLEUSE
multizone
muxc
@@ -1141,7 +1163,6 @@ netcpl
netframework
netsetup
netsh
newcolor
NEWDIALOGSTYLE
NEWFILE
NEWFILEHEADER
@@ -1202,6 +1223,7 @@ NORMALDISPLAY
NORMALUSER
NOSEARCH
NOSENDCHANGING
NOSIZE
nosize
notdefault
NOTHOUSANDS
@@ -1242,7 +1264,6 @@ OFN
ofs
OICI
OICIIO
oldcolor
olditem
oldpath
oldtheme
@@ -1309,6 +1330,7 @@ pchast
PCIDLIST
PCTSTR
PCWSTR
pdbs
PDBs
PDEVMODE
PDFs
@@ -1337,6 +1359,7 @@ phbm
phbmp
phicon
Photoshop
photoshop
phwnd
pici
pidl
@@ -1364,14 +1387,15 @@ POINTERID
POINTERUPDATE
Pokedex
Pomodoro
Popups
popups
POPUPWINDOW
portfile
POSITIONITEM
POWERBROADCAST
powerdisplay
POWERDISPLAYMODULEINTERFACE
powerocr
powerpnt
POWERRENAMECONTEXTMENU
powerrenameinput
POWERRENAMETEST
@@ -1427,6 +1451,7 @@ projectname
PROPERTYKEY
PROPVARIANT
prot
Prt
PRTL
prvpane
psapi
@@ -1472,6 +1497,7 @@ QUERYOPEN
QUEUESYNC
quickaccent
quicklinks
quickmask
QUNS
RAII
randi
@@ -1492,7 +1518,6 @@ READMODE
READOBJECTS
recents
RECTDESTINATION
rectp
RECTSOURCE
recursesubdirs
recyclebin
@@ -1580,14 +1605,15 @@ SAMESHORTCUTPREVIOUSLYMAPPED
samsung
sancov
SAVEFAILED
scanled
schedtasks
SCID
SCL
Scode
SCREENFONTS
screenruler
screensaver
screenshots
Scrollback
scrollviewer
sddl
SDKDDK
@@ -1757,6 +1783,7 @@ STDAPI
stdc
stdcpp
stdcpplatest
stdext
STDMETHODCALLTYPE
STDMETHODIMP
steamapps
@@ -1879,6 +1906,7 @@ TNP
Toggleable
tontrager
Toolhelp
toolsets
toolwindow
TOPDOWNDIB
TOUCHEVENTF
@@ -1928,6 +1956,7 @@ ums
uncompilable
UNCPRIORITY
UNDNAME
ungroup
UNICODETEXT
unins
uninsdeletekey
@@ -1940,6 +1969,8 @@ UNLEN
UNORM
unparsable
unremapped
Unsend
Unsubscribes
untriaged
unvirtualized
unwide
@@ -1974,6 +2005,7 @@ vcgtq
VCINSTALLDIR
vcp
Vcpkg
vcpkg
vcpname
VCRT
vcruntime
@@ -1996,6 +2028,7 @@ VIRTKEY
VIRTUALDESK
VISEGRADRELAY
visiblecolorformats
visio
visualeffects
vkey
vmovl
@@ -2080,13 +2113,16 @@ winlogon
winmd
winml
WINNT
winproj
winres
winrt
winsdk
winsta
WINTHRESHOLD
WINVER
winword
winxamlmanager
wireframes
withinrafael
Withscript
wixproj
@@ -2157,6 +2193,7 @@ xxxxxx
ycombinator
yinle
yinyue
yoko
YVIRTUALSCREEN
zamora
Zenbook

View File

@@ -18,6 +18,13 @@ MIcrosoftEdgeLauncherCsharp
# marker for ignoring a comment to the end of the line
// #no-spell-check.*$
# JavaScript regex literals that start with \b can be reported as "b..." words.
# Example: /\bclass\s+.../
^\s*/\\[b].{3,}?/[gim]*\s*(?:\)(?:;|$)|,$)
# GitHub API header token used in code (not natural language).
\bx-ratelimit-reset\b
# Gaelic
Gàidhlig

View File

@@ -163,7 +163,7 @@ configuration:
association: Collaborator
then:
- addReply:
reply: Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
reply: We've identified this issue as a duplicate of an existing one and are closing this thread so discussion stays in one place.<br/><br/>Please see the comment above for the link to the original tracking issue, and feel free to subscribe there for updates.
- closeIssue
- removeLabel:
label: Needs-Triage

377
.github/scripts/telemetry-pr-check.js vendored Normal file
View File

@@ -0,0 +1,377 @@
#!/usr/bin/env node
/**
* Detects telemetry-event additions/modifications in a pull request and
* posts (or updates) a PR comment when telemetry-related changes are found.
*
* This script is executed by .github/workflows/telemetry-pr-check.yml.
* Keep both files aligned when changing trigger behavior, env usage, or messaging.
*/
const fs = require('node:fs');
const REVIEWER_LOGIN = 'chatasweetie';
const REVIEWER_MENTION = `@${REVIEWER_LOGIN}`;
const COMMENT_MARKER = '<!-- telemetry-event-check -->';
const COMMENT_BODY_WITH_PRIVACY_UPDATE = `${COMMENT_MARKER}
Thank you for contributing to PowerToys. We've detected that this PR might include a new or modified telemetry event. After this PR is merged, please follow these next steps:
- [ ] Reach out to Jessica (${REVIEWER_MENTION}) to follow up on the next steps: https://aka.ms/pt-telemetry-process
`;
const COMMENT_BODY_WITHOUT_PRIVACY_UPDATE = `${COMMENT_MARKER}
Thank you for contributing to PowerToys. We've detected that this PR might include a new or modified telemetry event. Please ensure the following before merging:
- [ ] Add your telemetry events to [DATA_AND_PRIVACY](https://github.com/microsoft/PowerToys/blob/main/DATA_AND_PRIVACY.md).md within this PR.
- [ ] Reach out to Jessica (${REVIEWER_MENTION}) to follow up on the next steps: https://aka.ms/pt-telemetry-process`;
const TELEMETRY_PATH_PATTERNS = [
/(^|\/)trace\.(h|hpp|cpp|cs)$/i,
/(^|\/)telemetry\//i,
/(^|\/)events\/.+event\.cs$/i,
/^src\/common\/Telemetry\//i,
/^src\/common\/ManagedTelemetry\//i,
/^src\/runner\/trace\.(h|cpp)$/i,
/^src\/settings-ui\/.+\/Telemetry\//i,
];
const TELEMETRY_LINE_PATTERNS = [
/TraceLoggingWriteWrapper\s*\(/,
/\bTraceLoggingWrite\s*\(/,
/\bTRACELOGGING_DEFINE_PROVIDER\b/,
/\bTraceLoggingOptionProjectTelemetry\b/,
/\bProjectTelemetryPrivacyDataTag\b/,
/\bPROJECT_KEYWORD_MEASURE\b/,
/\bRegisterProvider\s*\(/,
/\bUnregisterProvider\s*\(/,
/\bPowerToysTelemetry\.Log\.WriteEvent\s*\(/,
/\bclass\s+\w+\s*:\s*EventBase\s*,\s*IEvent\b/,
/\bclass\s+\w+\s*:\s*TelemetryBase\b/,
/\bPartA_PrivTags\b/,
/\[EventData\]/,
/\bEventName\b/,
];
function requireEnv(name) {
const value = process.env[name];
if (!value) {
throw new Error(`Missing required environment variable: ${name}`);
}
return value;
}
function validateRepository(repository) {
if (!/^[^/]+\/[^/]+$/.test(repository)) {
throw new Error(
`GITHUB_REPOSITORY must be in owner/repo format, received: ${JSON.stringify(repository)}`
);
}
}
function readEventPayload(eventPath) {
let raw;
try {
raw = fs.readFileSync(eventPath, 'utf8');
} catch (error) {
throw new Error(`Failed to read event payload at ${eventPath}: ${error.message}`);
}
try {
return JSON.parse(raw);
} catch (error) {
throw new Error(`Failed to parse JSON from ${eventPath}: ${error.message}`);
}
}
function resolvePullNumber(event) {
const fromPullRequest = event?.pull_request?.number;
const fromWorkflowDispatch = event?.inputs?.pr_number;
const rawPullNumber = fromPullRequest ?? fromWorkflowDispatch;
if (rawPullNumber === undefined || rawPullNumber === null || rawPullNumber === '') {
throw new Error(
'Unable to determine pull request number from event payload. Expected pull_request.number or inputs.pr_number.'
);
}
const pullNumber = Number.parseInt(String(rawPullNumber), 10);
if (!Number.isInteger(pullNumber) || pullNumber <= 0) {
throw new Error(`Invalid pull request number: ${JSON.stringify(rawPullNumber)}`);
}
return pullNumber;
}
function isTelemetryPath(filePath) {
return TELEMETRY_PATH_PATTERNS.some((pattern) => pattern.test(filePath));
}
function changedLinesFromPatch(patch) {
if (!patch) {
return [];
}
return patch
.split('\n')
.filter((line) => {
if (line.startsWith('+++') || line.startsWith('---')) {
return false;
}
return line.startsWith('+') || line.startsWith('-');
})
.map((line) => line.slice(1));
}
function hasTelemetryLineSignal(lines) {
return lines.some((line) => TELEMETRY_LINE_PATTERNS.some((pattern) => pattern.test(line)));
}
async function apiRequest(url, method = 'GET', body) {
const token = requireEnv('GITHUB_TOKEN');
let response;
try {
response = await fetch(url, {
method,
headers: {
Authorization: `Bearer ${token}`,
Accept: 'application/vnd.github+json',
'Content-Type': 'application/json',
},
body: body ? JSON.stringify(body) : undefined,
});
} catch (error) {
throw new Error(`Network error during ${method} ${url}: ${error.message}`);
}
if (!response.ok) {
const text = await response.text();
const rateLimitReset = response.headers.get('x-ratelimit-reset');
const rateLimitHint =
response.status === 403 && rateLimitReset
? ` (rate limit reset at epoch ${rateLimitReset})`
: '';
throw new Error(`${method} ${url} failed (${response.status})${rateLimitHint}: ${text}`);
}
if (response.status === 204) {
return null;
}
try {
return await response.json();
} catch (error) {
throw new Error(`Failed to parse JSON response for ${method} ${url}: ${error.message}`);
}
}
async function getAllPullFiles(apiBaseUrl, repository, pullNumber) {
const files = [];
let page = 1;
while (true) {
const url = `${apiBaseUrl}/repos/${repository}/pulls/${pullNumber}/files?per_page=100&page=${page}`;
const batch = await apiRequest(url);
if (!Array.isArray(batch)) {
throw new Error(`Unexpected response while listing PR files on page ${page}.`);
}
if (batch.length === 0) {
break;
}
files.push(...batch);
if (batch.length < 100) {
break;
}
page += 1;
}
return files;
}
async function getPullRequest(apiBaseUrl, repository, pullNumber) {
const url = `${apiBaseUrl}/repos/${repository}/pulls/${pullNumber}`;
const pullRequest = await apiRequest(url);
if (!pullRequest || typeof pullRequest !== 'object') {
throw new Error('Unexpected response while fetching pull request details.');
}
return pullRequest;
}
async function ensureReviewerRequested(apiBaseUrl, repository, pullNumber, pullRequest) {
const authorLogin = String(pullRequest?.user?.login || '').toLowerCase();
const targetReviewer = REVIEWER_LOGIN.toLowerCase();
if (authorLogin === targetReviewer) {
console.log(`Skipping reviewer request: ${REVIEWER_LOGIN} is the PR author.`);
return;
}
const requestedReviewers = Array.isArray(pullRequest?.requested_reviewers)
? pullRequest.requested_reviewers
: [];
const alreadyRequested = requestedReviewers.some(
(reviewer) => String(reviewer?.login || '').toLowerCase() === targetReviewer
);
if (alreadyRequested) {
console.log(`Reviewer ${REVIEWER_LOGIN} is already requested.`);
return;
}
const url = `${apiBaseUrl}/repos/${repository}/pulls/${pullNumber}/requested_reviewers`;
try {
await apiRequest(url, 'POST', { reviewers: [REVIEWER_LOGIN] });
console.log(`Requested reviewer ${REVIEWER_LOGIN}.`);
} catch (error) {
// Reviewer request should not fail the telemetry guidance workflow.
console.warn(
`Unable to request reviewer ${REVIEWER_LOGIN}: ${error instanceof Error ? error.message : String(error)}`
);
}
}
async function findExistingTelemetryComment(apiBaseUrl, repository, pullNumber) {
let page = 1;
while (true) {
const commentsUrl = `${apiBaseUrl}/repos/${repository}/issues/${pullNumber}/comments?per_page=100&page=${page}`;
const comments = await apiRequest(commentsUrl);
if (!Array.isArray(comments)) {
throw new Error(`Unexpected response while listing issue comments on page ${page}.`);
}
const existing = comments.find(
(comment) => typeof comment.body === 'string' && comment.body.includes(COMMENT_MARKER)
);
if (existing) {
return existing;
}
if (comments.length < 100) {
return null;
}
page += 1;
}
}
function detectTelemetryChanges(files) {
const matches = [];
for (const file of files) {
const filename = file.filename || '';
const telemetryPath = isTelemetryPath(filename);
const changedLines = changedLinesFromPatch(file.patch);
const telemetryLineSignal = hasTelemetryLineSignal(changedLines);
// Some large diffs omit patch content. If the file path is telemetry-centric,
// treat it as a telemetry modification to avoid false negatives.
const patchUnavailable = !file.patch && telemetryPath;
if (telemetryPath || telemetryLineSignal || patchUnavailable) {
matches.push({
filename,
telemetryPath,
telemetryLineSignal,
patchUnavailable,
});
}
}
return matches;
}
function hasDataAndPrivacyChange(files) {
return files.some((file) => {
const filename = (file.filename || '').toLowerCase();
return filename === 'data_and_privacy.md';
});
}
async function upsertPrComment(apiBaseUrl, repository, pullNumber, body) {
const existing = await findExistingTelemetryComment(apiBaseUrl, repository, pullNumber);
if (existing) {
const updateUrl = `${apiBaseUrl}/repos/${repository}/issues/comments/${existing.id}`;
await apiRequest(updateUrl, 'PATCH', { body });
console.log(`Updated existing telemetry comment (id: ${existing.id}).`);
return;
}
const createUrl = `${apiBaseUrl}/repos/${repository}/issues/${pullNumber}/comments`;
await apiRequest(createUrl, 'POST', { body });
console.log('Created telemetry comment on PR.');
}
async function main() {
const eventPath = requireEnv('GITHUB_EVENT_PATH');
const repository = requireEnv('GITHUB_REPOSITORY');
const apiBaseUrl = process.env.GITHUB_API_URL || 'https://api.github.com';
validateRepository(repository);
let parsedApiBaseUrl;
try {
parsedApiBaseUrl = new URL(apiBaseUrl);
} catch {
throw new Error(`Invalid GITHUB_API_URL: ${JSON.stringify(apiBaseUrl)}`);
}
const event = readEventPayload(eventPath);
const pullNumber = resolvePullNumber(event);
console.log(`Event name: ${process.env.GITHUB_EVENT_NAME || 'unknown'}`);
console.log(`Repository: ${repository}`);
console.log(`PR number: ${pullNumber}`);
const files = await getAllPullFiles(parsedApiBaseUrl.origin, repository, pullNumber);
if (files.length === 0) {
console.log('No changed files found for PR; skipping telemetry comment update.');
return;
}
const matches = detectTelemetryChanges(files);
const dataAndPrivacyChanged = hasDataAndPrivacyChange(files);
console.log(`Scanned ${files.length} changed files.`);
console.log(`Telemetry matches found: ${matches.length}.`);
console.log(`DATA_AND_PRIVACY.md changed: ${dataAndPrivacyChanged}.`);
if (matches.length === 0) {
console.log('No telemetry-related additions/modifications detected.');
return;
}
for (const match of matches) {
console.log(
`- ${match.filename} (telemetryPath=${match.telemetryPath}, telemetryLineSignal=${match.telemetryLineSignal}, patchUnavailable=${match.patchUnavailable})`
);
}
try {
const pullRequest = await getPullRequest(parsedApiBaseUrl.origin, repository, pullNumber);
await ensureReviewerRequested(parsedApiBaseUrl.origin, repository, pullNumber, pullRequest);
} catch (error) {
console.warn(
'Failed to fetch PR details or request reviewer; continuing to post telemetry guidance comment.'
);
console.warn(error instanceof Error ? error.stack || error.message : error);
}
const commentBody = dataAndPrivacyChanged
? COMMENT_BODY_WITH_PRIVACY_UPDATE
: COMMENT_BODY_WITHOUT_PRIVACY_UPDATE;
await upsertPrComment(apiBaseUrl, repository, pullNumber, commentBody);
}
main().catch((error) => {
console.error('Telemetry PR check failed.');
console.error(error instanceof Error ? error.stack || error.message : error);
process.exit(1);
});

View File

@@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Apply area labels with AI
uses: actions/github-script@v9
uses: actions/github-script@v7
env:
# actions/github-script does not propagate `github-token` to
# process.env. Expose it explicitly so the inline script can
@@ -88,8 +88,8 @@ jobs:
'Product-Advanced Paste',
'Product-Always On Top',
'Product-Awake',
'Product-ColorPicker',
'Product-Command Not Found',
'Product-Color Picker',
'Product-CommandNotFound',
'Product-Command Palette',
'Product-CropAndLock',
'Product-Environment Variables',
@@ -98,7 +98,7 @@ jobs:
'Product-File Locksmith',
'Product-Find My Mouse',
'Product-Grab And Move',
'Product-Hosts',
'Product-Hosts File Editor',
'Product-Image Resizer',
'Product-Keyboard Manager',
'Product-LightSwitch',
@@ -109,7 +109,7 @@ jobs:
'Product-Mouse Without Borders',
'Product-New+',
'Product-Peek',
'Product-Power Display',
'Product-PowerDisplay',
'Product-PowerRename',
'Product-PowerToys Run',
'Product-Quick Accent',

View File

@@ -0,0 +1,35 @@
# NOTE: This workflow depends on .github/scripts/telemetry-pr-check.js for telemetry detection and PR comments.
# Keep this workflow and script behavior in sync when making changes.
name: Telemetry PR Check
on:
pull_request_target:
types: [opened, reopened, synchronize, ready_for_review]
workflow_dispatch:
inputs:
pr_number:
description: "Pull Request Number to test against"
required: true
type: string
permissions:
contents: read
pull-requests: write
concurrency:
group: telemetry-pr-check-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
detect-telemetry-events:
if: ${{ github.event.pull_request.draft == false }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Detect telemetry event changes and comment PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node .github/scripts/telemetry-pr-check.js

5
.gitignore vendored
View File

@@ -370,3 +370,8 @@ installer/*/*.wxs.bk
.squad-workstream
.github/agents/**squad**.md
.github/workflows/**squad**.yml
# vcpkg manifest mode installed packages
vcpkg_installed/
deps/vcpkg/

6
.gitmodules vendored
View File

@@ -1,6 +0,0 @@
[submodule "deps/spdlog"]
path = deps/spdlog
url = https://github.com/gabime/spdlog.git
[submodule "deps/expected-lite"]
path = deps/expected-lite
url = https://github.com/martinmoene/expected-lite.git

View File

@@ -212,6 +212,7 @@
"WinUI3Apps\\PowerToys.NewPlus.ShellExtension.win10.dll",
"PowerAccent.Core.dll",
"PowerAccent.Common.dll",
"PowerToys.PowerAccent.dll",
"PowerToys.PowerAccent.exe",
"PowerToys.PowerAccentModuleInterface.dll",
@@ -243,8 +244,12 @@
"WinUI3Apps\\PowerToys.RegistryPreview.dll",
"WinUI3Apps\\PowerToys.RegistryPreview.exe",
"PowerToys.ShortcutGuide.exe",
"PowerToys.ShortcutGuideModuleInterface.dll",
"WinUI3Apps\\PowerToys.ShortcutGuide.exe",
"WinUI3Apps\\PowerToys.ShortcutGuide.dll",
"WinUI3Apps\\PowerToys.ShortcutGuideModuleInterface.dll",
"WinUI3Apps\\PowerToys.ShortcutGuide.IndexYmlGenerator.dll",
"WinUI3Apps\\PowerToys.ShortcutGuide.IndexYmlGenerator.exe",
"WinUI3Apps\\ShortcutGuide.CPPProject.dll",
"PowerToys.ZoomIt.exe",
"PowerToys.ZoomItModuleInterface.dll",
@@ -383,6 +388,11 @@
"ColorCode.Core.dll",
"Microsoft.SemanticKernel.Connectors.Ollama.dll",
"OllamaSharp.dll",
"WinUI3Apps\\Google.Apis.dll",
"WinUI3Apps\\Google.Apis.Auth.dll",
"WinUI3Apps\\Google.Apis.Core.dll",
"WinUI3Apps\\Google.GenAI.dll",
"WinUI3Apps\\YamlDotNet.dll",
"boost_regex-vc143-mt-gd-x32-1_87.dll",
"boost_regex-vc143-mt-gd-x64-1_87.dll",

View File

@@ -104,6 +104,10 @@ extends:
# Have msbuild use the release nuget config profile
additionalBuildOptions: /p:RestoreConfigFile="$(Build.SourcesDirectory)\.pipelines\release-nuget.config" /p:EnableCmdPalAOT=true
beforeBuildSteps:
# Install the Terrapin retrieval tool, which replaces vcpkg's download handler
# to redirect it to a safe Microsoft-controlled location
- template: .pipelines/v2/templates/steps-install-terrapin.yml@self
# Sets versions for all PowerToy created DLLs
- pwsh: |-
.pipelines/versionSetting.ps1 -versionNumber '${{ parameters.versionNumber }}' -DevEnvironment ''
@@ -140,6 +144,10 @@ extends:
signCertName: $(SigningSignCertName)
useManagedIdentity: $(SigningUseManagedIdentity)
clientId: $(SigningOriginalClientId)
beforeBuildSteps:
# Install the Terrapin retrieval tool, which replaces vcpkg's download handler
# to redirect it to a safe Microsoft-controlled location
- template: .pipelines/v2/templates/steps-install-terrapin.yml@self
- stage: Publish
displayName: Publish

View File

@@ -270,6 +270,34 @@ jobs:
parameters:
directory: $(build.sourcesdirectory)\src\modules\cmdpal
# --- vcpkg detection + binary cache --------------------------------------
# PowerToys consumes spdlog (and, over time, other native deps) via vcpkg in
# manifest mode. steps-install-vcpkg.yml prefers the vcpkg shipped with
# Visual Studio (Microsoft.VisualStudio.Component.Vcpkg) and falls back to a
# fresh clone of microsoft/vcpkg into deps/vcpkg if VS doesn't have it.
# Either way it sets the VCPKG_ROOT pipeline variable; MSBuild integration
# is wired globally from Cpp.Build.props (with vcpkg.targets in
# Cpp.Build.targets) using the three-tier VcpkgRoot fallback
# (env var > VS-shipped > deps/vcpkg runtime clone).
#
# Vcpkg's MSBuild integration runs `vcpkg install` once per project, so the
# binary cache below saves ~3-5 minutes per triplet on cache hits.
- template: .\steps-install-vcpkg.yml
parameters:
useVSPreview: ${{ parameters.useVSPreview }}
- ${{ if eq(parameters.enablePackageCaching, true) }}:
- task: Cache@2
displayName: 'Cache vcpkg binary archives'
inputs:
# Key on the inputs vcpkg uses to compute its package ABI: the manifest,
# configuration, every overlay-port file, and the agent OS.
key: '"vcpkg" | "$(Agent.OS)" | vcpkg.json | vcpkg-configuration.json | deps/vcpkg-overlays/**'
restoreKeys: |
"vcpkg" | "$(Agent.OS)"
"vcpkg"
path: $(LOCALAPPDATA)\vcpkg\archives
- ${{ parameters.beforeBuildSteps }}

View File

@@ -15,6 +15,9 @@ parameters:
- name: signingIdentity
type: object
default: {}
- name: beforeBuildSteps
type: stepList
default: []
jobs:
- job: "BuildSDK"
@@ -45,6 +48,8 @@ jobs:
parameters:
directory: $(build.sourcesdirectory)\src\modules\cmdpal
- ${{ parameters.beforeBuildSteps }}
- pwsh: |-
& "$(build.sourcesdirectory)\src\modules\cmdpal\extensionsdk\nuget\BuildSDKHelper.ps1" -Configuration "Release" -BuildStep "build" -IsAzurePipelineBuild
displayName: Build SDK

View File

@@ -0,0 +1,6 @@
steps:
- pwsh: |-
nuget install -source "https://microsoft.pkgs.visualstudio.com/Dart/_packaging/PowerToysDependencies/nuget/v3/index.json" TerrapinRetrievalTool -Prerelease -OutputDirectory _trt -Config "$(Build.SourcesDirectory)\.pipelines\release-nuget.config"
$TerrapinRetrievalToolPath = (Get-Item _trt\TerrapinRetrievalTool.*\win-x64\TerrapinRetrievalTool.exe).FullName
Write-Host "##vso[task.setvariable variable=X_VCPKG_ASSET_SOURCES]x-script,${TerrapinRetrievalToolPath} -b https://vcpkg.storage.devpackages.microsoft.io/artifacts/ -a true -u None -p {url} -s {sha512} -d {dst};x-block-origin"
displayName: Set up the Terrapin Retrieval Tool (vcpkg cache)

View File

@@ -0,0 +1,41 @@
# Adapted from microsoft/terminal build/pipelines/templates-v2/steps-install-vcpkg.yml.
#
# Detects vcpkg from (in order):
# 1. The Visual Studio installation (Microsoft.VisualStudio.Component.Vcpkg,
# declared in the repo-root .vsconfig).
# 2. A local clone at deps/vcpkg, cloned and bootstrapped on demand.
#
# Sets the pipeline-scoped VCPKG_ROOT variable; the rest of the build
# resolves vcpkg through it (see the three-tier VcpkgRoot fallback in
# Cpp.Build.props). No repo-level vcpkg submodule required.
parameters:
- name: useVSPreview
type: boolean
default: false
steps:
- pwsh: |-
# vswhere -prerelease is opt-in via the useVSPreview parameter so CI on
# stable VS doesn't accidentally pick up a Preview install when both
# are present. Matches the existing useVSPreview plumbing for
# verifyAndSetLatestVCToolsVersion.ps1.
$vswhereArgs = @('-latest', '-requires', 'Microsoft.VisualStudio.Component.Vcpkg', '-property', 'installationPath')
$useVSPreview = '${{ parameters.useVSPreview }}' -eq 'True'
if ($useVSPreview) { $vswhereArgs = @('-prerelease') + $vswhereArgs }
$VsInstallRoot = & 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' @vswhereArgs
If ([String]::IsNullOrEmpty($VsInstallRoot)) {
Remove-Item -Recurse -Force deps/vcpkg -ErrorAction:Ignore
git clone https://github.com/microsoft/vcpkg deps/vcpkg
if ($LASTEXITCODE -ne 0) { throw "git clone vcpkg failed (exit $LASTEXITCODE)" }
Push-Location deps/vcpkg
& ./bootstrap-vcpkg.bat -disableMetrics
if ($LASTEXITCODE -ne 0) { Pop-Location; throw "bootstrap-vcpkg failed (exit $LASTEXITCODE)" }
$VcpkgRoot = $PWD
Pop-Location
Write-Host "Using vcpkg from local checkout ($VcpkgRoot)"
} Else {
$VcpkgRoot = Join-Path $VsInstallRoot 'VC\vcpkg'
Write-Host "Using vcpkg from Visual Studio installation ($VcpkgRoot)"
}
Write-Host "##vso[task.setvariable variable=VCPKG_ROOT]$VcpkgRoot"
displayName: Detect VS vcpkg or bootstrap locally

View File

@@ -48,6 +48,11 @@ foreach ($csprojFile in $csprojFilesArray) {
continue
}
# The PowerAccent.Common project does not target WinRT, so skip it
if ($csprojFile -like '*PowerAccent.Common.csproj') {
continue
}
$importExists = Test-ImportSharedCsWinRTProps -filePath $csprojFile
if (!$importExists) {
Write-Output "$csprojFile need to import 'Common.Dotnet.CsWinRT.props'."

View File

@@ -18,6 +18,7 @@
"Microsoft.VisualStudio.Component.VC.ATL.ARM64.Spectre",
"Microsoft.VisualStudio.Component.VC.ATL",
"Microsoft.VisualStudio.Component.VC.ATL.Spectre",
"Microsoft.VisualStudio.Component.Vcpkg",
"Microsoft.VisualStudio.ComponentGroup.WindowsAppSDK.Cs"
]
}

View File

@@ -39,7 +39,8 @@
<PropertyGroup>
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
<PreferredToolArchitecture Condition="'$(PROCESSOR_ARCHITECTURE)' == 'ARM64' or '$(PROCESSOR_ARCHITEW6432)' == 'ARM64'">arm64</PreferredToolArchitecture>
<VcpkgEnabled>false</VcpkgEnabled>
<!-- vcpkg.targets is imported via Cpp.Build.targets after Microsoft.Cpp.targets. -->
<ForceImportAfterCppTargets>$(MSBuildThisFileDirectory)Cpp.Build.targets</ForceImportAfterCppTargets>
<ReplaceWildcardsInProjectItems>true</ReplaceWildcardsInProjectItems>
<ExternalIncludePath>$(MSBuildThisFileDirectory)deps;$(MSBuildThisFileDirectory)packages;$(ExternalIncludePath)</ExternalIncludePath>
<!-- Enable control flow guard for C++ projects that don't consume any C++ files -->
@@ -121,6 +122,48 @@
<SpectreMitigation>Spectre</SpectreMitigation>
</PropertyGroup>
<!--
vcpkg integration. Set globally and loaded before Microsoft.Cpp.props (via
ForceImportBeforeCppProps) so that vcpkg.props' ClCompile hook is in place
before the C++ targets run. VcpkgRoot is resolved via the same three-tier
fallback used by microsoft/terminal (env var → VS-shipped → deps/vcpkg).
-->
<PropertyGroup Label="vcpkg">
<VcpkgEnabled>true</VcpkgEnabled>
<VcpkgEnableManifest>true</VcpkgEnableManifest>
<VcpkgManifestEnabled>true</VcpkgManifestEnabled>
<VcpkgManifestRoot>$(MSBuildThisFileDirectory)</VcpkgManifestRoot>
<VcpkgOSTarget>windows</VcpkgOSTarget>
<VcpkgUseStatic>true</VcpkgUseStatic>
<!--
Force VcpkgConfiguration to follow $(Configuration). Without this,
vcpkg.props infers VcpkgConfiguration from $(UseDebugLibraries), which
Microsoft.Cpp.Default.props has already defaulted to 'false' by the
time vcpkg.props is imported here (the PowerToys-wide Debug override
below runs LATER). That would silently link the Release-built spdlog
into Debug consumers and trigger LNK2038 (MT/MTd, _ITERATOR_DEBUG_LEVEL).
-->
<VcpkgConfiguration>$(Configuration)</VcpkgConfiguration>
<!-- vcpkg validates triplets case-sensitively; PowerToys uses ARM64 capital-case. -->
<VcpkgPlatformTarget Condition="'$(Platform)' == 'ARM64'">arm64</VcpkgPlatformTarget>
<VcpkgApplocalDeps>false</VcpkgApplocalDeps>
<VcpkgInstalledDir>$(MSBuildThisFileDirectory)vcpkg_installed\$(Platform)\</VcpkgInstalledDir>
<VcpkgRoot Condition="'$(VcpkgRoot)' == ''">$(VCPKG_ROOT)</VcpkgRoot>
<VcpkgRoot Condition="'$(VcpkgRoot)' == '' and '$(VsInstallRoot)' != ''">$(VsInstallRoot)\VC\vcpkg</VcpkgRoot>
<VcpkgRoot Condition="'$(VcpkgRoot)' == '' or !Exists('$(VcpkgRoot)\vcpkg.exe')">$(MSBuildThisFileDirectory)deps\vcpkg</VcpkgRoot>
<CAExcludePath>$(CAExcludePath);$(VcpkgInstalledDir)</CAExcludePath>
<VCPkgLocalAppDataDisabled>true</VCPkgLocalAppDataDisabled>
</PropertyGroup>
<!-- Fail fast with an actionable message instead of opaque C1083 spdlog/spdlog.h errors. -->
<Target Name="PowerToysEnsureVcpkgAvailable"
BeforeTargets="PrepareForBuild"
Condition="'$(MSBuildProjectExtension)' == '.vcxproj' and '$(VcpkgEnabled)' == 'true' and !Exists('$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props')">
<Error Text="PowerToys requires the 'vcpkg' Visual Studio component, but it was not found.%0A%0AOpen the Visual Studio Installer, click Modify on your VS install, search for 'vcpkg', enable 'C++ vcpkg package manager', and click Modify. (Visual Studio will also prompt you to install missing .vsconfig components when you open PowerToys.slnx.)%0A%0AIf you have vcpkg installed elsewhere, set the VCPKG_ROOT environment variable to its root before building.%0A%0ASearched: '$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props'" />
</Target>
<Import Project="$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props"
Condition="'$(MSBuildProjectExtension)' == '.vcxproj' and Exists('$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props')" />
<!-- Debug/Release props -->
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>

16
Cpp.Build.targets Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<!--
PowerToys global C++ post-targets. Wired in via
<ForceImportAfterCppTargets> in Cpp.Build.props so MSBuild loads this
file AFTER Microsoft.Cpp.targets for every .vcxproj.
Conditionally imports vcpkg.targets to hook ClCompile into vcpkg's
VcpkgInstallManifestDependencies target so spdlog headers are
auto-discovered on the include path and spdlog.lib is auto-linked.
vcpkg.props is imported in Cpp.Build.props (before Microsoft.Cpp.props);
vcpkg.targets needs the matching "after" hook here.
-->
<Import Project="$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.targets"
Condition="'$(MSBuildProjectExtension)' == '.vcxproj' and '$(VcpkgEnabled)' == 'true' and Exists('$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.targets')" />
</Project>

View File

@@ -41,34 +41,34 @@
<PackageVersion Include="MessagePack" Version="3.1.3" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.102" />
<PackageVersion Include="Microsoft.CommandPalette.Extensions" Version="0.9.260303001" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="10.0.7" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="10.0.8" />
<!-- Including Microsoft.Bcl.AsyncInterfaces to force version, since it's used by Microsoft.SemanticKernel. -->
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.7" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.8" />
<PackageVersion Include="Microsoft.Graphics.Win2D" Version="1.3.2" />
<PackageVersion Include="Microsoft.Windows.CppWinRT" Version="2.0.250303.1" />
<PackageVersion Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.16" />
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.9.1" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.9.1-preview.1.25474.6" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="10.0.7" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="10.0.7" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.7" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.7" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.7" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.7" />
<PackageVersion Include="Microsoft.Extensions.Hosting.WindowsServices" Version="10.0.7" />
<PackageVersion Include="Microsoft.Extensions.AI" Version="10.2.0" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="10.0.1-preview.1.25571.5" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="10.0.8" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="10.0.8" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.8" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.8" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.8" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<PackageVersion Include="Microsoft.Extensions.Hosting.WindowsServices" Version="10.0.8" />
<PackageVersion Include="Microsoft.AI.Foundry.Local" Version="0.3.0" />
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.66.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.66.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.AzureAIInference" Version="1.66.0-beta" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.Google" Version="1.66.0-alpha" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.MistralAI" Version="1.66.0-alpha" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.Ollama" Version="1.66.0-alpha" />
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.71.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.71.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.AzureAIInference" Version="1.71.0-beta" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.Google" Version="1.71.0-alpha" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.MistralAI" Version="1.71.0-alpha" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.Ollama" Version="1.71.0-alpha" />
<PackageVersion Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.3719.77" />
<!-- Package Microsoft.Win32.SystemEvents added as a hack for being able to exclude the runtime assets so they don't conflict with 8.0.1. This is a dependency of System.Drawing.Common but the 8.0.1 version wasn't published to nuget. -->
<PackageVersion Include="Microsoft.Win32.SystemEvents" Version="10.0.7" />
<PackageVersion Include="Microsoft.Win32.SystemEvents" Version="10.0.8" />
<PackageVersion Include="Microsoft.WindowsPackageManager.ComInterop" Version="1.10.340" />
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="10.0.7" />
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="10.0.8" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.269" />
<!-- CsWinRT version needs to be set to have a WinRT.Runtime.dll at the same version contained inside the NET SDK we're currently building on CI. -->
<!--
@@ -90,11 +90,12 @@
<PackageVersion Include="MSTest" Version="$(MSTestVersion)" />
<PackageVersion Include="MSTest.TestFramework" Version="$(MSTestVersion)" />
<PackageVersion Include="NJsonSchema" Version="11.4.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
<PackageVersion Include="NLog" Version="5.2.8" />
<PackageVersion Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageVersion Include="NLog.Schema" Version="5.2.8" />
<PackageVersion Include="OpenAI" Version="2.5.0" />
<PackageVersion Include="OpenAI" Version="2.7.0" />
<PackageVersion Include="Polly.Core" Version="8.6.5" />
<PackageVersion Include="ReverseMarkdown" Version="4.1.0" />
<PackageVersion Include="RtfPipe" Version="2.0.7677.4303" />
<PackageVersion Include="ScipBe.Common.Office.OneNote" Version="3.0.1" />
@@ -105,28 +106,28 @@
<PackageVersion Include="StreamJsonRpc" Version="2.21.69" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<!-- Package System.CodeDom added as a hack for being able to exclude the runtime assets so they don't conflict with 8.0.1. This is a dependency of System.Management but the 8.0.1 version wasn't published to nuget. -->
<PackageVersion Include="System.CodeDom" Version="10.0.7" />
<PackageVersion Include="System.CodeDom" Version="10.0.8" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.ComponentModel.Composition" Version="10.0.7" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="10.0.7" />
<PackageVersion Include="System.Data.OleDb" Version="10.0.7" />
<PackageVersion Include="System.ComponentModel.Composition" Version="10.0.8" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="10.0.8" />
<PackageVersion Include="System.Data.OleDb" Version="10.0.8" />
<!-- Package System.Diagnostics.EventLog added as a hack for being able to exclude the runtime assets so they don't conflict with 8.0.1. This is a dependency of System.Data.OleDb but the 8.0.1 version wasn't published to nuget. -->
<PackageVersion Include="System.Diagnostics.EventLog" Version="10.0.7" />
<PackageVersion Include="System.Diagnostics.EventLog" Version="10.0.8" />
<!-- Package System.Diagnostics.PerformanceCounter added as a hack for being able to exclude the runtime assets so they don't conflict with 8.0.11. -->
<PackageVersion Include="System.Diagnostics.PerformanceCounter" Version="10.0.7" />
<PackageVersion Include="System.ClientModel" Version="1.7.0" />
<PackageVersion Include="System.Drawing.Common" Version="10.0.7" />
<PackageVersion Include="System.Diagnostics.PerformanceCounter" Version="10.0.8" />
<PackageVersion Include="System.ClientModel" Version="1.8.1" />
<PackageVersion Include="System.Drawing.Common" Version="10.0.8" />
<PackageVersion Include="System.IO.Abstractions" Version="22.0.13" />
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="22.0.13" />
<PackageVersion Include="System.Management" Version="10.0.7" />
<PackageVersion Include="System.Management" Version="10.0.8" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Numerics.Tensors" Version="9.0.11" />
<PackageVersion Include="System.Numerics.Tensors" Version="10.0.2" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<PackageVersion Include="System.Runtime.Caching" Version="10.0.7" />
<PackageVersion Include="System.ServiceProcess.ServiceController" Version="10.0.7" />
<PackageVersion Include="System.Text.Encoding.CodePages" Version="10.0.7" />
<PackageVersion Include="System.Text.Json" Version="10.0.7" />
<PackageVersion Include="System.Runtime.Caching" Version="10.0.8" />
<PackageVersion Include="System.ServiceProcess.ServiceController" Version="10.0.8" />
<PackageVersion Include="System.Text.Encoding.CodePages" Version="10.0.8" />
<PackageVersion Include="System.Text.Json" Version="10.0.8" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="ToolGood.Words.Pinyin" Version="3.1.0.3" />
<PackageVersion Include="UnicodeInformation" Version="2.6.0" />
@@ -134,8 +135,8 @@
<PackageVersion Include="UTF.Unknown" Version="2.6.0" />
<PackageVersion Include="WinUIEx" Version="2.8.0" />
<PackageVersion Include="WmiLight" Version="6.14.0" />
<PackageVersion Include="WPF-UI" Version="3.0.5" />
<PackageVersion Include="WyHash" Version="1.0.5" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
<PackageVersion Include="WixToolset.Heat" Version="5.0.2" />
<PackageVersion Include="WixToolset.Firewall.wixext" Version="5.0.2" />
<PackageVersion Include="WixToolset.Util.wixext" Version="5.0.2" />

View File

@@ -1600,5 +1600,5 @@ SOFTWARE.
- UTF.Unknown
- WinUIEx
- WmiLight
- WPF-UI
- WyHash
- YamlDotNet

View File

@@ -57,6 +57,7 @@
<Project Path="src/common/UnitTests-CommonLib/UnitTests-CommonLib.vcxproj" Id="1a066c63-64b3-45f8-92fe-664e1cce8077" />
<Project Path="src/common/UnitTests-CommonUtils/UnitTests-CommonUtils.vcxproj" Id="8b5cfb38-ccba-40a8-ad7a-89c57b070884" />
<Project Path="src/common/updating/updating.vcxproj" Id="17da04df-e393-4397-9cf0-84dabe11032e" />
<Project Path="src/common/updating/UnitTests/UpdatingUnitTests.vcxproj" Id="a1b2c3d4-e5f6-7890-abcd-ef1234567890" />
<Project Path="src/common/version/version.vcxproj" Id="cc6e41ac-8174-4e8a-8d22-85dd7f4851df" />
</Folder>
<Folder Name="/common/interop/">
@@ -67,10 +68,7 @@
<Project Path="src/common/interop/PowerToys.Interop.vcxproj" Id="f055103b-f80b-4d0c-bf48-057c55620033" />
</Folder>
<Folder Name="/common/log/">
<Project Path="src/common/logger/logger.vcxproj" Id="d9b8fc84-322a-4f9f-bbb9-20915c47ddfd">
<BuildDependency Project="src/logging/logging.vcxproj" />
</Project>
<Project Path="src/logging/logging.vcxproj" Id="7e1e3f13-2bd6-3f75-a6a7-873a2b55c60f" />
<Project Path="src/common/logger/logger.vcxproj" Id="d9b8fc84-322a-4f9f-bbb9-20915c47ddfd" />
</Folder>
<Folder Name="/common/notifications/">
<Project Path="src/common/notifications/BackgroundActivator/BackgroundActivator.vcxproj" Id="0b593a6c-4143-4337-860e-db5710fb87db" />
@@ -470,6 +468,12 @@
<Platform Solution="*|x64" Project="x64" />
</Project>
</Folder>
<Folder Name="/modules/DesktopGrass/">
<Project Path="src/modules/DesktopGrass/DesktopGrass.Native/DesktopGrass.Native.vcxproj" Id="b0d4e1b0-1f5e-4c2d-9f44-da8c3f1a2a11" />
</Folder>
<Folder Name="/modules/DesktopGrass/Tests/">
<Project Path="src/modules/DesktopGrass/DesktopGrass.Native.Tests/DesktopGrass.Native.Tests.vcxproj" />
</Folder>
<Folder Name="/modules/imageresizer/">
<Project Path="src/modules/imageresizer/dll/ImageResizerExt.vcxproj" Id="0b43679e-edfa-4da0-ad30-f4628b308b1b" />
<Project Path="src/modules/imageresizer/ImageResizerCLI/ImageResizerCLI.csproj">
@@ -801,6 +805,14 @@
<Project Path="src/modules/peek/peek/peek.vcxproj" Id="a1425b53-3d61-4679-8623-e64a0d3d0a48" />
</Folder>
<Folder Name="/modules/PowerAccent/">
<Project Path="src/modules/poweraccent/PowerAccent.Common.UnitTests/PowerAccent.Common.UnitTests.csproj">
<Platform Solution="*|ARM64" Project="ARM64" />
<Platform Solution="*|x64" Project="x64" />
</Project>
<Project Path="src/modules/poweraccent/PowerAccent.Common/PowerAccent.Common.csproj">
<Platform Solution="*|ARM64" Project="ARM64" />
<Platform Solution="*|x64" Project="x64" />
</Project>
<Project Path="src/modules/poweraccent/PowerAccent.Core/PowerAccent.Core.csproj">
<Platform Solution="*|ARM64" Project="ARM64" />
<Platform Solution="*|x64" Project="x64" />
@@ -989,9 +1001,16 @@
<Platform Solution="*|x64" Project="x64" />
</Project>
</Folder>
<Folder Name="/modules/shortcutguide/">
<Project Path="src/modules/ShortcutGuide/ShortcutGuide/ShortcutGuide.vcxproj" Id="2edb3eb4-fa92-4bff-b2d8-566584837231" />
<Project Path="src/modules/ShortcutGuide/ShortcutGuideModuleInterface/ShortcutGuideModuleInterface.vcxproj" Id="2d604c07-51fc-46bb-9eb7-75aecc7f5e81" />
<Folder Name="/modules/ShortcutGuide/">
<Project Path="src/modules/ShortcutGuide/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator.csproj">
<Platform Solution="*|ARM64" Project="ARM64" />
<Platform Solution="*|x64" Project="x64" />
</Project>
<Project Path="src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuide.Ui.csproj">
<Platform Solution="*|ARM64" Project="ARM64" />
<Platform Solution="*|x64" Project="x64" />
</Project>
<Project Path="src/modules/ShortcutGuide/ShortcutGuideModuleInterface/ShortcutGuideModuleInterface.vcxproj" Id="e487304a-b1fb-4e6b-8e70-014051af5b99" />
</Folder>
<Folder Name="/modules/Workspaces/">
<Project Path="src/modules/Workspaces/Workspaces.ModuleServices/Workspaces.ModuleServices.csproj">
@@ -1126,3 +1145,5 @@
<Project Path="src/Update/PowerToys.Update.vcxproj" Id="44ce9ae1-4390-42c5-bacc-0fd6b40aa203" />
<Project Path="tools/project_template/ModuleTemplate/ModuleTemplateCompileTest.vcxproj" Id="64a80062-4d8b-4229-8a38-dfa1d7497749" />
</Solution>

1
deps/expected-lite vendored

Submodule deps/expected-lite deleted from 95b9cb015f

7
deps/expected.props vendored
View File

@@ -1,7 +0,0 @@
<Project>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)expected-lite\include\nonstd\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
</Project>

1
deps/spdlog vendored

Submodule deps/spdlog deleted from 616866fcf4

View File

@@ -1,94 +0,0 @@
// spdlog-msvc-fix.h
//
// Workaround for MSVC 14.51 (compiler version 19.51, _MSC_VER >= 1951) removing
// stdext::checked_array_iterator. Force-included for all spdlog consumers via
// deps/spdlog.props, because spdlog v1.8.5's bundled fmt format.h(357) still
// references this type inside #if defined(_SECURE_SCL) && _SECURE_SCL -- a
// branch entered in Debug builds where _ITERATOR_DEBUG_LEVEL > 0.
//
// On MSVC 14.50 and earlier, the type still exists in <iterator>, so this shim
// is a no-op via the _MSC_VER guard. On MSVC 14.51+, it provides a minimal
// pointer-backed substitute that satisfies the bundled fmt's usage:
//
// template <typename T> using checked_ptr = stdext::checked_array_iterator<T*>;
// template <typename T> checked_ptr<T> make_checked(T* p, size_t size) {
// return {p, size};
// }
// ... return make_checked(get_data(c) + size, n);
//
// When deps/spdlog is bumped past v1.14 (which ships fmt 10.2 and drops this
// dependency), this shim and its <ForcedIncludeFiles> entry in deps/spdlog.props
// can be deleted.
#pragma once
#if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER >= 1951
#include <cstddef>
#include <iterator>
#include <type_traits>
namespace stdext
{
template <typename _Ptr>
class checked_array_iterator
{
_Ptr _Myarray = nullptr;
std::size_t _Mysize = 0;
std::size_t _Myindex = 0;
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = std::remove_cv_t<std::remove_pointer_t<_Ptr>>;
using difference_type = std::ptrdiff_t;
using pointer = _Ptr;
using reference = std::remove_pointer_t<_Ptr>&;
constexpr checked_array_iterator() = default;
constexpr checked_array_iterator(_Ptr arr, std::size_t size, std::size_t idx = 0) noexcept
: _Myarray(arr), _Mysize(size), _Myindex(idx)
{
}
constexpr reference operator*() const noexcept { return _Myarray[_Myindex]; }
constexpr pointer operator->() const noexcept { return _Myarray + _Myindex; }
constexpr reference operator[](difference_type n) const noexcept
{
return _Myarray[_Myindex + static_cast<std::size_t>(n)];
}
constexpr checked_array_iterator& operator++() noexcept { ++_Myindex; return *this; }
constexpr checked_array_iterator operator++(int) noexcept { auto t = *this; ++_Myindex; return t; }
constexpr checked_array_iterator& operator--() noexcept { --_Myindex; return *this; }
constexpr checked_array_iterator operator--(int) noexcept { auto t = *this; --_Myindex; return t; }
constexpr checked_array_iterator& operator+=(difference_type n) noexcept
{
_Myindex = static_cast<std::size_t>(static_cast<difference_type>(_Myindex) + n);
return *this;
}
constexpr checked_array_iterator& operator-=(difference_type n) noexcept
{
_Myindex = static_cast<std::size_t>(static_cast<difference_type>(_Myindex) - n);
return *this;
}
friend constexpr checked_array_iterator operator+(checked_array_iterator it, difference_type n) noexcept { it += n; return it; }
friend constexpr checked_array_iterator operator+(difference_type n, checked_array_iterator it) noexcept { return it + n; }
friend constexpr checked_array_iterator operator-(checked_array_iterator it, difference_type n) noexcept { it -= n; return it; }
friend constexpr difference_type operator-(checked_array_iterator a, checked_array_iterator b) noexcept
{
return static_cast<difference_type>(a._Myindex) - static_cast<difference_type>(b._Myindex);
}
friend constexpr bool operator==(checked_array_iterator a, checked_array_iterator b) noexcept { return a._Myindex == b._Myindex; }
friend constexpr bool operator!=(checked_array_iterator a, checked_array_iterator b) noexcept { return !(a == b); }
friend constexpr bool operator<(checked_array_iterator a, checked_array_iterator b) noexcept { return a._Myindex < b._Myindex; }
friend constexpr bool operator>(checked_array_iterator a, checked_array_iterator b) noexcept { return b < a; }
friend constexpr bool operator<=(checked_array_iterator a, checked_array_iterator b) noexcept { return !(b < a); }
friend constexpr bool operator>=(checked_array_iterator a, checked_array_iterator b) noexcept { return !(a < b); }
};
} // namespace stdext
#endif // __cplusplus && _MSC_VER >= 1951

19
deps/spdlog.props vendored
View File

@@ -1,9 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)spdlog\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>SPDLOG_WCHAR_TO_UTF8_SUPPORT;SPDLOG_COMPILED_LIB;SPDLOG_WCHAR_FILENAMES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ForcedIncludeFiles>$(MSBuildThisFileDirectory)spdlog-msvc-fix\include\spdlog-msvc-fix.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
</ClCompile>
</ItemDefinitionGroup>
<!--
SPDLOG_* preprocessor defines for spdlog consumers. The actual vcpkg
integration (VcpkgEnabled, VcpkgRoot, triplet, manifest install) lives
in Cpp.Build.props; this file just carries the defines that match how
the pre-vcpkg in-tree build was configured.
-->
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>SPDLOG_WCHAR_TO_UTF8_SUPPORT;SPDLOG_COMPILED_LIB;SPDLOG_WCHAR_FILENAMES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
</Project>

View File

@@ -0,0 +1,16 @@
--- a/include/spdlog/fmt/bundled/format.h
+++ b/include/spdlog/fmt/bundled/format.h
@@ -354,7 +354,12 @@ inline typename Container::value_type* get_data(Container& c) {
return c.data();
}
-#if defined(_SECURE_SCL) && _SECURE_SCL
+// PowerToys: stdext::checked_array_iterator was deprecated in VS 2019 16.10
+// and removed entirely in MSVC 14.51 (compiler 19.51, _MSC_VER >= 1951;
+// see microsoft/STL STL4043). Skip the broken branch on those toolsets so the
+// pointer-based fallback below is used instead. Drop this guard once
+// deps/spdlog is bumped past v1.14 (which ships fmt 10.2 and removes this code).
+#if defined(_SECURE_SCL) && _SECURE_SCL && (!defined(_MSC_VER) || _MSC_VER < 1951)
// Make a checked iterator to avoid MSVC warnings.
template <typename T> using checked_ptr = stdext::checked_array_iterator<T*>;
template <typename T> checked_ptr<T> make_checked(T* p, size_t size) {

View File

@@ -0,0 +1,43 @@
# PowerToys overlay port for spdlog.
#
# Pinned to the same git commit that the deleted deps/spdlog submodule pointed
# at, so this is a 1:1 submodule->vcpkg migration with no version change
# (per the maintainer guidance: convert one submodule at a time, atomic
# commit, don't also bump the version).
#
# A single hunk patch works around MSVC 14.51 STL4043 (removal of
# stdext::checked_array_iterator) in spdlog's bundled fmt 7. Drop this overlay
# (and switch to upstream vcpkg's spdlog port) once PowerToys bumps spdlog
# past v1.14, which ships fmt 10.2 and removes the affected code path.
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO gabime/spdlog
REF 616866fcf40340ea25a8f218369bad810ef58e72
SHA512 2076c527c7768627e6856b2f7ef663b185fd6251894cffd9299203d00f3d2de5696461060442dd72b96c9d3f0fd27f7f63ad2edfdf295e9b06c5fac6d6212faf
HEAD_REF v1.x
PATCHES
msvc-14.51-stdext-checked-array-iterator.patch
)
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DSPDLOG_BUILD_EXAMPLE=OFF
-DSPDLOG_BUILD_TESTS=OFF
-DSPDLOG_BUILD_BENCH=OFF
-DSPDLOG_FMT_EXTERNAL=OFF
-DSPDLOG_WCHAR_SUPPORT=ON
-DSPDLOG_WCHAR_FILENAMES=ON
-DSPDLOG_NO_EXCEPTIONS=OFF
-DSPDLOG_BUILD_SHARED=OFF
)
vcpkg_cmake_install()
vcpkg_cmake_config_fixup(PACKAGE_NAME spdlog CONFIG_PATH lib/cmake/spdlog)
vcpkg_fixup_pkgconfig()
vcpkg_copy_pdbs()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

18
deps/vcpkg-overlays/spdlog/vcpkg.json vendored Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "spdlog",
"version-string": "1.8.5-pt-616866fc",
"port-version": 0,
"description": "Very fast, header-only/compiled, C++ logging library. PowerToys overlay pinned to gabime/spdlog@616866fc (the exact submodule commit before this migration), with a single-hunk patch that works around MSVC 14.51 removing stdext::checked_array_iterator (STL4043).",
"homepage": "https://github.com/gabime/spdlog",
"license": "MIT",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}

View File

@@ -97,6 +97,10 @@ The Shell Process Debugging Tool is a Visual Studio extension that helps debug m
- Check Event Viewer for application crashes related to `PowerToys.Settings.exe`
- Crash dumps can be obtained from Event Viewer
### Debugging Command Palette
Command Palette can be easily debugged using the solution filter in `src/modules/cmdpal/Command Palette.slnf`. This will open Command Palette as its own Visual Studio solution that can be run and debugged directly in Visual Studio without the need for the Shell Process Debugging Tool.
## Troubleshooting Build Errors
### Missing Image Files or Corrupted Build State

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -9,12 +9,14 @@
[Pull Requests](https://github.com/microsoft/PowerToys/pulls?q=is%3Apr+is%3Aopen+label%3A%22Product-Shortcut+Guide%22+)
## Overview
Shortcut Guide is a PowerToy that displays an overlay of available keyboard shortcuts when the Windows key is pressed and held. It provides a visual reference for Windows key combinations, helping users discover and utilize built-in Windows shortcuts.
Shortcut Guide is a PowerToy that displays an overlay of available keyboard shortcuts when a user-set keyboard shortcut is pressed. It helps users discover and remember keyboard shortcuts for Windows and apps.
> [!NOTE]
> The spec for the manifest files is in development and will be linked here once available.
## Usage
- Press and hold the Windows key to display the overlay of available shortcuts
- Press the hotkey again to dismiss the overlay
- The overlay displays Windows shortcuts with their corresponding actions
- Press the user-defined hotkey to display the overlay
- Press the hotkey again or press ESC to dismiss the overlay
## Build and Debug Instructions
@@ -25,67 +27,89 @@ Shortcut Guide is a PowerToy that displays an overlay of available keyboard shor
4. The executable is named PowerToys.ShortcutGuide.exe
### Debug
1. Right-click the ShortcutGuide project and select 'Set as Startup Project'
1. Right-click the ShortcutGuide.Ui project and select 'Set as Startup Project'
2. Right-click the project again and select 'Debug'
## Code Structure
> [!NOTE]
> When run in debug mode, the window behaves differently than in release mode. It will not automatically close when loosing focus, it will be displayed on top of all other windows, and it is not hidden from the taskbar.
![Diagram](../images/shortcutguide/diagram.png)
## Project Structure
### Core Files
The Shortcut Guide module consists of the following 4 projects:
#### [`dllmain.cpp`](/src/modules/shortcut_guide/dllmain.cpp)
Contains DLL boilerplate code. Implements the PowertoyModuleIface, including enable/disable functionality and GPO policy handling. Captures hotkey events and starts the PowerToys.ShortcutGuide.exe process to display the shortcut guide window.
### [`ShortcutGuide.Ui`](/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuide.Ui.csproj
#### [`shortcut_guide.cpp`](/src/modules/shortcut_guide/shortcut_guide.cpp)
Contains the module interface code. It initializes the settings values and the keyboard event listener. Defines the OverlayWindow class, which manages the overall logic and event handling for the PowerToys Shortcut Guide.
This is the main UI project for the Shortcut Guide module. Upon startup it does the following tasks:
#### [`overlay_window.cpp`](/src/modules/shortcut_guide/overlay_window.cpp)
Contains the code for loading the SVGs, creating and rendering of the overlay window. Manages and displays overlay windows with SVG graphics through two main classes:
- D2DOverlaySVG: Handles loading, resizing, and manipulation of SVG graphics
- D2DOverlayWindow: Manages the display and behavior of the overlay window
1. Copies the built-in manifest files to the users manifest directory (overwriting existing files).
2. Generate the `index.yml` manifest file.
3. Populate the PowerToys shortcut manifest with the user-defined shortcuts.
4. Starts the UI.
#### [`keyboard_state.cpp`](/src/modules/shortcut_guide/keyboard_state.cpp)
Contains helper methods for checking the current state of the keyboard.
### Related files in PowerToys.Interop
#### [`target_state.cpp`](/src/modules/shortcut_guide/target_state.cpp)
State machine that handles the keyboard events. It's responsible for deciding when to show the overlay, when to suppress the Start menu (if the overlay is displayed long enough), etc. Handles state transitions and synchronization to ensure the overlay is shown or hidden appropriately based on user interactions.
#### [`excluded_app.cpp`](/src/modules/ShortcutGuide/ShortcutGuide.CPPProject/excluded_app.cpp)
#### [`trace.cpp`](/src/modules/shortcut_guide/trace.cpp)
Contains code for telemetry.
This file contains one function with the following signature:
### Supporting Files
```cpp
__declspec(dllexport) bool IsCurrentWindowExcludedFromShortcutGuide()
```
#### [`animation.cpp`](/src/modules/shortcut_guide/animation.cpp)
Handles the timing and interpolation of animations. Calculates the current value of an animation based on elapsed time and a specified easing function.
This function checks if the current window is excluded from the Shortcut Guide overlay. It returns `true` if the current window is excluded otherwise it returns `false`.
#### [`d2d_svg.cpp`](/src/modules/shortcut_guide/d2d_svg.cpp)
Provides functionality for loading, resizing, recoloring, rendering, and manipulating SVG images using Direct2D.
#### [`tasklist_positions.cpp`](/src/modules/ShortcutGuide/ShortcutGuide.CPPProject/tasklist_positions.cpp)
#### [`d2d_text.cpp`](/src/modules/shortcut_guide/d2d_text.cpp)
Handles creation, resizing, alignment, and rendering of text using Direct2D and DirectWrite.
This file contains helper functions to retrieve the positions of the taskbar buttons. It exports the following function:
#### [`d2d_window.cpp`](/src/modules/shortcut_guide/d2d_window.cpp)
Manages a window using Direct2D and Direct3D for rendering. Handles window creation, resizing, rendering, and destruction.
```cpp
__declspec(dllexport) TasklistButton* get_buttons(HMONITOR monitor, int* size)
```
#### [`native_event_waiter.cpp`](/src/modules/shortcut_guide/native_event_waiter.cpp)
Waits for a named event and executes a specified action when the event is triggered. Uses a separate thread to handle event waiting and action execution.
This function retrieves the positions of the taskbar buttons for a given monitor. It returns an array of `TasklistButton` structures (max 10), which contain the position and size of each button.
#### [`tasklist_positions.cpp`](/src/modules/shortcut_guide/tasklist_positions.cpp)
Handles retrieving and updating the positions and information of taskbar buttons in Windows.
`monitor` must be the monitor handle of the monitor containing the taskbar instance of which the buttons should be retrieved.
#### [`main.cpp`](/src/modules/shortcut_guide/main.cpp)
The entry point for the PowerToys Shortcut Guide application. Handles initialization, ensures single instance execution, manages parent process termination, creates and displays the overlay window, and runs the main event loop.
`size` will contain the resulting array size.
It determines the positions through Windows `FindWindowEx` function.
For the primary taskbar it searches for:
* A window called "Shell_TrayWnd"
* that contains a window called "ReBarWindow32"
* that contains a window called "MSTaskSwWClass"
* that contains a window called "MSTaskListWClass"
For any secondary taskbar it searches for:
* A window called "Shell_SecondaryTrayWnd"
* that contains a window called "WorkerW"
* that contains a window called "MSTaskListWClass"
It then enumerates all the button elements inside "MSTaskListWClass" while skipping such with a same name (which implies the user does not use combining taskbar buttons)
If this method fails, which it will for newer versions of Windows, it falls back to searching for:
* A window called "Shell_TrayWnd" or "Shell_SecondaryTrayWnd"
* that contains a window called "Windows.UI.Composition.DesktopWindowContentBridge"
* that contains a window called "Windows.UI.Input.InputSite.WindowClass"
* the first child element
It then enumerates all the button elements inside the selected while skipping such with a same name (which implies the user does not use combining taskbar buttons) and such that do not start with "Appid:" (which are not actual taskbar buttons related to apps, but others like the widgets or the search button).
### [`ShortcutGuide.IndexYmlGenerator`](/src/modules/ShortcutGuide/ShortcutGuide.IndexYmlGenerator/)
This application generates the `index.yml` manifest file.
It is a separate project so that its code can be easier ported to WinGet in the future.
### [`ShortcutGuideModuleInterface`](/src/modules/ShortcutGuide/ShortcutGuideModuleInterface/ShortcutGuideModuleInterface.vcxproj)
The module interface that handles opening and closing the user interface.
## Features and Limitations
- The overlay displays Windows shortcuts (Windows key combinations)
- The module supports localization, but only for the Windows controls on the left side of the overlay
- Currently the displayed shortcuts (Except the ones from PowerToys) are not localized.
- It's currently rated as a P3 (lower priority) module
## Future Development
A community-contributed version 2 is in development that will support:
- Application-specific shortcuts based on the active application
- Additional shortcuts beyond Windows key combinations
- PowerToys shortcuts
- Implementing with WinGet to get new shortcut manifest files
- Adding localization support for the built-in manifest files

Binary file not shown.

Before

Width:  |  Height:  |  Size: 275 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

@@ -0,0 +1,318 @@
# WinGet Manifest Keyboard Shortcuts schema
## 1 What this spec is about
This spec provides an extension to the existing [WinGet manifest schema](https://github.com/microsoft/winget-pkgs/blob/master/doc/manifest/README.md) in form of an additional yaml file, that describes keyboard shortcuts the application provides.
These yaml files are saved on a per-user base and so called manifest interpreters can then display these manifests in a human-friendly version.
### 1.1 What this spec is not about
This spec does not provide a way to back up or save user-defined keyboard shortcuts.
## 2 Save location of manifests
### 2.1 WinGet
These files are saved online along with the other manifest files in the [WinGet Package repository](https://github.com/microsoft/winget-pkgs).
### 2.2 Locally
All manifests and one index file are saved locally under `%LocalAppData%/Microsoft/WinGet/KeyboardShortcuts`. All apps are allowed to add their manifest files there. In addition Package Managers (like WinGet) and manifest interpreters (like PowerToys Shortcut Guide) can control and add other manifests themselves.
#### 2.2.1 Downloading manifests
When WinGet or other package managers download a package, they should also download the corresponding keyboard shortcuts manifest file and save it in the local directory, given such a file exists in the WinGet repository.
The downloader is also responsible for updating the local `index.yaml` file, which contains all the information about the different manifest files that are saved in the same directory.
#### 2.2.2 Updating manifests
When a manifest interpreter starts, it should download the latest version of the manifests from the WinGet repository and save them in the local directory. If a manifest interpreter is not able to download the manifests or they do not exist, it should use the locally saved manifests.
The updater is also responsible for updating the local `index.yaml` file, which contains all the information about the different manifest files that are saved in the same directory.
> Note: WinGet must provide a way to update the keyboard shortcuts manifests given a package id.
### 2.3 File names
The file name of a keyboard shortcuts file is the WinGet package identifier, plus the locale of the strings of the file and at last the `.KBSC.yaml` file extension.
For example the package "test.bar" saves its manifest with `en-US` strings in `test.bar.en-US.KBSC.yaml`.
#### 2.3.1 No winget package available
If an application has no corresponding WinGet package its name starts with a plus (`+`) symbol.
### 2.4 Reserved namespaces
Every name starting with `+WindowsNT` is reserved for the Windows OS and its components.
## 3 File syntax
All relevant files are written in [YAML](https://yaml.org/spec).
> Note: A JSON schema will be provided as soon as the spec reaches a further step
### 3.1 Manifest Schema vNext Keyboard Shortcuts File
```
PackageName: # The package unique identifier
WindowFilter: # The filter of window processes to which the shortcuts apply to
BackgroundProcess: # Optionally allows applying WindowFilter to background processes
Shortcuts: # List of sections with keyboard shortcuts
- SectionName: # Name of the category of shortcuts
Properties: # List of shortcuts in the category
- Name: # Name of the shortcut
Description: # Optional description of the shortcut
AdditionalInfo: # Optional additional information about the shortcut
Recommended: # Optionally determines if the shortcut is displayed in a designated recommended area
Shortcut: # An array of shortcuts that need to be pressed
- Win: # Determines if the Windows Key is part of the shortcut
Ctrl: # Determines if the Ctrl Key is part of the shortcut
Shift: # Determines if the Shift Key is part of the shortcut
Alt: # Determines if the Alt Key is part of the shortcut
Keys: # Array of keys that need to be pressed
```
Per Application/Package one or more Keyboard manifests can be declared. Every manifest must have a different locale and the same `PackageName`, `WindowFilter` and `BackgroundProcess` fields.
<details>
<summary><b>PackageName</b> - The package unique identifier</summary>
Package identifier (see 2.1 for more information on the package identifier).
</details>
<details>
<summary><b>WindowFilter</b> - The filter of window processes to which the shortcuts apply to</summary>
This field declares for which process name the shortcuts should be shown (To rephrase: For which processes the shortcut will have an effect if pressed). The value can be either an exact process executable name, for example `explorer.exe` or `chrome.exe`, or a single asterisk (`*`) to apply to any process. No other wildcard patterns are supported by this specification.
</details>
<details>
<summary><b>BackgroundProcess</b> - Optionally allows applying WindowFilter to background processes.</summary>
**Optional field**
Defaults to `False`. Determines if WindowFilter should apply to background processes as well (Rephrased: When the process is running, the shortcuts will apply).
</details>
<details>
<summary><b>Shortcuts</b> - List of sections with keyboard shortcuts</summary>
List of different section (also called categories) of shortcuts.
</details>
<details>
<summary><b>SectionName</b> - Name of the category of shortcuts</summary>
Name of the section of shortcuts.
**Special sections**:
Special sections start with an identifier enclosed between `<` and `>`. This declares the category as a special display. If the interpreter of the manifest file can't understand the content this section should be left out.
</details>
<details>
<summary><b>Properties</b> - List of shortcuts in the category</summary>
</details>
<details>
<summary><b>Name</b> - Name of the shortcut</summary>
Name of the shortcut. This is the name that will be displayed in the interpreter.
</details>
<details>
<summary><b>Description</b> - Optional description of the shortcut</summary>
Optional description of the shortcut. This is the description that will be displayed by the interpreter.
</details>
<details>
<summary><b>AdditionalInfo</b> - Optional additional information about the shortcut</summary>
Array of additional information about the shortcut. This is the additional information that will be displayed by the interpreter and are not part of this manifest.
**Example**:
For example, if the shortcut is only available on a certain Windows version, this information could be added here.
```yaml
AdditionalInfo:
- MinWindowsVersion: "10.0.19041.0"
```
</details>
<details>
<summary><b>Shortcut</b> - An array of shortcuts that need to be pressed</summary>
An array of shortcuts that need to be pressed. This allows defining sequential shortcuts that need to be pressed in order to trigger the action.
</details>
<details>
<summary><b>Win</b> - Determines if the Windows Key is part of the shortcut</summary>
Refers to the left Windows Key on the keyboard.
</details>
<details>
<summary><b>Ctrl</b> - Determines if the Ctrl Key is part of the shortcut</summary>
Refers to the left Ctrl Key on the keyboard.
</details>
<details>
<summary><b>Shift</b> - Determines if the Shift Key is part of the shortcut</summary>
Refers to the left Shift Key on the keyboard.
</details>
<details>
<summary><b>Alt</b> - Determines if the Alt Key is part of the shortcut</summary>
Refers to the left Alt Key on the keyboard.
</details>
<details>
<summary><b>Recommended</b> - Optionally determines if the shortcut is displayed in a designated recommended area</summary>
**Optional field**
Defaults to `False`. Determines if the shortcut should be displayed in a designated recommended area. This is a visual hint for the user that this shortcut is important.
</details>
<details>
<summary><b>Keys</b> - Array of keys that need to be pressed</summary>
A string array of all the keys that need to be pressed. If a number is supplied, it should be read as a [KeyCode](https://learn.microsoft.com/windows/win32/inputdev/virtual-key-codes) and displayed accordingly (based on the Keyboard Layout of the user).
**Special keys**:
Special keys are enclosed between `<` and `>` and correspond to a key that should be displayed in a certain way. If the interpreter of the manifest file can't understand the content, the brackets should be left out.
|Name|Description|
|----|-----------|
|`<Office>`| Corresponds to the Office key on some Windows keyboards |
|`<Copilot>`| Corresponds to the Copilot key on some Windows keyboards |
|`<Left>`| Corresponds to the left arrow key |
|`<Right>`| Corresponds to the right arrow key |
|`<Up>`| Corresponds to the up arrow key |
|`<Down>`| Corresponds to the down arrow key |
|`<Enter>`| Corresponds to the Enter key |
|`<Space>`| Corresponds to the Space key |
|`<Tab>`| Corresponds to the Tab key |
|`<Backspace>`| Corresponds to the Backspace key |
|`<Delete>`| Corresponds to the Delete key |
|`<Insert>`| Corresponds to the Insert key |
|`<Home>`| Corresponds to the Home key |
|`<End>`| Corresponds to the End key |
|`<PrtScr>`| Corresponds to the Print Screen key |
|`<Pause>`| Corresponds to the pause key |
|`<PageUp>`| Corresponds to the Page Up key |
|`<PageDown>`| Corresponds to the Page Down key |
|`<Escape>`| Corresponds to the Escape key |
|`<Arrow>`| Corresponds to either the left, right, up or down arrow key |
|`<ArrowLR>`| Corresponds to either the left or right arrow key |
|`<ArrowUD>`| Corresponds to either the up or down arrow key |
|`<Underlined letter>`| Corresponds to any letter that is _underlined_ in the UI |
</details>
#### 3.2.2 Example
```yaml
PackageName: Microsoft.PowerToys
WindowFilter: "*"
BackgroundProcess: True
Shortcuts:
- SectionName: General
Properties:
- Name: Advanced Paste
Shortcut:
- Win: True
Ctrl: False
Alt: False
Shift: False
Keys:
- 86
Description: Open Advanced Paste window
- Name: Advanced Paste
Shortcut:
- Win: True
Ctrl: True
Alt: True
Shift: False
Keys:
- 86
Description: Paste as plain text directly
```
### 3.2 `index.yaml` file
The `index.yaml` file is a file that contains all the information about the different manifest files that are saved in the same directory. This file is only available locally and is not saved in the WinGet repository as it is specific to the user.
```yaml
DefaultShellName: # The package identifier of the default shell used in Windows
Index: # List of all manifest files
- WindowFilter: # The filter of window processes to which the shortcuts apply to
BackgroundProcess: # Optionally allows applying WindowFilter to background processes
Apps: # List of all manifest files for the filter
```
<details>
<summary><b>DefaultShellName</b> - The package identifier of the default shell used in Windows</summary>
This declares the package identifier of the default shell used in Windows. Most commonly it is `+WindowsNT.Shell`. Although not enforced, only the shell declared in the registry key `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell` should be used here.
</details>
<details>
<summary><b>Index</b> - List of all manifest files</summary>
</details>
<details>
<summary><b>WindowFilter</b> - The filter of window processes to which the shortcuts apply to</summary>
See the `WindowFilter` field in the manifest file for more information.
</details>
<details>
<summary><b>BackgroundProcess</b> - Optionally allows applying WindowFilter to background processes</summary>
**Optional field**
See the `BackgroundProcess` field in the manifest file for more information.
</details>
<details>
<summary><b>Apps</b> - List of all the package identifiers applying for the filter</summary>
</details>
#### 3.2.1 Example
```yaml
DefaultShellName: "+WindowsNT.Shell"
Index:
- Filter: "*"
BackgroundProcess: True
Apps: ["+WindowsNT.Shell", "Microsoft.PowerToys"]
- Filter: "explorer.exe"
Apps: ["+WindowsNT.WindowsExplorer"]
- Filter: "taskmgr.exe"
Apps: ["+WindowsNT.TaskManager"]
- Filter: "msedge.exe"
Apps: ["+WindowsNT.Edge"]
```

View File

@@ -79,3 +79,4 @@ Below are community created plugins that target a website or software. They are
| [Linear](https://github.com/vednig/powertoys-linear) | [vednig](https://github.com/vednig) | Create Linear Issues directly from Powertoys Run |
| [PerplexitySearchShortcut](https://github.com/0x6f677548/PowerToys-Run-PerplexitySearchShortcut) | [0x6f677548](https://github.com/0x6f677548) | Search Perplexity |
| [SpeedTest](https://github.com/ruslanlap/PowerToysRun-SpeedTest) | [ruslanlap](https://github.com/ruslanlap) | One-command internet speed tests with real-time results, modern UI, and shareable links. |
| [DiskAnalyzer](https://github.com/thetsaw/PowerToys.Plugin) | [thetsaw](https://github.com/thetsaw) | Scan folders, find the largest files, and view drive space usage with visual progress bars. |

View File

@@ -8,9 +8,6 @@
</Project>
<Project Path="../src/common/Telemetry/EtwTrace/EtwTrace.vcxproj" Id="8f021b46-362b-485c-bfba-ccf83e820cbd" />
<Project Path="../src/common/version/version.vcxproj" Id="cc6e41ac-8174-4e8a-8d22-85dd7f4851df" />
<Project Path="../src/logging/logging.vcxproj" Id="7e1e3f13-2bd6-3f75-a6a7-873a2b55c60f">
<Build Solution="Debug|ARM64" Project="false" />
</Project>
<Project Path="PowerToysSetupCustomActionsVNext/PowerToysSetupCustomActionsVNext.vcxproj" Id="b3a354b0-1e54-4b55-a962-fb5af9330c19">
<Build Solution="Debug|ARM64" Project="false" />
</Project>

View File

@@ -0,0 +1,25 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<?include $(sys.CURRENTDIR)\Common.wxi?>
<Fragment>
<!--
DesktopGrass ships a single statically-linked native executable
(DesktopGrass.Native.exe, /MT CRT, no external runtime dependencies). It is
emitted to the root build output and harvested automatically by the root
sweep in generateAllFileComponents.ps1 into BaseApplicationsComponentGroup.
This component group only carries the module's uninstall marker so the
feature can be referenced explicitly from Product.wxs, matching the
per-module convention used by Awake/Hosts/etc.
-->
<ComponentGroup Id="DesktopGrassComponentGroup">
<Component Id="RemoveDesktopGrassRegistry" Guid="42C1C544-8FD8-422A-85A2-139D99D38B52" Directory="INSTALLFOLDER">
<RegistryKey Root="$(var.RegistryScope)" Key="Software\Classes\powertoys\components">
<RegistryValue Type="string" Name="RemoveDesktopGrassRegistry" Value="" KeyPath="yes" />
</RegistryKey>
</Component>
</ComponentGroup>
</Fragment>
</Wix>

View File

@@ -115,6 +115,7 @@ call powershell.exe -NonInteractive -executionpolicy Unrestricted -File $(MSBuil
<Compile Include="BaseApplications.wxs" />
<Compile Include="CmdPal.wxs" />
<Compile Include="ColorPicker.wxs" />
<Compile Include="DesktopGrass.wxs" />
<Compile Include="EnvironmentVariables.wxs" />
<Compile Include="FileExplorerPreview.wxs" />
<Compile Include="FileLocksmith.wxs" />

View File

@@ -45,6 +45,7 @@
<ComponentGroupRef Id="WinUI3ApplicationsComponentGroup" />
<ComponentGroupRef Id="AwakeComponentGroup" />
<ComponentGroupRef Id="ColorPickerComponentGroup" />
<ComponentGroupRef Id="DesktopGrassComponentGroup" />
<ComponentGroupRef Id="FileExplorerPreviewComponentGroup" />
<ComponentGroupRef Id="FileLocksmithComponentGroup" />
<ComponentGroupRef Id="HostsComponentGroup" />

View File

@@ -2,26 +2,39 @@
<?include $(sys.CURRENTDIR)\Common.wxi?>
<?define ShortcutGuideSvgFiles=?>
<?define ShortcutGuideSvgFilesPath=$(var.BinDir)\Assets\ShortcutGuide\?>
<?define ShortcutGuideAssetsFiles=?>
<?define ShortcutGuideAssetsFilesPath=$(var.BinDir)WinUI3Apps\Assets\ShortcutGuide\?>
<?define ShortcutGuideManifestsFiles=?>
<?define ShortcutGuideManifestsFilesPath=$(var.BinDir)WinUI3Apps\Assets\ShortcutGuide\Manifests\?>
<Fragment>
<!-- Shortcut guide files -->
<DirectoryRef Id="BaseApplicationsAssetsFolder">
<Directory Id="ShortcutGuideSvgsInstallFolder" Name="ShortcutGuide" />
<DirectoryRef Id="WinUI3AppsAssetsFolder">
<Directory Id="ShortcutGuideAssetsFolder" Name="ShortcutGuide">
<Directory Id="ShortcutGuideManifestsFolder" Name="Manifests" />
</Directory>
</DirectoryRef>
<DirectoryRef Id="ShortcutGuideSvgsInstallFolder" FileSource="$(var.ShortcutGuideSvgFilesPath)">
<DirectoryRef Id="ShortcutGuideAssetsFolder" FileSource="$(var.ShortcutGuideAssetsFilesPath)">
<!-- Generated by generateFileComponents.ps1 -->
<!--ShortcutGuideSvgFiles_Component_Def-->
<!--ShortcutGuideAssetsFiles_Component_Def-->
</DirectoryRef>
<DirectoryRef Id="ShortcutGuideManifestsFolder" FileSource="$(var.ShortcutGuideManifestsFilesPath)">
<!-- Generated by generateFileComponents.ps1 -->
<!--ShortcutGuideManifestsFiles_Component_Def-->
</DirectoryRef>
<!-- Shortcut guide -->
<ComponentGroup Id="ShortcutGuideComponentGroup">
<Component Id="RemoveShortcutGuideFolder" Guid="AD1ABC55-B593-4A60-A86A-BA8C0ED493A5" Directory="ShortcutGuideSvgsInstallFolder">
<ComponentGroup Id="ShortcutGuideComponentGroup" >
<Component Id="RemoveShortcutGuideFolder" Guid="AD1ABC55-B593-4A60-A86A-BA8C0ED493A5" Directory="ShortcutGuideAssetsFolder" >
<RegistryKey Root="$(var.RegistryScope)" Key="Software\Classes\powertoys\components">
<RegistryValue Type="string" Name="RemoveShortcutGuideFolder" Value="" KeyPath="yes" />
<RegistryValue Type="string" Name="RemoveShortcutGuideFolder" Value="" KeyPath="yes"/>
</RegistryKey>
<RemoveFolder Id="RemoveFolderShortcutGuideSvgsInstallFolder" Directory="ShortcutGuideSvgsInstallFolder" On="uninstall" />
<RemoveFolder Id="RemoveFolderShortcutGuideAssetsInstallFolder" Directory="ShortcutGuideAssetsFolder" On="uninstall"/>
</Component>
<Component Id="RemoveShortcutGuideManifestsFolder" Guid="F47E2C3A-8D91-4B6F-A2E5-9C8D7F6A1B3E" Directory="ShortcutGuideManifestsFolder" >
<RegistryKey Root="$(var.RegistryScope)" Key="Software\Classes\powertoys\components">
<RegistryValue Type="string" Name="RemoveShortcutGuideManifestsFolder" Value="" KeyPath="yes"/>
</RegistryKey>
<RemoveFolder Id="RemoveFolderShortcutGuideManifestsInstallFolder" Directory="ShortcutGuideManifestsFolder" On="uninstall"/>
</Component>
</ComponentGroup>

View File

@@ -28,7 +28,7 @@ Function Generate-FileList() {
$fileExclusionList = @("*.pdb", "*.lastcodeanalysissucceeded", "createdump.exe", "powertoys.exe")
$fileInclusionList = @("*.dll", "*.exe", "*.json", "*.msix", "*.png", "*.gif", "*.ico", "*.cur", "*.svg", "index.html", "reg.js", "gitignore.js", "srt.js", "monacoSpecialLanguages.js", "customTokenThemeRules.js", "*.pri")
$fileInclusionList = @("*.dll", "*.exe", "*.json", "*.msix", "*.png", "*.gif", "*.ico", "*.cur", "*.svg", "index.html", "reg.js", "gitignore.js", "srt.js", "monacoSpecialLanguages.js", "customTokenThemeRules.js", "*.pri", "*.yml")
# MFC DLLs leak into the output via WindowsAppSDKSelfContained but no PowerToys binary imports them.
# Verified with dumpbin /dependents across all 2176 binaries — zero consumers.
@@ -112,6 +112,8 @@ Function Generate-FileComponents() {
foreach ($file in $fileList) {
$fileTmp = $file -replace "-", "_"
$fileTmp = $fileTmp -replace "[^A-Za-z0-9_.]", "_"
if ($fileTmp -match "^[^A-Za-z_]") { $fileTmp = "_$fileTmp" }
$componentDefs +=
@"
<File Id="$($fileListName)_File_$($fileTmp)" Source="`$(var.$($fileListName)Path)\$($file)" />`r`n
@@ -397,8 +399,24 @@ Generate-FileComponents -fileListName "ValueGeneratorImagesCmpFiles" -wxsFilePat
## Plugins
#ShortcutGuide
Generate-FileList -fileDepsJson "" -fileListName ShortcutGuideSvgFiles -wxsFilePath $PSScriptRoot\ShortcutGuide.wxs -depsPath "$PSScriptRoot..\..\..\$platform\Release\Assets\ShortcutGuide\"
Generate-FileComponents -fileListName "ShortcutGuideSvgFiles" -wxsFilePath $PSScriptRoot\ShortcutGuide.wxs
# Ensure manifest yml files are in the build output (the Build target's CopyToOutputDirectory
# may not run reliably under -graph mode in solution builds).
$sgManifestsSrc = "$PSScriptRoot..\..\..\src\modules\ShortcutGuide\ShortcutGuide.Ui\Assets\ShortcutGuide\Manifests"
$sgManifestsDst = "$PSScriptRoot..\..\..\$platform\Release\WinUI3Apps\Assets\ShortcutGuide\Manifests"
Write-Host "ShortcutGuide manifests: src=$sgManifestsSrc exists=$(Test-Path $sgManifestsSrc)"
Write-Host "ShortcutGuide manifests: dst=$sgManifestsDst exists=$(Test-Path $sgManifestsDst)"
if (Test-Path $sgManifestsSrc) {
New-Item -Path $sgManifestsDst -ItemType Directory -Force | Out-Null
Copy-Item "$sgManifestsSrc\*.yml" -Destination $sgManifestsDst -Force
$copied = (Get-ChildItem "$sgManifestsDst\*.yml" -ErrorAction SilentlyContinue).Count
Write-Host "ShortcutGuide manifests: copied $copied yml files to build output"
} else {
Write-Host "WARNING: ShortcutGuide manifest source not found at $sgManifestsSrc"
}
Generate-FileList -fileDepsJson "" -fileListName ShortcutGuideAssetsFiles -wxsFilePath $PSScriptRoot\ShortcutGuide.wxs -depsPath "$PSScriptRoot..\..\..\$platform\Release\WinUI3Apps\Assets\ShortcutGuide\"
Generate-FileComponents -fileListName "ShortcutGuideAssetsFiles" -wxsFilePath $PSScriptRoot\ShortcutGuide.wxs
Generate-FileList -fileDepsJson "" -fileListName ShortcutGuideManifestsFiles -wxsFilePath $PSScriptRoot\ShortcutGuide.wxs -depsPath "$PSScriptRoot..\..\..\$platform\Release\WinUI3Apps\Assets\ShortcutGuide\Manifests\"
Generate-FileComponents -fileListName "ShortcutGuideManifestsFiles" -wxsFilePath $PSScriptRoot\ShortcutGuide.wxs
#Settings
Generate-FileList -fileDepsJson "" -fileListName SettingsV2AssetsFiles -wxsFilePath $PSScriptRoot\Settings.wxs -depsPath "$PSScriptRoot..\..\..\$platform\Release\WinUI3Apps\Assets\Settings\"

View File

@@ -14,7 +14,6 @@
<PropertyGroup Label="Configuration">
</PropertyGroup>
<Import Project="$(RepoRoot)deps\expected.props" />
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
</PropertyGroup>

View File

@@ -14,6 +14,8 @@
#include <common/updating/updating.h>
#include <common/updating/updateState.h>
#include <common/updating/installer.h>
#include <common/updating/configBackup.h>
#include <common/updating/updateLifecycle.h>
#include <common/utils/elevation.h>
#include <common/utils/HttpClient.h>
@@ -21,6 +23,8 @@
#include <common/utils/resources.h>
#include <common/utils/timeutil.h>
#include <wil/resource.h>
#include <common/SettingsAPI/settings_helpers.h>
#include <common/logger/logger.h>
@@ -36,17 +40,59 @@ using namespace cmdArg;
namespace fs = std::filesystem;
void CleanupStaleTempUpdaters()
{
// Remove orphaned PowerToys.Update.*.exe files from previous runs
try
{
std::error_code ec;
const auto tempDir = fs::temp_directory_path();
for (const auto& entry : fs::directory_iterator(tempDir, ec))
{
if (ec)
{
break;
}
if (!entry.is_regular_file())
{
continue;
}
const auto filename = entry.path().filename().wstring();
if (filename.starts_with(L"PowerToys.Update.") && filename.ends_with(L".exe"))
{
// Skip our own file (current PID)
const auto ownFilename = L"PowerToys.Update." + std::to_wstring(GetCurrentProcessId()) + L".exe";
if (filename == ownFilename)
{
continue;
}
fs::remove(entry.path(), ec);
// Failure to delete is expected if another updater is still running
}
}
}
catch (...)
{
// Best-effort cleanup; don't block the update
}
}
std::optional<fs::path> CopySelfToTempDir()
{
CleanupStaleTempUpdaters();
std::error_code error;
auto dst_path = fs::temp_directory_path() / "PowerToys.Update.exe";
auto dst_path = fs::temp_directory_path() / (L"PowerToys.Update." + std::to_wstring(GetCurrentProcessId()) + L".exe");
fs::copy_file(get_module_filename(), dst_path, fs::copy_options::overwrite_existing, error);
if (error)
{
return std::nullopt;
}
return std::move(dst_path);
return dst_path;
}
std::optional<fs::path> ObtainInstaller(bool& isUpToDate)
@@ -57,34 +103,9 @@ std::optional<fs::path> ObtainInstaller(bool& isUpToDate)
auto state = UpdateState::read();
const auto new_version_info = std::move(get_github_version_info_async()).get();
if (std::holds_alternative<version_up_to_date>(*new_version_info))
{
isUpToDate = true;
Logger::error("Invoked with -update_now argument, but no update was available");
return std::nullopt;
}
if (state.state == UpdateState::readyToDownload || state.state == UpdateState::errorDownloading)
{
if (!new_version_info)
{
Logger::error(L"Couldn't obtain github version info: {}", new_version_info.error());
return std::nullopt;
}
// Cleanup old updates before downloading the latest
updating::cleanup_updates();
auto downloaded_installer = std::move(download_new_version_async(std::get<new_version_download_info>(*new_version_info))).get();
if (!downloaded_installer)
{
Logger::error("Couldn't download new installer");
}
return downloaded_installer;
}
else if (state.state == UpdateState::readyToInstall)
// Handle readyToInstall first — the installer is already on disk,
// so we don't need a GitHub API call (which may fail if offline).
if (state.state == UpdateState::readyToInstall)
{
fs::path installer{ get_pending_updates_path() / state.downloadedInstallerFilename };
if (fs::is_regular_file(installer))
@@ -97,12 +118,44 @@ std::optional<fs::path> ObtainInstaller(bool& isUpToDate)
return std::nullopt;
}
}
else if (state.state == UpdateState::upToDate)
if (state.state == UpdateState::upToDate)
{
isUpToDate = true;
return std::nullopt;
}
const auto new_version_info = std::move(get_github_version_info_async()).get();
// Check for error BEFORE dereferencing — the old code crashed here
// when GitHub API was unreachable (new_version_info held an error string).
if (!new_version_info)
{
Logger::error(L"Couldn't obtain github version info: {}", new_version_info.error());
return std::nullopt;
}
if (std::holds_alternative<version_up_to_date>(*new_version_info))
{
isUpToDate = true;
Logger::error("Invoked with -update_now argument, but no update was available");
return std::nullopt;
}
if (state.state == UpdateState::readyToDownload || state.state == UpdateState::errorDownloading)
{
// Cleanup old updates before downloading the latest
updating::cleanup_updates();
auto downloaded_installer = std::move(download_new_version_async(std::get<new_version_download_info>(*new_version_info))).get();
if (!downloaded_installer)
{
Logger::error("Couldn't download new installer");
}
return downloaded_installer;
}
Logger::error("Invoked with -update_now argument, but update state was invalid");
return std::nullopt;
}
@@ -116,13 +169,32 @@ bool InstallNewVersionStage1(fs::path installer)
if (pt_main_window != nullptr)
{
SendMessageW(pt_main_window, WM_CLOSE, 0, 0);
// Get the process that owns the tray window so we can wait for it to exit
DWORD ptProcessId = 0;
GetWindowThreadProcessId(pt_main_window, &ptProcessId);
// Use SendMessageTimeoutW to avoid blocking indefinitely if the
// tray window thread is hung or unresponsive.
DWORD_PTR result = 0;
SendMessageTimeoutW(pt_main_window, WM_CLOSE, 0, 0, SMTO_ABORTIFHUNG, 5000, &result);
// Wait for PT to actually exit before launching installer.
// Without this, the installer may find PT files locked.
if (ptProcessId != 0)
{
wil::unique_handle ptProcess{ OpenProcess(SYNCHRONIZE, FALSE, ptProcessId) };
if (ptProcess)
{
WaitForSingleObject(ptProcess.get(), 10000); // 10 second timeout
}
}
}
std::wstring arguments{ UPDATE_NOW_LAUNCH_STAGE2 };
arguments += L" \"";
arguments += installer.c_str();
arguments += L"\"";
// Pass the install directory so Stage 2 can relaunch PowerToys after install
const std::wstring installDir = get_module_folderpath();
std::wstring arguments = updating::BuildStage2Arguments(
UPDATE_NOW_LAUNCH_STAGE2, installer, fs::path(installDir));
SHELLEXECUTEINFOW sei{ sizeof(sei) };
sei.fMask = { SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC };
sei.lpFile = copy_in_temp->c_str();
@@ -190,9 +262,16 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
LPWSTR* args = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if (!args || nArgs < 2)
{
if (args)
{
LocalFree(args);
}
return 1;
}
// D3 fix: ensure args is freed on all exit paths
auto freeArgs = wil::scope_exit([&] { LocalFree(args); });
std::wstring_view action{ args[1] };
std::filesystem::path logFilePath(PTSettingsHelper::get_root_save_folder_location());
@@ -201,6 +280,11 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
if (action == UPDATE_NOW_LAUNCH_STAGE1)
{
// Backup config files before the update to protect against corruption
Logger::info("Backing up config files before update");
auto backupResult = updating::BackupConfigFiles(fs::path(PTSettingsHelper::get_root_save_folder_location()));
Logger::info("Config backup complete: {} files backed up, {} errors", backupResult.filesBackedUp, backupResult.errors);
bool isUpToDate = false;
auto installerPath = ObtainInstaller(isUpToDate);
bool failed = !installerPath.has_value();
@@ -217,6 +301,12 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
}
else if (action == UPDATE_NOW_LAUNCH_STAGE2)
{
if (nArgs < 3)
{
Logger::error("Stage 2 invoked without installer path argument");
return 1;
}
using namespace std::string_view_literals;
const bool failed = !InstallNewVersionStage2(args[2]);
if (failed)
@@ -227,6 +317,39 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
state.state = UpdateState::errorDownloading;
});
}
// Always check for corrupted configs after Stage 2, regardless
// of install success/failure. A failed install may still corrupt configs.
Logger::info("Checking for corrupted config files after update");
auto restoreResult = updating::RestoreCorruptedConfigs(fs::path(PTSettingsHelper::get_root_save_folder_location()));
Logger::info("Config restore check complete: {}/{} files restored, {} errors",
restoreResult.filesRestored, restoreResult.filesChecked, restoreResult.errors);
if (!failed)
{
// Relaunch PowerToys from the install directory
if (updating::CanRelaunchAfterUpdate(nArgs))
{
std::wstring ptExePath = updating::BuildPowerToysExePath(args[3]);
Logger::info(L"Relaunching PowerToys after update: {}", ptExePath);
SHELLEXECUTEINFOW sei{ sizeof(sei) };
sei.fMask = { SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC };
sei.lpFile = ptExePath.c_str();
sei.nShow = SW_SHOWNORMAL;
sei.lpParameters = UPDATE_REPORT_SUCCESS;
if (!ShellExecuteExW(&sei))
{
Logger::error(L"Failed to relaunch PowerToys after update");
}
}
else
{
Logger::warn("Install directory not provided to Stage 2 - cannot relaunch PowerToys");
}
}
return failed;
}

View File

@@ -14,7 +14,6 @@
<PropertyGroup Label="Configuration">
</PropertyGroup>
<Import Project="$(RepoRoot)deps\expected.props" />
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
</PropertyGroup>

View File

@@ -2,43 +2,35 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ManagedCommon
{
public static class IdRecoveryHelper
{
/// <summary>
/// Fixes invalid IDs in the given list by assigning unique values.
/// It ensures that all IDs are non-empty and unique, correcting any duplicates or empty IDs.
/// Ensures that all items in the provided list have unique IDs. Duplicate IDs are replaced
/// with the next available unique ID.
/// </summary>
/// <param name="items">The list of items that may contain invalid IDs.</param>
/// <param name="items">The list of items that may contain duplicate IDs.</param>
public static void RecoverInvalidIds<T>(IEnumerable<T> items)
where T : class, IHasId
{
var idSet = new HashSet<int>();
int newId = 0;
var sortedItems = items.OrderBy(i => i.Id).ToList(); // Sort items by ID for consistent processing
var seenIds = new HashSet<int>();
int nextAvailableId = 0;
// Iterate through the list and fix invalid IDs
foreach (var item in sortedItems)
foreach (var item in items)
{
// If the ID is invalid or already exists in the set (duplicate), assign a new unique ID
if (!idSet.Add(item.Id))
// If this ID is already used, assign a new unique ID.
if (!seenIds.Add(item.Id))
{
// Find the next available unique ID
while (idSet.Contains(newId))
// Find the next unused ID.
while (!seenIds.Add(nextAvailableId))
{
newId++;
nextAvailableId++;
}
item.Id = newId;
idSet.Add(newId); // Add the newly assigned ID to the set
item.Id = nextAvailableId;
}
}
}

View File

@@ -27,7 +27,7 @@
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..\;..\utils;..\Telemetry;..\..\;..\..\..\deps\;..\..\..\deps\spdlog\include;..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.260126.7\include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\;..\utils;..\Telemetry;..\..\;..\..\..\deps\;..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.260126.7\include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp23</LanguageStandard>
<PreprocessorDefinitions>SPDLOG_WCHAR_TO_UTF8_SUPPORT;SPDLOG_HEADER_ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>

View File

@@ -259,6 +259,10 @@ namespace winrt::PowerToys::Interop::implementation
{
return CommonSharedConstants::TERMINATE_POWER_DISPLAY_EVENT;
}
hstring Constants::AutoDisablePowerDisplayEvent()
{
return CommonSharedConstants::POWER_DISPLAY_AUTO_DISABLE_EVENT;
}
hstring Constants::RefreshPowerDisplayMonitorsEvent()
{
return CommonSharedConstants::REFRESH_POWER_DISPLAY_MONITORS_EVENT;

View File

@@ -68,6 +68,7 @@ namespace winrt::PowerToys::Interop::implementation
static hstring ShowCmdPalEvent();
static hstring TogglePowerDisplayEvent();
static hstring TerminatePowerDisplayEvent();
static hstring AutoDisablePowerDisplayEvent();
static hstring RefreshPowerDisplayMonitorsEvent();
static hstring SettingsUpdatedPowerDisplayEvent();
static hstring PowerDisplaySendSettingsTelemetryEvent();

View File

@@ -65,6 +65,7 @@ namespace PowerToys
static String ShowCmdPalEvent();
static String TogglePowerDisplayEvent();
static String TerminatePowerDisplayEvent();
static String AutoDisablePowerDisplayEvent();
static String RefreshPowerDisplayMonitorsEvent();
static String SettingsUpdatedPowerDisplayEvent();
static String PowerDisplaySendSettingsTelemetryEvent();

View File

@@ -41,7 +41,6 @@
</PropertyGroup>
<PropertyGroup Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
@@ -100,6 +99,7 @@
<ClInclude Include="Constants.h">
<DependentUpon>KeyboardListener.idl</DependentUpon>
</ClInclude>
<ClInclude Include="excluded_app.h" />
<ClInclude Include="HotkeyManager.h">
<DependentUpon>HotkeyManager.idl</DependentUpon>
</ClInclude>
@@ -114,6 +114,7 @@
<ClInclude Include="pch.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="shared_constants.h" />
<ClInclude Include="tasklist_positions.h" />
<ClInclude Include="TwoWayPipeMessageIPCManaged.h">
<DependentUpon>TwoWayPipeMessageIPCManaged.idl</DependentUpon>
</ClInclude>
@@ -127,6 +128,7 @@
<ClCompile Include="Constants.cpp">
<DependentUpon>KeyboardListener.idl</DependentUpon>
</ClCompile>
<ClCompile Include="excluded_app.cpp" />
<ClCompile Include="HotkeyManager.cpp">
<DependentUpon>HotkeyManager.idl</DependentUpon>
</ClCompile>
@@ -140,6 +142,7 @@
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="tasklist_positions.cpp" />
<ClCompile Include="TwoWayPipeMessageIPCManaged.cpp">
<DependentUpon>TwoWayPipeMessageIPCManaged.idl</DependentUpon>
</ClCompile>
@@ -165,6 +168,9 @@
<Midl Include="TwoWayPipeMessageIPCManaged.idl" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SettingsAPI\SettingsAPI.vcxproj">
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
</ProjectReference>
<ProjectReference Include="..\version\version.vcxproj">
<Project>{cc6e41ac-8174-4e8a-8d22-85dd7f4851df}</Project>
</ProjectReference>

View File

@@ -54,6 +54,12 @@
<ClInclude Include="Constants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="excluded_app.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="tasklist_positions.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="keyboard_layout.cpp">
@@ -83,6 +89,12 @@
<ClCompile Include="Constants.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="excluded_app.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="tasklist_positions.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="interop.rc">

View File

@@ -0,0 +1,41 @@
#include "pch.h"
#include "excluded_app.h"
#include <../utils/string_utils.h>
extern "C"
{
__declspec(dllexport) bool IsCurrentWindowExcludedFromShortcutGuide()
{
PowerToysSettings::PowerToyValues settings = PowerToysSettings::PowerToyValues::load_from_settings_file(L"Shortcut Guide");
auto settingsObject = settings.get_raw_json();
std::wstring apps = settingsObject.GetNamedObject(L"properties").GetNamedObject(L"disabled_apps").GetNamedString(L"value").c_str();
auto excludedUppercase = apps;
CharUpperBuffW(excludedUppercase.data(), static_cast<DWORD>(excludedUppercase.length()));
std::wstring_view view(excludedUppercase);
view = left_trim<wchar_t>(trim<wchar_t>(view));
m_excludedApps.clear();
while (!view.empty())
{
auto pos = (std::min)(view.find_first_of(L"\r\n"), view.length());
m_excludedApps.emplace_back(view.substr(0, pos));
view.remove_prefix(pos);
view = left_trim<wchar_t>(trim<wchar_t>(view));
}
if (m_excludedApps.empty())
{
return false;
}
if (HWND foregroundApp{ GetForegroundWindow() })
{
auto processPath = get_process_path(foregroundApp);
CharUpperBuffW(processPath.data(), static_cast<DWORD>(processPath.length()));
return check_excluded_app(foregroundApp, processPath, m_excludedApps);
}
return false;
}
}

View File

@@ -0,0 +1,7 @@
#pragma once
extern "C"
{
std::vector<std::wstring> m_excludedApps;
__declspec(dllexport) bool IsCurrentWindowExcludedFromShortcutGuide();
}

View File

@@ -12,3 +12,29 @@
#include <winrt/Windows.Foundation.Collections.h>
#include <Windows.h>
#include <Endpointvolume.h>
#include <vector>
#include <UIAutomation.h>
#include <dxgi1_3.h>
#include <d3d11_2.h>
#include <d2d1_3.h>
#include <d2d1_3helper.h>
#include <d2d1helper.h>
#include <dwrite.h>
#include <dcomp.h>
#include <dwmapi.h>
#include <Shobjidl.h>
#include <Shlwapi.h>
#include <string>
#include <algorithm>
#include <chrono>
#include <mutex>
#include <thread>
#include <functional>
#include <condition_variable>
#include <stdexcept>
#include <tuple>
#include <unordered_set>
#include <filesystem>
#include <common/utils/excluded_apps.h>
#include <common/utils/process_path.h>
#include <../SettingsAPI/settings_objects.h>

View File

@@ -165,6 +165,7 @@ namespace CommonSharedConstants
const wchar_t SETTINGS_UPDATED_POWER_DISPLAY_EVENT[] = L"Local\\PowerToysPowerDisplay-SettingsUpdatedEvent-2e4d6f8a-1c3b-5e7f-9a1d-4c6e8f0b2d3e";
const wchar_t POWER_DISPLAY_SEND_SETTINGS_TELEMETRY_EVENT[] = L"Local\\PowerToysPowerDisplay-SettingsTelemetryEvent-8c4f2a1d-5e3b-7f9c-1a6d-3b8e5f2c9a7d";
const wchar_t HOTKEY_UPDATED_POWER_DISPLAY_EVENT[] = L"Local\\PowerToysPowerDisplay-HotkeyUpdatedEvent-9d5f3a2b-7e1c-4b8a-6f3d-2a9e5c7b1d4f";
const wchar_t POWER_DISPLAY_AUTO_DISABLE_EVENT[] = L"Local\\PowerToysPowerDisplay-AutoDisableEvent-1a7bd9af-d2e0-4e57-8879-0e1c353994d0";
const wchar_t RESCAN_POWER_DISPLAY_MONITORS_EVENT[] = L"Local\\PowerToysPowerDisplay-RescanMonitorsEvent-7f3e8c5a-1d4b-4a9e-bc6f-5d8a2b9e3c4f";
// IPC Messages used in PowerDisplay (Named Pipe communication)

View File

@@ -0,0 +1,246 @@
#include "pch.h"
#include "tasklist_positions.h"
// Tried my hardest adapting this to C#, but FindWindowW didn't work properly in C#. ~Noraa Junker
static winrt::com_ptr<IUIAutomation> automation;
static winrt::com_ptr<IUIAutomationElement> element;
static winrt::com_ptr<IUIAutomationCondition> true_condition;
extern "C"
{
HWND GetTaskbarHwndForCursorMonitor(HMONITOR monitor)
{
POINT pt;
if (!GetCursorPos(&pt))
return nullptr;
// Find the primary taskbar
HWND primaryTaskbar = FindWindowW(L"Shell_TrayWnd", nullptr);
if (primaryTaskbar)
{
MONITORINFO mi = { sizeof(mi) };
if (GetWindowRect(primaryTaskbar, &mi.rcMonitor))
{
HMONITOR primaryMonitor = MonitorFromRect(&mi.rcMonitor, MONITOR_DEFAULTTONEAREST);
if (primaryMonitor == monitor)
return primaryTaskbar;
}
}
// Find the secondary taskbar(s)
HWND secondaryTaskbar = nullptr;
while ((secondaryTaskbar = FindWindowExW(nullptr, secondaryTaskbar, L"Shell_SecondaryTrayWnd", nullptr)) != nullptr)
{
MONITORINFO mi = { sizeof(mi) };
RECT rc;
if (GetWindowRect(secondaryTaskbar, &rc))
{
HMONITOR taskbarMonitor = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST);
if (monitor == taskbarMonitor)
return secondaryTaskbar;
}
}
return nullptr;
}
void update(HMONITOR monitor)
{
// Get HWND of the tasklist for the monitor under the cursor
auto taskbar_hwnd = GetTaskbarHwndForCursorMonitor(monitor);
if (!taskbar_hwnd)
return;
wchar_t class_name[64] = {};
GetClassNameW(taskbar_hwnd, class_name, 64);
HWND tasklist_hwnd = nullptr;
if (wcscmp(class_name, L"Shell_TrayWnd") == 0)
{
// Primary taskbar structure
tasklist_hwnd = FindWindowExW(taskbar_hwnd, 0, L"ReBarWindow32", nullptr);
if (!tasklist_hwnd)
return;
tasklist_hwnd = FindWindowExW(tasklist_hwnd, 0, L"MSTaskSwWClass", nullptr);
if (!tasklist_hwnd)
return;
tasklist_hwnd = FindWindowExW(tasklist_hwnd, 0, L"MSTaskListWClass", nullptr);
if (!tasklist_hwnd)
return;
}
else if (wcscmp(class_name, L"Shell_SecondaryTrayWnd") == 0)
{
// Secondary taskbar structure
HWND worker_hwnd = FindWindowExW(taskbar_hwnd, 0, L"WorkerW", nullptr);
if (!worker_hwnd)
return;
tasklist_hwnd = FindWindowExW(worker_hwnd, 0, L"MSTaskListWClass", nullptr);
if (!tasklist_hwnd)
return;
}
else
{
// Unknown taskbar type
return;
}
if (!automation)
{
winrt::check_hresult(CoCreateInstance(CLSID_CUIAutomation,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IUIAutomation,
automation.put_void()));
winrt::check_hresult(automation->CreateTrueCondition(true_condition.put()));
}
element = nullptr;
winrt::check_hresult(automation->ElementFromHandle(tasklist_hwnd, element.put()));
}
void update_new(HMONITOR monitor)
{
// Get HWND of the tasklist for the monitor under the cursor
auto taskbar_hwnd = GetTaskbarHwndForCursorMonitor(monitor);
if (!taskbar_hwnd)
return;
wchar_t class_name[64] = {};
GetClassNameW(taskbar_hwnd, class_name, 64);
HWND tasklist_hwnd = nullptr;
if (wcscmp(class_name, L"Shell_TrayWnd") == 0 || wcscmp(class_name, L"Shell_SecondaryTrayWnd") == 0)
{
// Primary taskbar structure
tasklist_hwnd = FindWindowExW(taskbar_hwnd, 0, L"Windows.UI.Composition.DesktopWindowContentBridge", nullptr);
if (!tasklist_hwnd)
return;
tasklist_hwnd = FindWindowExW(tasklist_hwnd, 0, L"Windows.UI.Input.InputSite.WindowClass", nullptr);
if (!tasklist_hwnd)
return;
}
else
{
// Unknown taskbar type
return;
}
if (!automation)
{
winrt::check_hresult(CoCreateInstance(CLSID_CUIAutomation,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IUIAutomation,
automation.put_void()));
winrt::check_hresult(automation->CreateTrueCondition(true_condition.put()));
}
winrt::com_ptr<IUIAutomationElement> tempElement;
element = nullptr;
winrt::check_hresult(automation->ElementFromHandle(tasklist_hwnd, tempElement.put()));
winrt::check_hresult(
tempElement->FindFirst(TreeScope_Children, true_condition.get(), element.put()));
}
bool update_buttons(std::vector<TasklistButton>& buttons)
{
if (!automation || !element)
{
return false;
}
winrt::com_ptr<IUIAutomationElementArray> elements;
if (element->FindAll(TreeScope_Children, true_condition.get(), elements.put()) < 0)
return false;
if (!elements)
return false;
int count;
if (elements->get_Length(&count) < 0)
return false;
winrt::com_ptr<IUIAutomationElement> child;
std::vector<TasklistButton> found_buttons;
found_buttons.reserve(count);
for (int i = 0; i < count; ++i)
{
child = nullptr;
if (elements->GetElement(i, child.put()) < 0)
return false;
TasklistButton button = {};
if (VARIANT var_rect; child->GetCurrentPropertyValue(UIA_BoundingRectanglePropertyId, &var_rect) >= 0)
{
if (var_rect.vt == (VT_R8 | VT_ARRAY))
{
LONG pos;
double value;
pos = 0;
SafeArrayGetElement(var_rect.parray, &pos, &value);
button.x = static_cast<long>(value);
pos = 1;
SafeArrayGetElement(var_rect.parray, &pos, &value);
button.y = static_cast<long>(value);
pos = 2;
SafeArrayGetElement(var_rect.parray, &pos, &value);
button.width = static_cast<long>(value);
pos = 3;
SafeArrayGetElement(var_rect.parray, &pos, &value);
button.height = static_cast<long>(value);
}
VariantClear(&var_rect);
}
else
{
return false;
}
if (BSTR automation_id; child->get_CurrentAutomationId(&automation_id) >= 0)
{
wcsncpy_s(button.name, automation_id, _countof(button.name));
SysFreeString(automation_id);
if (wcsncmp(button.name, L"Appid:", wcslen(L"Appid:")) != 0)
{
continue;
}
}
found_buttons.push_back(button);
}
// assign keynums
buttons.clear();
for (auto& button : found_buttons)
{
if (buttons.empty())
{
button.keynum = 1;
buttons.push_back(std::move(button));
}
else
{
if (button.x < buttons.back().x || button.y < buttons.back().y) // skip 2nd row
break;
if (wcsncmp(button.name, buttons.back().name, _countof(button.name)) == 0)
continue; // skip buttons from the same app
button.keynum = buttons.back().keynum + 1;
buttons.push_back(std::move(button));
if (buttons.back().keynum == 10)
break; // no more than 10 buttons
}
}
return true;
}
__declspec(dllexport) TasklistButton* get_buttons(HMONITOR monitor, int* size)
{
update(monitor);
static std::vector<TasklistButton> buttons;
update_buttons(buttons);
*size = static_cast<int>(buttons.size());
if (*size == 0)
{
// After a certain Windows update, the old method stopped working, try the new one
update_new(monitor);
update_buttons(buttons);
*size = static_cast<int>(buttons.size());
}
return buttons.data();
}
}

View File

@@ -0,0 +1,19 @@
#pragma once
struct TasklistButton
{
wchar_t name[256];
int x;
int y;
int width;
int height;
int keynum;
};
extern "C"
{
// Helper to get the taskbar HWND for the monitor under the cursor
HWND GetTaskbarHwndForCursorMonitor(HMONITOR monitor);
bool update_buttons(std::vector<TasklistButton>& buttons);
__declspec(dllexport) TasklistButton* get_buttons(HMONITOR monitor, int* size);
}

View File

@@ -70,9 +70,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\logging\logging.vcxproj">
<Project>{7e1e3f13-2bd6-3f75-a6a7-873a2b55c60f}</Project>
</ProjectReference>
<ProjectReference Include="..\version\version.vcxproj">
<Project>{cc6e41ac-8174-4e8a-8d22-85dd7f4851df}</Project>
</ProjectReference>

View File

@@ -0,0 +1,679 @@
// 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.
#include "pch.h"
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iterator>
#include <string>
#include <vector>
#include <common/updating/configBackup.h>
#include <common/updating/updateLifecycle.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace fs = std::filesystem;
namespace UpdatingUnitTests
{
// Helper to create a temp directory for test isolation.
// Each instance gets a unique subdirectory to prevent test interference.
class TempDir
{
public:
TempDir()
{
wchar_t tempPath[MAX_PATH + 1];
GetTempPathW(MAX_PATH, tempPath);
static std::atomic<int> counter{0};
m_path = fs::path(tempPath) / (L"PowerToysUpdateTests_" + std::to_wstring(counter++));
// Ensure clean state
std::error_code ec;
fs::remove_all(m_path, ec);
fs::create_directories(m_path, ec);
}
~TempDir()
{
std::error_code ec;
fs::remove_all(m_path, ec);
}
const fs::path& path() const { return m_path; }
// Write a file with the given content
void WriteFile(const fs::path& relativePath, const std::string& content)
{
auto fullPath = m_path / relativePath;
fs::create_directories(fullPath.parent_path());
std::ofstream file(fullPath, std::ios::binary);
file.write(content.data(), content.size());
}
// Write a file with raw bytes (including null bytes for corruption testing)
void WriteFileBytes(const fs::path& relativePath, const std::vector<char>& bytes)
{
auto fullPath = m_path / relativePath;
fs::create_directories(fullPath.parent_path());
std::ofstream file(fullPath, std::ios::binary);
file.write(bytes.data(), bytes.size());
}
// Read file content as string
std::string ReadFile(const fs::path& relativePath)
{
auto fullPath = m_path / relativePath;
std::ifstream file(fullPath, std::ios::binary);
return std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
}
bool FileExists(const fs::path& relativePath)
{
return fs::exists(m_path / relativePath);
}
private:
fs::path m_path;
};
TEST_CLASS(IsJsonFileCorruptedTests)
{
public:
// Tests IsJsonFileCorrupted: valid JSON with no null bytes returns false.
// Covers: configBackup.h IsJsonFileCorrupted — happy path, full file scan.
TEST_METHOD(CleanJsonFileIsNotCorrupted)
{
TempDir dir;
dir.WriteFile(L"settings.json", R"({"theme":"dark","startup":true})");
Assert::IsFalse(updating::IsJsonFileCorrupted(dir.path() / L"settings.json"));
}
// Tests IsJsonFileCorrupted: zero-length file returns false (empty is not corrupted).
// Covers: configBackup.h IsJsonFileCorrupted — file.read returns 0 bytes immediately.
TEST_METHOD(EmptyFileIsNotCorrupted)
{
TempDir dir;
dir.WriteFile(L"empty.json", "");
Assert::IsFalse(updating::IsJsonFileCorrupted(dir.path() / L"empty.json"));
}
// Tests IsJsonFileCorrupted: file containing embedded null bytes returns true.
// Covers: configBackup.h IsJsonFileCorrupted — null byte detection within buffer.
TEST_METHOD(FileWithNullBytesIsCorrupted)
{
TempDir dir;
std::vector<char> corrupted = { '{', '"', 'a', '"', ':', '\0', '\0', '\0', '}' };
dir.WriteFileBytes(L"corrupted.json", corrupted);
Assert::IsTrue(updating::IsJsonFileCorrupted(dir.path() / L"corrupted.json"));
}
// Tests IsJsonFileCorrupted: file entirely filled with 0x00 bytes returns true.
// Reproduces the exact bug from #46179 where installer zeroed out JSON files.
// Covers: configBackup.h IsJsonFileCorrupted — first byte is null.
TEST_METHOD(FileFilledWithNullBytesIsCorrupted)
{
TempDir dir;
std::vector<char> allNulls(1024, '\0');
dir.WriteFileBytes(L"workspaces.json", allNulls);
Assert::IsTrue(updating::IsJsonFileCorrupted(dir.path() / L"workspaces.json"));
}
// Tests IsJsonFileCorrupted: path that does not exist returns false.
// Covers: configBackup.h IsJsonFileCorrupted — file.is_open() check.
TEST_METHOD(NonExistentFileIsNotCorrupted)
{
TempDir dir;
Assert::IsFalse(updating::IsJsonFileCorrupted(dir.path() / L"missing.json"));
}
// Tests IsJsonFileCorrupted: file larger than the 4096-byte read chunk
// with no null bytes returns false.
// Covers: configBackup.h IsJsonFileCorrupted — multi-chunk while loop.
TEST_METHOD(LargeCleanFileIsNotCorrupted)
{
TempDir dir;
std::string largeContent(8192, 'x');
dir.WriteFile(L"large.json", largeContent);
Assert::IsFalse(updating::IsJsonFileCorrupted(dir.path() / L"large.json"));
}
// Tests IsJsonFileCorrupted: null byte placed after the first 4096-byte
// chunk boundary is still detected.
// Covers: configBackup.h IsJsonFileCorrupted — second chunk scan.
TEST_METHOD(NullByteAtEndOfLargeFileIsDetected)
{
TempDir dir;
std::string content(5000, 'x');
content[4999] = '\0';
std::vector<char> bytes(content.begin(), content.end());
dir.WriteFileBytes(L"sneaky.json", bytes);
Assert::IsTrue(updating::IsJsonFileCorrupted(dir.path() / L"sneaky.json"));
}
};
TEST_CLASS(BackupConfigFilesTests)
{
public:
// Tests BackupConfigFiles: root-level .json files are copied to ConfigBackup.
// Covers: configBackup.h BackupConfigFiles — root directory_iterator,
// is_regular_file && extension == ".json" branch.
// Setup: Two root-level JSON files.
TEST_METHOD(BackupCopiesRootJsonFiles)
{
TempDir dir;
dir.WriteFile(L"settings.json", R"({"theme":"dark"})");
dir.WriteFile(L"UpdateState.json", R"({"state":0})");
updating::BackupConfigFiles(dir.path());
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\settings.json"));
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\UpdateState.json"));
Assert::AreEqual(std::string(R"({"theme":"dark"})"), dir.ReadFile(L"ConfigBackup\\settings.json"));
}
// Tests BackupConfigFiles: .json files inside module subdirectories are
// copied to ConfigBackup/<module>/.
// Covers: configBackup.h BackupConfigFiles — is_directory branch,
// module directory_iterator with extension filter.
// Setup: Root JSON + two module directories with JSON files.
TEST_METHOD(BackupCopiesModuleJsonFiles)
{
TempDir dir;
dir.WriteFile(L"settings.json", R"({"theme":"dark"})");
dir.WriteFile(L"FancyZones\\settings.json", R"({"zones":[]})");
dir.WriteFile(L"Workspaces\\workspaces.json", R"({"workspaces":[]})");
updating::BackupConfigFiles(dir.path());
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\FancyZones\\settings.json"));
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\Workspaces\\workspaces.json"));
Assert::AreEqual(std::string(R"({"zones":[]})"),
dir.ReadFile(L"ConfigBackup\\FancyZones\\settings.json"));
}
// Tests BackupConfigFiles: non-.json files at root level are not copied.
// Covers: configBackup.h BackupConfigFiles — extension filter excludes .log.
// Setup: One JSON file + one .log file at root.
TEST_METHOD(BackupSkipsNonJsonFiles)
{
TempDir dir;
dir.WriteFile(L"settings.json", R"({"theme":"dark"})");
dir.WriteFile(L"debug.log", "log data");
updating::BackupConfigFiles(dir.path());
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\settings.json"));
Assert::IsFalse(dir.FileExists(L"ConfigBackup\\debug.log"));
}
// Tests BackupConfigFiles: the "Updates" directory is explicitly skipped.
// Covers: configBackup.h BackupConfigFiles — dirName == L"Updates" continue.
// Setup: Root JSON + Updates directory containing a file.
TEST_METHOD(BackupSkipsUpdatesDirectory)
{
TempDir dir;
dir.WriteFile(L"settings.json", R"({"theme":"dark"})");
dir.WriteFile(L"Updates\\installer.exe", "fake exe");
updating::BackupConfigFiles(dir.path());
Assert::IsFalse(dir.FileExists(L"ConfigBackup\\Updates"));
}
// Tests BackupConfigFiles: running backup twice overwrites the previous
// backup with current file content.
// Covers: configBackup.h BackupConfigFiles — fs::remove_all(backupDir) +
// copy_options::overwrite_existing.
// Setup: Backup, modify original, backup again.
TEST_METHOD(BackupOverwritesPreviousBackup)
{
TempDir dir;
dir.WriteFile(L"settings.json", R"({"version":1})");
updating::BackupConfigFiles(dir.path());
// Update the original
dir.WriteFile(L"settings.json", R"({"version":2})");
updating::BackupConfigFiles(dir.path());
Assert::AreEqual(std::string(R"({"version":2})"), dir.ReadFile(L"ConfigBackup\\settings.json"));
}
// Tests BackupConfigFiles: non-.json files inside module subdirectories
// (e.g., FancyZones/zones.dat) should NOT be backed up.
// Covers: configBackup.h BackupConfigFiles — extension filter in module loop.
TEST_METHOD(BackupSkipsNonJsonFilesInModuleDirs)
{
TempDir dir;
dir.WriteFile(L"settings.json", R"({})");
dir.WriteFile(L"FancyZones\\settings.json", R"({"zones":[]})");
dir.WriteFile(L"FancyZones\\zones.dat", "binary data");
updating::BackupConfigFiles(dir.path());
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\FancyZones\\settings.json"));
Assert::IsFalse(dir.FileExists(L"ConfigBackup\\FancyZones\\zones.dat"));
}
// Tests BackupConfigFiles: empty root directory with no files produces
// an empty ConfigBackup dir without errors.
// Covers: configBackup.h BackupConfigFiles — empty directory_iterator.
TEST_METHOD(BackupEmptyRootDirSucceeds)
{
TempDir dir;
// Root dir exists but has no files
updating::BackupConfigFiles(dir.path());
Assert::IsTrue(dir.FileExists(L"ConfigBackup"));
}
};
TEST_CLASS(RestoreCorruptedConfigsTests)
{
public:
// Tests RestoreCorruptedConfigs: corrupted root-level JSON file is restored
// from the good backup copy.
// Covers: configBackup.h RestoreCorruptedConfigs — root file restore branch,
// fs::exists + IsJsonFileCorrupted + backup integrity check.
// Setup: Good file -> backup -> corrupt original -> restore.
TEST_METHOD(RestoreFixesCorruptedRootFile)
{
TempDir dir;
const std::string goodContent = R"({"theme":"dark"})";
dir.WriteFile(L"settings.json", goodContent);
// Backup
updating::BackupConfigFiles(dir.path());
// Corrupt the original
std::vector<char> corrupted(goodContent.size(), '\0');
dir.WriteFileBytes(L"settings.json", corrupted);
Assert::IsTrue(updating::IsJsonFileCorrupted(dir.path() / L"settings.json"));
// Restore
updating::RestoreCorruptedConfigs(dir.path());
Assert::IsFalse(updating::IsJsonFileCorrupted(dir.path() / L"settings.json"));
Assert::AreEqual(goodContent, dir.ReadFile(L"settings.json"));
}
// Tests RestoreCorruptedConfigs: corrupted module-level JSON file is restored
// from the good backup copy.
// Covers: configBackup.h RestoreCorruptedConfigs — module directory branch,
// moduleBackupEntry restore with integrity check.
// Setup: Module file + root file -> backup -> corrupt module file -> restore.
TEST_METHOD(RestoreFixesCorruptedModuleFile)
{
TempDir dir;
const std::string goodContent = R"({"workspaces":[]})";
dir.WriteFile(L"Workspaces\\workspaces.json", goodContent);
dir.WriteFile(L"settings.json", R"({})");
updating::BackupConfigFiles(dir.path());
// Corrupt the module file
std::vector<char> corrupted(goodContent.size(), '\0');
dir.WriteFileBytes(L"Workspaces\\workspaces.json", corrupted);
updating::RestoreCorruptedConfigs(dir.path());
Assert::AreEqual(goodContent, dir.ReadFile(L"Workspaces\\workspaces.json"));
}
// Tests RestoreCorruptedConfigs: clean (non-corrupted) files are NOT
// overwritten by backup — preserves user changes made after backup.
// Covers: configBackup.h RestoreCorruptedConfigs — IsJsonFileCorrupted
// returns false, copy_file is skipped.
// Setup: File -> backup -> modify (but keep valid) -> restore.
TEST_METHOD(RestoreLeavesCleanFilesUntouched)
{
TempDir dir;
dir.WriteFile(L"settings.json", R"({"version":1})");
updating::BackupConfigFiles(dir.path());
// Modify original (but keep it clean JSON)
dir.WriteFile(L"settings.json", R"({"version":2})");
updating::RestoreCorruptedConfigs(dir.path());
// Should NOT have been restored since it's not corrupted
Assert::AreEqual(std::string(R"({"version":2})"), dir.ReadFile(L"settings.json"));
}
// Tests RestoreCorruptedConfigs: when no ConfigBackup directory exists,
// restore silently does nothing (no crash, no data loss).
// Covers: configBackup.h RestoreCorruptedConfigs — !fs::exists(backupDir)
// early return.
// Setup: File with no prior backup.
TEST_METHOD(RestoreHandlesMissingBackupDirectory)
{
TempDir dir;
dir.WriteFile(L"settings.json", R"({"theme":"dark"})");
// No backup was created - restore should silently do nothing
updating::RestoreCorruptedConfigs(dir.path());
Assert::AreEqual(std::string(R"({"theme":"dark"})"), dir.ReadFile(L"settings.json"));
}
// Tests RestoreCorruptedConfigs: end-to-end scenario with multiple modules,
// some corrupted and some clean, verifying selective restore.
// Covers: configBackup.h RestoreCorruptedConfigs — both root and module
// branches, selective restore based on corruption status.
// Setup: 4 modules -> backup -> corrupt 2 -> restore -> verify all 4.
TEST_METHOD(FullBackupAndRestoreRoundTrip)
{
TempDir dir;
// Set up a realistic config structure
dir.WriteFile(L"settings.json", R"({"startup":true,"theme":"dark"})");
dir.WriteFile(L"FancyZones\\settings.json", R"({"zones":[{"id":1}]})");
dir.WriteFile(L"Workspaces\\workspaces.json", R"({"workspaces":[{"name":"dev"}]})");
dir.WriteFile(L"KeyboardManager\\default.json", R"({"remaps":[]})");
// Backup
updating::BackupConfigFiles(dir.path());
// Corrupt some files (simulating #46179 scenario)
dir.WriteFileBytes(L"Workspaces\\workspaces.json", std::vector<char>(100, '\0'));
dir.WriteFileBytes(L"settings.json", std::vector<char>(50, '\0'));
// Leave FancyZones and KBM clean
// Restore
updating::RestoreCorruptedConfigs(dir.path());
// Corrupted files should be restored
Assert::AreEqual(std::string(R"({"startup":true,"theme":"dark"})"), dir.ReadFile(L"settings.json"));
Assert::AreEqual(std::string(R"({"workspaces":[{"name":"dev"}]})"), dir.ReadFile(L"Workspaces\\workspaces.json"));
// Clean files should be unchanged
Assert::AreEqual(std::string(R"({"zones":[{"id":1}]})"), dir.ReadFile(L"FancyZones\\settings.json"));
Assert::AreEqual(std::string(R"({"remaps":[]})"), dir.ReadFile(L"KeyboardManager\\default.json"));
}
// Tests RestoreCorruptedConfigs: when the original file has been deleted
// (not corrupted), restore should NOT recreate it from backup. The installer
// may have intentionally removed obsolete config files.
// Covers: configBackup.h RestoreCorruptedConfigs — fs::exists guard.
TEST_METHOD(RestoreSkipsDeletedOriginals)
{
TempDir dir;
dir.WriteFile(L"obsolete.json", R"({"old":true})");
updating::BackupConfigFiles(dir.path());
// Installer deletes the file
std::error_code ec;
fs::remove(dir.path() / L"obsolete.json", ec);
updating::RestoreCorruptedConfigs(dir.path());
// Should NOT be recreated
Assert::IsFalse(dir.FileExists(L"obsolete.json"));
}
// Tests RestoreCorruptedConfigs: when the backup file itself is corrupted
// (e.g., disk error during backup), restore should NOT copy corrupted
// backup over the original — that would make things worse.
// Covers: configBackup.h RestoreCorruptedConfigs — backup integrity check (B2 fix).
TEST_METHOD(RestoreSkipsCorruptedBackup)
{
TempDir dir;
dir.WriteFile(L"settings.json", R"({"theme":"dark"})");
updating::BackupConfigFiles(dir.path());
// Corrupt BOTH the original AND the backup
std::vector<char> nulls(50, '\0');
dir.WriteFileBytes(L"settings.json", nulls);
dir.WriteFileBytes(L"ConfigBackup\\settings.json", nulls);
updating::RestoreCorruptedConfigs(dir.path());
// Original should still be corrupted — we don't restore from bad backup
Assert::IsTrue(updating::IsJsonFileCorrupted(dir.path() / L"settings.json"));
}
};
// Simulates what actually happens during a PowerToys upgrade:
// 1. User has settings from normal use
// 2. Updater backs up before install (Stage 1)
// 3. Installer runs and corrupts some files (simulated)
// 4. Updater restores corrupted files (Stage 2)
// 5. PT relaunches and finds working configs
TEST_CLASS(UpgradeSimulationTests)
{
public:
// Tests full upgrade simulation: backup -> installer corrupts files -> restore.
// Verifies that corrupted files are restored and clean files are untouched.
// Covers: configBackup.h BackupConfigFiles + RestoreCorruptedConfigs —
// end-to-end with 5 modules, 2 corrupted, 3 clean.
// Setup: Realistic config structure with multiple modules.
TEST_METHOD(SimulateUpgradeWithCorruption)
{
TempDir dir;
// === User's real config state before upgrade ===
dir.WriteFile(L"settings.json",
R"({"startup":true,"theme":"dark","run_elevated":false,"download_updates_automatically":true})");
dir.WriteFile(L"FancyZones\\settings.json",
R"({"zones":[{"id":1,"rect":{"x":0,"y":0,"w":960,"h":1080}}]})");
dir.WriteFile(L"Workspaces\\workspaces.json",
R"({"workspaces":[{"name":"dev","apps":["code","terminal"]}]})");
dir.WriteFile(L"KeyboardManager\\default.json",
R"({"remapKeys":{"inProcess":[{"original":"0x41","new":"0x42"}]}})");
dir.WriteFile(L"MouseWithoutBorders\\settings.json",
R"({"machineKey":"abc123","connectToAll":true})");
// Non-JSON files that should be left alone
dir.WriteFile(L"update.log", "2026-04-11 update started");
// === Stage 1: Backup before killing PT ===
updating::BackupConfigFiles(dir.path());
// Verify backup was created correctly
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\settings.json"));
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\FancyZones\\settings.json"));
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\Workspaces\\workspaces.json"));
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\KeyboardManager\\default.json"));
Assert::IsTrue(dir.FileExists(L"ConfigBackup\\MouseWithoutBorders\\settings.json"));
Assert::IsFalse(dir.FileExists(L"ConfigBackup\\update.log"));
// === Installer runs: some files get corrupted (the #46179 scenario) ===
// Workspaces JSON filled with null bytes
dir.WriteFileBytes(L"Workspaces\\workspaces.json", std::vector<char>(512, '\0'));
// Main settings partially corrupted (null bytes injected)
std::vector<char> partialCorrupt = { '{', '"', 's', '\0', '\0', '\0', '\0', '}' };
dir.WriteFileBytes(L"settings.json", partialCorrupt);
// FancyZones, KBM, and MWB survive the install fine
// (this is realistic - not all files get corrupted)
// === Stage 2: Restore after install completes ===
updating::RestoreCorruptedConfigs(dir.path());
// === Verify: PT relaunches and finds working configs ===
// Corrupted files should be restored from backup
Assert::IsFalse(updating::IsJsonFileCorrupted(dir.path() / L"settings.json"));
Assert::IsFalse(updating::IsJsonFileCorrupted(dir.path() / L"Workspaces\\workspaces.json"));
Assert::AreEqual(
std::string(R"({"startup":true,"theme":"dark","run_elevated":false,"download_updates_automatically":true})"),
dir.ReadFile(L"settings.json"));
Assert::AreEqual(
std::string(R"({"workspaces":[{"name":"dev","apps":["code","terminal"]}]})"),
dir.ReadFile(L"Workspaces\\workspaces.json"));
// Clean files should be untouched (not overwritten with backup)
Assert::AreEqual(
std::string(R"({"zones":[{"id":1,"rect":{"x":0,"y":0,"w":960,"h":1080}}]})"),
dir.ReadFile(L"FancyZones\\settings.json"));
Assert::AreEqual(
std::string(R"({"remapKeys":{"inProcess":[{"original":"0x41","new":"0x42"}]}})"),
dir.ReadFile(L"KeyboardManager\\default.json"));
Assert::AreEqual(
std::string(R"({"machineKey":"abc123","connectToAll":true})"),
dir.ReadFile(L"MouseWithoutBorders\\settings.json"));
}
// Tests upgrade from an old version that has fewer modules than the new version.
// Verifies that new module configs (created by the installer) are not touched
// by restore, while corrupted old configs are restored.
// Covers: configBackup.h RestoreCorruptedConfigs — module dir in root that
// has no corresponding backup entry.
// Setup: Old version with 1 module -> backup -> new installer adds module -> corrupt old -> restore.
TEST_METHOD(SimulateUpgradeFromVeryOldVersion)
{
TempDir dir;
// Old version had fewer modules - only settings.json
dir.WriteFile(L"settings.json", R"({"theme":"dark","powertoys_version":"v0.60.0"})");
// Backup
updating::BackupConfigFiles(dir.path());
// New installer creates new module dirs that didn't exist before
dir.WriteFile(L"NewModule\\settings.json", R"({"enabled":true})");
// Old settings get corrupted during upgrade
dir.WriteFileBytes(L"settings.json", std::vector<char>(100, '\0'));
// Restore
updating::RestoreCorruptedConfigs(dir.path());
// Old settings restored
Assert::AreEqual(
std::string(R"({"theme":"dark","powertoys_version":"v0.60.0"})"),
dir.ReadFile(L"settings.json"));
// New module settings untouched (no backup existed for them)
Assert::AreEqual(
std::string(R"({"enabled":true})"),
dir.ReadFile(L"NewModule\\settings.json"));
}
};
// Tests for the update lifecycle: argument passing between Stage 1 and Stage 2,
// relaunch path construction, and the handoff that was broken in #42004/#43011/#44071.
TEST_CLASS(UpdateLifecycleTests)
{
public:
// Tests BuildStage2Arguments: output contains the stage 2 flag, installer path,
// and install directory — all three components needed for Stage 2.
// Covers: updateLifecycle.h BuildStage2Arguments — concatenation logic.
// Setup: Typical paths with spaces (Program Files).
TEST_METHOD(BuildStage2ArgumentsContainsInstallerAndInstallDir)
{
const auto args = updating::BuildStage2Arguments(
L"-update_now_stage_2",
L"C:\\Users\\test\\AppData\\Local\\PowerToys\\Updates\\powertoyssetup-x64.exe",
L"C:\\Program Files\\PowerToys");
// Must contain the stage 2 flag
Assert::IsTrue(args.find(L"-update_now_stage_2") != std::wstring::npos);
// Must contain the installer path (quoted)
Assert::IsTrue(args.find(L"powertoyssetup-x64.exe") != std::wstring::npos);
// Must contain the install directory (quoted) — this was MISSING before our fix
Assert::IsTrue(args.find(L"C:\\Program Files\\PowerToys") != std::wstring::npos);
}
// Tests BuildStage2Arguments: both paths are wrapped in double quotes to
// survive CommandLineToArgvW parsing when paths contain spaces.
// Covers: updateLifecycle.h BuildStage2Arguments — quote wrapping.
// Setup: Installer path with spaces.
TEST_METHOD(BuildStage2ArgumentsQuotesBothPaths)
{
const auto args = updating::BuildStage2Arguments(
L"-update_now_stage_2",
L"C:\\path with spaces\\installer.exe",
L"C:\\Program Files\\PowerToys");
// Count quotes — should have 4 (open/close for each path)
size_t quoteCount = std::count(args.begin(), args.end(), L'"');
Assert::AreEqual(size_t{ 4 }, quoteCount);
}
// Tests BuildPowerToysExePath: appends "PowerToys.exe" to the install dir.
// Covers: updateLifecycle.h BuildPowerToysExePath — fs::path / operator.
// Setup: Standard install path without trailing backslash.
TEST_METHOD(BuildPowerToysExePathAppendsExeName)
{
const auto path = updating::BuildPowerToysExePath(L"C:\\Program Files\\PowerToys");
Assert::AreEqual(std::wstring(L"C:\\Program Files\\PowerToys\\PowerToys.exe"), path);
}
// Tests BuildPowerToysExePath: trailing backslash does not produce double
// backslash (e.g., "...PowerToys\\PowerToys.exe").
// Covers: updateLifecycle.h BuildPowerToysExePath — fs::path normalizes separators.
// Setup: Install path with trailing backslash.
TEST_METHOD(BuildPowerToysExePathHandlesTrailingBackslash)
{
const auto path = updating::BuildPowerToysExePath(L"C:\\Program Files\\PowerToys\\");
Assert::AreEqual(std::wstring(L"C:\\Program Files\\PowerToys\\PowerToys.exe"), path);
}
// Tests BuildPowerToysExePath: empty string produces just "PowerToys.exe".
// Covers: updateLifecycle.h BuildPowerToysExePath — fs::path with empty input.
// Setup: Empty install directory string.
TEST_METHOD(BuildPowerToysExePathHandlesEmptyString)
{
const auto path = updating::BuildPowerToysExePath(L"");
Assert::AreEqual(std::wstring(L"PowerToys.exe"), path);
}
// Tests CanRelaunchAfterUpdate: returns true when Stage 2 receives
// the install directory (argCount >= 4), false otherwise.
// This is the gate that prevents relaunch when using an old Stage 1
// that didn't pass the install dir (#42004/#43011/#44071).
// Covers: updateLifecycle.h CanRelaunchAfterUpdate.
TEST_METHOD(CanRelaunchReflectsArgCount)
{
// Old Stage 1 (pre-fix): only passed action + installer = 3 args
Assert::IsFalse(updating::CanRelaunchAfterUpdate(0));
Assert::IsFalse(updating::CanRelaunchAfterUpdate(1));
Assert::IsFalse(updating::CanRelaunchAfterUpdate(2));
Assert::IsFalse(updating::CanRelaunchAfterUpdate(3));
// New Stage 1 (post-fix): passes action + installer + installDir = 4 args
Assert::IsTrue(updating::CanRelaunchAfterUpdate(4));
Assert::IsTrue(updating::CanRelaunchAfterUpdate(5));
}
// Tests BuildStage2Arguments + CommandLineToArgvW round-trip: the exact
// scenario where Stage 1 builds args and Windows parses them in Stage 2.
// Verifies quoting is correct so paths with spaces survive the round trip.
// Covers: updateLifecycle.h BuildStage2Arguments — quote correctness.
// Setup: Realistic paths with spaces and version numbers.
TEST_METHOD(Stage2ArgumentsCanBeRoundTrippedThroughCommandLineToArgvW)
{
const std::wstring installerPath = L"C:\\Users\\test user\\AppData\\Local\\PowerToys\\Updates\\powertoyssetup-0.86.0-x64.exe";
const std::wstring installDir = L"C:\\Program Files\\PowerToys";
const auto args = updating::BuildStage2Arguments(L"-update_now_stage_2", installerPath, installDir);
// Simulate what Windows does: prepend a fake exe name and parse
std::wstring commandLine = L"PowerToys.Update.exe " + args;
int argc = 0;
LPWSTR* argv = CommandLineToArgvW(commandLine.c_str(), &argc);
Assert::IsNotNull(argv);
Assert::AreEqual(4, argc);
Assert::AreEqual(std::wstring(L"-update_now_stage_2"), std::wstring(argv[1]));
Assert::AreEqual(installerPath, std::wstring(argv[2]));
Assert::AreEqual(installDir, std::wstring(argv[3]));
LocalFree(argv);
}
};
}

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>UpdatingUnitTests</RootNamespace>
<ProjectSubType>NativeUnitTestProject</ProjectSubType>
<ProjectName>Updating.UnitTests</ProjectName>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\tests\UpdatingUnitTests\</OutDir>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..\;..\..\;..\..\..\;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="UpdatingTests.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

View File

@@ -0,0 +1,5 @@
// 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.
#include "pch.h"

View File

@@ -0,0 +1,17 @@
// 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.
#ifndef PCH_H
#define PCH_H
#include <atomic>
#include <Windows.h>
// Suppressing 26466 - Don't use static_cast downcasts - in CppUnitTest.h
#pragma warning(push)
#pragma warning(disable : 26466)
#include "CppUnitTest.h"
#pragma warning(pop)
#endif //PCH_H

View File

@@ -0,0 +1,228 @@
// 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.
#pragma once
#include <filesystem>
#include <fstream>
#include <string>
namespace updating
{
namespace fs = std::filesystem;
struct BackupResult
{
int filesBackedUp{ 0 };
int errors{ 0 };
};
struct RestoreResult
{
int filesRestored{ 0 };
int filesChecked{ 0 };
int errors{ 0 };
};
// Check if a JSON file is corrupted (contains null bytes, as seen in #46179)
inline bool IsJsonFileCorrupted(const fs::path& filePath)
{
try
{
std::ifstream file(filePath, std::ios::binary);
if (!file.is_open())
{
return false;
}
constexpr size_t c_readChunkSize{ 4096 };
char buffer[c_readChunkSize];
while (file.read(buffer, c_readChunkSize) || file.gcount() > 0)
{
const auto bytesRead = file.gcount();
for (std::streamsize i = 0; i < bytesRead; ++i)
{
if (buffer[i] == '\0')
{
return true;
}
}
}
return false;
}
catch (...)
{
return true;
}
}
// Backup all JSON config files before update to protect against corruption (#46179)
inline BackupResult BackupConfigFiles(const fs::path& rootPath)
{
BackupResult result{};
try
{
const fs::path backupDir = rootPath / L"ConfigBackup";
std::error_code ec;
fs::remove_all(backupDir, ec);
fs::create_directories(backupDir, ec);
if (ec)
{
result.errors++;
return result;
}
for (const auto& entry : fs::directory_iterator(rootPath, ec))
{
if (ec)
{
result.errors++;
break;
}
if (entry.is_regular_file() && entry.path().extension() == L".json")
{
std::error_code copyEc;
fs::copy_file(entry.path(), backupDir / entry.path().filename(), fs::copy_options::overwrite_existing, copyEc);
if (copyEc)
{
result.errors++;
}
else
{
result.filesBackedUp++;
}
}
else if (entry.is_directory())
{
const auto dirName = entry.path().filename().wstring();
if (dirName == L"ConfigBackup" || dirName == L"Updates")
{
continue;
}
const auto moduleBackup = backupDir / entry.path().filename();
fs::create_directories(moduleBackup, ec);
std::error_code moduleEc;
for (const auto& moduleEntry : fs::directory_iterator(entry.path(), moduleEc))
{
if (moduleEc)
{
result.errors++;
break;
}
if (moduleEntry.is_regular_file() && moduleEntry.path().extension() == L".json")
{
std::error_code copyEc;
fs::copy_file(moduleEntry.path(), moduleBackup / moduleEntry.path().filename(), fs::copy_options::overwrite_existing, copyEc);
if (copyEc)
{
result.errors++;
}
else
{
result.filesBackedUp++;
}
}
}
}
}
}
catch (...)
{
result.errors++;
}
return result;
}
// Restore JSON configs from backup if corruption is detected after update.
// Cleans up the backup directory afterward.
inline RestoreResult RestoreCorruptedConfigs(const fs::path& rootPath)
{
RestoreResult result{};
try
{
const fs::path backupDir = rootPath / L"ConfigBackup";
if (!fs::exists(backupDir))
{
return result;
}
std::error_code ec;
for (const auto& backupEntry : fs::directory_iterator(backupDir, ec))
{
if (ec)
{
result.errors++;
break;
}
if (backupEntry.is_regular_file() && backupEntry.path().extension() == L".json")
{
const auto originalPath = rootPath / backupEntry.path().filename();
result.filesChecked++;
if (fs::exists(originalPath) && IsJsonFileCorrupted(originalPath) && !IsJsonFileCorrupted(backupEntry.path()))
{
std::error_code copyEc;
fs::copy_file(backupEntry.path(), originalPath, fs::copy_options::overwrite_existing, copyEc);
if (copyEc)
{
result.errors++;
}
else
{
result.filesRestored++;
}
}
}
else if (backupEntry.is_directory())
{
const auto moduleDir = rootPath / backupEntry.path().filename();
std::error_code moduleEc;
for (const auto& moduleBackupEntry : fs::directory_iterator(backupEntry.path(), moduleEc))
{
if (moduleEc)
{
result.errors++;
break;
}
if (moduleBackupEntry.is_regular_file() && moduleBackupEntry.path().extension() == L".json")
{
const auto originalModulePath = moduleDir / moduleBackupEntry.path().filename();
result.filesChecked++;
if (fs::exists(originalModulePath) && IsJsonFileCorrupted(originalModulePath) && !IsJsonFileCorrupted(moduleBackupEntry.path()))
{
std::error_code copyEc;
fs::copy_file(moduleBackupEntry.path(), originalModulePath, fs::copy_options::overwrite_existing, copyEc);
if (copyEc)
{
result.errors++;
}
else
{
result.filesRestored++;
}
}
}
}
}
}
// Clean up backup directory after restore check
fs::remove_all(backupDir, ec);
}
catch (...)
{
result.errors++;
}
return result;
}
}

View File

@@ -24,8 +24,6 @@
#include <regex>
#include <charconv>
#include <expected.hpp>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.ApplicationModel.h>

View File

@@ -0,0 +1,47 @@
// 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.
#pragma once
#include <filesystem>
#include <string>
namespace updating
{
namespace fs = std::filesystem;
// Build the command-line arguments for Stage 2.
// Stage 1 passes the installer path and the PT install directory
// so Stage 2 can run the installer and relaunch PowerToys afterward.
// Note: paths containing embedded double-quote characters are not supported.
// This is safe because install paths come from get_module_folderpath().
inline std::wstring BuildStage2Arguments(
const std::wstring& stage2Flag,
const fs::path& installerPath,
const fs::path& installDir)
{
std::wstring arguments{ stage2Flag };
arguments += L" \"";
arguments += installerPath.c_str();
arguments += L"\" \"";
arguments += installDir.c_str();
arguments += L"\"";
return arguments;
}
// Build the full path to PowerToys.exe from the install directory.
// Used by Stage 2 to relaunch PT after a successful update.
inline std::wstring BuildPowerToysExePath(const std::wstring& installDir)
{
return (std::filesystem::path(installDir) / L"PowerToys.exe").wstring();
}
// Determine whether Stage 2 has enough information to relaunch PT.
// Returns true if the install directory argument was provided.
inline bool CanRelaunchAfterUpdate(int argCount)
{
// args[0]=exe, args[1]=action, args[2]=installer, args[3]=installDir
return argCount >= 4;
}
}

View File

@@ -87,11 +87,7 @@ namespace updating
// If the current version starts with 0.0.*, it means we're on a local build from a farm and shouldn't check for updates.
if constexpr (VERSION_MAJOR == 0 && VERSION_MINOR == 0)
{
#if USE_STD_EXPECTED
co_return std::unexpected(LOCAL_BUILD_ERROR);
#else
co_return nonstd::make_unexpected(LOCAL_BUILD_ERROR);
#endif
}
try
@@ -143,11 +139,7 @@ namespace updating
catch (...)
{
}
#if USE_STD_EXPECTED
co_return std::unexpected(NETWORK_ERROR);
#else
co_return nonstd::make_unexpected(NETWORK_ERROR);
#endif
}
#pragma warning(pop)

View File

@@ -5,14 +5,7 @@
#include <filesystem>
#include <variant>
#include <winrt/Windows.Foundation.h>
//#if __MSVC_VERSION__ >= 1933 // MSVC begin to support std::unexpected in 19.33
#if __has_include(<expected> ) // use the same way with excepted-lite to detect std::unexcepted, as using it as backup
#include <expected>
#define USE_STD_EXPECTED 1
#else
#include <expected.hpp>
#define USE_STD_EXPECTED 0
#endif
#include <common/version/helper.h>
#include <wil/coroutine.h>
@@ -31,12 +24,7 @@ namespace updating
std::wstring installer_filename;
};
using github_version_info = std::variant<new_version_download_info, version_up_to_date>;
#if USE_STD_EXPECTED
using github_version_result = std::expected<github_version_info, std::wstring>;
#else
using github_version_result = nonstd::expected<github_version_info, std::wstring>;
#endif
wil::task<github_version_result> get_github_version_info_async(bool prerelease = false);
wil::task<std::optional<std::filesystem::path>> download_new_version_async(new_version_download_info new_version);

View File

@@ -9,7 +9,6 @@
<ProjectName>ApplicationUpdate</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="..\..\..\deps\expected.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>

View File

@@ -1,164 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{7E1E3F13-2BD6-3F75-A6A7-873A2B55C60F}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<ProjectName>spdlog</ProjectName>
</PropertyGroup>
<Import Project="$(RepoRoot)deps\spdlog.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<OutDir>$(RepoRoot)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<DebugInformationFormat>None</DebugInformationFormat>
<ExceptionHandling>Sync</ExceptionHandling>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<WarningLevel>Level4</WarningLevel>
<PreprocessorDefinitions>WIN32;_WINDOWS;SPDLOG_COMPILED_LIB;SPDLOG_WCHAR_FILENAMES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ObjectFileName>$(IntDir)</ObjectFileName>
<FunctionLevelLinking>true</FunctionLevelLinking>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
</ClCompile>
<Lib>
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="$(RepoRoot)deps\spdlog\src\spdlog.cpp" />
<ClCompile Include="$(RepoRoot)deps\spdlog\src\stdout_sinks.cpp" />
<ClCompile Include="$(RepoRoot)deps\spdlog\src\color_sinks.cpp" />
<ClCompile Include="$(RepoRoot)deps\spdlog\src\file_sinks.cpp" />
<ClCompile Include="$(RepoRoot)deps\spdlog\src\async.cpp" />
<ClCompile Include="$(RepoRoot)deps\spdlog\src\cfg.cpp" />
<ClCompile Include="$(RepoRoot)deps\spdlog\src\fmt.cpp" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\async.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\async_logger-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\async_logger.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\common-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\common.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\formatter.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fwd.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\logger-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\logger.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\pattern_formatter-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\pattern_formatter.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\spdlog-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\spdlog.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\stopwatch.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\tweakme.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\version.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\backtracer-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\backtracer.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\circular_q.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\console_globals.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\file_helper-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\file_helper.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\fmt_helper.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\log_msg-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\log_msg.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\log_msg_buffer-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\log_msg_buffer.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\mpmc_blocking_q.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\null_mutex.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\os-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\os.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\periodic_worker-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\periodic_worker.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\registry-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\registry.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\synchronous_factory.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\tcp_client-windows.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\tcp_client.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\thread_pool-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\thread_pool.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\details\windows_include.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\android_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\ansicolor_sink-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\ansicolor_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\base_sink-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\base_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\basic_file_sink-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\basic_file_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\daily_file_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\dist_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\dup_filter_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\msvc_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\null_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\ostream_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\ringbuffer_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\rotating_file_sink-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\rotating_file_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\sink-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\stdout_color_sinks-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\stdout_color_sinks.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\stdout_sinks-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\stdout_sinks.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\syslog_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\systemd_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\tcp_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\win_eventlog_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\wincolor_sink-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\sinks\wincolor_sink.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bin_to_hex.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\chrono.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\fmt.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\ostr.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\chrono.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\color.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\compile.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\core.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\format-inl.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\format.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\locale.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\os.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\ostream.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\posix.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\printf.h" />
<ClInclude Include="$(RepoRoot)deps\spdlog\include\spdlog\fmt\bundled\ranges.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -1,122 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="$(ProjectDir)..\..\deps\spdlog\src\spdlog.cpp" />
<ClCompile Include="$(ProjectDir)..\..\deps\spdlog\src\stdout_sinks.cpp" />
<ClCompile Include="$(ProjectDir)..\..\deps\spdlog\src\color_sinks.cpp" />
<ClCompile Include="$(ProjectDir)..\..\deps\spdlog\src\file_sinks.cpp" />
<ClCompile Include="$(ProjectDir)..\..\deps\spdlog\src\async.cpp" />
<ClCompile Include="$(ProjectDir)..\..\deps\spdlog\src\cfg.cpp" />
<ClCompile Include="$(ProjectDir)..\..\deps\spdlog\src\fmt.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\async.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\async_logger-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\async_logger.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\common-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\common.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\formatter.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fwd.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\logger-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\logger.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\pattern_formatter-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\pattern_formatter.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\spdlog-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\spdlog.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\stopwatch.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\tweakme.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\version.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\backtracer-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\backtracer.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\circular_q.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\console_globals.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\file_helper-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\file_helper.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\fmt_helper.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\log_msg-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\log_msg.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\log_msg_buffer-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\log_msg_buffer.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\mpmc_blocking_q.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\null_mutex.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\os-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\os.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\periodic_worker-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\periodic_worker.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\registry-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\registry.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\synchronous_factory.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\tcp_client-windows.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\tcp_client.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\thread_pool-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\thread_pool.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\details\windows_include.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\android_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\ansicolor_sink-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\ansicolor_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\base_sink-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\base_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\basic_file_sink-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\basic_file_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\daily_file_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\dist_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\dup_filter_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\msvc_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\null_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\ostream_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\ringbuffer_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\rotating_file_sink-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\rotating_file_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\sink-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\stdout_color_sinks-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\stdout_color_sinks.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\stdout_sinks-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\stdout_sinks.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\syslog_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\systemd_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\tcp_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\win_eventlog_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\wincolor_sink-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\sinks\wincolor_sink.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bin_to_hex.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\chrono.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\fmt.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\ostr.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\chrono.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\color.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\compile.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\core.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\format-inl.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\format.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\locale.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\os.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\ostream.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\posix.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\printf.h" />
<ClInclude Include="$(ProjectDir)..\..\deps\spdlog\include\spdlog\fmt\bundled\ranges.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">
<UniqueIdentifier>{CDF4BA23-560C-3A6F-8D1C-2F5ACA434329}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\spdlog">
<UniqueIdentifier>{EFFE8123-D806-3145-8ABC-B48562A6C8F2}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\spdlog\details">
<UniqueIdentifier>{C546A431-88F1-390F-B0F0-D9CAC274B7F5}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\spdlog\fmt">
<UniqueIdentifier>{08320F28-6D0D-3217-B0B3-A98758C02C97}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\spdlog\fmt\bundled">
<UniqueIdentifier>{C856528D-4506-3A62-B279-CBB4558CB61D}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\spdlog\sinks">
<UniqueIdentifier>{A5EE33C4-AB64-38F0-BF4A-CCD02FFAB715}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files">
<UniqueIdentifier>{8B480F42-A230-3344-A387-2D050CFF7D9C}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

View File

@@ -2,6 +2,8 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Text;
using AdvancedPaste.Helpers;
using Windows.ApplicationModel.DataTransfer;
@@ -13,15 +15,26 @@ namespace AdvancedPaste.FuzzTests
{
public static void FuzzToJsonFromXmlOrCsv(ReadOnlySpan<byte> input)
{
// Decode the input bytes as UTF-8 text. `ReadOnlySpan<byte>.ToString()`
// returns the type name (e.g. "System.ReadOnlySpan<Byte>[N]") rather
// than the bytes, so an explicit decode is required to actually exercise
// the helper with the provided input.
string text = Encoding.UTF8.GetString(input);
var dataPackage = new DataPackage();
dataPackage.SetText(text);
// Use GetAwaiter().GetResult() so any thrown exception surfaces with its
// original type. `Task.Run(...).Result` wraps thrown exceptions in an
// AggregateException, which would prevent the
// `when (ex is ArgumentException)` filter below from matching.
try
{
var dataPackage = new DataPackage();
dataPackage.SetText(input.ToString());
_ = Task.Run(async () => await JsonHelper.ToJsonFromXmlOrCsvAsync(dataPackage.GetView())).Result;
_ = Task.Run(async () => await JsonHelper.ToJsonFromXmlOrCsvAsync(dataPackage.GetView())).GetAwaiter().GetResult();
}
catch (Exception ex) when (ex is ArgumentException)
{
// This is an example. It's important to filter out any *expected* exceptions from our code here.
// It's important to filter out any *expected* exceptions from our code here.
// However, catching all exceptions is considered an anti-pattern because it may suppress legitimate
// issues, such as a NullReferenceException thrown by our code. In this case, we still re-throw
// the exception, as the ToJsonFromXmlOrCsvAsync method is not expected to throw any exceptions.

View File

@@ -57,7 +57,21 @@ namespace AdvancedPaste.Helpers
return string.Empty;
}
var text = await clipboardData.GetTextAsync();
string text;
try
{
text = await clipboardData.GetTextAsync();
}
catch (Exception ex)
{
// GetTextAsync goes through WinRT/COM and can fail for reasons outside
// our control (e.g. clipboard contention, malformed payloads from other
// apps). The contract for this helper is that it does not throw — any
// failure to read clipboard text should be treated as "no text".
Logger.LogError("Failed reading text from clipboard", ex);
return string.Empty;
}
string jsonText = string.Empty;
// If the text is already JSON, return it

View File

@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<ProjectGuid>{C2E4F2B0-3A0E-4B1D-A23C-DA8C3F1A2A22}</ProjectGuid>
<RootNamespace>DesktopGrass.Native.Tests</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>DesktopGrass.Native.Tests</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v145</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v145</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v145</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v145</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<PropertyGroup>
<OutDir>$(MSBuildProjectDirectory)\out\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(MSBuildProjectDirectory)\obj\$(Platform)\$(Configuration)\</IntDir>
<TargetName>DesktopGrass.Native.Tests</TargetName>
<!-- No precompiled header; opt out of the PowerToys-wide PCH default. -->
<UsePrecompiledHeaders>false</UsePrecompiledHeaders>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>UNICODE;_UNICODE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalIncludeDirectories>$(MSBuildProjectDirectory)\src;$(MSBuildProjectDirectory)\third_party\catch2;$(MSBuildProjectDirectory)\..\DesktopGrass.Native\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\prng_tests.cpp" />
<ClCompile Include="src\blade_gen_tests.cpp" />
<ClCompile Include="src\sway_tests.cpp" />
<ClCompile Include="src\gust_tests.cpp" />
<ClCompile Include="src\cut_tests.cpp" />
<ClCompile Include="src\regrowth_tests.cpp" />
<ClCompile Include="src\flower_tests.cpp" />
<ClCompile Include="src\mushroom_tests.cpp" />
<ClCompile Include="src\ambient_gust_tests.cpp" />
<ClCompile Include="src\scene_tests.cpp" />
<ClCompile Include="src\entity_skeleton_tests.cpp" />
<ClCompile Include="src\desert_tests.cpp" />
<ClCompile Include="src\winter_tests.cpp" />
<ClCompile Include="src\pine_tests.cpp" />
<ClCompile Include="src\autumn_tests.cpp" />
<ClCompile Include="src\ocean_tests.cpp" />
<ClCompile Include="src\critter_tests.cpp" />
<ClCompile Include="src\sheep_greeting_tests.cpp" />
<ClCompile Include="src\cat_tests.cpp" />
<ClCompile Include="src\cat_coat_tests.cpp" />
<ClCompile Include="src\bunny_tests.cpp" />
<ClCompile Include="src\hedgehog_tests.cpp" />
<ClCompile Include="src\butterfly_tests.cpp" />
<ClCompile Include="src\firefly_tests.cpp" />
<ClCompile Include="src\bird_flyby_tests.cpp" />
<ClCompile Include="src\persistence_tests.cpp" />
<ClCompile Include="src\config_tests.cpp" />
<ClCompile Include="src\autostart_tests.cpp" />
<ClCompile Include="src\click_through_smoke_test.cpp" />
<ClCompile Include="src\pacing_tests.cpp" />
<ClCompile Include="src\prop_spacing_tests.cpp" />
<ClCompile Include="..\DesktopGrass.Native\src\AutoStart.cpp" />
<ClCompile Include="..\DesktopGrass.Native\src\Config.cpp" />
<ClCompile Include="..\DesktopGrass.Native\src\Pacing.cpp" />
<ClCompile Include="..\DesktopGrass.Native\src\Persistence.cpp" />
<ClCompile Include="..\DesktopGrass.Native\src\Sim.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\snapshot_data.h" />
<ClInclude Include="..\DesktopGrass.Native\src\AutoStart.h" />
<ClInclude Include="..\DesktopGrass.Native\src\Config.h" />
<ClInclude Include="..\DesktopGrass.Native\src\Json.h" />
<ClInclude Include="..\DesktopGrass.Native\src\Pacing.h" />
<ClInclude Include="..\DesktopGrass.Native\src\Persistence.h" />
<ClInclude Include="third_party\catch2\catch.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

View File

@@ -0,0 +1,57 @@
// snapshot_gen.cpp
// One-shot tool that prints the canonical PRNG + blade snapshot. Used to seed
// constants in DesktopGrass.Native.Tests/src/snapshot_data.h. Not part of the
// shipped binary. Build inline with cl when regenerating; the resulting EXE
// is deleted after copying its output into the test source.
#include <cstdio>
#include <cstdint>
#include "../src/Sim.h"
int main() {
using namespace desktopgrass;
Prng p;
prng_init(p, CANONICAL_TEST_SEED);
std::printf("// canonical PRNG snapshot (seed = 0x6B6173746F)\n");
std::printf("constexpr uint64_t CANONICAL_PRNG_SNAPSHOT[16] = {\n");
for (int i = 0; i < 16; ++i) {
uint64_t v = prng_next_u64(p);
std::printf(" 0x%016llXull,\n", static_cast<unsigned long long>(v));
}
std::printf("};\n");
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
std::printf("\n// blade count: %zu\n", blades.size());
std::printf("constexpr size_t CANONICAL_BLADE_COUNT = %zu;\n", blades.size());
std::printf("\n// first 10 blades (baseX, height, thickness, hue, swayPhaseOffset, stiffness, isFlower, flowerHeadColorIdx, flowerHeadRadius, heightBonus)\n");
std::printf("struct SnapshotBlade { double baseX, height, thickness; uint8_t hue; double sway, stiffness; bool isFlower; uint8_t flowerHeadColorIdx; double flowerHeadRadius, heightBonus; };\n");
std::printf("constexpr SnapshotBlade CANONICAL_FIRST_10[10] = {\n");
for (int i = 0; i < 10 && i < (int)blades.size(); ++i) {
const Blade& b = blades[i];
std::printf(" { %.17g, %.17g, %.17g, %u, %.17g, %.17g, %s, %u, %.17g, %.17g },\n",
b.baseX, b.height, b.thickness, (unsigned)b.hue,
b.swayPhaseOffset, b.stiffness,
b.isFlower ? "true" : "false",
(unsigned)b.flowerHeadColorIdx,
b.flowerHeadRadius, b.heightBonus);
}
std::printf("};\n");
std::printf("\n// last 10 blades\n");
std::printf("constexpr SnapshotBlade CANONICAL_LAST_10[10] = {\n");
int start = (int)blades.size() - 10;
if (start < 0) start = 0;
for (int i = start; i < (int)blades.size(); ++i) {
const Blade& b = blades[i];
std::printf(" { %.17g, %.17g, %.17g, %u, %.17g, %.17g, %s, %u, %.17g, %.17g },\n",
b.baseX, b.height, b.thickness, (unsigned)b.hue,
b.swayPhaseOffset, b.stiffness,
b.isFlower ? "true" : "false",
(unsigned)b.flowerHeadColorIdx,
b.flowerHeadRadius, b.heightBonus);
}
std::printf("};\n");
return 0;
}

View File

@@ -0,0 +1,252 @@
// ambient_gust_tests.cpp
//
// Ambient gust scheduler tests (architecture.md §8.1).
//
// Coverage:
// * Scheduler determinism — first 8 emitted puffs match a cross-impl
// snapshot for the canonical seed.
// * Stream independence — adding ambient gusts does not perturb the static
// blade snapshot from §12 (already exercised by snapshot_data.h, but
// repeated here as a focused regression).
// * Idle ticks consume zero PRNG draws.
// * Apply kernel matches §8.1 (half radius, magnitude scales with magFactor).
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include "snapshot_data.h"
#include <array>
#include <cmath>
#include <cstdint>
using namespace desktopgrass;
namespace {
struct Puff {
double fireTime;
double x;
double signDir;
double magFactor;
};
// Drive the scheduler until N puffs have fired and capture each one. The
// scheduler fires when sim.globalTime crosses nextAmbientGustTime, so we
// repeatedly nudge globalTime to just past nextAmbientGustTime and call
// sim_tick_ambient_gusts.
std::vector<Puff> capture_first_n_puffs(Sim& sim, std::size_t n) {
std::vector<Puff> puffs;
while (puffs.size() < n) {
const double fireTime = sim.nextAmbientGustTime;
sim.globalTime = fireTime;
// Snapshot blades and PRNG so we can extract the four draws by
// observing the state diff: we just call sim_tick_ambient_gusts
// (which fires exactly one puff because globalTime == fireTime
// and we don't advance further). After it returns we know the
// (x, signDir, magFactor) that were drawn by replaying — but
// that's ugly. Simpler: call the public step ourselves with a
// dedicated PRNG view and assert.
//
// Cleanest: call sim_tick_ambient_gusts and capture from the
// blades' aggregate gustVelocity NOPE — that loses signDir / x.
//
// Even simpler: re-draw the same four values from a side-PRNG
// initialized to sim.ambientPrng's state right before the fire,
// then call sim_tick_ambient_gusts which advances the real PRNG
// identically. We assert the two PRNGs end at the same state.
Prng peek = sim.ambientPrng;
const double x = prng_uniform(peek, 0.0, sim.monitorWidth);
const double signDir = prng_uniform(peek, 0.0, 1.0) < 0.5 ? -1.0 : 1.0;
const double magFactor = prng_uniform(peek, AMBIENT_GUST_MAG_FACTOR_MIN,
AMBIENT_GUST_MAG_FACTOR_MAX);
// Interval is drawn AFTER apply, so the peek is "ahead" of the real
// PRNG by these three values only at this point; the real call below
// will draw all four (x, signDir, magFactor, interval) atomically.
sim_tick_ambient_gusts(sim);
puffs.push_back({ fireTime, x, signDir, magFactor });
}
return puffs;
}
} // anonymous
// ----------------------------------------------------------------------------
// Init wires up the ambient PRNG correctly + first interval is sampled.
// ----------------------------------------------------------------------------
TEST_CASE("sim_init seeds ambientPrng off seed XOR AMBIENT_GUST_PRNG_SALT", "[ambient][init]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
Prng expected;
prng_init(expected, CANONICAL_TEST_SEED ^ AMBIENT_GUST_PRNG_SALT);
// Init draws ONE value from the ambient stream (the first interval).
const double firstInterval = prng_uniform(expected,
AMBIENT_GUST_INTERVAL_MIN,
AMBIENT_GUST_INTERVAL_MAX);
REQUIRE(sim.monitorWidth == Approx(1920.0));
REQUIRE(sim.nextAmbientGustTime == Approx(firstInterval));
REQUIRE(sim.nextAmbientGustTime >= AMBIENT_GUST_INTERVAL_MIN);
REQUIRE(sim.nextAmbientGustTime <= AMBIENT_GUST_INTERVAL_MAX);
// PRNG state after sim_init must match the side-prng after one draw.
REQUIRE(sim.ambientPrng.state == expected.state);
}
// ----------------------------------------------------------------------------
// Idle ticks consume zero PRNG draws.
// ----------------------------------------------------------------------------
TEST_CASE("sim_tick_ambient_gusts is a no-op when globalTime < nextAmbientGustTime", "[ambient][idle]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
const uint64_t stateBefore = sim.ambientPrng.state;
// Many idle ticks across less than the minimum interval.
sim.globalTime = AMBIENT_GUST_INTERVAL_MIN * 0.5;
for (int i = 0; i < 100; ++i) sim_tick_ambient_gusts(sim);
REQUIRE(sim.ambientPrng.state == stateBefore);
REQUIRE(sim.nextAmbientGustTime >= sim.globalTime);
}
// ----------------------------------------------------------------------------
// Scheduler determinism — pin the first eight puffs.
// ----------------------------------------------------------------------------
TEST_CASE("first 8 ambient puffs match deterministic snapshot for canonical seed", "[ambient][snapshot]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
std::vector<Puff> puffs = capture_first_n_puffs(sim, 8);
REQUIRE(puffs.size() == 8);
// Bounded sanity for every puff.
for (const Puff& p : puffs) {
REQUIRE(p.x >= 0.0);
REQUIRE(p.x <= 1920.0);
REQUIRE((p.signDir == -1.0 || p.signDir == 1.0));
REQUIRE(p.magFactor >= AMBIENT_GUST_MAG_FACTOR_MIN);
REQUIRE(p.magFactor <= AMBIENT_GUST_MAG_FACTOR_MAX);
REQUIRE(p.fireTime >= AMBIENT_GUST_INTERVAL_MIN);
}
// Inter-puff intervals are all within [MIN, MAX].
for (std::size_t i = 1; i < puffs.size(); ++i) {
const double interval = puffs[i].fireTime - puffs[i - 1].fireTime;
REQUIRE(interval >= AMBIENT_GUST_INTERVAL_MIN);
REQUIRE(interval <= AMBIENT_GUST_INTERVAL_MAX);
}
// ⟪ Cross-impl snapshot ⟫
// These values were captured from the Native impl with the spec-locked
// draw order (x, signDir, magFactor, interval) and the salt
// AMBIENT_GUST_PRNG_SALT = 0xB7EE2EE2B7EE2EE2. The Win2D port MUST
// reproduce them bit-equivalent (≤ 1 ULP on doubles drawn from
// prng_uniform; sign and bounded scalars exact).
//
// First puff's fireTime equals the first interval drawn at sim_init.
// Subsequent fireTimes are cumulative.
//
// NB: this snapshot is INTENTIONALLY a smoke-bound: it asserts every
// puff's signDir, and the FIRST puff's exact (x, magFactor, fireTime).
// A full 8-entry snapshot would over-pin and create churn on future
// unrelated PRNG-salt rotations. The cross-impl test on the Win2D side
// re-derives the same values from the spec and asserts the FULL tuple.
// The first puff fires at sim.nextAmbientGustTime as set in sim_init.
Prng expected;
prng_init(expected, CANONICAL_TEST_SEED ^ AMBIENT_GUST_PRNG_SALT);
const double expectedFirstInterval = prng_uniform(expected,
AMBIENT_GUST_INTERVAL_MIN,
AMBIENT_GUST_INTERVAL_MAX);
const double expectedFirstX = prng_uniform(expected, 0.0, 1920.0);
const double expectedFirstSign = prng_uniform(expected, 0.0, 1.0) < 0.5 ? -1.0 : 1.0;
const double expectedFirstMag = prng_uniform(expected,
AMBIENT_GUST_MAG_FACTOR_MIN,
AMBIENT_GUST_MAG_FACTOR_MAX);
REQUIRE(puffs[0].fireTime == Approx(expectedFirstInterval));
REQUIRE(puffs[0].x == Approx(expectedFirstX));
REQUIRE(puffs[0].signDir == expectedFirstSign);
REQUIRE(puffs[0].magFactor == Approx(expectedFirstMag));
}
// ----------------------------------------------------------------------------
// Apply kernel matches §8.1 (half radius, magnitude scales linearly).
// ----------------------------------------------------------------------------
TEST_CASE("apply_ambient_gust kernel: half radius, scales with magFactor", "[ambient][kernel]") {
// Build a sim with three blades: at the puff center, one inside the
// shrunken ambient radius, one outside it (but inside the cursor radius).
Sim sim;
sim.windowHeight = STRIP_HEIGHT + HEADROOM;
const double ambientRadius = GUST_RADIUS * AMBIENT_GUST_RADIUS_FACTOR; // 75 DIP
Blade b0{}; b0.baseX = 100.0; b0.height = 20.0; b0.cutHeight = 1.0;
Blade b1{}; b1.baseX = 100.0 + ambientRadius * 0.5; b1.height = 20.0; b1.cutHeight = 1.0;
Blade b2{}; b2.baseX = 100.0 + ambientRadius + 5.0; b2.height = 20.0; b2.cutHeight = 1.0;
sim.blades = { b0, b1, b2 };
const double magFactor = 0.5;
sim_apply_ambient_gust(sim, /*x=*/100.0, /*signDir=*/+1.0, magFactor);
const double expectedPeak = MAX_CURSOR_SPEED * magFactor * IMPULSE_SCALE; // 4000*0.5*0.003 = 6.0
REQUIRE(sim.blades[0].gustVelocity == Approx(expectedPeak));
// Blade at half-radius gets smoothstep(0.5) = 0.5.
REQUIRE(sim.blades[1].gustVelocity == Approx(expectedPeak * 0.5));
// Blade outside ambient radius is untouched.
REQUIRE(sim.blades[2].gustVelocity == Approx(0.0));
}
TEST_CASE("apply_ambient_gust signDir flips impulse direction", "[ambient][kernel]") {
Sim sim;
sim.windowHeight = STRIP_HEIGHT + HEADROOM;
Blade b{}; b.baseX = 100.0; b.height = 20.0; b.cutHeight = 1.0;
sim.blades = { b };
sim_apply_ambient_gust(sim, 100.0, -1.0, 0.5);
const double expectedPeak = MAX_CURSOR_SPEED * 0.5 * IMPULSE_SCALE;
REQUIRE(sim.blades[0].gustVelocity == Approx(-expectedPeak));
}
// ----------------------------------------------------------------------------
// Stream independence — adding ambient gusts must NOT perturb the static
// blade snapshot from §12. (sim_init's first blade still matches.)
// ----------------------------------------------------------------------------
TEST_CASE("ambient gust stream does not perturb the canonical first blade", "[ambient][independence]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, 1.0);
REQUIRE(sim.blades.size() == desktopgrass::test::CANONICAL_BLADE_COUNT);
const Blade& first = sim.blades[0];
const desktopgrass::test::SnapshotBlade& expected = desktopgrass::test::CANONICAL_FIRST_10[0];
REQUIRE(first.baseX == Approx(expected.baseX));
REQUIRE(first.height == Approx(expected.height));
REQUIRE(first.thickness == Approx(expected.thickness));
REQUIRE(first.hue == expected.hue);
}
// ----------------------------------------------------------------------------
// sim_tick wires the scheduler into the per-frame loop.
// ----------------------------------------------------------------------------
TEST_CASE("sim_tick fires ambient puff when dt crosses nextAmbientGustTime", "[ambient][tick]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
const double fireTime = sim.nextAmbientGustTime;
REQUIRE(fireTime > 0.0);
// Stash PRNG state to detect a fire.
const uint64_t stateBefore = sim.ambientPrng.state;
// Tick with dt that does NOT cross — no fire.
sim_tick(sim, fireTime * 0.5, nullptr, 0);
REQUIRE(sim.ambientPrng.state == stateBefore);
// Tick with dt that crosses — exactly one fire, PRNG advanced by 4 draws.
sim_tick(sim, fireTime, nullptr, 0);
REQUIRE(sim.ambientPrng.state != stateBefore);
REQUIRE(sim.nextAmbientGustTime > sim.globalTime);
}

View File

@@ -0,0 +1,156 @@
#include "../third_party/catch2/catch.hpp"
#include "AutoStart.h"
#include "Persistence.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <atomic>
#include <filesystem>
#include <fstream>
#include <string>
#include <vector>
namespace {
std::wstring unique_subkey(const wchar_t* name) {
static std::atomic<int> counter{0};
return std::wstring(L"Software\\DesktopGrass.Test.")
+ std::to_wstring(GetCurrentProcessId()) + L"."
+ std::to_wstring(GetTickCount64()) + L"."
+ std::to_wstring(counter.fetch_add(1)) + L"."
+ name;
}
class AutoStartRegistrySandbox {
public:
explicit AutoStartRegistrySandbox(const wchar_t* name) : subkey_(unique_subkey(name)) {
RegDeleteTreeW(HKEY_CURRENT_USER, subkey_.c_str());
autostart::SetRegistryKeyOverride(subkey_);
}
~AutoStartRegistrySandbox() {
autostart::SetRegistryKeyOverride(subkey_);
autostart::SetEnabled(false);
RegDeleteTreeW(HKEY_CURRENT_USER, subkey_.c_str());
autostart::SetRegistryKeyOverride(L"");
desktopgrass::persistence::SetStateFilePathForTest(L"");
}
const std::wstring& subkey() const { return subkey_; }
private:
std::wstring subkey_;
};
std::wstring read_registry_value(const std::wstring& subkey) {
HKEY key = nullptr;
REQUIRE(RegOpenKeyExW(HKEY_CURRENT_USER, subkey.c_str(), 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS);
DWORD type = 0;
DWORD byteCount = 0;
const std::wstring valueName = autostart::GetRegistryValueName();
REQUIRE(RegQueryValueExW(key, valueName.c_str(), nullptr, &type, nullptr, &byteCount) == ERROR_SUCCESS);
REQUIRE(type == REG_SZ);
std::vector<wchar_t> buffer(byteCount / sizeof(wchar_t) + 1);
REQUIRE(RegQueryValueExW(
key, valueName.c_str(), nullptr, &type,
reinterpret_cast<BYTE*>(buffer.data()), &byteCount) == ERROR_SUCCESS);
RegCloseKey(key);
return std::wstring(buffer.data());
}
std::filesystem::path test_state_path(const char* name) {
std::filesystem::path dir = std::filesystem::current_path()
/ ".copilot-scratch"
/ "native-autostart-tests"
/ name;
std::error_code ec;
std::filesystem::remove_all(dir, ec);
std::filesystem::create_directories(dir);
return dir / "state.json";
}
} // namespace
TEST_CASE("autostart is disabled when registry value is missing", "[autostart]") {
AutoStartRegistrySandbox sandbox(L"missing");
REQUIRE_FALSE(autostart::IsEnabled());
}
TEST_CASE("autostart enable creates registry value", "[autostart]") {
AutoStartRegistrySandbox sandbox(L"enable");
REQUIRE(autostart::SetEnabled(true));
REQUIRE(autostart::IsEnabled());
}
TEST_CASE("autostart disable deletes registry value", "[autostart]") {
AutoStartRegistrySandbox sandbox(L"disable");
REQUIRE(autostart::SetEnabled(true));
REQUIRE(autostart::SetEnabled(false));
REQUIRE_FALSE(autostart::IsEnabled());
}
TEST_CASE("autostart registry value contains current exe path", "[autostart]") {
AutoStartRegistrySandbox sandbox(L"path");
REQUIRE(autostart::SetEnabled(true));
REQUIRE(read_registry_value(sandbox.subkey()) == autostart::GetCurrentExePath());
}
TEST_CASE("autostart enable is idempotent", "[autostart]") {
AutoStartRegistrySandbox sandbox(L"enable-idempotent");
REQUIRE(autostart::SetEnabled(true));
REQUIRE(autostart::SetEnabled(true));
REQUIRE(autostart::IsEnabled());
}
TEST_CASE("autostart disable missing value is no-op", "[autostart]") {
AutoStartRegistrySandbox sandbox(L"disable-missing");
REQUIRE(autostart::SetEnabled(false));
REQUIRE_FALSE(autostart::IsEnabled());
}
TEST_CASE("autostart persisted true reconciles registry on startup", "[autostart][persistence]") {
AutoStartRegistrySandbox sandbox(L"persisted-true");
const auto path = test_state_path("persisted-true");
desktopgrass::persistence::SetStateFilePathForTest(path.wstring());
desktopgrass::persistence::AppState state;
state.autoStart = true;
REQUIRE(desktopgrass::persistence::SaveAppState(state));
desktopgrass::persistence::AppState loaded;
REQUIRE(desktopgrass::persistence::LoadAppState(loaded));
REQUIRE(autostart::ReconcileWithState(loaded.autoStart));
REQUIRE(autostart::IsEnabled());
}
TEST_CASE("autostart persisted false reconciles registry on startup", "[autostart][persistence]") {
AutoStartRegistrySandbox sandbox(L"persisted-false");
const auto path = test_state_path("persisted-false");
desktopgrass::persistence::SetStateFilePathForTest(path.wstring());
REQUIRE(autostart::SetEnabled(true));
desktopgrass::persistence::AppState state;
state.autoStart = false;
REQUIRE(desktopgrass::persistence::SaveAppState(state));
desktopgrass::persistence::AppState loaded;
REQUIRE(desktopgrass::persistence::LoadAppState(loaded));
REQUIRE(autostart::ReconcileWithState(loaded.autoStart));
REQUIRE_FALSE(autostart::IsEnabled());
}

View File

@@ -0,0 +1,600 @@
// autumn_tests.cpp
//
// Autumn scene tests (architecture.md §16.5).
#include "../third_party/catch2/catch.hpp"
#include "Persistence.h"
#include "Sim.h"
#include "snapshot_data.h"
#include <algorithm>
#include <array>
#include <cmath>
#include <filesystem>
using namespace desktopgrass;
namespace {
constexpr double kMonitor1920 = 1920.0;
constexpr double kEpsilon = 1e-9;
constexpr double kTwoPi = 6.28318530717958647692;
Sim make_sim(uint64_t seed = CANONICAL_TEST_SEED,
double width = kMonitor1920,
double density = DEFAULT_DENSITY) {
return sim_init(seed, width, density);
}
Sim make_autumn_sim(uint64_t seed = CANONICAL_TEST_SEED,
double width = kMonitor1920,
double density = DEFAULT_DENSITY) {
Sim sim = make_sim(seed, width, density);
sim_set_scene(sim, Scene::Autumn);
return sim;
}
int count_kind(const Sim& sim, EntityKind kind) {
return static_cast<int>(std::count_if(sim.entities.begin(), sim.entities.end(),
[kind](const Entity& e) { return e.kind == kind; }));
}
int count_maples(const Sim& sim) {
return static_cast<int>(std::count_if(sim.blades.begin(), sim.blades.end(),
[](const Blade& b) { return b.isMaple; }));
}
int count_new_leaf_spawns(Sim& sim, double seconds, double dt = 0.05) {
int count = 0;
const int steps = static_cast<int>(std::ceil(seconds / dt));
for (int i = 0; i < steps; ++i) {
sim_tick(sim, dt, nullptr, 0);
for (const Entity& e : sim.entities) {
if (e.kind == EntityKind::Leaf && e.age == Approx(0.0).margin(kEpsilon)) {
++count;
}
}
}
return count;
}
const Entity& spawn_next_leaf(Sim& sim) {
const double dt = std::max(0.0, sim.nextLeafSpawnTime - sim.globalTime);
sim_tick(sim, dt, nullptr, 0);
auto it = std::find_if(sim.entities.rbegin(), sim.entities.rend(),
[](const Entity& e) { return e.kind == EntityKind::Leaf && e.age == Approx(0.0).margin(kEpsilon); });
REQUIRE(it != sim.entities.rend());
return *it;
}
const Blade* first_maple(const Sim& sim) {
auto it = std::find_if(sim.blades.begin(), sim.blades.end(),
[](const Blade& b) { return b.isMaple; });
return it == sim.blades.end() ? nullptr : &*it;
}
Sim make_autumn_sim_with_maple(uint64_t* outSeed = nullptr) {
for (uint64_t offset = 0; offset < 512; ++offset) {
const uint64_t seed = CANONICAL_TEST_SEED + offset;
Sim sim = make_autumn_sim(seed);
if (count_maples(sim) > 0) {
if (outSeed) *outSeed = seed;
return sim;
}
}
FAIL("Unable to find deterministic seed with a maple");
return make_autumn_sim();
}
// Find an Autumn sim that contains at least one leafy (non-bare) maple, and
// return a pointer to it. The returned pointer is valid for the lifetime of
// the returned-by-out sim.
inline const Blade* first_leafy_maple(const Sim& sim) {
auto it = std::find_if(sim.blades.begin(), sim.blades.end(),
[](const Blade& b) { return b.isMaple && !b.mapleIsBare; });
return it == sim.blades.end() ? nullptr : &*it;
}
Sim make_autumn_sim_with_leafy_maple() {
for (uint64_t offset = 0; offset < 2048; ++offset) {
Sim sim = make_autumn_sim(CANONICAL_TEST_SEED + offset);
if (first_leafy_maple(sim) != nullptr) return sim;
}
FAIL("Unable to find deterministic seed with a leafy maple");
return make_autumn_sim();
}
std::filesystem::path autumn_state_path() {
std::filesystem::path dir = std::filesystem::current_path()
/ ".copilot-scratch"
/ "native-autumn-tests";
std::error_code ec;
std::filesystem::remove_all(dir, ec);
std::filesystem::create_directories(dir);
return dir / "state.json";
}
} // namespace
TEST_CASE("Autumn scene count bumps to five", "[autumn][scene]") {
REQUIRE(SCENE_COUNT == 5);
}
TEST_CASE("Autumn scene enum value is pinned", "[autumn][scene]") {
REQUIRE(static_cast<int>(Scene::Autumn) == 3);
}
TEST_CASE("Autumn palette is pinned in scene palettes", "[autumn][palette]") {
for (int i = 0; i < PALETTE_SIZE; ++i) {
REQUIRE(SCENE_PALETTES[static_cast<int>(Scene::Autumn)][i] == AUTUMN_PALETTE[i]);
}
}
TEST_CASE("Autumn does not change default scene", "[autumn][scene]") {
REQUIRE(SCENE_DEFAULT == Scene::Grass);
}
TEST_CASE("Leaf constants match Autumn spec", "[autumn][leaf][constants]") {
REQUIRE(LEAF_SPAWN_RATE_PER_SEC_1920DIP == Approx(1.4));
REQUIRE(LEAF_FALL_SPEED_MIN == Approx(14.0));
REQUIRE(LEAF_FALL_SPEED_MAX == Approx(26.0));
REQUIRE(LEAF_HORIZONTAL_DRIFT_AMP == Approx(32.0));
REQUIRE(LEAF_HORIZONTAL_DRIFT_FREQ == Approx(1.4));
REQUIRE(LEAF_ROTATION_SPEED_MIN == Approx(0.8));
REQUIRE(LEAF_ROTATION_SPEED_MAX == Approx(2.4));
REQUIRE(LEAF_SIZE_MIN == Approx(4.0));
REQUIRE(LEAF_SIZE_MAX == Approx(7.0));
REQUIRE(LEAF_SPAWN_Y_OFFSET == Approx(-10.0));
REQUIRE(LEAF_COLOR_COUNT == 6);
constexpr uint32_t expected[LEAF_COLOR_COUNT] = {
0xFFD96B0Cu, 0xFFB54D1Eu, 0xFFE89A3Cu,
0xFFC23E12u, 0xFFE6C849u, 0xFF8C2E0Fu,
};
for (int i = 0; i < LEAF_COLOR_COUNT; ++i) {
REQUIRE(LEAF_COLORS[i] == expected[i]);
}
REQUIRE(LEAF_PRNG_SALT == 0x1EA1DEC1D1EA1D05ull);
}
TEST_CASE("Autumn leaf spawn rate is gated and near mean", "[autumn][leaf]") {
Sim autumn = make_autumn_sim();
const int count = count_new_leaf_spawns(autumn, 100.0);
REQUIRE(count >= 112);
REQUIRE(count <= 168);
}
TEST_CASE("Only Autumn spawns leaves", "[autumn][leaf][gating]") {
for (Scene scene : { Scene::Grass, Scene::Desert, Scene::Winter }) {
Sim sim = make_sim();
sim_set_scene(sim, scene);
count_new_leaf_spawns(sim, 30.0);
REQUIRE(count_kind(sim, EntityKind::Leaf) == 0);
}
}
TEST_CASE("Leaf fall speed stays within pinned range", "[autumn][leaf]") {
Sim sim = make_autumn_sim();
for (int i = 0; i < 32; ++i) {
const Entity& e = spawn_next_leaf(sim);
REQUIRE(e.vy >= LEAF_FALL_SPEED_MIN);
REQUIRE(e.vy <= LEAF_FALL_SPEED_MAX);
REQUIRE(e.baseSpeed == Approx(e.vy));
}
}
TEST_CASE("Leaf size stays within pinned range", "[autumn][leaf]") {
Sim sim = make_autumn_sim();
for (int i = 0; i < 32; ++i) {
const Entity& e = spawn_next_leaf(sim);
REQUIRE(e.size >= LEAF_SIZE_MIN);
REQUIRE(e.size <= LEAF_SIZE_MAX);
}
}
TEST_CASE("Leaf color variant stays within pinned range", "[autumn][leaf]") {
Sim sim = make_autumn_sim();
for (int i = 0; i < 32; ++i) {
const Entity& e = spawn_next_leaf(sim);
REQUIRE(e.colorVariant < LEAF_COLOR_COUNT);
}
}
TEST_CASE("Leaf PRNG draw order matches side stream", "[autumn][leaf][prng]") {
Sim sim = make_autumn_sim();
Prng side;
prng_init(side, CANONICAL_TEST_SEED ^ LEAF_PRNG_SALT);
const double lambda = LEAF_SPAWN_RATE_PER_SEC_1920DIP * sim.monitorWidth / 1920.0;
double expectedNext = 0.0;
for (int i = 0; i < 8; ++i) {
const Entity& e = spawn_next_leaf(sim);
const double xFrac = prng_uniform(side, 0.0, 1.0);
const double expectedSpawnX = xFrac * sim.monitorWidth;
const double expectedFallSpeed = prng_uniform(side, LEAF_FALL_SPEED_MIN, LEAF_FALL_SPEED_MAX);
const double expectedPhase = prng_uniform(side, 0.0, kTwoPi);
const double rotationMag = prng_uniform(side, LEAF_ROTATION_SPEED_MIN, LEAF_ROTATION_SPEED_MAX);
const double rotationSign = (prng_next_u64(side) & 1ull) != 0ull ? 1.0 : -1.0;
const double expectedRotation = prng_uniform(side, 0.0, kTwoPi);
const double expectedSize = prng_uniform(side, LEAF_SIZE_MIN, LEAF_SIZE_MAX);
const uint8_t expectedColor = static_cast<uint8_t>(prng_index(side, LEAF_COLOR_COUNT));
expectedNext += prng_exponential(side, lambda);
REQUIRE(e.x0 == Approx(expectedSpawnX).margin(kEpsilon));
REQUIRE(e.x == Approx(expectedSpawnX + LEAF_HORIZONTAL_DRIFT_AMP * std::sin(expectedPhase)).margin(kEpsilon));
REQUIRE(e.vy == Approx(expectedFallSpeed).margin(kEpsilon));
REQUIRE(e.phaseX == Approx(expectedPhase).margin(kEpsilon));
REQUIRE(e.rotationSpeed == Approx(rotationMag * rotationSign).margin(kEpsilon));
REQUIRE(e.rotation == Approx(expectedRotation).margin(kEpsilon));
REQUIRE(e.size == Approx(expectedSize).margin(kEpsilon));
REQUIRE(e.colorVariant == expectedColor);
REQUIRE(sim.nextLeafSpawnTime == Approx(expectedNext).margin(kEpsilon));
}
}
TEST_CASE("Leaf despawns when past ground", "[autumn][leaf]") {
Sim sim = make_autumn_sim();
Entity e{};
e.kind = EntityKind::Leaf;
e.y = sim.windowHeight + 0.1;
e.lifetime = -1.0;
sim.entities.push_back(e);
sim.nextLeafSpawnTime = 1.0e9;
sim_tick_entities(sim, 0.0);
REQUIRE(count_kind(sim, EntityKind::Leaf) == 0);
}
TEST_CASE("Leaf ignores click-cut interaction", "[autumn][leaf]") {
Sim sim = make_autumn_sim();
Entity e{};
e.kind = EntityKind::Leaf;
e.x = 200.0;
e.y = sim.windowHeight - 5.0;
e.size = 5.0;
e.lifetime = -1.0;
sim.entities.push_back(e);
InputEvent click{};
click.type = EventType::Click;
click.x = e.x;
click.y = e.y;
click.time = sim.globalTime;
sim_apply_click(sim, click);
REQUIRE(count_kind(sim, EntityKind::Leaf) == 1);
}
TEST_CASE("Leaf EntityKind value is pinned", "[autumn][leaf][enum]") {
REQUIRE(static_cast<int>(EntityKind::Leaf) == 11);
}
TEST_CASE("Maple constants match Autumn spec", "[autumn][maple][constants]") {
REQUIRE(MAPLE_PROBABILITY == Approx(0.0070));
REQUIRE(MAPLE_HEIGHT_MIN == Approx(50.0));
REQUIRE(MAPLE_HEIGHT_MAX == Approx(85.0));
REQUIRE(MAPLE_TRUNK_WIDTH_MIN == Approx(6.0));
REQUIRE(MAPLE_TRUNK_WIDTH_MAX == Approx(10.0));
REQUIRE(MAPLE_CANOPY_RADIUS_MIN == Approx(14.0));
REQUIRE(MAPLE_CANOPY_RADIUS_MAX == Approx(24.0));
REQUIRE(MAPLE_TRUNK_COLOR == 0xFF4A2C18u);
REQUIRE(MAPLE_TRUNK_DARK == 0xFF2F1B0Eu);
REQUIRE(MAPLE_CANOPY_COLOR_COUNT == 4);
constexpr uint32_t expected[MAPLE_CANOPY_COLOR_COUNT] = {
0xFFD96B0Cu, 0xFFE89A3Cu, 0xFFC23E12u, 0xFFE6C849u,
};
for (int i = 0; i < MAPLE_CANOPY_COLOR_COUNT; ++i) {
REQUIRE(MAPLE_CANOPY_COLORS[i] == expected[i]);
}
REQUIRE(MAPLE_BARE_FRACTION == Approx(0.20));
REQUIRE(MAPLE_PRNG_SALT == 0xC1AA51EC1AA51Eull);
}
TEST_CASE("Maples generate only in Autumn", "[autumn][maple][gating]") {
for (Scene scene : { Scene::Grass, Scene::Desert, Scene::Winter }) {
Sim sim = make_sim();
sim_set_scene(sim, scene);
REQUIRE(count_maples(sim) == 0);
}
REQUIRE(count_maples(make_autumn_sim_with_maple()) > 0);
}
TEST_CASE("Maple promotion probability is near spec", "[autumn][maple]") {
int totalSlots = 0;
int totalMaples = 0;
for (uint64_t seed = CANONICAL_TEST_SEED; seed < CANONICAL_TEST_SEED + 200; ++seed) {
Sim sim = make_autumn_sim(seed);
totalSlots += static_cast<int>(sim.blades.size());
totalMaples += count_maples(sim);
}
const double fraction = static_cast<double>(totalMaples) / static_cast<double>(totalSlots);
REQUIRE(fraction >= MAPLE_PROBABILITY * 0.75);
REQUIRE(fraction <= MAPLE_PROBABILITY * 1.25);
}
TEST_CASE("Maple height stays within pinned range", "[autumn][maple]") {
Sim sim = make_autumn_sim_with_maple();
for (const Blade& b : sim.blades) if (b.isMaple) {
REQUIRE(b.mapleHeight >= MAPLE_HEIGHT_MIN);
REQUIRE(b.mapleHeight <= MAPLE_HEIGHT_MAX);
}
}
TEST_CASE("Maple trunk width stays within pinned range", "[autumn][maple]") {
Sim sim = make_autumn_sim_with_maple();
for (const Blade& b : sim.blades) if (b.isMaple) {
REQUIRE(b.mapleTrunkWidth >= MAPLE_TRUNK_WIDTH_MIN);
REQUIRE(b.mapleTrunkWidth <= MAPLE_TRUNK_WIDTH_MAX);
}
}
TEST_CASE("Maple canopy radius stays within pinned range", "[autumn][maple]") {
Sim sim = make_autumn_sim_with_maple();
for (const Blade& b : sim.blades) if (b.isMaple) {
REQUIRE(b.mapleCanopyRadius >= MAPLE_CANOPY_RADIUS_MIN);
REQUIRE(b.mapleCanopyRadius <= MAPLE_CANOPY_RADIUS_MAX);
}
}
TEST_CASE("Maple canopy color variant stays within pinned range", "[autumn][maple]") {
Sim sim = make_autumn_sim_with_maple();
for (const Blade& b : sim.blades) if (b.isMaple) {
REQUIRE(b.mapleCanopyColorIdx < MAPLE_CANOPY_COLOR_COUNT);
}
}
TEST_CASE("Maple bare fraction is near spec", "[autumn][maple]") {
int totalMaples = 0;
int totalBare = 0;
for (uint64_t seed = CANONICAL_TEST_SEED; seed < CANONICAL_TEST_SEED + 400; ++seed) {
Sim sim = make_autumn_sim(seed);
for (const Blade& b : sim.blades) if (b.isMaple) {
++totalMaples;
if (b.mapleIsBare) ++totalBare;
}
}
REQUIRE(totalMaples > 100);
const double fraction = static_cast<double>(totalBare) / static_cast<double>(totalMaples);
REQUIRE(fraction >= MAPLE_BARE_FRACTION - 0.05);
REQUIRE(fraction <= MAPLE_BARE_FRACTION + 0.05);
}
TEST_CASE("Maple PRNG draw order matches side stream", "[autumn][maple][prng]") {
uint64_t seed = 0;
Sim sim = make_autumn_sim_with_maple(&seed);
Prng side;
prng_init(side, seed ^ MAPLE_PRNG_SALT);
for (std::size_t i = 0; i < sim.blades.size(); ++i) {
const double r = prng_uniform(side, 0.0, 1.0);
if (r >= MAPLE_PROBABILITY) {
REQUIRE_FALSE(sim.blades[i].isMaple);
continue;
}
const double expectedHeight = prng_uniform(side, MAPLE_HEIGHT_MIN, MAPLE_HEIGHT_MAX);
const double expectedTrunkWidth = prng_uniform(side, MAPLE_TRUNK_WIDTH_MIN, MAPLE_TRUNK_WIDTH_MAX);
const double expectedCanopyRadius = prng_uniform(side, MAPLE_CANOPY_RADIUS_MIN, MAPLE_CANOPY_RADIUS_MAX);
const uint8_t expectedColor = static_cast<uint8_t>(prng_index(side, MAPLE_CANOPY_COLOR_COUNT));
const bool expectedBare = prng_uniform(side, 0.0, 1.0) < MAPLE_BARE_FRACTION;
const Blade& b = sim.blades[i];
REQUIRE(b.isMaple);
REQUIRE(b.mapleHeight == Approx(expectedHeight).margin(kEpsilon));
REQUIRE(b.mapleTrunkWidth == Approx(expectedTrunkWidth).margin(kEpsilon));
REQUIRE(b.mapleCanopyRadius == Approx(expectedCanopyRadius).margin(kEpsilon));
REQUIRE(b.mapleCanopyColorIdx == expectedColor);
REQUIRE(b.mapleIsBare == expectedBare);
return;
}
FAIL("Expected a maple promotion");
}
TEST_CASE("Maples are cuttable through existing cut model", "[autumn][maple]") {
Sim sim = make_autumn_sim_with_maple();
const Blade* maple = first_maple(sim);
REQUIRE(maple != nullptr);
const double clickX = maple->baseX;
InputEvent click{};
click.type = EventType::Click;
click.x = clickX;
click.y = sim.windowHeight - 1.0;
click.time = sim.globalTime;
sim_apply_click(sim, click);
sim_tick(sim, CUT_DURATION_SEC + 0.01, nullptr, 0);
const Blade& cutMaple = *std::find_if(sim.blades.begin(), sim.blades.end(),
[clickX](const Blade& b) { return b.isMaple && b.baseX == Approx(clickX); });
// Cut blades now settle at their per-blade stubble floor, not flat zero.
REQUIRE(cutMaple.cutFloor > 0.0);
REQUIRE(cutMaple.cutHeight == Approx(cutMaple.cutFloor).margin(kEpsilon));
}
TEST_CASE("Autumn is critter-free", "[autumn][critter][gating]") {
Sim sim = make_autumn_sim();
REQUIRE(count_kind(sim, EntityKind::Sheep) == 0);
REQUIRE(count_kind(sim, EntityKind::Cat) == 0);
REQUIRE(count_kind(sim, EntityKind::Bunny) == 0);
REQUIRE(count_kind(sim, EntityKind::Hedgehog) == 0);
}
TEST_CASE("Autumn does not spawn snowflakes", "[autumn][weather]") {
Sim sim = make_autumn_sim();
for (int i = 0; i < 500; ++i) sim_tick(sim, 0.05, nullptr, 0);
REQUIRE(count_kind(sim, EntityKind::Snowflake) == 0);
}
TEST_CASE("Autumn scene persists round-trip", "[autumn][persistence]") {
const auto path = autumn_state_path();
persistence::SetStateFilePathForTest(path.wstring());
persistence::AppState expected;
expected.scene = Scene::Autumn;
REQUIRE(persistence::SaveAppState(expected));
persistence::AppState actual;
REQUIRE(persistence::LoadAppState(actual));
REQUIRE(actual.scene == Scene::Autumn);
}
TEST_CASE("Leaf puff constants are pinned", "[autumn][leaf][puff][constants]") {
REQUIRE(LEAF_PUFF_COUNT_MIN == 4);
REQUIRE(LEAF_PUFF_COUNT_MAX == 7);
REQUIRE(LEAF_PUFF_BURST_SPEED_MIN == Approx(18.0));
REQUIRE(LEAF_PUFF_BURST_SPEED_MAX == Approx(42.0));
REQUIRE(LEAF_PUFF_DRAG == Approx(2.2));
REQUIRE(LEAF_PUFF_COOLDOWN_SEC == Approx(1.5));
REQUIRE(LEAF_PUFF_HOVER_RADIUS_MUL == Approx(1.15));
REQUIRE(LEAF_PUFF_MIN_CUT_HEIGHT == Approx(0.5));
REQUIRE(LEAF_PUFF_START_OFFSET_FRAC == Approx(0.4));
}
TEST_CASE("Hovering a leafy maple sheds a leaf puff", "[autumn][leaf][puff]") {
Sim sim = make_autumn_sim_with_leafy_maple();
const Blade* maple = first_leafy_maple(sim);
REQUIRE(maple != nullptr);
const double cx = maple->baseX;
const double cy = sim.windowHeight - maple->mapleHeight * maple->cutHeight;
const int before = count_kind(sim, EntityKind::Leaf);
InputEvent mv{};
mv.type = EventType::Move;
mv.x = cx;
mv.y = cy;
mv.time = sim.globalTime;
sim_apply_move(sim, mv);
const int puffed = count_kind(sim, EntityKind::Leaf) - before;
REQUIRE(puffed >= LEAF_PUFF_COUNT_MIN);
REQUIRE(puffed <= LEAF_PUFF_COUNT_MAX);
const bool anyBurst = std::any_of(sim.entities.begin(), sim.entities.end(),
[](const Entity& e) { return e.kind == EntityKind::Leaf && e.vx != 0.0; });
REQUIRE(anyBurst);
}
TEST_CASE("Leaf puff respects a per-tree cooldown", "[autumn][leaf][puff]") {
Sim sim = make_autumn_sim_with_leafy_maple();
const Blade* maple = first_leafy_maple(sim);
const double cx = maple->baseX;
const double cy = sim.windowHeight - maple->mapleHeight * maple->cutHeight;
InputEvent mv{};
mv.type = EventType::Move;
mv.x = cx;
mv.y = cy;
mv.time = sim.globalTime;
sim_apply_move(sim, mv);
const int afterFirst = count_kind(sim, EntityKind::Leaf);
REQUIRE(afterFirst > 0);
sim_apply_move(sim, mv);
REQUIRE(count_kind(sim, EntityKind::Leaf) == afterFirst);
sim.globalTime += LEAF_PUFF_COOLDOWN_SEC + 0.1;
mv.time = sim.globalTime;
sim_apply_move(sim, mv);
REQUIRE(count_kind(sim, EntityKind::Leaf) > afterFirst);
}
TEST_CASE("Leaf puff ignores cursor away from canopy", "[autumn][leaf][puff]") {
Sim sim = make_autumn_sim_with_leafy_maple();
const Blade* maple = first_leafy_maple(sim);
const int before = count_kind(sim, EntityKind::Leaf);
InputEvent mv{};
mv.type = EventType::Move;
mv.x = maple->baseX + 400.0;
mv.y = sim.windowHeight - maple->mapleHeight * maple->cutHeight;
mv.time = sim.globalTime;
sim_apply_move(sim, mv);
REQUIRE(count_kind(sim, EntityKind::Leaf) == before);
}
TEST_CASE("Leaf puff does not fire outside Autumn", "[autumn][leaf][puff][gating]") {
Sim sim = make_autumn_sim_with_leafy_maple();
const Blade* maple = first_leafy_maple(sim);
const double cx = maple->baseX;
const double cy = sim.windowHeight - maple->mapleHeight * maple->cutHeight;
sim.currentScene = Scene::Grass;
const int before = count_kind(sim, EntityKind::Leaf);
InputEvent mv{};
mv.type = EventType::Move;
mv.x = cx;
mv.y = cy;
mv.time = sim.globalTime;
sim_apply_move(sim, mv);
REQUIRE(count_kind(sim, EntityKind::Leaf) == before);
}
TEST_CASE("Puff burst decays so leaves settle into flutter", "[autumn][leaf][puff]") {
Sim sim = make_autumn_sim_with_leafy_maple();
const Blade* maple = first_leafy_maple(sim);
InputEvent mv{};
mv.type = EventType::Move;
mv.x = maple->baseX;
mv.y = sim.windowHeight - maple->mapleHeight * maple->cutHeight;
mv.time = sim.globalTime;
sim_apply_move(sim, mv);
REQUIRE(count_kind(sim, EntityKind::Leaf) > 0);
for (int i = 0; i < 40; ++i) sim_tick(sim, 0.05, nullptr, 0);
for (const Entity& e : sim.entities) {
if (e.kind == EntityKind::Leaf) REQUIRE(e.vx == Approx(0.0).margin(kEpsilon));
}
}
TEST_CASE("Re-entering Autumn clears the puff cooldown", "[autumn][leaf][puff]") {
Sim sim = make_autumn_sim_with_leafy_maple();
const Blade* maple = first_leafy_maple(sim);
InputEvent mv{};
mv.type = EventType::Move;
mv.x = maple->baseX;
mv.y = sim.windowHeight - maple->mapleHeight * maple->cutHeight;
mv.time = sim.globalTime;
sim_apply_move(sim, mv);
REQUIRE(count_kind(sim, EntityKind::Leaf) > 0);
// Leaving and re-entering Autumn regenerates the (deterministic) maples and
// must reset their puff cooldown so the fresh scene can puff immediately.
sim_set_scene(sim, Scene::Grass);
sim_set_scene(sim, Scene::Autumn);
const Blade* maple2 = first_leafy_maple(sim);
REQUIRE(maple2 != nullptr);
const int before = count_kind(sim, EntityKind::Leaf);
InputEvent mv2{};
mv2.type = EventType::Move;
mv2.x = maple2->baseX;
mv2.y = sim.windowHeight - maple2->mapleHeight * maple2->cutHeight;
mv2.time = sim.globalTime;
sim_apply_move(sim, mv2);
REQUIRE(count_kind(sim, EntityKind::Leaf) > before);
}
TEST_CASE("Autumn PRNG salts are unique", "[autumn][prng]") {
constexpr std::array<uint64_t, 16> salts = {
REGROW_PRNG_SALT,
FLOWER_PRNG_SALT,
MUSHROOM_PRNG_SALT,
AMBIENT_GUST_PRNG_SALT,
CACTUS_PRNG_SALT,
TUMBLEWEED_PRNG_SALT,
CRITTER_PRNG_SALT,
BUTTERFLY_PRNG_SALT,
FIREFLY_PRNG_SALT,
BIRD_FLYBY_PRNG_SALT,
SNOWFLAKE_PRNG_SALT,
PINE_PRNG_SALT,
LEAF_PRNG_SALT,
MAPLE_PRNG_SALT,
LEAF_PUFF_PRNG_SALT,
};
for (std::size_t i = 0; i < salts.size(); ++i) {
for (std::size_t j = i + 1; j < salts.size(); ++j) {
REQUIRE(salts[i] != salts[j]);
}
}
}

View File

@@ -0,0 +1,365 @@
// bird_flyby_tests.cpp - §17.8 ambient bird flyby tests.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <algorithm>
#include <cmath>
#include <vector>
using namespace desktopgrass;
namespace {
constexpr double Monitor1920 = 1920.0;
constexpr double TwoPi = 6.28318530717958647692;
Sim build_sim(uint64_t seed = CANONICAL_TEST_SEED) {
Sim sim = sim_init(seed, Monitor1920, DEFAULT_DENSITY);
sim.currentScene = Scene::Grass;
sim.entities.clear();
return sim;
}
int count_birds(const Sim& sim) {
return static_cast<int>(std::count_if(sim.entities.begin(), sim.entities.end(),
[](const Entity& e) { return e.kind == EntityKind::Bird; }));
}
std::vector<Entity> birds(const Sim& sim) {
std::vector<Entity> out;
for (const Entity& e : sim.entities) {
if (e.kind == EntityKind::Bird) out.push_back(e);
}
return out;
}
int prng_count(Prng& side, int minCount, int maxCount) {
const double draw = prng_uniform(side, static_cast<double>(minCount), static_cast<double>(maxCount + 1));
int count = static_cast<int>(std::floor(draw));
if (count < minCount) count = minCount;
if (count > maxCount) count = maxCount;
return count;
}
void reset_bird_stream_fresh(Sim& sim, uint64_t seed) {
prng_init(sim.birdFlybyPrng, seed ^ BIRD_FLYBY_PRNG_SALT);
sim.nextBirdFlybyAtTime = sim.globalTime;
}
void reset_bird_schedule(Sim& sim, uint64_t seed) {
prng_init(sim.birdFlybyPrng, seed ^ BIRD_FLYBY_PRNG_SALT);
sim.nextBirdFlybyAtTime = sim.globalTime + bird_flyby_sample_interval(sim.birdFlybyPrng);
}
uint64_t find_seed_for_flock_size(int size) {
for (uint64_t i = 1; i < 10000; ++i) {
Sim sim = build_sim(CANONICAL_TEST_SEED + i);
reset_bird_stream_fresh(sim, CANONICAL_TEST_SEED + i);
sim_spawn_bird_flyby(sim);
if (count_birds(sim) == size) return CANONICAL_TEST_SEED + i;
}
return CANONICAL_TEST_SEED;
}
uint64_t find_v_seed(int minSize) {
for (uint64_t i = 1; i < 10000; ++i) {
Sim sim = build_sim(CANONICAL_TEST_SEED + i);
reset_bird_stream_fresh(sim, CANONICAL_TEST_SEED + i);
sim_spawn_bird_flyby(sim);
auto flock = birds(sim);
if (static_cast<int>(flock.size()) >= minSize && flock[0].colorVariant == 0) {
return CANONICAL_TEST_SEED + i;
}
}
return CANONICAL_TEST_SEED;
}
} // namespace
TEST_CASE("Bird flyby constants are pinned to spec values", "[bird][constants]") {
REQUIRE(BIRD_FLYBY_SPAWN_RATE_PER_HOUR == Approx(15.0));
REQUIRE(BIRD_FLOCK_SIZE_MIN == 3);
REQUIRE(BIRD_FLOCK_SIZE_MAX == 7);
REQUIRE(BIRD_FLOCK_FORMATION_SPACING == Approx(9.0));
REQUIRE(BIRD_FLOCK_V_ANGLE_DEG == Approx(22.0));
REQUIRE(BIRD_SPEED_MIN == Approx(65.0));
REQUIRE(BIRD_SPEED_MAX == Approx(95.0));
REQUIRE(BIRD_ALTITUDE_MIN == Approx(78.0));
REQUIRE(BIRD_ALTITUDE_MAX == Approx(96.0));
REQUIRE(BIRD_BODY_LENGTH == Approx(3.6));
REQUIRE(BIRD_WING_SPAN == Approx(5.0));
REQUIRE(BIRD_WING_FLAP_FREQ == Approx(7.0));
REQUIRE(BIRD_WING_FLAP_PHASE_JITTER == Approx(0.6));
REQUIRE(BIRD_BODY_COLOR == 0xFF1A1610u);
REQUIRE(BIRD_WING_OPEN_RATIO == Approx(1.0));
REQUIRE(BIRD_WING_FOLD_RATIO == Approx(0.30));
REQUIRE(BIRD_FADE_IN_FRAC == Approx(0.08));
REQUIRE(BIRD_FADE_OUT_FRAC == Approx(0.08));
REQUIRE(BIRD_DRIFT_AMP_Y == Approx(3.0));
REQUIRE(BIRD_DRIFT_FREQ_Y == Approx(0.8));
REQUIRE(BIRD_FLYBY_PRNG_SALT == 0xB12D1F1A1B12D1Aull);
}
TEST_CASE("Bird flyby PRNG salt is unique", "[bird][constants]") {
const uint64_t salts[] = {
REGROW_PRNG_SALT, FLOWER_PRNG_SALT, MUSHROOM_PRNG_SALT,
AMBIENT_GUST_PRNG_SALT, CACTUS_PRNG_SALT, TUMBLEWEED_PRNG_SALT,
CRITTER_PRNG_SALT, BUTTERFLY_PRNG_SALT, FIREFLY_PRNG_SALT,
SNOWFLAKE_PRNG_SALT, PINE_PRNG_SALT,
};
for (uint64_t salt : salts) {
REQUIRE(BIRD_FLYBY_PRNG_SALT != salt);
}
}
TEST_CASE("Bird flyby flock size stays in range over seeds", "[bird][spawn]") {
for (uint64_t i = 0; i < 256; ++i) {
const uint64_t seed = CANONICAL_TEST_SEED + i * 0x9E3779B97F4A7C15ull;
Sim sim = build_sim(seed);
reset_bird_stream_fresh(sim, seed);
sim_spawn_bird_flyby(sim);
REQUIRE(count_birds(sim) >= BIRD_FLOCK_SIZE_MIN);
REQUIRE(count_birds(sim) <= BIRD_FLOCK_SIZE_MAX);
}
}
TEST_CASE("Bird flyby leader altitude stays in range", "[bird][spawn]") {
for (uint64_t i = 0; i < 128; ++i) {
const uint64_t seed = CANONICAL_TEST_SEED + i;
Sim sim = build_sim(seed);
reset_bird_stream_fresh(sim, seed);
sim_spawn_bird_flyby(sim);
auto flock = birds(sim);
REQUIRE(!flock.empty());
REQUIRE(flock[0].altitudeAnchor >= BIRD_ALTITUDE_MIN);
REQUIRE(flock[0].altitudeAnchor < BIRD_ALTITUDE_MAX);
}
}
TEST_CASE("Bird flyby leader speed stays in range", "[bird][spawn]") {
for (uint64_t i = 0; i < 128; ++i) {
const uint64_t seed = CANONICAL_TEST_SEED + i;
Sim sim = build_sim(seed);
reset_bird_stream_fresh(sim, seed);
sim_spawn_bird_flyby(sim);
auto flock = birds(sim);
REQUIRE(!flock.empty());
REQUIRE(flock[0].baseSpeed >= BIRD_SPEED_MIN);
REQUIRE(flock[0].baseSpeed < BIRD_SPEED_MAX);
REQUIRE(std::abs(flock[0].vx) == Approx(flock[0].baseSpeed));
}
}
TEST_CASE("Bird flyby PRNG draw order matches side stream", "[bird][prng]") {
const uint64_t seed = 0xB17D5EED1234ull;
Sim sim = build_sim(seed);
reset_bird_stream_fresh(sim, seed);
Prng side;
prng_init(side, seed ^ BIRD_FLYBY_PRNG_SALT);
sim_spawn_bird_flyby(sim);
const int expectedCount = prng_count(side, BIRD_FLOCK_SIZE_MIN, BIRD_FLOCK_SIZE_MAX);
const uint64_t directionBit = prng_next_u64(side) & 1ull;
const double direction = directionBit != 0ull ? 1.0 : -1.0;
const double leaderAltitude = prng_uniform(side, BIRD_ALTITUDE_MIN, BIRD_ALTITUDE_MAX);
const double leaderSpeed = prng_uniform(side, BIRD_SPEED_MIN, BIRD_SPEED_MAX);
const uint64_t formationStyle = prng_next_u64(side) & 1ull;
std::vector<double> wingPhases;
std::vector<double> driftPhases;
for (int i = 0; i < expectedCount; ++i) {
wingPhases.push_back(prng_uniform(side, -BIRD_WING_FLAP_PHASE_JITTER, BIRD_WING_FLAP_PHASE_JITTER));
driftPhases.push_back(prng_uniform(side, 0.0, TwoPi));
}
auto flock = birds(sim);
REQUIRE(static_cast<int>(flock.size()) == expectedCount);
REQUIRE(sim.birdFlybyPrng.state == side.state);
const double spawnX = direction > 0.0 ? -50.0 : Monitor1920 + 50.0;
const double sinAngle = std::sin(BIRD_FLOCK_V_ANGLE_DEG * 3.14159265358979323846 / 180.0);
for (int i = 0; i < expectedCount; ++i) {
const double along = -static_cast<double>(i) * BIRD_FLOCK_FORMATION_SPACING;
double perpendicular = 0.0;
if (formationStyle == 0ull) {
const int armIndex = (i + 1) / 2;
const double sideSign = (i % 2) == 0 ? 1.0 : -1.0;
perpendicular = sideSign * static_cast<double>(armIndex) * BIRD_FLOCK_FORMATION_SPACING * sinAngle;
} else {
perpendicular = static_cast<double>(i) * BIRD_FLOCK_FORMATION_SPACING * sinAngle;
}
const Entity& e = flock[static_cast<std::size_t>(i)];
REQUIRE(e.x0 == Approx(spawnX + direction * along));
REQUIRE(e.x == Approx(e.x0));
REQUIRE(e.vx == Approx(direction * leaderSpeed));
REQUIRE(e.baseSpeed == Approx(leaderSpeed));
REQUIRE(e.altitudeAnchor == Approx(leaderAltitude - perpendicular));
REQUIRE(e.phaseX == Approx(wingPhases[static_cast<std::size_t>(i)]));
REQUIRE(e.phaseY == Approx(driftPhases[static_cast<std::size_t>(i)]));
REQUIRE(e.formationOffsetAlongFlight == Approx(along));
REQUIRE(e.formationOffsetPerpendicular == Approx(perpendicular));
REQUIRE(e.colorVariant == static_cast<uint8_t>(formationStyle));
REQUIRE(e.spawnTime == Approx(sim.globalTime));
}
}
TEST_CASE("Bird flybys are Grass scene only", "[bird][scene]") {
for (Scene scene : { Scene::Desert, Scene::Winter }) {
Sim sim = build_sim();
sim_set_scene(sim, scene);
sim.entities.clear();
reset_bird_schedule(sim, CANONICAL_TEST_SEED);
for (int i = 0; i < 8 * 3600; ++i) {
sim.globalTime += 1.0;
sim_tick_bird_flybys(sim);
}
REQUIRE(count_birds(sim) == 0);
}
}
TEST_CASE("Bird flyby Poisson spawns when schedule elapses", "[bird][time]") {
Sim sim = build_sim(0xDAD1B17Dull);
reset_bird_schedule(sim, 0xDAD1B17Dull);
int flybys = 0;
for (int i = 0; i < 10 * 3600; ++i) {
sim.globalTime += 1.0;
const int before = count_birds(sim);
sim_tick_bird_flybys(sim);
if (count_birds(sim) > before) {
++flybys;
sim.entities.clear();
}
}
const double observedPerHour = static_cast<double>(flybys) / 10.0;
REQUIRE(observedPerHour == Approx(BIRD_FLYBY_SPAWN_RATE_PER_HOUR).epsilon(0.15));
}
TEST_CASE("Bird V formation geometry is locked", "[bird][formation]") {
const uint64_t seed = find_v_seed(5);
Sim sim = build_sim(seed);
reset_bird_stream_fresh(sim, seed);
sim_spawn_bird_flyby(sim);
auto flock = birds(sim);
REQUIRE(flock.size() >= 5);
REQUIRE(flock[0].colorVariant == 0);
REQUIRE(flock[0].formationOffsetAlongFlight == Approx(0.0));
for (std::size_t i = 1; i < flock.size(); ++i) {
REQUIRE(std::fabs(flock[0].formationOffsetAlongFlight)
< std::fabs(flock[i].formationOffsetAlongFlight));
REQUIRE(flock[i - 1].formationOffsetAlongFlight - flock[i].formationOffsetAlongFlight
== Approx(BIRD_FLOCK_FORMATION_SPACING));
const double expectedSign = (i % 2 == 0) ? 1.0 : -1.0;
REQUIRE((flock[i].formationOffsetPerpendicular > 0.0 ? 1.0 : -1.0) == expectedSign);
}
}
TEST_CASE("Bird wing flap scale stays in range", "[bird][wing]") {
for (int i = 0; i < 200; ++i) {
const double t = i * 0.137;
const double phase = -BIRD_WING_FLAP_PHASE_JITTER
+ (2.0 * BIRD_WING_FLAP_PHASE_JITTER) * (static_cast<double>(i) / 199.0);
const double scale = bird_wing_scale(t, phase);
REQUIRE(scale >= BIRD_WING_FOLD_RATIO);
REQUIRE(scale <= BIRD_WING_OPEN_RATIO);
}
}
TEST_CASE("Bird wing phases decorrelate within a flock", "[bird][wing]") {
for (uint64_t i = 1; i < 10000; ++i) {
const uint64_t seed = CANONICAL_TEST_SEED + i;
Sim sim = build_sim(seed);
reset_bird_stream_fresh(sim, seed);
sim_spawn_bird_flyby(sim);
auto flock = birds(sim);
if (flock.size() != 5) continue;
std::vector<double> distinct;
for (const Entity& e : flock) {
const double scale = bird_wing_scale(1.234, e.phaseX);
bool seen = false;
for (double existing : distinct) {
if (std::fabs(existing - scale) < 1e-6) { seen = true; break; }
}
if (!seen) distinct.push_back(scale);
}
if (distinct.size() >= 3) {
REQUIRE(distinct.size() >= 3);
return;
}
}
FAIL("no decorrelated 5-bird flock found");
}
TEST_CASE("Birds despawn past opposite boundary", "[bird][despawn]") {
Sim sim = build_sim();
sim.currentScene = Scene::Desert;
sim.entities.clear();
Entity bird{};
bird.kind = EntityKind::Bird;
bird.x = Monitor1920 + 49.0;
bird.y = 10.0;
bird.vx = 20.0;
bird.altitudeAnchor = BIRD_ALTITUDE_MIN;
bird.lifetime = -1.0;
sim.entities.push_back(bird);
sim_tick_entities(sim, 0.2);
REQUIRE(count_birds(sim) == 0);
}
TEST_CASE("Birds do not interact with cuts or critters", "[bird][interaction]") {
Sim sim = build_sim();
sim.entities.clear();
Entity bird{};
bird.kind = EntityKind::Bird;
bird.x = 500.0;
bird.y = sim.windowHeight - STRIP_HEIGHT - 10.0;
bird.vx = BIRD_SPEED_MIN;
bird.baseSpeed = BIRD_SPEED_MIN;
bird.altitudeAnchor = BIRD_ALTITUDE_MIN;
bird.lifetime = -1.0;
sim.entities.push_back(bird);
Entity sheep{};
sheep.kind = EntityKind::Sheep;
sheep.x = bird.x;
sheep.y = sim.windowHeight - SHEEP_BODY_HEIGHT - SHEEP_LEG_LENGTH;
sheep.vx = SHEEP_WALK_SPEED_MIN;
sheep.state = SHEEP_STATE_WALKING;
sheep.stateTimer = 10.0;
sim.entities.push_back(sheep);
InputEvent ev{};
ev.type = EventType::Click;
ev.x = bird.x;
ev.y = bird.y;
sim_apply_click(sim, ev);
REQUIRE(sim.entities[0].kind == EntityKind::Bird);
REQUIRE(sim.entities[0].baseSpeed == Approx(BIRD_SPEED_MIN));
REQUIRE(sim.entities[1].state == SHEEP_STATE_WALKING);
for (const Blade& b : sim.blades) REQUIRE(b.cutAnimStart < 0.0);
}
TEST_CASE("Bird flyby Poisson inter-arrivals keep expected mean", "[bird][poisson]") {
const uint64_t seed = 0x510B17D00ull;
Sim sim = build_sim(seed);
reset_bird_schedule(sim, seed);
double prev = sim.globalTime;
double totalInterval = 0.0;
constexpr int Events = 100;
for (int i = 0; i < Events; ++i) {
sim.globalTime = sim.nextBirdFlybyAtTime;
totalInterval += sim.globalTime - prev;
prev = sim.globalTime;
sim_tick_bird_flybys(sim);
sim.entities.clear();
}
const double expectedMean = 3600.0 / BIRD_FLYBY_SPAWN_RATE_PER_HOUR;
REQUIRE((totalInterval / Events) == Approx(expectedMean).epsilon(0.20));
}

View File

@@ -0,0 +1,153 @@
// blade_gen_tests.cpp
//
// Snapshot + invariant tests for procedural blade generation (architecture.md §5).
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include "snapshot_data.h"
#include <cmath>
#include <vector>
using namespace desktopgrass;
using namespace desktopgrass::test;
namespace {
void requireBladeEquals(const Blade& actual, const SnapshotBlade& expected, std::size_t index) {
INFO("blade index = " << index);
REQUIRE(actual.baseX == Approx(expected.baseX ).margin(1e-12));
REQUIRE(actual.height == Approx(expected.height ).margin(1e-12));
REQUIRE(actual.thickness == Approx(expected.thickness ).margin(1e-12));
REQUIRE(actual.hue == expected.hue);
REQUIRE(actual.swayPhaseOffset == Approx(expected.sway ).margin(1e-12));
REQUIRE(actual.stiffness == Approx(expected.stiffness ).margin(1e-12));
REQUIRE(actual.isFlower == expected.isFlower);
REQUIRE(actual.flowerHeadColorIdx == expected.flowerHeadColorIdx);
REQUIRE(actual.flowerHeadRadius == Approx(expected.flowerHeadRadius).margin(1e-12));
REQUIRE(actual.heightBonus == Approx(expected.heightBonus ).margin(1e-12));
}
} // anonymous
TEST_CASE("blade generation matches the canonical snapshot", "[blade-gen][snapshot]") {
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
REQUIRE(blades.size() == CANONICAL_BLADE_COUNT);
SECTION("first 10 blades match") {
for (std::size_t i = 0; i < 10; ++i) {
requireBladeEquals(blades[i], CANONICAL_FIRST_10[i], i);
}
}
SECTION("last 10 blades match") {
const std::size_t start = blades.size() - 10;
for (std::size_t i = 0; i < 10; ++i) {
requireBladeEquals(blades[start + i], CANONICAL_LAST_10[i], start + i);
}
}
}
TEST_CASE("blade fields stay within spec ranges", "[blade-gen]") {
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
constexpr double TWO_PI = 6.283185307179586;
for (std::size_t i = 0; i < blades.size(); ++i) {
const Blade& b = blades[i];
INFO("blade index = " << i);
REQUIRE(b.baseX >= 0.0);
REQUIRE(b.baseX < 1920.0);
REQUIRE(b.height >= BLADE_HEIGHT_MIN);
REQUIRE(b.height < BLADE_HEIGHT_MAX);
REQUIRE(b.thickness >= BLADE_THICKNESS_MIN);
REQUIRE(b.thickness < BLADE_THICKNESS_MAX);
REQUIRE(b.hue < PALETTE_SIZE);
REQUIRE(b.swayPhaseOffset >= 0.0);
REQUIRE(b.swayPhaseOffset < TWO_PI);
REQUIRE(b.stiffness >= STIFFNESS_MIN);
REQUIRE(b.stiffness < STIFFNESS_MAX);
REQUIRE(b.cutHeight == Approx(1.0));
REQUIRE(b.gustVelocity == Approx(0.0));
REQUIRE(b.cutAnimStart == Approx(-1.0));
REQUIRE(b.cutInitialHeight == Approx(1.0));
if (b.isFlower) {
REQUIRE(b.flowerHeadColorIdx < FLOWER_PALETTE_SIZE);
REQUIRE(b.flowerHeadRadius >= FLOWER_HEAD_RADIUS_MIN);
REQUIRE(b.flowerHeadRadius < FLOWER_HEAD_RADIUS_MAX);
REQUIRE(b.heightBonus >= FLOWER_HEIGHT_BONUS_MIN);
REQUIRE(b.heightBonus < FLOWER_HEIGHT_BONUS_MAX);
} else {
REQUIRE(b.flowerHeadColorIdx == 0);
REQUIRE(b.flowerHeadRadius == Approx(0.0));
REQUIRE(b.heightBonus == Approx(1.0));
}
}
}
TEST_CASE("flower count is near configured probability and ordinary blades use defaults", "[blade-gen][flowers]") {
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
REQUIRE(blades.size() > 100);
std::size_t flowerCount = 0;
for (const Blade& b : blades) {
if (b.isFlower) {
++flowerCount;
} else {
REQUIRE(b.flowerHeadColorIdx == 0);
REQUIRE(b.flowerHeadRadius == Approx(0.0));
REQUIRE(b.heightBonus == Approx(1.0));
}
}
const double n = static_cast<double>(blades.size());
const double p = FLOWER_PROBABILITY;
const double mu = n * p;
const double sd = std::sqrt(n * p * (1.0 - p));
REQUIRE(flowerCount >= static_cast<std::size_t>(std::floor(mu - 3.0 * sd)));
REQUIRE(flowerCount <= static_cast<std::size_t>(std::ceil(mu + 3.0 * sd)));
}
TEST_CASE("blade baseX is strictly increasing", "[blade-gen]") {
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
REQUIRE(blades.size() > 0);
for (std::size_t i = 1; i < blades.size(); ++i) {
INFO("between " << (i-1) << " and " << i);
REQUIRE(blades[i].baseX > blades[i-1].baseX);
}
}
TEST_CASE("blade generation is deterministic across repeat runs", "[blade-gen]") {
std::vector<Blade> a, b;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, a);
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, b);
REQUIRE(a.size() == b.size());
for (std::size_t i = 0; i < a.size(); ++i) {
REQUIRE(a[i].baseX == b[i].baseX);
REQUIRE(a[i].height == b[i].height);
REQUIRE(a[i].thickness == b[i].thickness);
REQUIRE(a[i].hue == b[i].hue);
REQUIRE(a[i].swayPhaseOffset == b[i].swayPhaseOffset);
REQUIRE(a[i].stiffness == b[i].stiffness);
}
}
TEST_CASE("density scales blade count roughly linearly", "[blade-gen]") {
std::vector<Blade> low, high;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 0.5, low);
generate_blades(CANONICAL_TEST_SEED, 1920.0, 2.0, high);
REQUIRE(low.size() > 0);
REQUIRE(high.size() > low.size() * 3); // 4x density ≈ 4x blades, allow slack
}
TEST_CASE("blade count near plan default at density 1.25", "[blade-gen]") {
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.25, blades);
// Plan target: ~400 blades per 1920 px at the v1 default density of 1.25.
REQUIRE(blades.size() >= 350);
REQUIRE(blades.size() <= 450);
}

View File

@@ -0,0 +1,311 @@
// bunny_tests.cpp
//
// §18 Bunny critter tests. Mirrors Win2D BunnyTests.cs.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <algorithm>
#include <cmath>
#include <cwchar>
using namespace desktopgrass;
namespace {
constexpr double Monitor1920 = 1920.0;
int count_kind(const Sim& sim, EntityKind kind) {
return static_cast<int>(std::count_if(sim.entities.begin(), sim.entities.end(),
[kind](const Entity& e) { return e.kind == kind; }));
}
Sim build_grass_sim(uint64_t seed = CANONICAL_TEST_SEED) {
Sim sim = sim_init(seed, Monitor1920, DEFAULT_DENSITY);
sim_set_scene(sim, Scene::Grass);
sim_set_critter(sim, CritterKind::Bunny);
return sim;
}
Entity bunny_entity(double x = 500.0, double vx = BUNNY_HOP_SPEED_MIN) {
Entity e{};
e.kind = EntityKind::Bunny;
e.size = BUNNY_BODY_RADIUS;
e.x = x;
e.y = STRIP_HEIGHT + HEADROOM - BUNNY_BODY_HEIGHT - BUNNY_LEG_LENGTH;
e.vx = vx;
e.rotationSpeed = std::abs(vx);
e.lifetime = -1.0;
e.state = BUNNY_STATE_HOPPING;
e.stateTimer = BUNNY_HOP_DURATION;
return e;
}
InputEvent click_event(double x, double y) {
InputEvent ev{};
ev.type = EventType::Click;
ev.x = x;
ev.y = y;
ev.time = 0.0;
return ev;
}
int prng_count(Prng& side, int minCount, int maxCount) {
const double draw = prng_uniform(side, static_cast<double>(minCount), static_cast<double>(maxCount + 1));
int count = static_cast<int>(std::floor(draw));
if (count < minCount) count = minCount;
if (count > maxCount) count = maxCount;
return count;
}
void advance_sheep(Prng& side, int count) {
for (int i = 0; i < count; ++i) {
const double margin = SHEEP_BODY_RADIUS + 8.0;
(void)prng_uniform(side, margin, Monitor1920 - margin);
(void)prng_uniform(side, SHEEP_WALK_SPEED_MIN, SHEEP_WALK_SPEED_MAX);
(void)prng_uniform(side, 0.0, 1.0);
(void)prng_next_u32(side);
(void)prng_uniform(side, SHEEP_WALK_DURATION_MIN, SHEEP_WALK_DURATION_MAX);
(void)prng_index(side, static_cast<uint32_t>(sizeof(SHEEP_NAME_POOL) / sizeof(SHEEP_NAME_POOL[0])));
}
}
void advance_cats(Prng& side, int count) {
for (int i = 0; i < count; ++i) {
const double margin = CAT_BODY_RADIUS + 8.0;
(void)prng_uniform(side, margin, Monitor1920 - margin);
(void)prng_uniform(side, CAT_WALK_SPEED_MIN, CAT_WALK_SPEED_MAX);
(void)prng_uniform(side, 0.0, 1.0);
(void)prng_next_u32(side);
(void)prng_uniform(side, CAT_WALK_DURATION_MIN, CAT_WALK_DURATION_MAX);
(void)prng_index(side, static_cast<uint32_t>(sizeof(CAT_NAME_POOL) / sizeof(CAT_NAME_POOL[0])));
(void)prng_index(side, static_cast<uint32_t>(CAT_COAT_VARIANT_COUNT));
}
}
bool bunny_name_in_pool(const Entity& e) {
if (e.nameIndex >= sizeof(BUNNY_NAME_POOL) / sizeof(BUNNY_NAME_POOL[0])) return false;
const wchar_t* name = BUNNY_NAME_POOL[e.nameIndex];
for (const wchar_t* candidate : BUNNY_NAME_POOL) {
if (std::wcscmp(name, candidate) == 0) return true;
}
return false;
}
} // namespace
TEST_CASE("Bunny constants are pinned to spec values", "[bunny][constants]") {
REQUIRE(BUNNY_COUNT_MIN == 1);
REQUIRE(BUNNY_COUNT_MAX == 2);
REQUIRE(BUNNY_HOP_SPEED_MIN == Approx(22.0));
REQUIRE(BUNNY_HOP_SPEED_MAX == Approx(38.0));
REQUIRE(BUNNY_BODY_RADIUS == Approx(8.0));
REQUIRE(BUNNY_BODY_HEIGHT == Approx(6.5));
REQUIRE(BUNNY_HEAD_RADIUS == Approx(4.2));
REQUIRE(BUNNY_EAR_HEIGHT == Approx(9.0));
REQUIRE(BUNNY_EAR_WIDTH == Approx(2.2));
REQUIRE(BUNNY_EAR_SPACING == Approx(3.0));
REQUIRE(BUNNY_LEG_LENGTH == Approx(4.0));
REQUIRE(BUNNY_TAIL_RADIUS == Approx(2.4));
REQUIRE(BUNNY_BODY_COLOR == 0xFF8A6A4Au);
REQUIRE(BUNNY_BELLY_COLOR == 0xFFC4A98Du);
REQUIRE(BUNNY_EAR_COLOR == 0xFF8A6A4Au);
REQUIRE(BUNNY_EAR_INNER_COLOR == 0xFFD9A0A0u);
REQUIRE(BUNNY_TAIL_COLOR == 0xFFF7F4EBu);
REQUIRE(BUNNY_EYE_COLOR == 0xFF1A1208u);
REQUIRE(BUNNY_NOSE_COLOR == 0xFF8A4040u);
REQUIRE(BUNNY_STATE_HOPPING == 0);
REQUIRE(BUNNY_STATE_GRAZING == 1);
REQUIRE(BUNNY_STATE_IDLE == 2);
REQUIRE(BUNNY_STATE_SLEEPING == 3);
REQUIRE(BUNNY_STATE_STARTLED == 4);
REQUIRE(BUNNY_HOP_DURATION == Approx(0.40));
REQUIRE(BUNNY_HOP_HEIGHT == Approx(8.0));
REQUIRE(BUNNY_HOP_GAP_MIN == Approx(0.05));
REQUIRE(BUNNY_HOP_GAP_MAX == Approx(0.20));
REQUIRE(BUNNY_GRAZE_DURATION_MIN == Approx(2.5));
REQUIRE(BUNNY_GRAZE_DURATION_MAX == Approx(4.5));
REQUIRE(BUNNY_IDLE_DURATION_MIN == Approx(2.0));
REQUIRE(BUNNY_IDLE_DURATION_MAX == Approx(4.0));
REQUIRE(BUNNY_SLEEP_DURATION_MIN == Approx(6.0));
REQUIRE(BUNNY_SLEEP_DURATION_MAX == Approx(12.0));
REQUIRE(BUNNY_GRAZE_PROBABILITY == Approx(0.55));
REQUIRE(BUNNY_IDLE_PROBABILITY == Approx(0.30));
REQUIRE(BUNNY_SLEEP_PROB == Approx(0.05));
REQUIRE(BUNNY_STARTLE_RADIUS == Approx(90.0));
REQUIRE(BUNNY_STARTLE_BOOST == Approx(2.0));
REQUIRE(BUNNY_STARTLE_HOP_HEIGHT == Approx(14.0));
REQUIRE(BUNNY_STARTLE_DURATION == Approx(3.0));
REQUIRE(BUNNY_NOSE_TWITCH_FREQ == Approx(6.0));
REQUIRE(BUNNY_NOSE_TWITCH_AMP == Approx(0.5));
REQUIRE(BUNNY_EAR_WIGGLE_FREQ == Approx(1.2));
REQUIRE(BUNNY_EAR_WIGGLE_AMP == Approx(0.20));
REQUIRE(BUNNY_ZZZ_CYCLE_SEC == Approx(SHEEP_ZZZ_CYCLE_SEC));
REQUIRE(BUNNY_ZZZ_RISE == Approx(SHEEP_ZZZ_RISE * 0.7));
REQUIRE(BUNNY_ZZZ_SIZE_START == Approx(SHEEP_ZZZ_SIZE_START * 0.7));
REQUIRE(BUNNY_ZZZ_SIZE_END == Approx(SHEEP_ZZZ_SIZE_END * 0.7));
REQUIRE(sizeof(BUNNY_NAME_POOL) / sizeof(BUNNY_NAME_POOL[0]) == 12);
REQUIRE(std::wcscmp(BUNNY_NAME_POOL[0], L"Clover") == 0);
REQUIRE(std::wcscmp(BUNNY_NAME_POOL[11], L"Snowdrop") == 0);
}
TEST_CASE("Grass generation produces bunny count in range", "[bunny][gen]") {
for (uint64_t i = 0; i < 128; ++i) {
const uint64_t seed = CANONICAL_TEST_SEED + i * 0x9E3779B97F4A7C15ull;
Sim sim = build_grass_sim(seed);
const int bunnies = count_kind(sim, EntityKind::Bunny);
REQUIRE(bunnies >= BUNNY_COUNT_MIN);
REQUIRE(bunnies <= BUNNY_COUNT_MAX);
}
}
TEST_CASE("Bunnies are Grass scene only", "[bunny][scene]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, Monitor1920, DEFAULT_DENSITY);
sim_set_scene(sim, Scene::Desert);
REQUIRE(count_kind(sim, EntityKind::Bunny) == 0);
sim_set_scene(sim, Scene::Winter);
REQUIRE(count_kind(sim, EntityKind::Bunny) == 0);
sim_set_critter(sim, CritterKind::Bunny);
REQUIRE(count_kind(sim, EntityKind::Bunny) == 0);
}
TEST_CASE("Generated bunnies have speed range", "[bunny][gen]") {
Sim sim = build_grass_sim();
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Bunny) continue;
REQUIRE(std::abs(e.vx) >= BUNNY_HOP_SPEED_MIN);
REQUIRE(std::abs(e.vx) < BUNNY_HOP_SPEED_MAX);
REQUIRE(e.rotationSpeed == Approx(std::abs(e.vx)));
}
}
TEST_CASE("Generated bunnies have names in pool", "[bunny][gen]") {
Sim sim = build_grass_sim();
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Bunny) continue;
REQUIRE(bunny_name_in_pool(e));
}
}
TEST_CASE("Bunny PRNG draw order follows sheep and cats", "[bunny][prng]") {
Prng side;
prng_init(side, CANONICAL_TEST_SEED ^ CRITTER_PRNG_SALT);
Sim sim = build_grass_sim();
const int sheepCount = prng_count(side, SHEEP_COUNT_MIN, SHEEP_COUNT_MAX);
advance_sheep(side, sheepCount);
const int catCount = prng_count(side, CAT_COUNT_MIN, CAT_COUNT_MAX);
advance_cats(side, catCount);
const int bunnyCount = prng_count(side, BUNNY_COUNT_MIN, BUNNY_COUNT_MAX);
REQUIRE(count_kind(sim, EntityKind::Bunny) == bunnyCount);
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Bunny) continue;
const double margin = BUNNY_BODY_RADIUS + 8.0;
const double xFrac = prng_uniform(side, 0.0, 1.0);
const double expectedX = margin + xFrac * (Monitor1920 - 2.0 * margin);
const uint64_t vxSign = prng_next_u64(side) & 1ull;
const double expectedDir = vxSign != 0ull ? 1.0 : -1.0;
const double expectedSpeed = prng_uniform(side, BUNNY_HOP_SPEED_MIN, BUNNY_HOP_SPEED_MAX);
const uint8_t expectedName = static_cast<uint8_t>(prng_index(side,
static_cast<uint32_t>(sizeof(BUNNY_NAME_POOL) / sizeof(BUNNY_NAME_POOL[0]))));
REQUIRE(e.x == Approx(expectedX));
REQUIRE(e.vx == Approx(expectedDir * expectedSpeed));
REQUIRE(e.nameIndex == expectedName);
++seen;
}
REQUIRE(seen == bunnyCount);
}
TEST_CASE("Bunny edge bounce flips direction", "[bunny][motion]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, Monitor1920, DEFAULT_DENSITY);
sim.currentScene = Scene::Desert;
sim.entities.clear();
Entity e = bunny_entity(Monitor1920 - (BUNNY_BODY_RADIUS + 2.0) + 0.1, BUNNY_HOP_SPEED_MIN);
e.stateTimer = 10.0;
sim.entities.push_back(e);
sim_tick_entities(sim, 0.016);
REQUIRE(sim.entities.front().vx < 0.0);
}
TEST_CASE("Bunny startle radius hops away and outside click does nothing", "[bunny][click]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, Monitor1920, DEFAULT_DENSITY);
sim.entities.clear();
Entity e = bunny_entity(500.0, -BUNNY_HOP_SPEED_MIN);
e.state = BUNNY_STATE_IDLE;
e.stateTimer = 3.0;
sim.entities.push_back(e);
sim_apply_click(sim, click_event(500.0 - 20.0, e.y));
REQUIRE(sim.entities.front().state == BUNNY_STATE_STARTLED);
REQUIRE(sim.entities.front().vx > 0.0);
REQUIRE(sim.entities.front().stateTimer == Approx(BUNNY_STARTLE_DURATION));
Entity after = sim.entities.front();
const double vxBefore = after.vx;
const uint8_t stateBefore = after.state;
sim_apply_click(sim, click_event(after.x + BUNNY_STARTLE_RADIUS + 10.0, after.y));
REQUIRE(sim.entities.front().state == stateBefore);
REQUIRE(sim.entities.front().vx == Approx(vxBefore));
}
TEST_CASE("Bunny wakes from sleep on startle", "[bunny][click]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, Monitor1920, DEFAULT_DENSITY);
sim.entities.clear();
Entity e = bunny_entity(500.0, BUNNY_HOP_SPEED_MIN);
e.state = BUNNY_STATE_SLEEPING;
e.stateTimer = 10.0;
sim.entities.push_back(e);
sim_apply_click(sim, click_event(e.x + 10.0, e.y));
REQUIRE(sim.entities.front().state == BUNNY_STATE_STARTLED);
REQUIRE(sim.entities.front().state != BUNNY_STATE_SLEEPING);
REQUIRE(sim.entities.front().vx < 0.0);
}
TEST_CASE("Bunny hop arc is bounded", "[bunny][motion]") {
REQUIRE(bunny_hop_y_offset(0.0, false) == Approx(0.0));
REQUIRE(bunny_hop_y_offset(BUNNY_HOP_DURATION, false) == Approx(0.0).margin(1e-12));
const double peak = bunny_hop_y_offset(BUNNY_HOP_DURATION * 0.5, false);
REQUIRE(peak > 0.0);
REQUIRE(peak <= BUNNY_HOP_HEIGHT);
}
TEST_CASE("Bunny state transition probabilities are stable", "[bunny][state]") {
Prng p;
prng_init(p, CANONICAL_TEST_SEED ^ CRITTER_PRNG_SALT);
constexpr int N = 10000;
int graze = 0;
int idle = 0;
int sleep = 0;
for (int i = 0; i < N; ++i) {
const uint8_t state = bunny_choose_rest_state(p);
if (state == BUNNY_STATE_GRAZING) ++graze;
else if (state == BUNNY_STATE_IDLE) ++idle;
else if (state == BUNNY_STATE_SLEEPING) ++sleep;
}
const double sleepProb = BUNNY_SLEEP_PROB;
const double activeWeight = BUNNY_GRAZE_PROBABILITY + BUNNY_IDLE_PROBABILITY;
const double expectedGraze = (1.0 - sleepProb) * BUNNY_GRAZE_PROBABILITY / activeWeight;
const double expectedIdle = (1.0 - sleepProb) * BUNNY_IDLE_PROBABILITY / activeWeight;
REQUIRE(static_cast<double>(sleep) / N == Approx(sleepProb).margin(0.02));
REQUIRE(static_cast<double>(graze) / N == Approx(expectedGraze).margin(0.02));
REQUIRE(static_cast<double>(idle) / N == Approx(expectedIdle).margin(0.02));
}
TEST_CASE("Bunny sleep probability is stable", "[bunny][state]") {
constexpr int N = 20000;
Prng p;
prng_init(p, CANONICAL_TEST_SEED ^ 0x1234ull);
int sleep = 0;
for (int i = 0; i < N; ++i) {
if (bunny_choose_rest_state(p) == BUNNY_STATE_SLEEPING) ++sleep;
}
REQUIRE(static_cast<double>(sleep) / N == Approx(BUNNY_SLEEP_PROB).margin(0.02));
}

View File

@@ -0,0 +1,180 @@
// butterfly_tests.cpp - §17.6 ambient Butterfly tests.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <algorithm>
#include <cmath>
using namespace desktopgrass;
namespace {
constexpr double Monitor1920 = 1920.0;
int count_kind(const Sim& sim, EntityKind kind) {
return static_cast<int>(std::count_if(sim.entities.begin(), sim.entities.end(),
[kind](const Entity& e) { return e.kind == kind; }));
}
Sim build_grass_sim(uint64_t seed = CANONICAL_TEST_SEED) {
Sim sim = sim_init(seed, Monitor1920, DEFAULT_DENSITY);
sim_set_scene(sim, Scene::Grass);
return sim;
}
int prng_count(Prng& side, int minCount, int maxCount) {
const double draw = prng_uniform(side, static_cast<double>(minCount), static_cast<double>(maxCount + 1));
int count = static_cast<int>(std::floor(draw));
if (count < minCount) count = minCount;
if (count > maxCount) count = maxCount;
return count;
}
const Entity* first_butterfly(const Sim& sim) {
for (const Entity& e : sim.entities) if (e.kind == EntityKind::Butterfly) return &e;
return nullptr;
}
} // namespace
TEST_CASE("Butterfly constants are pinned to spec values", "[butterfly][constants]") {
REQUIRE(BUTTERFLY_COUNT_MIN == 2);
REQUIRE(BUTTERFLY_COUNT_MAX == 4);
REQUIRE(BUTTERFLY_SPEED_MIN == Approx(18.0));
REQUIRE(BUTTERFLY_SPEED_MAX == Approx(32.0));
REQUIRE(BUTTERFLY_BODY_LENGTH == Approx(2.4));
REQUIRE(BUTTERFLY_WING_RADIUS == Approx(3.5));
REQUIRE(BUTTERFLY_WING_OFFSET == Approx(2.2));
REQUIRE(BUTTERFLY_FLUTTER_FREQ == Approx(16.0));
REQUIRE(BUTTERFLY_FLUTTER_MIN_SCALE == Approx(0.20));
REQUIRE(BUTTERFLY_MEANDER_FREQ_Y == Approx(0.8));
REQUIRE(BUTTERFLY_MEANDER_AMP_Y == Approx(16.0));
REQUIRE(BUTTERFLY_MEANDER_FREQ_X == Approx(0.5));
REQUIRE(BUTTERFLY_MEANDER_AMP_X == Approx(0.4));
REQUIRE(BUTTERFLY_ALTITUDE_MIN == Approx(18.0));
REQUIRE(BUTTERFLY_ALTITUDE_MAX == Approx(70.0));
REQUIRE(BUTTERFLY_BODY_COLOR == 0xFF2A2018u);
REQUIRE(BUTTERFLY_COLOR_COUNT == 5);
REQUIRE(BUTTERFLY_PRNG_SALT == 0xB07DEF1E0001ull);
}
TEST_CASE("Grass generation produces butterfly count in range", "[butterfly][gen]") {
for (uint64_t i = 0; i < 128; ++i) {
const uint64_t seed = CANONICAL_TEST_SEED + i * 0x9E3779B97F4A7C15ull;
Sim sim = build_grass_sim(seed);
REQUIRE(count_kind(sim, EntityKind::Butterfly) >= BUTTERFLY_COUNT_MIN);
REQUIRE(count_kind(sim, EntityKind::Butterfly) <= BUTTERFLY_COUNT_MAX);
}
}
TEST_CASE("Butterflies are Grass scene only", "[butterfly][scene]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, Monitor1920, DEFAULT_DENSITY);
sim_set_scene(sim, Scene::Desert);
REQUIRE(count_kind(sim, EntityKind::Butterfly) == 0);
sim_set_scene(sim, Scene::Winter);
REQUIRE(count_kind(sim, EntityKind::Butterfly) == 0);
}
TEST_CASE("Generated butterflies have speed altitude and color ranges", "[butterfly][gen]") {
Sim sim = build_grass_sim();
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Butterfly) continue;
REQUIRE(e.baseSpeed >= BUTTERFLY_SPEED_MIN);
REQUIRE(e.baseSpeed < BUTTERFLY_SPEED_MAX);
REQUIRE(e.altitudeAnchor >= BUTTERFLY_ALTITUDE_MIN);
REQUIRE(e.altitudeAnchor < BUTTERFLY_ALTITUDE_MAX);
REQUIRE(e.colorVariant < BUTTERFLY_COLOR_COUNT);
}
}
TEST_CASE("Butterfly PRNG draw order matches side stream", "[butterfly][prng]") {
Prng side;
prng_init(side, CANONICAL_TEST_SEED ^ BUTTERFLY_PRNG_SALT);
Sim sim = build_grass_sim();
const int expectedCount = prng_count(side, BUTTERFLY_COUNT_MIN, BUTTERFLY_COUNT_MAX);
REQUIRE(count_kind(sim, EntityKind::Butterfly) == expectedCount);
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Butterfly) continue;
const double xFrac = prng_uniform(side, 0.0, 1.0);
const double yFrac = prng_uniform(side, 0.0, 1.0);
const uint64_t vxSign = prng_next_u64(side) & 1ull;
const double expectedDir = vxSign != 0ull ? 1.0 : -1.0;
const double expectedSpeed = prng_uniform(side, BUTTERFLY_SPEED_MIN, BUTTERFLY_SPEED_MAX);
const uint8_t expectedColor = static_cast<uint8_t>(prng_index(side, static_cast<uint32_t>(BUTTERFLY_COLOR_COUNT)));
const double expectedPhaseY = prng_uniform(side, 0.0, 2.0 * 3.14159265358979323846);
const double expectedPhaseX = prng_uniform(side, 0.0, 2.0 * 3.14159265358979323846);
const double expectedAltitude = BUTTERFLY_ALTITUDE_MIN + yFrac * (BUTTERFLY_ALTITUDE_MAX - BUTTERFLY_ALTITUDE_MIN);
const double expectedVx = expectedDir * expectedSpeed * (1.0 + BUTTERFLY_MEANDER_AMP_X * std::sin(expectedPhaseX));
REQUIRE(e.x == Approx(xFrac * Monitor1920));
REQUIRE(e.altitudeAnchor == Approx(expectedAltitude));
REQUIRE(e.baseSpeed == Approx(expectedSpeed));
REQUIRE(e.vx == Approx(expectedVx));
REQUIRE(e.colorVariant == expectedColor);
REQUIRE(e.phaseY == Approx(expectedPhaseY));
REQUIRE(e.phaseX == Approx(expectedPhaseX));
++seen;
}
REQUIRE(seen == expectedCount);
}
TEST_CASE("Butterfly edge wrap preserves altitude anchor", "[butterfly][motion]") {
Sim sim = build_grass_sim();
auto it = std::find_if(sim.entities.begin(), sim.entities.end(), [](const Entity& e) { return e.kind == EntityKind::Butterfly; });
REQUIRE(it != sim.entities.end());
const double margin = BUTTERFLY_WING_OFFSET + BUTTERFLY_WING_RADIUS;
it->x = Monitor1920 + margin + 1.0;
it->vx = std::abs(it->vx);
const double altitude = it->altitudeAnchor;
sim.currentScene = Scene::Desert;
sim_tick_entities(sim, 0.016);
REQUIRE(it->x == Approx(-margin));
REQUIRE(it->altitudeAnchor == Approx(altitude));
}
TEST_CASE("Butterflies do not interact with cuts or pets", "[butterfly][interaction]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, Monitor1920, DEFAULT_DENSITY);
sim.entities.clear();
Entity butterfly{};
butterfly.kind = EntityKind::Butterfly;
butterfly.x = 500.0;
butterfly.y = sim.windowHeight - STRIP_HEIGHT - 5.0;
butterfly.vx = BUTTERFLY_SPEED_MIN;
butterfly.baseSpeed = BUTTERFLY_SPEED_MIN;
butterfly.altitudeAnchor = BUTTERFLY_ALTITUDE_MIN;
butterfly.lifetime = -1.0;
sim.entities.push_back(butterfly);
Entity sheep{};
sheep.kind = EntityKind::Sheep;
sheep.x = butterfly.x;
sheep.y = sim.windowHeight - SHEEP_BODY_HEIGHT - SHEEP_LEG_LENGTH;
sheep.vx = SHEEP_WALK_SPEED_MIN;
sheep.state = SHEEP_STATE_WALKING;
sheep.stateTimer = 10.0;
sim.entities.push_back(sheep);
InputEvent ev{};
ev.type = EventType::Click;
ev.x = butterfly.x;
ev.y = butterfly.y;
sim_apply_click(sim, ev);
REQUIRE(sim.entities[0].kind == EntityKind::Butterfly);
REQUIRE(sim.entities[0].baseSpeed == Approx(BUTTERFLY_SPEED_MIN));
REQUIRE(sim.entities[1].state == SHEEP_STATE_WALKING);
for (const Blade& b : sim.blades) REQUIRE(b.cutAnimStart < 0.0);
}
TEST_CASE("Butterfly wing scale stays within flutter bounds", "[butterfly][render]") {
for (int i = 0; i < 200; ++i) {
const double t = i * 0.05;
const double scale = butterfly_wing_scale(t, 1.3);
REQUIRE(scale >= BUTTERFLY_FLUTTER_MIN_SCALE);
REQUIRE(scale <= 1.0);
}
}

View File

@@ -0,0 +1,158 @@
// cat_coat_tests.cpp
//
// §17 Cat coat palette and deterministic coat variant tests. Mirrors Win2D CatCoatTests.cs.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <cmath>
#include <cstdint>
using namespace desktopgrass;
namespace {
int count_kind(const Sim& sim, EntityKind kind) {
int n = 0;
for (const Entity& e : sim.entities) if (e.kind == kind) ++n;
return n;
}
constexpr CatCoatPalette EXPECTED_CAT_COATS[CAT_COAT_VARIANT_COUNT] = {
{ 0xFF6B6259u, 0xFF3D3733u, 0xFF6B6259u, 0xFF3D3733u, 0xFF1A1614u },
{ 0xFFD89A6Fu, 0xFFA56B40u, 0xFFD89A6Fu, 0xFFA56B40u, 0xFF2B1A0Eu },
{ 0xFF2A2522u, 0xFF140F0Cu, 0xFF2A2522u, 0xFF140F0Cu, 0xFFD9B85Bu },
{ 0xFFEDE9E1u, 0xFFBDB7ABu, 0xFFEDE9E1u, 0xFFBDB7ABu, 0xFF1F1817u },
{ 0xFF7A5F3Cu, 0xFF4E3F26u, 0xFF7A5F3Cu, 0xFF4E3F26u, 0xFF1A1108u },
{ 0xFFC9B898u, 0xFF8E7F6Bu, 0xFFC9B898u, 0xFF8E7F6Bu, 0xFF2E251Du },
};
uint8_t next_cat_coat_after_prefix(Prng& side) {
(void)prng_uniform(side, CAT_BODY_RADIUS + 8.0, 1920.0 - (CAT_BODY_RADIUS + 8.0));
(void)prng_uniform(side, CAT_WALK_SPEED_MIN, CAT_WALK_SPEED_MAX);
(void)prng_uniform(side, 0.0, 1.0);
(void)prng_next_u32(side);
(void)prng_uniform(side, CAT_WALK_DURATION_MIN, CAT_WALK_DURATION_MAX);
(void)prng_index(side, static_cast<uint32_t>(sizeof(CAT_NAME_POOL) / sizeof(CAT_NAME_POOL[0])));
return static_cast<uint8_t>(prng_index(side, static_cast<uint32_t>(CAT_COAT_VARIANT_COUNT)));
}
} // namespace
TEST_CASE("Cat coat variant count is pinned", "[cat][coat][constants]") {
REQUIRE(CAT_COAT_VARIANT_COUNT == 6);
}
TEST_CASE("Cat coat palette zero matches backward-compatible aliases", "[cat][coat][constants]") {
REQUIRE(CAT_COAT_PALETTES[0].body == CAT_BODY_COLOR);
REQUIRE(CAT_COAT_PALETTES[0].leg == CAT_LEG_COLOR);
REQUIRE(CAT_COAT_PALETTES[0].face == CAT_FACE_COLOR);
REQUIRE(CAT_COAT_PALETTES[0].ear == CAT_EAR_COLOR);
REQUIRE(CAT_COAT_PALETTES[0].ink == CAT_INK_COLOR);
}
TEST_CASE("All cat coat palettes are pinned", "[cat][coat][constants]") {
for (int i = 0; i < CAT_COAT_VARIANT_COUNT; ++i) {
CAPTURE(i);
REQUIRE(CAT_COAT_PALETTES[i].body == EXPECTED_CAT_COATS[i].body);
REQUIRE(CAT_COAT_PALETTES[i].leg == EXPECTED_CAT_COATS[i].leg);
REQUIRE(CAT_COAT_PALETTES[i].face == EXPECTED_CAT_COATS[i].face);
REQUIRE(CAT_COAT_PALETTES[i].ear == EXPECTED_CAT_COATS[i].ear);
REQUIRE(CAT_COAT_PALETTES[i].ink == EXPECTED_CAT_COATS[i].ink);
}
}
TEST_CASE("Cat coat body colors are distinct", "[cat][coat][constants]") {
for (int i = 0; i < CAT_COAT_VARIANT_COUNT; ++i) {
for (int j = i + 1; j < CAT_COAT_VARIANT_COUNT; ++j) {
CAPTURE(i);
CAPTURE(j);
REQUIRE(CAT_COAT_PALETTES[i].body != CAT_COAT_PALETTES[j].body);
}
}
}
TEST_CASE("Canonical cat flock pins deterministic coat variants", "[cat][coat][gen]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
const uint8_t expectedCoats[] = { 1 };
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Cat) continue;
REQUIRE(seen < static_cast<int>(sizeof(expectedCoats) / sizeof(expectedCoats[0])));
REQUIRE(e.coatVariantIndex == expectedCoats[seen]);
++seen;
}
REQUIRE(seen == static_cast<int>(sizeof(expectedCoats) / sizeof(expectedCoats[0])));
}
TEST_CASE("Cat coat PRNG draw follows nameIndex", "[cat][coat][prng]") {
Prng side;
prng_init(side, CANONICAL_TEST_SEED ^ CRITTER_PRNG_SALT);
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
const double countDraw = prng_uniform(side, CAT_COUNT_MIN, CAT_COUNT_MAX + 1);
int expectedCount = static_cast<int>(std::floor(countDraw));
if (expectedCount < CAT_COUNT_MIN) expectedCount = CAT_COUNT_MIN;
if (expectedCount > CAT_COUNT_MAX) expectedCount = CAT_COUNT_MAX;
REQUIRE(count_kind(sim, EntityKind::Cat) == expectedCount);
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Cat) continue;
const uint8_t expectedCoat = next_cat_coat_after_prefix(side);
REQUIRE(e.coatVariantIndex == expectedCoat);
++seen;
}
REQUIRE(seen == expectedCount);
}
TEST_CASE("Generated cat coats always stay within palette range", "[cat][coat][gen]") {
for (uint64_t i = 0; i < 128; ++i) {
const uint64_t seed = CANONICAL_TEST_SEED + i * 0x9E3779B97F4A7C15ull;
Sim sim = sim_init(seed, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Cat) continue;
REQUIRE(e.coatVariantIndex < CAT_COAT_VARIANT_COUNT);
++seen;
}
REQUIRE(seen >= CAT_COUNT_MIN);
REQUIRE(seen <= CAT_COUNT_MAX);
}
}
TEST_CASE("Sheep keep default coat variant zero", "[cat][coat][sheep]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Sheep);
REQUIRE(count_kind(sim, EntityKind::Sheep) >= SHEEP_COUNT_MIN);
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Sheep) continue;
REQUIRE(e.coatVariantIndex == 0);
}
}
TEST_CASE("Fixed cat count coat PRNG skips only the count draw", "[cat][coat][count][prng]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
sim_set_critter_count(sim, 3);
REQUIRE(count_kind(sim, EntityKind::Cat) == 3);
Prng side;
prng_init(side, CANONICAL_TEST_SEED ^ CRITTER_PRNG_SALT);
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Cat) continue;
const uint8_t expectedCoat = next_cat_coat_after_prefix(side);
REQUIRE(e.coatVariantIndex == expectedCoat);
++seen;
}
REQUIRE(seen == 3);
}

View File

@@ -0,0 +1,332 @@
// cat_tests.cpp
//
// §17 Cat critter tests. Mirrors Win2D CatTests.cs.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <algorithm>
#include <cmath>
using namespace desktopgrass;
namespace {
int count_kind(const Sim& sim, EntityKind kind) {
return static_cast<int>(std::count_if(sim.entities.begin(), sim.entities.end(),
[kind](const Entity& e) { return e.kind == kind; }));
}
Entity* first_kind(Sim& sim, EntityKind kind) {
for (Entity& e : sim.entities) if (e.kind == kind) return &e;
return nullptr;
}
const Entity* first_kind(const Sim& sim, EntityKind kind) {
for (const Entity& e : sim.entities) if (e.kind == kind) return &e;
return nullptr;
}
void keep_first_cat_only(Sim& sim) {
Entity* cat = first_kind(sim, EntityKind::Cat);
REQUIRE(cat != nullptr);
const Entity copy = *cat;
sim.entities.clear();
sim.entities.push_back(copy);
}
InputEvent click_event(double x, double y) {
InputEvent ev{};
ev.type = EventType::Click;
ev.x = x;
ev.y = y;
ev.time = 0.0;
return ev;
}
} // namespace
TEST_CASE("CritterKind::Cat and CRITTER_COUNT are pinned", "[cat][enum]") {
REQUIRE(static_cast<int>(CritterKind::None) == 0);
REQUIRE(static_cast<int>(CritterKind::Sheep) == 1);
REQUIRE(static_cast<int>(CritterKind::Cat) == 2);
REQUIRE(static_cast<int>(CritterKind::Bunny) == 3);
REQUIRE(CRITTER_COUNT == 4);
REQUIRE(CRITTER_DEFAULT == CritterKind::None);
}
TEST_CASE("EntityKind::Cat is pinned", "[cat][enum]") {
REQUIRE(static_cast<int>(EntityKind::None) == 0);
REQUIRE(static_cast<int>(EntityKind::Tumbleweed) == 1);
REQUIRE(static_cast<int>(EntityKind::Snowflake) == 2);
REQUIRE(static_cast<int>(EntityKind::Sheep) == 3);
REQUIRE(static_cast<int>(EntityKind::Cat) == 4);
}
TEST_CASE("Cat constants are pinned to spec values", "[cat][constants]") {
REQUIRE(CAT_COUNT_MIN == 1);
REQUIRE(CAT_COUNT_MAX == 2);
REQUIRE(CAT_WALK_SPEED_MIN == Approx(10.0));
REQUIRE(CAT_WALK_SPEED_MAX == Approx(22.0));
REQUIRE(CAT_POUNCE_SPEED == Approx(60.0));
REQUIRE(CAT_BODY_RADIUS == Approx(11.0));
REQUIRE(CAT_BODY_HEIGHT == Approx(7.0));
REQUIRE(CAT_HEAD_RADIUS == Approx(4.5));
REQUIRE(CAT_LEG_LENGTH == Approx(5.0));
REQUIRE(CAT_TAIL_LENGTH == Approx(13.0));
REQUIRE(CAT_TAIL_THICKNESS == Approx(1.6));
REQUIRE(CAT_EAR_HEIGHT == Approx(4.5));
REQUIRE(CAT_BODY_COLOR == 0xFF6B6259u);
REQUIRE(CAT_LEG_COLOR == 0xFF3D3733u);
REQUIRE(CAT_FACE_COLOR == 0xFF6B6259u);
REQUIRE(CAT_EAR_COLOR == 0xFF3D3733u);
REQUIRE(CAT_INK_COLOR == 0xFF1A1614u);
REQUIRE(CAT_WALK_PERIOD == Approx(0.50));
REQUIRE(CAT_LEG_CYCLE_AMP == Approx(1.6));
REQUIRE(CAT_HEAD_BOB_AMP == Approx(0.4));
REQUIRE(CAT_TAIL_SWAY_FREQ == Approx(1.2));
REQUIRE(CAT_TAIL_SWAY_AMP == Approx(0.35));
REQUIRE(CAT_STATE_WALKING == SHEEP_STATE_WALKING);
REQUIRE(CAT_STATE_IDLE == SHEEP_STATE_IDLE);
REQUIRE(CAT_STATE_SLEEPING == SHEEP_STATE_SLEEPING);
REQUIRE(CAT_STATE_POUNCING == SHEEP_STATE_HOPPING);
REQUIRE(CAT_WALK_DURATION_MIN == Approx(6.0));
REQUIRE(CAT_WALK_DURATION_MAX == Approx(10.0));
REQUIRE(CAT_IDLE_DURATION_MIN == Approx(4.0));
REQUIRE(CAT_IDLE_DURATION_MAX == Approx(8.0));
REQUIRE(CAT_SLEEP_DURATION_MIN == Approx(20.0));
REQUIRE(CAT_SLEEP_DURATION_MAX == Approx(40.0));
REQUIRE(CAT_POUNCE_DURATION == Approx(0.45));
REQUIRE(CAT_IDLE_PROBABILITY == Approx(0.65));
REQUIRE(CAT_SLEEP_PROBABILITY == Approx(0.30));
REQUIRE(CAT_SLEEP_FROM_IDLE_PROB == Approx(0.50));
REQUIRE(CAT_POUNCE_RADIUS == Approx(80.0));
REQUIRE(CAT_POUNCE_HEIGHT == Approx(9.0));
REQUIRE(CAT_CURIOUS_RADIUS == Approx(100.0));
REQUIRE(CAT_CURIOUS_HEAD_TURN_MAX == Approx(0.7));
}
TEST_CASE("sim_init defaults to None and does not generate cats until selected", "[cat][init]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
REQUIRE(sim.currentCritter == CritterKind::None);
REQUIRE(count_kind(sim, EntityKind::Cat) == 0);
sim_set_critter(sim, CritterKind::Cat);
REQUIRE(count_kind(sim, EntityKind::Cat) >= CAT_COUNT_MIN);
}
TEST_CASE("sim_set_critter(Cat) produces deterministic cats", "[cat][gen]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
REQUIRE(sim.currentCritter == CritterKind::Cat);
const int k = count_kind(sim, EntityKind::Cat);
REQUIRE(k >= CAT_COUNT_MIN);
REQUIRE(k <= CAT_COUNT_MAX);
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Cat) continue;
REQUIRE(e.state == CAT_STATE_WALKING);
REQUIRE(e.stateTimer >= CAT_WALK_DURATION_MIN);
REQUIRE(e.stateTimer < CAT_WALK_DURATION_MAX);
REQUIRE(std::fabs(e.vx) >= CAT_WALK_SPEED_MIN);
REQUIRE(std::fabs(e.vx) < CAT_WALK_SPEED_MAX);
const double margin = e.size + 8.0;
REQUIRE(e.x >= margin);
REQUIRE(e.x <= sim.monitorWidth - margin);
REQUIRE(e.y == Approx(sim.windowHeight - CAT_BODY_HEIGHT - CAT_LEG_LENGTH));
REQUIRE(e.size == Approx(CAT_BODY_RADIUS));
REQUIRE(e.lifetime < 0.0);
REQUIRE(e.nameIndex < sizeof(CAT_NAME_POOL) / sizeof(CAT_NAME_POOL[0]));
REQUIRE(e.coatVariantIndex < CAT_COAT_VARIANT_COUNT);
}
}
TEST_CASE("Cat PRNG draw order matches a side stream", "[cat][prng]") {
// count, then per-cat: x, speed, dir-coin, seed, stateTimer, nameIndex, coatVariantIndex
Prng side;
prng_init(side, CANONICAL_TEST_SEED ^ CRITTER_PRNG_SALT);
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
const double countDraw = prng_uniform(side, CAT_COUNT_MIN, CAT_COUNT_MAX + 1);
int expectedCount = static_cast<int>(std::floor(countDraw));
if (expectedCount < CAT_COUNT_MIN) expectedCount = CAT_COUNT_MIN;
if (expectedCount > CAT_COUNT_MAX) expectedCount = CAT_COUNT_MAX;
REQUIRE(count_kind(sim, EntityKind::Cat) == expectedCount);
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Cat) continue;
const double margin = CAT_BODY_RADIUS + 8.0;
const double expectedX = prng_uniform(side, margin, 1920.0 - margin);
const double expectedSpeed = prng_uniform(side, CAT_WALK_SPEED_MIN, CAT_WALK_SPEED_MAX);
const double dirCoin = prng_uniform(side, 0.0, 1.0);
const double expectedDir = (dirCoin < 0.5) ? -1.0 : 1.0;
const uint32_t expectedSeed = prng_next_u32(side);
const double expectedTimer = prng_uniform(side, CAT_WALK_DURATION_MIN, CAT_WALK_DURATION_MAX);
const uint8_t expectedNameIndex = static_cast<uint8_t>(prng_index(side,
static_cast<uint32_t>(sizeof(CAT_NAME_POOL) / sizeof(CAT_NAME_POOL[0]))));
const uint8_t expectedCoatVariantIndex = static_cast<uint8_t>(prng_index(side,
static_cast<uint32_t>(CAT_COAT_VARIANT_COUNT)));
REQUIRE(e.x == Approx(expectedX));
REQUIRE(e.vx == Approx(expectedSpeed * expectedDir));
REQUIRE(e.seed == expectedSeed);
REQUIRE(e.stateTimer == Approx(expectedTimer));
REQUIRE(e.nameIndex == expectedNameIndex);
REQUIRE(e.coatVariantIndex == expectedCoatVariantIndex);
++seen;
}
REQUIRE(seen == expectedCount);
}
TEST_CASE("sim_set_critter(None) clears ambient cats", "[cat][toggle]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
REQUIRE(count_kind(sim, EntityKind::Cat) >= CAT_COUNT_MIN);
sim_set_critter(sim, CritterKind::None);
REQUIRE(sim.currentCritter == CritterKind::None);
REQUIRE(count_kind(sim, EntityKind::Cat) == 0);
REQUIRE(count_kind(sim, EntityKind::Bunny) == 0);
}
TEST_CASE("Switching between critter species replaces the previous species", "[cat][toggle]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
REQUIRE(count_kind(sim, EntityKind::Cat) >= CAT_COUNT_MIN);
REQUIRE(count_kind(sim, EntityKind::Sheep) == 0);
sim_set_critter(sim, CritterKind::Sheep);
REQUIRE(count_kind(sim, EntityKind::Cat) == 0);
REQUIRE(count_kind(sim, EntityKind::Sheep) >= SHEEP_COUNT_MIN);
sim_set_critter(sim, CritterKind::Cat);
REQUIRE(count_kind(sim, EntityKind::Sheep) == 0);
REQUIRE(count_kind(sim, EntityKind::Cat) >= CAT_COUNT_MIN);
}
TEST_CASE("sim_set_scene gates active Cat to Grass", "[cat][scene]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
const int catsGrass = count_kind(sim, EntityKind::Cat);
REQUIRE(catsGrass >= CAT_COUNT_MIN);
sim_set_scene(sim, Scene::Desert);
REQUIRE(sim.currentCritter == CritterKind::Cat);
REQUIRE(count_kind(sim, EntityKind::Cat) == 0);
sim_set_scene(sim, Scene::Winter);
REQUIRE(sim.currentCritter == CritterKind::Cat);
REQUIRE(count_kind(sim, EntityKind::Cat) == 0);
sim_set_scene(sim, Scene::Grass);
REQUIRE(count_kind(sim, EntityKind::Cat) == catsGrass);
}
TEST_CASE("Click within CAT_POUNCE_RADIUS pounces toward the click", "[cat][click]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
keep_first_cat_only(sim);
Entity& cat = sim.entities.front();
cat.x = 500.0;
cat.vx = -CAT_WALK_SPEED_MIN;
cat.age = 5.0;
sim_apply_click(sim, click_event(cat.x + 16.0, sim.windowHeight - 20.0));
const Entity& after = sim.entities.front();
REQUIRE(after.state == CAT_STATE_POUNCING);
REQUIRE(after.stateTimer == Approx(CAT_POUNCE_DURATION));
REQUIRE(after.age == Approx(0.0));
REQUIRE(after.vx == Approx(CAT_POUNCE_SPEED));
}
TEST_CASE("Click outside CAT_POUNCE_RADIUS leaves cat alone", "[cat][click]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
keep_first_cat_only(sim);
Entity& cat = sim.entities.front();
cat.x = 500.0;
cat.vx = -CAT_WALK_SPEED_MIN;
const uint8_t stateBefore = cat.state;
const double vxBefore = cat.vx;
sim_apply_click(sim, click_event(cat.x + CAT_POUNCE_RADIUS + 5.0, sim.windowHeight - 20.0));
const Entity& after = sim.entities.front();
REQUIRE(after.state == stateBefore);
REQUIRE(after.vx == Approx(vxBefore));
}
TEST_CASE("Cats do not greet other cats", "[cat][greeting]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
keep_first_cat_only(sim);
Entity first = sim.entities.front();
first.x = 400.0;
first.vx = CAT_WALK_SPEED_MIN;
first.state = CAT_STATE_WALKING;
first.stateTimer = 10.0;
first.age = SHEEP_GREET_MIN_AGE + 1.0;
Entity second = first;
second.x = first.x + 20.0;
second.vx = -CAT_WALK_SPEED_MIN;
sim.entities.clear();
sim.entities.push_back(first);
sim.entities.push_back(second);
sim_tick_entities(sim, 0.016);
REQUIRE(count_kind(sim, EntityKind::Cat) == 2);
for (const Entity& e : sim.entities) {
if (e.kind == EntityKind::Cat) REQUIRE(e.state != SHEEP_STATE_GREETING);
}
}
TEST_CASE("Cats do not greet sheep", "[cat][greeting]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Cat);
keep_first_cat_only(sim);
Entity cat = sim.entities.front();
cat.x = 400.0;
cat.vx = CAT_WALK_SPEED_MIN;
cat.state = CAT_STATE_WALKING;
cat.stateTimer = 10.0;
cat.age = SHEEP_GREET_MIN_AGE + 1.0;
Entity sheep{};
sheep.kind = EntityKind::Sheep;
sheep.size = SHEEP_BODY_RADIUS;
sheep.x = cat.x + 20.0;
sheep.y = sim.windowHeight - SHEEP_BODY_HEIGHT - SHEEP_LEG_LENGTH;
sheep.vx = -SHEEP_WALK_SPEED_MIN;
sheep.age = SHEEP_GREET_MIN_AGE + 1.0;
sheep.lifetime = -1.0;
sheep.state = SHEEP_STATE_WALKING;
sheep.stateTimer = 10.0;
sim.entities.clear();
sim.entities.push_back(cat);
sim.entities.push_back(sheep);
sim_tick_entities(sim, 0.016);
REQUIRE(count_kind(sim, EntityKind::Cat) == 1);
REQUIRE(count_kind(sim, EntityKind::Sheep) == 1);
for (const Entity& e : sim.entities) REQUIRE(e.state != SHEEP_STATE_GREETING);
}

View File

@@ -0,0 +1,176 @@
#include "../third_party/catch2/catch.hpp"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <atomic>
#include <chrono>
#include <string>
#include <thread>
namespace {
std::atomic<bool> g_probeReceivedLeftDown{false};
enum class ClickThroughResult {
Passed,
Skipped,
Failed,
};
std::wstring unique_class_name(const wchar_t* suffix) {
return std::wstring(L"DesktopGrass.Native.ClickThrough.")
+ std::to_wstring(GetCurrentProcessId()) + L"."
+ std::to_wstring(GetTickCount64()) + L"."
+ suffix;
}
LRESULT CALLBACK ProbeWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
if (msg == WM_LBUTTONDOWN) {
g_probeReceivedLeftDown.store(true, std::memory_order_release);
}
return DefWindowProcW(hwnd, msg, wp, lp);
}
LRESULT CALLBACK OverlayWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
return DefWindowProcW(hwnd, msg, wp, lp);
}
void pump_messages_for(std::chrono::milliseconds duration) {
const auto deadline = std::chrono::steady_clock::now() + duration;
MSG msg{};
do {
while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
if (g_probeReceivedLeftDown.load(std::memory_order_acquire)) {
return;
}
std::this_thread::sleep_for(std::chrono::milliseconds(5));
} while (std::chrono::steady_clock::now() < deadline);
}
bool has_interactive_desktop() {
if (GetConsoleWindow() == nullptr) {
return false;
}
HDESK inputDesktop = OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP);
if (inputDesktop == nullptr) {
return false;
}
CloseDesktop(inputDesktop);
return true;
}
ClickThroughResult spawn_probe_window_and_click_through_overlay() {
if (!has_interactive_desktop()) {
return ClickThroughResult::Skipped;
}
g_probeReceivedLeftDown.store(false, std::memory_order_release);
const HINSTANCE instance = GetModuleHandleW(nullptr);
const std::wstring probeClass = unique_class_name(L"Probe");
const std::wstring overlayClass = unique_class_name(L"Overlay");
WNDCLASSEXW probeWc{};
probeWc.cbSize = sizeof(probeWc);
probeWc.lpfnWndProc = ProbeWndProc;
probeWc.hInstance = instance;
probeWc.lpszClassName = probeClass.c_str();
WNDCLASSEXW overlayWc{};
overlayWc.cbSize = sizeof(overlayWc);
overlayWc.lpfnWndProc = OverlayWndProc;
overlayWc.hInstance = instance;
overlayWc.lpszClassName = overlayClass.c_str();
if (!RegisterClassExW(&probeWc)) {
return ClickThroughResult::Failed;
}
if (!RegisterClassExW(&overlayWc)) {
UnregisterClassW(probeClass.c_str(), instance);
return ClickThroughResult::Failed;
}
const int x = GetSystemMetrics(SM_XVIRTUALSCREEN) + 96;
const int y = GetSystemMetrics(SM_YVIRTUALSCREEN) + 96;
constexpr int kWidth = 96;
constexpr int kHeight = 64;
const int clickX = x + 24;
const int clickY = y + 24;
HWND probe = CreateWindowExW(
WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
probeClass.c_str(), L"DesktopGrass click-through probe",
WS_POPUP | WS_VISIBLE,
x, y, kWidth, kHeight,
nullptr, nullptr, instance, nullptr);
HWND overlay = nullptr;
bool ok = probe != nullptr;
if (ok) {
SetWindowPos(probe, HWND_TOPMOST, x, y, kWidth, kHeight, SWP_SHOWWINDOW);
overlay = CreateWindowExW(
WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST |
WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE,
overlayClass.c_str(), L"DesktopGrass click-through overlay",
WS_POPUP,
x, y, kWidth, kHeight,
nullptr, nullptr, instance, nullptr);
ok = overlay != nullptr;
}
if (ok) {
SetLayeredWindowAttributes(overlay, 0, 1, LWA_ALPHA);
ShowWindow(overlay, SW_SHOWNOACTIVATE);
SetWindowPos(overlay, HWND_TOPMOST, x, y, kWidth, kHeight,
SWP_SHOWWINDOW | SWP_NOACTIVATE);
pump_messages_for(std::chrono::milliseconds(50));
if (!SetCursorPos(clickX, clickY)) {
ok = false;
}
}
ClickThroughResult result = ClickThroughResult::Failed;
if (ok) {
INPUT inputs[2]{};
inputs[0].type = INPUT_MOUSE;
inputs[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
inputs[1].type = INPUT_MOUSE;
inputs[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
const UINT sent = SendInput(2, inputs, sizeof(INPUT));
if (sent != 2) {
result = ClickThroughResult::Skipped;
} else {
pump_messages_for(std::chrono::milliseconds(200));
result = g_probeReceivedLeftDown.load(std::memory_order_acquire)
? ClickThroughResult::Passed
: ClickThroughResult::Failed;
}
}
if (overlay) DestroyWindow(overlay);
if (probe) DestroyWindow(probe);
UnregisterClassW(overlayClass.c_str(), instance);
UnregisterClassW(probeClass.c_str(), instance);
return result;
}
} // namespace
TEST_CASE("Overlay click-through allows input to reach windows beneath", "[smoke][input]") {
const ClickThroughResult result = spawn_probe_window_and_click_through_overlay();
if (result == ClickThroughResult::Skipped) {
WARN("Skipping click-through smoke test: requires an interactive desktop and SendInput.");
SUCCEED("Requires interactive session");
return;
}
REQUIRE(result == ClickThroughResult::Passed);
}

View File

@@ -0,0 +1,154 @@
#include "../third_party/catch2/catch.hpp"
#include "Config.h"
#include <filesystem>
#include <fstream>
#include <sstream>
#include <string>
using namespace desktopgrass;
namespace {
std::filesystem::path test_config_path(const char* name) {
std::filesystem::path dir = std::filesystem::current_path()
/ ".copilot-scratch"
/ "native-config-tests"
/ name;
std::error_code ec;
std::filesystem::remove_all(dir, ec);
std::filesystem::create_directories(dir);
return dir / "config.json";
}
void write_text(const std::filesystem::path& path, const std::string& text) {
std::filesystem::create_directories(path.parent_path());
std::ofstream file(path, std::ios::binary | std::ios::trunc);
file << text;
}
std::string read_text(const std::filesystem::path& path) {
std::ifstream file(path, std::ios::binary);
std::ostringstream buffer;
buffer << file.rdbuf();
return buffer.str();
}
} // namespace
TEST_CASE("Config: missing file yields defaults and writes a template", "[config]") {
const std::filesystem::path path = test_config_path("missing");
REQUIRE_FALSE(std::filesystem::exists(path));
const config::Config cfg = config::LoadConfig(path.wstring());
CHECK(cfg.targetFps == config::kTargetFpsDefault);
CHECK(cfg.bladeDensity == Approx(config::kBladeDensityDefault));
// A default file should have been created and be re-readable (it is JSONC).
REQUIRE(std::filesystem::exists(path));
const config::Config reread = config::LoadConfig(path.wstring());
CHECK(reread.targetFps == config::kTargetFpsDefault);
CHECK(reread.bladeDensity == Approx(config::kBladeDensityDefault));
}
TEST_CASE("Config: valid values are parsed", "[config]") {
const std::filesystem::path path = test_config_path("valid");
write_text(path, "{ \"version\": 1, \"targetFps\": 60, \"bladeDensity\": 1.5 }");
const config::Config cfg = config::LoadConfig(path.wstring());
CHECK(cfg.targetFps == 60);
CHECK(cfg.bladeDensity == Approx(1.5));
}
TEST_CASE("Config: out-of-range values are clamped", "[config]") {
const std::filesystem::path path = test_config_path("clamp");
write_text(path, "{ \"targetFps\": 1000, \"bladeDensity\": 99.0 }");
config::Config cfg = config::LoadConfig(path.wstring());
CHECK(cfg.targetFps == config::kTargetFpsMax);
CHECK(cfg.bladeDensity == Approx(config::kBladeDensityMax));
write_text(path, "{ \"targetFps\": 0, \"bladeDensity\": 0.0 }");
cfg = config::LoadConfig(path.wstring());
CHECK(cfg.targetFps == config::kTargetFpsMin);
CHECK(cfg.bladeDensity == Approx(config::kBladeDensityMin));
}
TEST_CASE("Config: JSONC comments and trailing commas are tolerated", "[config]") {
const std::filesystem::path path = test_config_path("jsonc");
write_text(path,
"{\n"
" // a comment\n"
" \"targetFps\": 24, /* inline */\n"
" \"bladeDensity\": 2.0,\n" // trailing comma below
"}\n");
const config::Config cfg = config::LoadConfig(path.wstring());
CHECK(cfg.targetFps == 24);
CHECK(cfg.bladeDensity == Approx(2.0));
}
TEST_CASE("Config: malformed file falls back to defaults and is preserved", "[config]") {
const std::filesystem::path path = test_config_path("malformed");
write_text(path, "{ not valid json ");
const config::Config cfg = config::LoadConfig(path.wstring());
CHECK(cfg.targetFps == config::kTargetFpsDefault);
CHECK(cfg.bladeDensity == Approx(config::kBladeDensityDefault));
// The user's (broken) file must be left untouched for them to fix.
CHECK(read_text(path) == "{ not valid json ");
}
TEST_CASE("Config: missing keys fall back to per-key defaults", "[config]") {
const std::filesystem::path path = test_config_path("partial");
write_text(path, "{ \"targetFps\": 45 }");
const config::Config cfg = config::LoadConfig(path.wstring());
CHECK(cfg.targetFps == 45);
CHECK(cfg.bladeDensity == Approx(config::kBladeDensityDefault));
CHECK(cfg.swaySpeed == Approx(config::kSwaySpeedDefault));
CHECK(cfg.swayAmplitude == Approx(config::kSwayAmplitudeDefault));
}
TEST_CASE("Config: keys are matched case-insensitively", "[config]") {
const std::filesystem::path path = test_config_path("case-insensitive");
write_text(path,
"{ \"TargetFps\": 60, \"BLADEDENSITY\": 1.5, "
"\"SwaySpeed\": 0.5, \"swayamplitude\": 2.0 }");
const config::Config cfg = config::LoadConfig(path.wstring());
CHECK(cfg.targetFps == 60);
CHECK(cfg.bladeDensity == Approx(1.5));
CHECK(cfg.swaySpeed == Approx(0.5));
CHECK(cfg.swayAmplitude == Approx(2.0));
}
TEST_CASE("Config: sway knobs parse, clamp, and reject non-finite", "[config]") {
const std::filesystem::path path = test_config_path("sway");
// Defaults when absent.
write_text(path, "{ }");
config::Config cfg = config::LoadConfig(path.wstring());
CHECK(cfg.swaySpeed == Approx(config::kSwaySpeedDefault));
CHECK(cfg.swayAmplitude == Approx(config::kSwayAmplitudeDefault));
// Valid values parsed.
write_text(path, "{ \"swaySpeed\": 0.5, \"swayAmplitude\": 2.0 }");
cfg = config::LoadConfig(path.wstring());
CHECK(cfg.swaySpeed == Approx(0.5));
CHECK(cfg.swayAmplitude == Approx(2.0));
// Out-of-range clamped to bounds.
write_text(path, "{ \"swaySpeed\": 99.0, \"swayAmplitude\": -5.0 }");
cfg = config::LoadConfig(path.wstring());
CHECK(cfg.swaySpeed == Approx(config::kSwaySpeedMax));
CHECK(cfg.swayAmplitude == Approx(config::kSwayAmplitudeMin));
// Non-finite (inf from overflow) falls back to default, never poisons the sim.
write_text(path, "{ \"swaySpeed\": 1e999, \"swayAmplitude\": 1e999 }");
cfg = config::LoadConfig(path.wstring());
CHECK(cfg.swaySpeed == Approx(config::kSwaySpeedDefault));
CHECK(cfg.swayAmplitude == Approx(config::kSwayAmplitudeDefault));
}

View File

@@ -0,0 +1,379 @@
// critter_tests.cpp
//
// Critter subsystem tests (architecture.md §13.3 / §16). Orthogonal to Scene.
//
// Coverage:
// * CritterKind discriminants are spec-locked ({None=0, Sheep=1}).
// * EntityKind::Sheep == 3 (added after the original {None, Tumbleweed,
// Snowflake} enum).
// * SHEEP_* and CRITTER_* constants are pinned to spec values.
// * sim_init defaults sim.currentCritter to None (no sheep until the user
// opts in via tray).
// * sim_set_critter(Sheep) on CANONICAL_TEST_SEED + 1920 produces
// deterministic count K ∈ [SHEEP_COUNT_MIN, SHEEP_COUNT_MAX], with
// every sheep entity well-formed: kind=Sheep, state=Walking, stateTimer
// in [WALK_DURATION_MIN, MAX], speed in [WALK_SPEED_MIN, MAX], x within
// monitor margins.
// * sim_set_critter(None) erases all sheep but preserves scene entities
// (snowflakes/tumbleweeds aren't touched).
// * sim_set_scene preserves the active critter — flipping Grass→Desert
// re-spawns sheep on the new scene.
// * Sheep PRNG draw order is bit-identical to a side-stream Prng for the
// locked sequence (count, then per-sheep: x, speed, dir-coin, seed,
// stateTimer, nameIndex).
// * Click within SHEEP_STARTLE_RADIUS pushes a sheep into Hopping, flips
// vx away from the cursor, and resets age.
// * Click outside SHEEP_STARTLE_RADIUS leaves sheep state untouched.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <algorithm>
#include <cmath>
#include <cwchar>
using namespace desktopgrass;
namespace {
int count_kind(const Sim& sim, EntityKind kind) {
int n = 0;
for (const Entity& e : sim.entities) if (e.kind == kind) ++n;
return n;
}
int count_sheep(const Sim& sim) {
return count_kind(sim, EntityKind::Sheep);
}
const Entity* first_sheep(const Sim& sim) {
for (const Entity& e : sim.entities) if (e.kind == EntityKind::Sheep) return &e;
return nullptr;
}
} // namespace
TEST_CASE("CritterKind has spec-locked discriminants", "[critter][enum]") {
REQUIRE(static_cast<int>(CritterKind::None) == 0);
REQUIRE(static_cast<int>(CritterKind::Sheep) == 1);
REQUIRE(static_cast<int>(CritterKind::Cat) == 2);
REQUIRE(static_cast<int>(CritterKind::Bunny) == 3);
REQUIRE(static_cast<int>(EntityKind::Sheep) == 3);
REQUIRE(static_cast<int>(EntityKind::Bunny) == 6);
REQUIRE(static_cast<int>(EntityKind::Butterfly) == 7);
REQUIRE(static_cast<int>(EntityKind::Firefly) == 8);
REQUIRE(CRITTER_DEFAULT == CritterKind::None);
}
TEST_CASE("Sheep constants are pinned to spec values", "[critter][constants]") {
REQUIRE(SHEEP_COUNT_MIN == 2);
REQUIRE(SHEEP_COUNT_MAX == 3);
REQUIRE(sizeof(PET_COUNT_OPTIONS) / sizeof(PET_COUNT_OPTIONS[0]) == 6);
for (int i = 0; i < 6; ++i) REQUIRE(PET_COUNT_OPTIONS[i] == i + 1);
REQUIRE(PET_COUNT_DEFAULT_SHEEP == SHEEP_COUNT_MIN);
REQUIRE(PET_COUNT_DEFAULT_CAT == CAT_COUNT_MIN);
REQUIRE(PET_COUNT_MAX_PER_MONITOR == 6);
REQUIRE(sizeof(SHEEP_NAME_POOL) / sizeof(SHEEP_NAME_POOL[0]) == 8);
REQUIRE(sizeof(CAT_NAME_POOL) / sizeof(CAT_NAME_POOL[0]) == 8);
REQUIRE(std::wcscmp(SHEEP_NAME_POOL[0], L"Bessie") == 0);
REQUIRE(std::wcscmp(SHEEP_NAME_POOL[7], L"Hazel") == 0);
REQUIRE(std::wcscmp(CAT_NAME_POOL[0], L"Mittens") == 0);
REQUIRE(std::wcscmp(CAT_NAME_POOL[7], L"Juno") == 0);
REQUIRE(PET_NAME_HOVER_RADIUS == Approx(50.0));
REQUIRE(PET_NAME_FADE_DURATION == Approx(1.5));
REQUIRE(PET_NAME_FONT_SIZE == Approx(11.0));
REQUIRE(PET_NAME_OFFSET_Y == Approx(-8.0));
REQUIRE(PET_NAME_COLOR == 0xFFFFFFFFu);
REQUIRE(PET_NAME_SHADOW_COLOR == 0xC0000000u);
REQUIRE(SHEEP_WALK_SPEED_MIN == Approx(14.0));
REQUIRE(SHEEP_WALK_SPEED_MAX == Approx(26.0));
REQUIRE(SHEEP_BODY_RADIUS == Approx(12.0));
REQUIRE(SHEEP_HEAD_RADIUS == Approx(5.0));
REQUIRE(SHEEP_LEG_LENGTH == Approx(5.5));
REQUIRE(SHEEP_STATE_WALKING == 0);
REQUIRE(SHEEP_STATE_GRAZING == 1);
REQUIRE(SHEEP_STATE_IDLE == 2);
REQUIRE(SHEEP_STATE_SLEEPING == 3);
REQUIRE(SHEEP_STATE_HOPPING == 4);
REQUIRE(SHEEP_HOP_DURATION == Approx(0.55));
REQUIRE(SHEEP_HOP_HEIGHT == Approx(11.0));
REQUIRE(SHEEP_STARTLE_RADIUS == Approx(64.0));
REQUIRE(SHEEP_STARTLE_BOOST == Approx(1.6));
REQUIRE(SHEEP_GRAZE_PROBABILITY == Approx(0.60));
REQUIRE(SHEEP_IDLE_PROBABILITY == Approx(0.25));
REQUIRE(SHEEP_SLEEP_FROM_IDLE_PROB == Approx(0.30));
}
TEST_CASE("sim_init defaults critter to None", "[critter][init]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
REQUIRE(sim.currentCritter == CritterKind::None);
REQUIRE(count_sheep(sim) == 0);
}
TEST_CASE("sim_set_critter(Sheep) produces deterministic flock", "[critter][gen]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Sheep);
REQUIRE(sim.currentCritter == CritterKind::Sheep);
const int k = count_sheep(sim);
REQUIRE(k >= SHEEP_COUNT_MIN);
REQUIRE(k <= SHEEP_COUNT_MAX);
const double groundY = sim.windowHeight;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Sheep) continue;
REQUIRE(e.state == SHEEP_STATE_WALKING);
REQUIRE(e.stateTimer >= SHEEP_WALK_DURATION_MIN);
REQUIRE(e.stateTimer < SHEEP_WALK_DURATION_MAX);
REQUIRE(std::fabs(e.vx) >= SHEEP_WALK_SPEED_MIN);
REQUIRE(std::fabs(e.vx) < SHEEP_WALK_SPEED_MAX);
const double margin = e.size + 8.0;
REQUIRE(e.x >= margin);
REQUIRE(e.x <= sim.monitorWidth - margin);
REQUIRE(e.y == Approx(groundY - SHEEP_BODY_HEIGHT - SHEEP_LEG_LENGTH));
REQUIRE(e.lifetime < 0.0); // infinite — sheep don't expire
REQUIRE(e.nameIndex < sizeof(SHEEP_NAME_POOL) / sizeof(SHEEP_NAME_POOL[0]));
}
}
TEST_CASE("Sheep PRNG draw order matches a side stream", "[critter][prng]") {
// Independent side stream that walks the documented sequence:
// count
// per-sheep: x, speed, dir-coin, seed, stateTimer, nameIndex
Prng side;
prng_init(side, CANONICAL_TEST_SEED ^ CRITTER_PRNG_SALT);
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Sheep);
const double countDraw = prng_uniform(side, SHEEP_COUNT_MIN, SHEEP_COUNT_MAX + 1);
int expectedCount = static_cast<int>(std::floor(countDraw));
if (expectedCount < SHEEP_COUNT_MIN) expectedCount = SHEEP_COUNT_MIN;
if (expectedCount > SHEEP_COUNT_MAX) expectedCount = SHEEP_COUNT_MAX;
REQUIRE(count_sheep(sim) == expectedCount);
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Sheep) continue;
const double margin = SHEEP_BODY_RADIUS + 8.0;
const double expectedX = prng_uniform(side, margin, 1920.0 - margin);
const double expectedSpeed = prng_uniform(side, SHEEP_WALK_SPEED_MIN, SHEEP_WALK_SPEED_MAX);
const double dirCoin = prng_uniform(side, 0.0, 1.0);
const double expectedDir = (dirCoin < 0.5) ? -1.0 : 1.0;
const uint32_t expectedSeed = prng_next_u32(side);
const double expectedTimer = prng_uniform(side, SHEEP_WALK_DURATION_MIN, SHEEP_WALK_DURATION_MAX);
const uint8_t expectedNameIndex = static_cast<uint8_t>(prng_index(side,
static_cast<uint32_t>(sizeof(SHEEP_NAME_POOL) / sizeof(SHEEP_NAME_POOL[0]))));
REQUIRE(e.x == Approx(expectedX));
REQUIRE(e.vx == Approx(expectedSpeed * expectedDir));
REQUIRE(e.seed == expectedSeed);
REQUIRE(e.stateTimer == Approx(expectedTimer));
REQUIRE(e.nameIndex == expectedNameIndex);
++seen;
}
REQUIRE(seen == expectedCount);
}
TEST_CASE("canonical critter name indices are stable and species-local", "[critter][names]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Sheep);
const uint8_t expectedSheepNames[] = { 4, 7 };
int sheepSeen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Sheep) continue;
REQUIRE(sheepSeen < static_cast<int>(sizeof(expectedSheepNames) / sizeof(expectedSheepNames[0])));
REQUIRE(e.nameIndex == expectedSheepNames[sheepSeen]);
REQUIRE(std::wcscmp(SHEEP_NAME_POOL[e.nameIndex], sheepSeen == 0 ? L"Pippin" : L"Hazel") == 0);
++sheepSeen;
}
REQUIRE(sheepSeen == 2);
sim_set_critter(sim, CritterKind::Cat);
const uint8_t expectedCatNames[] = { 4 };
int catSeen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Cat) continue;
REQUIRE(catSeen < static_cast<int>(sizeof(expectedCatNames) / sizeof(expectedCatNames[0])));
REQUIRE(e.nameIndex == expectedCatNames[catSeen]);
REQUIRE(e.nameIndex < sizeof(CAT_NAME_POOL) / sizeof(CAT_NAME_POOL[0]));
REQUIRE(std::wcscmp(CAT_NAME_POOL[e.nameIndex], L"Smokey") == 0);
++catSeen;
}
REQUIRE(catSeen == 1);
}
TEST_CASE("sim_set_critter_count(0) preserves random sheep count draw", "[critter][count]") {
bool sawMin = false;
bool sawMax = false;
for (uint64_t i = 0; i < 64; ++i) {
const uint64_t seed = CANONICAL_TEST_SEED + i * 0x9E3779B97F4A7C15ull;
Sim sim = sim_init(seed, 1920.0, DEFAULT_DENSITY);
sim_set_critter_count(sim, 3);
sim_set_critter_count(sim, 0);
sim_set_critter(sim, CritterKind::Sheep);
Prng side;
prng_init(side, seed ^ CRITTER_PRNG_SALT);
const double countDraw = prng_uniform(side, SHEEP_COUNT_MIN, SHEEP_COUNT_MAX + 1);
int expectedCount = static_cast<int>(std::floor(countDraw));
if (expectedCount < SHEEP_COUNT_MIN) expectedCount = SHEEP_COUNT_MIN;
if (expectedCount > SHEEP_COUNT_MAX) expectedCount = SHEEP_COUNT_MAX;
REQUIRE(count_sheep(sim) == expectedCount);
sawMin = sawMin || expectedCount == SHEEP_COUNT_MIN;
sawMax = sawMax || expectedCount == SHEEP_COUNT_MAX;
}
REQUIRE(sawMin);
REQUIRE(sawMax);
}
TEST_CASE("fixed sheep count override skips the count PRNG draw", "[critter][count][prng]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Sheep);
sim_set_critter_count(sim, 3);
REQUIRE(sim.critterCountOverride == 3);
REQUIRE(count_sheep(sim) == 3);
Prng side;
prng_init(side, CANONICAL_TEST_SEED ^ CRITTER_PRNG_SALT);
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Sheep) continue;
const double margin = SHEEP_BODY_RADIUS + 8.0;
const double expectedX = prng_uniform(side, margin, 1920.0 - margin);
const double expectedSpeed = prng_uniform(side, SHEEP_WALK_SPEED_MIN, SHEEP_WALK_SPEED_MAX);
const double dirCoin = prng_uniform(side, 0.0, 1.0);
const double expectedDir = (dirCoin < 0.5) ? -1.0 : 1.0;
const uint32_t expectedSeed = prng_next_u32(side);
const double expectedTimer = prng_uniform(side, SHEEP_WALK_DURATION_MIN, SHEEP_WALK_DURATION_MAX);
const uint8_t expectedNameIndex = static_cast<uint8_t>(prng_index(side,
static_cast<uint32_t>(sizeof(SHEEP_NAME_POOL) / sizeof(SHEEP_NAME_POOL[0]))));
REQUIRE(e.x == Approx(expectedX));
REQUIRE(e.vx == Approx(expectedSpeed * expectedDir));
REQUIRE(e.seed == expectedSeed);
REQUIRE(e.stateTimer == Approx(expectedTimer));
REQUIRE(e.nameIndex == expectedNameIndex);
++seen;
}
REQUIRE(seen == 3);
}
TEST_CASE("fixed critter count override supports tray range and clamps", "[critter][count]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Sheep);
sim_set_critter_count(sim, 6);
REQUIRE(count_sheep(sim) == 6);
sim_set_critter_count(sim, 8);
REQUIRE(count_sheep(sim) == PET_COUNT_MAX_PER_MONITOR);
sim_set_critter(sim, CritterKind::Cat);
sim_set_critter_count(sim, 2);
REQUIRE(count_kind(sim, EntityKind::Cat) == 2);
REQUIRE(count_sheep(sim) == 0);
}
TEST_CASE("sim_set_critter(None) clears all ground critters",
"[critter][toggle]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Sheep);
REQUIRE(count_sheep(sim) >= SHEEP_COUNT_MIN);
REQUIRE(count_kind(sim, EntityKind::Cat) == 0);
sim_set_critter(sim, CritterKind::None);
REQUIRE(count_sheep(sim) == 0);
REQUIRE(count_kind(sim, EntityKind::Cat) == 0);
REQUIRE(count_kind(sim, EntityKind::Bunny) == 0);
REQUIRE(count_kind(sim, EntityKind::Hedgehog) == 0);
}
TEST_CASE("sim_set_scene gates active sheep to Grass", "[critter][scene]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Sheep);
const int sheepCountGrass = count_sheep(sim);
REQUIRE(sheepCountGrass >= SHEEP_COUNT_MIN);
sim_set_scene(sim, Scene::Desert);
REQUIRE(count_sheep(sim) == 0);
REQUIRE(sim.currentCritter == CritterKind::Sheep);
sim_set_scene(sim, Scene::Winter);
REQUIRE(count_sheep(sim) == 0);
REQUIRE(sim.currentCritter == CritterKind::Sheep);
sim_set_scene(sim, Scene::Grass);
REQUIRE(count_sheep(sim) == sheepCountGrass);
}
TEST_CASE("Click within SHEEP_STARTLE_RADIUS triggers hop away", "[critter][click]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Sheep);
Entity* target = nullptr;
for (Entity& e : sim.entities) {
if (e.kind == EntityKind::Sheep) { target = &e; break; }
}
REQUIRE(target != nullptr);
// Click 16 DIP to the left of the sheep — well within startle radius,
// inside the cut band (so the early y-gate doesn't reject).
const double clickX = target->x - 16.0;
const double clickY = sim.windowHeight - 20.0;
target->age = 5.0; // pre-set age to verify reset
InputEvent ev{};
ev.type = EventType::Click;
ev.x = clickX;
ev.y = clickY;
ev.time = 0.0;
sim_apply_click(sim, ev);
Entity* after = nullptr;
for (Entity& e : sim.entities) {
if (e.kind == EntityKind::Sheep) { after = &e; break; }
}
REQUIRE(after != nullptr);
REQUIRE(after->state == SHEEP_STATE_HOPPING);
REQUIRE(after->stateTimer == Approx(SHEEP_HOP_DURATION));
REQUIRE(after->age == Approx(0.0));
REQUIRE(after->vx > 0.0); // sheep was right of click → vx flipped to +
REQUIRE(std::fabs(after->vx) <= SHEEP_WALK_SPEED_MAX * SHEEP_STARTLE_BOOST);
}
TEST_CASE("Click outside SHEEP_STARTLE_RADIUS leaves sheep alone", "[critter][click]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
sim_set_critter(sim, CritterKind::Sheep);
Entity* target = nullptr;
for (Entity& e : sim.entities) {
if (e.kind == EntityKind::Sheep) { target = &e; break; }
}
REQUIRE(target != nullptr);
const uint8_t stateBefore = target->state;
const double vxBefore = target->vx;
// Click far away (300 DIP) but still in the cut band.
const double clickX = target->x + SHEEP_STARTLE_RADIUS + 200.0;
const double clickY = sim.windowHeight - 20.0;
InputEvent ev{};
ev.type = EventType::Click;
ev.x = clickX;
ev.y = clickY;
ev.time = 0.0;
sim_apply_click(sim, ev);
Entity* after = nullptr;
for (Entity& e : sim.entities) {
if (e.kind == EntityKind::Sheep) { after = &e; break; }
}
REQUIRE(after != nullptr);
REQUIRE(after->state == stateBefore);
REQUIRE(after->vx == Approx(vxBefore));
}

View File

@@ -0,0 +1,259 @@
// cut_tests.cpp
//
// Cut state animation tests (architecture.md §9).
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include "snapshot_data.h"
#include <cmath>
#include <vector>
using namespace desktopgrass;
using namespace desktopgrass::test;
namespace {
Sim make_sim_with_blades(std::initializer_list<double> baseXs) {
Sim sim;
sim.windowHeight = STRIP_HEIGHT + HEADROOM;
for (double x : baseXs) {
Blade b{};
b.baseX = x;
b.height = 20.0;
b.thickness = 1.5;
b.swayPhaseOffset = 0.0;
b.stiffness = 1.0;
b.cutHeight = 1.0;
b.cutInitialHeight = 1.0;
b.cutAnimStart = -1.0;
sim.blades.push_back(b);
}
return sim;
}
InputEvent click(double x, double y, double t) {
return InputEvent{ EventType::Click, x, y, t };
}
} // anonymous
TEST_CASE("click inside cut band animates blades within radius to 0", "[cut]") {
Sim sim = make_sim_with_blades({100.0, 110.0, 200.0});
const double y_in_band = sim.windowHeight - 40.0; // inside strip
InputEvent ev = click(100.0, y_in_band, 0.0);
sim_tick(sim, 0.0, &ev, 1);
// Apply 5 ticks of 50 ms (total = 250 ms > CUT_DURATION_SEC).
for (int i = 0; i < 5; ++i) {
sim_tick(sim, 0.05, nullptr, 0);
}
REQUIRE(sim.blades[0].cutHeight == Approx(0.0));
REQUIRE(sim.blades[0].cutAnimStart == Approx(-1.0));
REQUIRE(sim.blades[1].cutHeight == Approx(0.0));
// Blade at 200 is outside CUT_RADIUS = 30.
REQUIRE(sim.blades[2].cutHeight == Approx(1.0));
REQUIRE(sim.blades[2].cutAnimStart == Approx(-1.0));
}
TEST_CASE("cut animation is linear over CUT_DURATION_SEC", "[cut]") {
Sim sim = make_sim_with_blades({100.0});
const double y = sim.windowHeight - 40.0;
InputEvent ev = click(100.0, y, 0.0);
sim_tick(sim, 0.0, &ev, 1);
// After tick(0.0) globalTime = 0 still; cutAnimStart = 0.
// 50 ms in → cutHeight ≈ 0.75.
sim_tick(sim, 0.05, nullptr, 0);
REQUIRE(sim.blades[0].cutHeight == Approx(0.75).margin(1e-9));
// 100 ms in → 0.5.
sim_tick(sim, 0.05, nullptr, 0);
REQUIRE(sim.blades[0].cutHeight == Approx(0.5).margin(1e-9));
// 150 ms in → 0.25.
sim_tick(sim, 0.05, nullptr, 0);
REQUIRE(sim.blades[0].cutHeight == Approx(0.25).margin(1e-9));
// 200 ms in → 0.0 and idle.
sim_tick(sim, 0.05, nullptr, 0);
REQUIRE(sim.blades[0].cutHeight == Approx(0.0).margin(1e-9));
REQUIRE(sim.blades[0].cutAnimStart < 0.0);
}
TEST_CASE("click outside cut band is ignored", "[cut]") {
Sim sim = make_sim_with_blades({100.0});
const double y_above = sim.windowHeight - STRIP_HEIGHT - 5.0;
InputEvent ev = click(100.0, y_above, 0.0);
sim_tick(sim, 0.0, &ev, 1);
REQUIRE(sim.blades[0].cutHeight == Approx(1.0));
REQUIRE(sim.blades[0].cutAnimStart < 0.0);
}
TEST_CASE("repeat click on in-flight blade is idempotent", "[cut]") {
Sim sim = make_sim_with_blades({100.0});
const double y = sim.windowHeight - 40.0;
InputEvent first = click(100.0, y, 0.0);
sim_tick(sim, 0.0, &first, 1);
// Mid-animation second click → should not reset cutAnimStart.
sim_tick(sim, 0.05, nullptr, 0); // 0.05 elapsed; cutHeight = 0.75
const double startSnapshot = sim.blades[0].cutAnimStart;
const double heightSnapshot = sim.blades[0].cutHeight;
InputEvent second = click(100.0, y, 0.05);
sim_tick(sim, 0.0, &second, 1);
REQUIRE(sim.blades[0].cutAnimStart == Approx(startSnapshot));
REQUIRE(sim.blades[0].cutInitialHeight == Approx(1.0));
REQUIRE(sim.blades[0].cutHeight == Approx(heightSnapshot));
}
TEST_CASE("click on already-cut blade is a no-op", "[cut]") {
Sim sim = make_sim_with_blades({100.0});
sim.blades[0].cutHeight = 0.0;
sim.blades[0].cutInitialHeight = 0.0;
sim.blades[0].cutAnimStart = -1.0;
const double y = sim.windowHeight - 40.0;
InputEvent ev = click(100.0, y, 0.0);
sim_tick(sim, 0.0, &ev, 1);
REQUIRE(sim.blades[0].cutHeight == Approx(0.0));
REQUIRE(sim.blades[0].cutAnimStart < 0.0);
}
TEST_CASE("blades outside cut radius are untouched", "[cut]") {
Sim sim = make_sim_with_blades({100.0, 131.0, 200.0});
const double y = sim.windowHeight - 40.0;
InputEvent ev = click(100.0, y, 0.0);
sim_tick(sim, 0.0, &ev, 1);
REQUIRE(sim.blades[0].cutAnimStart >= 0.0);
REQUIRE(sim.blades[1].cutAnimStart < 0.0);
REQUIRE(sim.blades[2].cutAnimStart < 0.0);
}
TEST_CASE("compute_blade_stroke degenerates to a stump under threshold", "[cut][geometry]") {
Blade b{};
b.baseX = 100.0;
b.height = 20.0;
b.thickness = 1.5;
b.hue = 2;
b.cutHeight = 0.04; // below CUT_STUMP_THRESHOLD = 0.05
b.effectiveLean = 5.0;
b.cutInitialHeight = 1.0;
b.cutAnimStart = 0.0;
Stroke s = compute_blade_stroke(b, 110.0, Scene::Grass);
REQUIRE(s.tip.x == Approx(100.0));
REQUIRE(s.tip.y == Approx(110.0 - STUMP_HEIGHT));
REQUIRE(s.argb == PALETTE[2]);
}
TEST_CASE("compute_blade_stroke produces vertical line when lean is zero", "[cut][geometry]") {
Blade b{};
b.baseX = 100.0;
b.height = 20.0;
b.thickness = 1.5;
b.hue = 1;
b.cutHeight = 1.0;
b.effectiveLean = 0.0;
Stroke s = compute_blade_stroke(b, 110.0, Scene::Grass);
REQUIRE(s.base.x == Approx(100.0));
REQUIRE(s.base.y == Approx(110.0));
REQUIRE(s.tip.x == Approx(100.0));
REQUIRE(s.tip.y == Approx(90.0));
REQUIRE(s.control.x == Approx(100.0));
}
// ---------------------------------------------------------------------------
// Cut-floor (stubble) variation
// ---------------------------------------------------------------------------
TEST_CASE("generated blades get a per-blade cut floor within spec range", "[cut][floor]") {
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
REQUIRE(blades.size() > 50);
for (const Blade& b : blades) {
REQUIRE(b.cutFloor >= CUT_FLOOR_MIN);
REQUIRE(b.cutFloor < CUT_FLOOR_MAX);
// Stubble must render as a short blade, never a degenerate stump.
REQUIRE(b.cutFloor >= CUT_STUMP_THRESHOLD);
}
// The whole point is variation: not every blade settles at the same height.
bool varies = false;
for (std::size_t i = 1; i < blades.size(); ++i) {
if (blades[i].cutFloor != blades[0].cutFloor) { varies = true; break; }
}
REQUIRE(varies);
}
TEST_CASE("cut settles at the per-blade stubble floor, not flat zero", "[cut][floor]") {
Blade b{};
b.height = 20.0;
b.thickness = 1.5;
b.cutHeight = 1.0;
b.cutInitialHeight = 1.0;
b.cutFloor = 0.12;
b.cutAnimStart = 0.0;
// Advance past the full cut duration.
advance_cut(b, CUT_DURATION_SEC + 0.01);
REQUIRE(b.cutHeight == Approx(0.12));
REQUIRE(b.cutAnimStart == Approx(-1.0));
}
TEST_CASE("cut-down animation lerps toward the floor", "[cut][floor]") {
Blade b{};
b.height = 20.0;
b.cutHeight = 1.0;
b.cutInitialHeight = 1.0;
b.cutFloor = 0.10;
b.cutAnimStart = 0.0;
// Half-way through the cut: lerp(1.0 -> 0.10) at t=0.5 = 0.10 + 0.90*0.5.
advance_cut(b, CUT_DURATION_SEC * 0.5);
REQUIRE(b.cutHeight == Approx(0.10 + 0.90 * 0.5).margin(1e-9));
}
TEST_CASE("regrowth grows back from the floor to full height", "[cut][floor][regrowth]") {
Blade b{};
b.height = 20.0;
b.cutFloor = 0.10;
b.cutHeight = 0.10;
b.cutAnimStart = -1.0;
b.regrowDuration = 0.4;
b.regrowStart = 0.0;
// Half-way through regrowth: lerp(0.10 -> 1.0) at t=0.5.
advance_cut(b, 0.2);
REQUIRE(b.cutHeight == Approx(0.10 + 0.90 * 0.5).margin(1e-9));
// Fully regrown.
advance_cut(b, 0.4);
REQUIRE(b.cutHeight == Approx(1.0).margin(1e-9));
}
TEST_CASE("zero-floor blades still collapse fully (back-compat)", "[cut][floor]") {
Blade b{};
b.height = 20.0;
b.cutHeight = 1.0;
b.cutInitialHeight = 1.0;
b.cutFloor = 0.0;
b.cutAnimStart = 0.0;
advance_cut(b, CUT_DURATION_SEC + 0.01);
REQUIRE(b.cutHeight == Approx(0.0));
}

View File

@@ -0,0 +1,220 @@
// desert_tests.cpp - §14 Desert scene cacti + tumbleweeds.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include "snapshot_data.h"
#include <cmath>
#include <cstddef>
#include <vector>
using namespace desktopgrass;
namespace {
constexpr double kMonitor1920 = 1920.0;
struct ExpectedCactus {
std::size_t slotIndex = 0;
uint8_t type = 0;
double height = 0.0;
double width = 0.0;
int8_t armSide = +1;
};
ExpectedCactus first_expected_cactus(std::size_t bladeCount) {
Prng p;
prng_init(p, CANONICAL_TEST_SEED ^ CACTUS_PRNG_SALT);
for (std::size_t i = 0; i < bladeCount; ++i) {
const double r = prng_uniform(p, 0.0, 1.0);
if (r >= CACTUS_PROBABILITY) continue;
ExpectedCactus expected{};
expected.slotIndex = i;
expected.height = prng_uniform(p, CACTUS_HEIGHT_MIN, CACTUS_HEIGHT_MAX);
expected.width = prng_uniform(p, CACTUS_WIDTH_MIN, CACTUS_WIDTH_MAX);
const double armDraw = prng_uniform(p, 0.0, 1.0);
const double noArmThreshold = 1.0 - CACTUS_ARM_PROBABILITY;
const double twoArmThreshold = noArmThreshold + CACTUS_TWO_ARM_PROBABILITY * CACTUS_ARM_PROBABILITY;
if (armDraw < noArmThreshold) {
expected.type = 0;
} else if (armDraw < twoArmThreshold) {
expected.type = 2;
} else {
expected.type = 1;
expected.armSide = prng_uniform(p, 0.0, 1.0) < 0.5
? static_cast<int8_t>(-1)
: static_cast<int8_t>(+1);
}
if (expected.height < CACTUS_ARM_MIN_HEIGHT) {
expected.type = 0;
expected.armSide = +1;
}
return expected;
}
FAIL("canonical seed produced no cactus slot");
return {};
}
int expected_tumbleweed_count(double monitorWidth) {
if (monitorWidth < 480.0) return 0;
int count = static_cast<int>(std::floor(monitorWidth / 1920.0 * static_cast<double>(TUMBLEWEED_COUNT_PER_1920DIP)));
return count < 1 ? 1 : count;
}
} // anonymous
TEST_CASE("Desert constants are pinned", "[desert][constants]") {
REQUIRE(CACTUS_PROBABILITY == Approx(0.005));
REQUIRE(CACTUS_HEIGHT_MIN == Approx(30.0));
REQUIRE(CACTUS_HEIGHT_MAX == Approx(70.0));
REQUIRE(CACTUS_COLOR == 0xFF2D7A2Du);
REQUIRE(TUMBLEWEED_COUNT_PER_1920DIP == 4);
REQUIRE(TUMBLEWEED_SPEED_MAX == Approx(72.0));
REQUIRE(TUMBLEWEED_PRNG_SALT == 0x7B0117CA7B0117CAull);
}
TEST_CASE("sim_set_scene Desert clears entities and generates cacti", "[desert][scene]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, kMonitor1920, DEFAULT_DENSITY);
Entity fake{};
fake.kind = EntityKind::Snowflake;
sim.entities.push_back(fake);
sim_set_scene(sim, Scene::Desert);
REQUIRE(sim.currentScene == Scene::Desert);
REQUIRE(sim.entities.size() == static_cast<std::size_t>(expected_tumbleweed_count(kMonitor1920)));
for (const Entity& e : sim.entities) REQUIRE(e.kind == EntityKind::Tumbleweed);
std::size_t cactusCount = 0;
for (const Blade& b : sim.blades) if (b.isCactus) ++cactusCount;
REQUIRE(cactusCount >= 1);
REQUIRE(cactusCount <= 10);
}
TEST_CASE("First cactus matches the spec-derived PRNG snapshot", "[desert][cactus]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, kMonitor1920, DEFAULT_DENSITY);
const ExpectedCactus expected = first_expected_cactus(sim.blades.size());
sim_set_scene(sim, Scene::Desert);
REQUIRE(expected.slotIndex < sim.blades.size());
const Blade& b = sim.blades[expected.slotIndex];
REQUIRE(b.isCactus);
REQUIRE(b.cactusType == expected.type);
REQUIRE(b.cactusHeight == Approx(expected.height).margin(1e-12));
REQUIRE(b.cactusWidth == Approx(expected.width).margin(1e-12));
if (expected.type == 1) REQUIRE(b.cactusArmSide == expected.armSide);
}
TEST_CASE("Grass scene restores original flower and mushroom slot variants", "[desert][restore]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, kMonitor1920, DEFAULT_DENSITY);
const ExpectedCactus expected = first_expected_cactus(sim.blades.size());
REQUIRE(expected.slotIndex < sim.blades.size());
Blade& target = sim.blades[expected.slotIndex];
target.isFlower = true;
target.isMushroom = true;
target.originalIsFlower = true;
target.originalIsMushroom = true;
sim_set_scene(sim, Scene::Desert);
REQUIRE(sim.blades[expected.slotIndex].isCactus);
REQUIRE_FALSE(sim.blades[expected.slotIndex].isFlower);
REQUIRE_FALSE(sim.blades[expected.slotIndex].isMushroom);
sim_set_scene(sim, Scene::Grass);
REQUIRE_FALSE(sim.blades[expected.slotIndex].isCactus);
REQUIRE(sim.blades[expected.slotIndex].isFlower);
REQUIRE(sim.blades[expected.slotIndex].isMushroom);
}
TEST_CASE("Desert generates the expected tumbleweed count", "[desert][tumbleweed]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, kMonitor1920, DEFAULT_DENSITY);
sim_set_scene(sim, Scene::Desert);
const int expected = expected_tumbleweed_count(kMonitor1920);
REQUIRE(expected >= 1);
REQUIRE(sim.entities.size() == static_cast<std::size_t>(expected));
}
TEST_CASE("First tumbleweed matches the spec-derived PRNG snapshot", "[desert][tumbleweed]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, kMonitor1920, DEFAULT_DENSITY);
sim_set_scene(sim, Scene::Desert);
REQUIRE_FALSE(sim.entities.empty());
Prng p;
prng_init(p, CANONICAL_TEST_SEED ^ TUMBLEWEED_PRNG_SALT);
const double expectedSize = prng_uniform(p, TUMBLEWEED_SIZE_MIN, TUMBLEWEED_SIZE_MAX);
const double expectedX = prng_uniform(p, 0.0, kMonitor1920);
const double expectedY = sim.windowHeight - prng_uniform(p, TUMBLEWEED_Y_OFFSET_MIN, TUMBLEWEED_Y_OFFSET_MAX);
const double speed = prng_uniform(p, TUMBLEWEED_SPEED_MIN, TUMBLEWEED_SPEED_MAX);
const double direction = prng_uniform(p, 0.0, 1.0) < 0.5 ? -1.0 : 1.0;
const double expectedVx = direction * speed;
const double expectedRotation = prng_uniform(p, 0.0, 6.28318530717958647692);
const Entity& e = sim.entities[0];
REQUIRE(e.kind == EntityKind::Tumbleweed);
REQUIRE(e.size == Approx(expectedSize).margin(1e-12));
REQUIRE(e.x == Approx(expectedX).margin(1e-12));
REQUIRE(e.y == Approx(expectedY).margin(1e-12));
REQUIRE(e.vx == Approx(expectedVx).margin(1e-12));
REQUIRE(e.rotation == Approx(expectedRotation).margin(1e-12));
REQUIRE(e.rotationSpeed == Approx(expectedVx / expectedSize).margin(1e-12));
}
TEST_CASE("Tumbleweed respawns at the opposite edge when off-screen", "[desert][tumbleweed]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, kMonitor1920, DEFAULT_DENSITY);
sim_set_scene(sim, Scene::Desert);
REQUIRE_FALSE(sim.entities.empty());
sim.entities[0].x = sim.monitorWidth + 100.0;
sim_tick_entities(sim, 0.0);
const Entity& e = sim.entities[0];
REQUIRE(e.kind == EntityKind::Tumbleweed);
REQUIRE(e.x == Approx(-e.size).margin(1e-12));
REQUIRE(e.vx > 0.0);
}
TEST_CASE("Tumbleweed hops above its baseline then settles", "[desert][tumbleweed]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, kMonitor1920, DEFAULT_DENSITY);
sim_set_scene(sim, Scene::Desert);
REQUIRE_FALSE(sim.entities.empty());
double yBase = sim.entities[0].altitudeAnchor;
REQUIRE(sim.entities[0].y == Approx(yBase).margin(1e-9)); // starts grounded
double minY = sim.entities[0].y;
for (int i = 0; i < 900; ++i) {
sim_tick_entities(sim, 1.0 / 60.0);
Entity& t = sim.entities[0];
// Pin x on-screen so it doesn't roll off and respawn mid-test.
if (t.x < 50.0) t.x = 50.0;
if (t.x > sim.monitorWidth - 50.0) t.x = sim.monitorWidth - 50.0;
yBase = t.altitudeAnchor;
minY = std::min(minY, t.y);
REQUIRE(t.y <= yBase + 1e-6); // never sinks below the baseline
}
REQUIRE(minY < yBase - 1.0); // it left the ground at least once
}
TEST_CASE("Desert scene leaves the canonical first blade geometry bit-identical", "[desert][snapshot]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, kMonitor1920, 1.0);
REQUIRE(sim.blades.size() == desktopgrass::test::CANONICAL_BLADE_COUNT);
sim_set_scene(sim, Scene::Desert);
const Blade& first = sim.blades[0];
const auto& expected = desktopgrass::test::CANONICAL_FIRST_10[0];
REQUIRE(first.baseX == Approx(expected.baseX).margin(1e-12));
REQUIRE(first.height == Approx(expected.height).margin(1e-12));
REQUIRE(first.thickness == Approx(expected.thickness).margin(1e-12));
REQUIRE(first.hue == expected.hue);
REQUIRE(first.swayPhaseOffset == Approx(expected.sway).margin(1e-12));
REQUIRE(first.stiffness == Approx(expected.stiffness).margin(1e-12));
}

View File

@@ -0,0 +1,113 @@
// entity_skeleton_tests.cpp
//
// Entity subsystem skeleton tests (architecture.md §13.2).
//
// Coverage:
// * EntityKind discriminants match the spec ({None=0, Tumbleweed=1,
// Snowflake=2}).
// * MAX_ENTITIES_PER_MONITOR is the locked cap (= 64).
// * sim_init defaults sim.entities to empty, capacity >= cap.
// * sim_set_scene clears entities (currently a no-op since the Grass
// scene generates none; §14/§15 add per-scene generators).
// * sim_tick_entities is safe on empty (no exceptions, no growth).
// * Tick on empty entities does not perturb other sim state (blades
// untouched, ambient PRNG untouched).
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
using namespace desktopgrass;
TEST_CASE("EntityKind has spec-locked discriminants", "[entities][enum]") {
REQUIRE(static_cast<int>(EntityKind::None) == 0);
REQUIRE(static_cast<int>(EntityKind::Tumbleweed) == 1);
REQUIRE(static_cast<int>(EntityKind::Snowflake) == 2);
REQUIRE(static_cast<int>(EntityKind::Sheep) == 3);
REQUIRE(static_cast<int>(EntityKind::Cat) == 4);
REQUIRE(static_cast<int>(EntityKind::Bunny) == 6);
REQUIRE(static_cast<int>(EntityKind::Butterfly) == 7);
REQUIRE(static_cast<int>(EntityKind::Firefly) == 8);
REQUIRE(static_cast<int>(EntityKind::Bird) == 9);
REQUIRE(MAX_ENTITIES_PER_MONITOR == 64);
}
TEST_CASE("sim_init reserves entities capacity", "[entities][init]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, DEFAULT_DENSITY);
REQUIRE(sim.entities.empty());
REQUIRE(sim.entities.capacity() >= static_cast<std::size_t>(MAX_ENTITIES_PER_MONITOR));
REQUIRE(sim.entitySeed == CANONICAL_TEST_SEED);
}
TEST_CASE("sim_set_scene clears entities", "[entities][scene]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, 1.0);
// Push a fake entity directly to verify scene-transition removal runs.
Entity fake{};
fake.kind = EntityKind::Tumbleweed;
fake.x = 100.0;
sim.entities.push_back(fake);
REQUIRE(sim.entities.size() == 1);
sim_set_scene(sim, Scene::Winter);
REQUIRE(sim.entities.empty());
REQUIRE(sim.entities.capacity() >= static_cast<std::size_t>(MAX_ENTITIES_PER_MONITOR));
}
TEST_CASE("sim_tick_entities is a no-op on empty outside Grass", "[entities][tick]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, 1.0);
sim.currentScene = Scene::Desert;
const auto bladesBefore = sim.blades.size();
const auto prngBefore = sim.ambientPrng.state;
sim_tick_entities(sim, 0.016);
sim_tick_entities(sim, 0.5);
REQUIRE(sim.entities.empty());
REQUIRE(sim.blades.size() == bladesBefore);
REQUIRE(sim.ambientPrng.state == prngBefore);
}
TEST_CASE("sim_tick_entities advances a populated entity", "[entities][tick]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, 1.0);
sim.currentScene = Scene::Desert;
Entity e{};
e.kind = EntityKind::Tumbleweed;
e.x = 100.0;
e.y = 50.0;
e.vx = 50.0; // DIP/sec
e.vy = 0.0;
e.size = 10.0;
e.rotation = 0.5;
e.rotationSpeed = 1.0; // rad/sec
e.age = 0.0;
e.lifetime = -1.0; // infinite
e.seed = 0xDEADBEEF;
sim.entities.push_back(e);
const double dt = 0.5;
sim_tick_entities(sim, dt);
REQUIRE(sim.entities.size() == 1);
const Entity& after = sim.entities[0];
REQUIRE(after.x == Approx(100.0 + 50.0 * dt));
REQUIRE(after.y == Approx(50.0));
REQUIRE(after.rotation == Approx(0.5 + 1.0 * dt));
REQUIRE(after.age == Approx(0.0 + dt));
REQUIRE(after.kind == EntityKind::Tumbleweed);
}
TEST_CASE("sim_tick calls sim_tick_entities (wiring check)", "[entities][tick]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, 1920.0, 1.0);
sim.currentScene = Scene::Desert;
Entity e{};
e.kind = EntityKind::Snowflake;
e.x = 0.0; e.y = 0.0;
e.vx = 10.0; e.vy = 20.0;
e.size = 2.0;
e.age = 0.0; e.lifetime = 100.0;
sim.entities.push_back(e);
sim_tick(sim, 0.1, nullptr, 0);
REQUIRE(sim.entities.size() == 1);
REQUIRE(sim.entities[0].x == Approx(1.0)); // 10 * 0.1
REQUIRE(sim.entities[0].y == Approx(2.0)); // 20 * 0.1
}

View File

@@ -0,0 +1,195 @@
// firefly_tests.cpp - §17.7 ambient Firefly tests.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <algorithm>
#include <cmath>
#include <vector>
using namespace desktopgrass;
namespace {
constexpr double Monitor1920 = 1920.0;
int count_kind(const Sim& sim, EntityKind kind) {
return static_cast<int>(std::count_if(sim.entities.begin(), sim.entities.end(),
[kind](const Entity& e) { return e.kind == kind; }));
}
Sim build_grass_sim(uint64_t seed = CANONICAL_TEST_SEED) {
Sim sim = sim_init(seed, Monitor1920, DEFAULT_DENSITY);
sim_set_scene(sim, Scene::Grass);
return sim;
}
int prng_count(Prng& side, int minCount, int maxCount) {
const double draw = prng_uniform(side, static_cast<double>(minCount), static_cast<double>(maxCount + 1));
int count = static_cast<int>(std::floor(draw));
if (count < minCount) count = minCount;
if (count > maxCount) count = maxCount;
return count;
}
} // namespace
TEST_CASE("Firefly constants are pinned to spec values", "[firefly][constants]") {
REQUIRE(FIREFLY_COUNT_MIN == 3);
REQUIRE(FIREFLY_COUNT_MAX == 6);
REQUIRE(FIREFLY_DRIFT_SPEED_MIN == Approx(4.0));
REQUIRE(FIREFLY_DRIFT_SPEED_MAX == Approx(10.0));
REQUIRE(FIREFLY_BODY_RADIUS == Approx(1.2));
REQUIRE(FIREFLY_GLOW_RADIUS == Approx(5.0));
REQUIRE(FIREFLY_BLINK_PERIOD_MIN == Approx(1.4));
REQUIRE(FIREFLY_BLINK_PERIOD_MAX == Approx(2.6));
REQUIRE(FIREFLY_BLINK_DUTY == Approx(0.55));
REQUIRE(FIREFLY_BLINK_FADE == Approx(0.30));
REQUIRE(FIREFLY_DRIFT_FREQ_X == Approx(0.4));
REQUIRE(FIREFLY_DRIFT_FREQ_Y == Approx(0.6));
REQUIRE(FIREFLY_DRIFT_AMP_X == Approx(0.6));
REQUIRE(FIREFLY_DRIFT_AMP_Y == Approx(8.0));
REQUIRE(FIREFLY_ALTITUDE_MIN == Approx(8.0));
REQUIRE(FIREFLY_ALTITUDE_MAX == Approx(55.0));
REQUIRE(FIREFLY_BODY_COLOR == 0xFFFFEE88u);
REQUIRE(FIREFLY_GLOW_COLOR_RGB == 0xEEDD66u);
REQUIRE(FIREFLY_GLOW_ALPHA_MAX == 110);
REQUIRE(FIREFLY_BODY_ALPHA_MAX == 255);
REQUIRE(FIREFLY_PRNG_SALT == 0xF13EF1E7777ull);
}
TEST_CASE("Grass generation produces firefly count in range", "[firefly][gen]") {
for (uint64_t i = 0; i < 128; ++i) {
const uint64_t seed = CANONICAL_TEST_SEED + i * 0x9E3779B97F4A7C15ull;
Sim sim = build_grass_sim(seed);
REQUIRE(count_kind(sim, EntityKind::Firefly) >= FIREFLY_COUNT_MIN);
REQUIRE(count_kind(sim, EntityKind::Firefly) <= FIREFLY_COUNT_MAX);
}
}
TEST_CASE("Fireflies are Grass scene only", "[firefly][scene]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, Monitor1920, DEFAULT_DENSITY);
sim_set_scene(sim, Scene::Desert);
REQUIRE(count_kind(sim, EntityKind::Firefly) == 0);
sim_set_scene(sim, Scene::Winter);
REQUIRE(count_kind(sim, EntityKind::Firefly) == 0);
}
TEST_CASE("Generated fireflies have speed altitude and blink period ranges", "[firefly][gen]") {
Sim sim = build_grass_sim();
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Firefly) continue;
REQUIRE(e.baseSpeed >= FIREFLY_DRIFT_SPEED_MIN);
REQUIRE(e.baseSpeed < FIREFLY_DRIFT_SPEED_MAX);
REQUIRE(e.altitudeAnchor >= FIREFLY_ALTITUDE_MIN);
REQUIRE(e.altitudeAnchor < FIREFLY_ALTITUDE_MAX);
REQUIRE(e.blinkPeriod >= FIREFLY_BLINK_PERIOD_MIN);
REQUIRE(e.blinkPeriod < FIREFLY_BLINK_PERIOD_MAX);
}
}
TEST_CASE("Firefly PRNG draw order matches side stream", "[firefly][prng]") {
Prng side;
prng_init(side, CANONICAL_TEST_SEED ^ FIREFLY_PRNG_SALT);
Sim sim = build_grass_sim();
const int expectedCount = prng_count(side, FIREFLY_COUNT_MIN, FIREFLY_COUNT_MAX);
REQUIRE(count_kind(sim, EntityKind::Firefly) == expectedCount);
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Firefly) continue;
const double xFrac = prng_uniform(side, 0.0, 1.0);
const double yFrac = prng_uniform(side, 0.0, 1.0);
const uint64_t vxSign = prng_next_u64(side) & 1ull;
const double expectedDir = vxSign != 0ull ? 1.0 : -1.0;
const double expectedSpeed = prng_uniform(side, FIREFLY_DRIFT_SPEED_MIN, FIREFLY_DRIFT_SPEED_MAX);
const double expectedBlinkPeriod = prng_uniform(side, FIREFLY_BLINK_PERIOD_MIN, FIREFLY_BLINK_PERIOD_MAX);
const double expectedBlinkPhase = prng_uniform(side, 0.0, 1.0);
const double expectedPhaseY = prng_uniform(side, 0.0, 2.0 * 3.14159265358979323846);
const double expectedPhaseX = prng_uniform(side, 0.0, 2.0 * 3.14159265358979323846);
const double expectedAltitude = FIREFLY_ALTITUDE_MIN + yFrac * (FIREFLY_ALTITUDE_MAX - FIREFLY_ALTITUDE_MIN);
const double expectedVx = expectedDir * expectedSpeed * (1.0 + FIREFLY_DRIFT_AMP_X * std::sin(expectedPhaseX));
REQUIRE(e.x == Approx(xFrac * Monitor1920));
REQUIRE(e.altitudeAnchor == Approx(expectedAltitude));
REQUIRE(e.baseSpeed == Approx(expectedSpeed));
REQUIRE(e.blinkPeriod == Approx(expectedBlinkPeriod));
REQUIRE(e.blinkPhase == Approx(expectedBlinkPhase));
REQUIRE(e.vx == Approx(expectedVx));
REQUIRE(e.phaseY == Approx(expectedPhaseY));
REQUIRE(e.phaseX == Approx(expectedPhaseX));
++seen;
}
REQUIRE(seen == expectedCount);
}
TEST_CASE("Firefly edge wrap preserves altitude anchor", "[firefly][motion]") {
Sim sim = build_grass_sim();
auto it = std::find_if(sim.entities.begin(), sim.entities.end(), [](const Entity& e) { return e.kind == EntityKind::Firefly; });
REQUIRE(it != sim.entities.end());
const double margin = FIREFLY_GLOW_RADIUS;
it->x = Monitor1920 + margin + 1.0;
it->vx = std::abs(it->vx);
const double altitude = it->altitudeAnchor;
sim.currentScene = Scene::Desert;
sim_tick_entities(sim, 0.016);
REQUIRE(it->x == Approx(-margin));
REQUIRE(it->altitudeAnchor == Approx(altitude));
}
TEST_CASE("Fireflies do not interact with cuts or pets", "[firefly][interaction]") {
Sim sim = sim_init(CANONICAL_TEST_SEED, Monitor1920, DEFAULT_DENSITY);
sim.entities.clear();
Entity firefly{};
firefly.kind = EntityKind::Firefly;
firefly.x = 500.0;
firefly.y = sim.windowHeight - STRIP_HEIGHT - 5.0;
firefly.vx = FIREFLY_DRIFT_SPEED_MIN;
firefly.baseSpeed = FIREFLY_DRIFT_SPEED_MIN;
firefly.altitudeAnchor = FIREFLY_ALTITUDE_MIN;
firefly.blinkPeriod = FIREFLY_BLINK_PERIOD_MIN;
firefly.lifetime = -1.0;
sim.entities.push_back(firefly);
Entity sheep{};
sheep.kind = EntityKind::Sheep;
sheep.x = firefly.x;
sheep.y = sim.windowHeight - SHEEP_BODY_HEIGHT - SHEEP_LEG_LENGTH;
sheep.vx = SHEEP_WALK_SPEED_MIN;
sheep.state = SHEEP_STATE_WALKING;
sheep.stateTimer = 10.0;
sim.entities.push_back(sheep);
InputEvent ev{};
ev.type = EventType::Click;
ev.x = firefly.x;
ev.y = firefly.y;
sim_apply_click(sim, ev);
REQUIRE(sim.entities[0].kind == EntityKind::Firefly);
REQUIRE(sim.entities[0].baseSpeed == Approx(FIREFLY_DRIFT_SPEED_MIN));
REQUIRE(sim.entities[1].state == SHEEP_STATE_WALKING);
for (const Blade& b : sim.blades) REQUIRE(b.cutAnimStart < 0.0);
}
TEST_CASE("Firefly blink brightness has on and off phases", "[firefly][blink]") {
const double period = 2.0;
REQUIRE(firefly_blink_brightness(period * 0.25, period, 0.0) == Approx(1.0));
REQUIRE(firefly_blink_brightness(period * 0.80, period, 0.0) == Approx(0.0));
}
TEST_CASE("Firefly phases decorrelate visible brightness", "[firefly][blink]") {
const double period = 2.0;
const double phases[] = { 0.0, 0.0375, 0.075, 0.1125, 0.25, 0.80 };
std::vector<double> distinct;
for (double phase : phases) {
const double b = firefly_blink_brightness(0.0, period, phase);
bool seen = false;
for (double existing : distinct) {
if (std::fabs(existing - b) < 1e-6) { seen = true; break; }
}
if (!seen) distinct.push_back(b);
}
REQUIRE(distinct.size() >= 4);
}

View File

@@ -0,0 +1,54 @@
// flower_tests.cpp
//
// Tests for §5 flower stream + §7 head-render contract.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <cmath>
#include <vector>
using namespace desktopgrass;
TEST_CASE("flower stream is deterministic for a given seed", "[flowers]") {
std::vector<Blade> a, b;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, a);
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, b);
REQUIRE(a.size() == b.size());
for (std::size_t i = 0; i < a.size(); ++i) {
REQUIRE(a[i].isFlower == b[i].isFlower);
REQUIRE(a[i].flowerHeadColorIdx == b[i].flowerHeadColorIdx);
REQUIRE(a[i].flowerHeadRadius == b[i].flowerHeadRadius);
REQUIRE(a[i].heightBonus == b[i].heightBonus);
}
}
TEST_CASE("flower count is within 3-sigma of FLOWER_PROBABILITY", "[flowers]") {
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
REQUIRE(blades.size() > 100);
std::size_t flowerCount = 0;
for (const Blade& b : blades) if (b.isFlower) ++flowerCount;
const double n = static_cast<double>(blades.size());
const double p = FLOWER_PROBABILITY;
const double mu = n * p;
const double sd = std::sqrt(n * p * (1.0 - p));
// 3-sigma tolerance keeps this test stable across spec-conformant
// PRNG sequences. For seed=0x6B6173746F, n=321 we expect ~12.84 with
// sd≈3.51, so [2,24] is the acceptable range.
REQUIRE(flowerCount >= static_cast<std::size_t>(std::floor(mu - 3.0 * sd)));
REQUIRE(flowerCount <= static_cast<std::size_t>(std::ceil(mu + 3.0 * sd)));
}
TEST_CASE("flower stream does not perturb the main stream", "[flowers][conformance]") {
// Regenerate blades and assert the main-stream fields match the
// canonical snapshot. This is implicitly covered by blade_gen_tests
// (the first/last 10 still match), but pin it here for clarity.
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
REQUIRE(blades.size() > 0);
REQUIRE(blades[0].baseX == Approx(4.941073726820111).margin(1e-12));
REQUIRE(blades[0].height == Approx(24.469991818248864).margin(1e-12));
}

View File

@@ -0,0 +1,164 @@
// gust_tests.cpp
//
// Gust impulse model tests (architecture.md §8).
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <cmath>
using namespace desktopgrass;
namespace {
Sim make_sim_with_blades(std::initializer_list<double> baseXs) {
Sim sim;
sim.windowHeight = STRIP_HEIGHT + HEADROOM;
for (double x : baseXs) {
Blade b{};
b.baseX = x;
b.height = 20.0;
b.thickness = 1.5;
b.swayPhaseOffset = 0.0;
b.stiffness = 1.0;
b.cutHeight = 1.0;
b.cutInitialHeight = 1.0;
b.cutAnimStart = -1.0;
sim.blades.push_back(b);
}
return sim;
}
InputEvent move(double x, double y, double t) {
return InputEvent{ EventType::Move, x, y, t };
}
} // anonymous
TEST_CASE("first move event is a baseline; no impulse", "[gust]") {
Sim sim = make_sim_with_blades({100.0});
const double groundY = sim.windowHeight;
const double bandY = groundY - 10.0; // in band
sim_apply_move(sim, move(100.0, bandY, 0.0));
REQUIRE(sim.blades[0].gustVelocity == Approx(0.0));
REQUIRE(sim.prevCursorTime == Approx(0.0));
}
TEST_CASE("a second move inside the band emits an impulse", "[gust]") {
Sim sim = make_sim_with_blades({100.0, 200.0, 400.0});
const double bandY = sim.windowHeight - 10.0;
sim_apply_move(sim, move( 0.0, bandY, 0.0));
sim_apply_move(sim, move(100.0, bandY, 0.05)); // velocity = 2000 DIP/sec
// Blade at 100 is right under the cursor → max impulse.
// Expected magnitude:
// capped = 2000 (≤ 4000 cap)
// impulseMagnitude = 2000 * 0.003 = 6.0
// smoothstep at distance 0 = 1.0
// smoothstep at distance 100/150 (blade @ 200) = (1-2/3)² * (3 - 2*(1-2/3))
REQUIRE(sim.blades[0].gustVelocity == Approx(6.0).margin(1e-9));
// Blade outside radius (400, dist=300 > 150) → no impulse.
REQUIRE(sim.blades[2].gustVelocity == Approx(0.0));
REQUIRE(sim.blades[1].gustVelocity > 0.0);
REQUIRE(sim.blades[1].gustVelocity < 6.0);
}
TEST_CASE("impulse is signed by motion direction", "[gust]") {
Sim left = make_sim_with_blades({100.0});
Sim right = make_sim_with_blades({100.0});
const double y = left.windowHeight - 10.0;
sim_apply_move(left, move(200.0, y, 0.0));
sim_apply_move(left, move(100.0, y, 0.05)); // moving left
sim_apply_move(right, move( 0.0, y, 0.0));
sim_apply_move(right, move(100.0, y, 0.05)); // moving right
REQUIRE(left.blades[0].gustVelocity < 0.0);
REQUIRE(right.blades[0].gustVelocity > 0.0);
REQUIRE(std::fabs(left.blades[0].gustVelocity) ==
Approx(std::fabs(right.blades[0].gustVelocity)).margin(1e-9));
}
TEST_CASE("cursor speed is capped at MAX_CURSOR_SPEED", "[gust]") {
Sim sim = make_sim_with_blades({100.0});
const double y = sim.windowHeight - 10.0;
sim_apply_move(sim, move(0.0, y, 0.0));
sim_apply_move(sim, move(100000.0, y, 0.05)); // velocity ≈ 2e6 DIP/sec
// capped magnitude = MAX_CURSOR_SPEED * IMPULSE_SCALE = 4000 * 0.003 = 12
// but the blade is at distance ~100k from cursor: outside radius → no impulse
REQUIRE(sim.blades[0].gustVelocity == Approx(0.0));
}
TEST_CASE("max impulse at the cursor equals capped magnitude", "[gust]") {
Sim sim = make_sim_with_blades({1000.0});
const double y = sim.windowHeight - 10.0;
sim_apply_move(sim, move(0.0, y, 0.0));
sim_apply_move(sim, move(1000.0, y, 0.0001)); // velocity huge → saturates
// Saturated: cursor lands at x=1000 (blade), distance=0, smoothstep=1.0
REQUIRE(sim.blades[0].gustVelocity ==
Approx(MAX_CURSOR_SPEED * IMPULSE_SCALE).margin(1e-9));
}
TEST_CASE("moves outside the gust band don't emit impulses", "[gust]") {
Sim sim = make_sim_with_blades({100.0});
const double y_above_band = sim.windowHeight - STRIP_HEIGHT - HEADROOM - 20.0;
sim_apply_move(sim, move( 0.0, y_above_band, 0.0));
sim_apply_move(sim, move(100.0, y_above_band, 0.05));
REQUIRE(sim.blades[0].gustVelocity == Approx(0.0));
}
TEST_CASE("out-of-band move updates baseline; re-entry parity", "[gust]") {
Sim sim = make_sim_with_blades({700.0});
const double inBandY = sim.windowHeight - 10.0;
const double outOfBandY = sim.windowHeight - STRIP_HEIGHT - HEADROOM - 20.0;
// t0 in-band: primes baseline (first event, no impulse).
sim_apply_move(sim, move(500.0, inBandY, 0.0));
// t1 out-of-band: updates baseline but emits no impulse.
sim_apply_move(sim, move(520.0, outOfBandY, 0.05));
REQUIRE(sim.prevCursorX == Approx(520.0));
REQUIRE(sim.prevCursorTime == Approx(0.05));
REQUIRE(sim.blades[0].gustVelocity == Approx(0.0));
// t2 re-enter in-band: emits impulse off the out-of-band baseline.
sim_apply_move(sim, move(700.0, inBandY, 0.10));
const double dtEv = std::max(0.10 - 0.05, 1.0 / 1000.0);
const double velX = (700.0 - 520.0) / dtEv;
const double capped = std::max(-MAX_CURSOR_SPEED, std::min(velX, MAX_CURSOR_SPEED));
const double expected = capped * IMPULSE_SCALE; // distance 0 → smoothstep = 1
REQUIRE(sim.blades[0].gustVelocity == Approx(expected).margin(1e-9));
}
TEST_CASE("large time gap resets cursor baseline", "[gust]") {
Sim sim = make_sim_with_blades({100.0});
const double y = sim.windowHeight - 10.0;
sim_apply_move(sim, move( 0.0, y, 0.0));
sim_apply_move(sim, move(500.0, y, 0.5)); // > CURSOR_REINIT_GAP_SEC (0.25)
REQUIRE(sim.blades[0].gustVelocity == Approx(0.0));
}
TEST_CASE("impulse falls off smoothly with distance", "[gust]") {
Sim sim = make_sim_with_blades({100.0, 130.0, 175.0, 200.0, 249.0, 251.0});
const double y = sim.windowHeight - 10.0;
sim_apply_move(sim, move( 0.0, y, 0.0));
sim_apply_move(sim, move(100.0, y, 0.05));
// Monotonic falloff: cursor at 100.
REQUIRE(sim.blades[0].gustVelocity > sim.blades[1].gustVelocity);
REQUIRE(sim.blades[1].gustVelocity > sim.blades[2].gustVelocity);
REQUIRE(sim.blades[2].gustVelocity > sim.blades[3].gustVelocity);
REQUIRE(sim.blades[3].gustVelocity > sim.blades[4].gustVelocity);
// Just outside radius (251 → distance 151 > 150) → zero.
REQUIRE(sim.blades[5].gustVelocity == Approx(0.0));
}

View File

@@ -0,0 +1,371 @@
// hedgehog_tests.cpp
//
// §17.9 Hedgehog critter tests. Mirrors Win2D HedgehogTests.cs.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <algorithm>
#include <cmath>
#include <cwchar>
using namespace desktopgrass;
namespace {
constexpr double Monitor1920 = 1920.0;
int count_kind(const Sim& sim, EntityKind kind) {
return static_cast<int>(std::count_if(sim.entities.begin(), sim.entities.end(),
[kind](const Entity& e) { return e.kind == kind; }));
}
Sim build_sim(uint64_t seed = CANONICAL_TEST_SEED) {
return sim_init(seed, Monitor1920, DEFAULT_DENSITY);
}
Sim build_grass_sim(uint64_t seed = CANONICAL_TEST_SEED) {
Sim sim = build_sim(seed);
sim_set_scene(sim, Scene::Grass);
sim_set_critter(sim, CritterKind::Bunny);
return sim;
}
Entity hedgehog_entity(double x = 500.0, double vx = HEDGEHOG_WALK_SPEED_MIN) {
Entity e{};
e.kind = EntityKind::Hedgehog;
e.size = HEDGEHOG_BODY_RADIUS;
e.x = x;
e.y = STRIP_HEIGHT + HEADROOM - HEDGEHOG_BODY_HEIGHT - HEDGEHOG_LEG_LENGTH;
e.vx = vx;
e.vy = 0.0;
e.rotationSpeed = std::abs(vx);
e.lifetime = -1.0;
e.state = HEDGEHOG_STATE_WALKING;
e.stateTimer = HEDGEHOG_WALK_DURATION_MIN;
e.previousState = HEDGEHOG_STATE_WALKING;
return e;
}
InputEvent click_event(double x, double y) {
InputEvent ev{};
ev.type = EventType::Click;
ev.x = x;
ev.y = y;
ev.time = 0.0;
return ev;
}
int prng_count(Prng& side, int minCount, int maxCount) {
const double draw = prng_uniform(side, static_cast<double>(minCount), static_cast<double>(maxCount + 1));
int count = static_cast<int>(std::floor(draw));
if (count < minCount) count = minCount;
if (count > maxCount) count = maxCount;
return count;
}
void advance_sheep(Prng& side, int count) {
for (int i = 0; i < count; ++i) {
const double margin = SHEEP_BODY_RADIUS + 8.0;
(void)prng_uniform(side, margin, Monitor1920 - margin);
(void)prng_uniform(side, SHEEP_WALK_SPEED_MIN, SHEEP_WALK_SPEED_MAX);
(void)prng_uniform(side, 0.0, 1.0);
(void)prng_next_u32(side);
(void)prng_uniform(side, SHEEP_WALK_DURATION_MIN, SHEEP_WALK_DURATION_MAX);
(void)prng_index(side, static_cast<uint32_t>(sizeof(SHEEP_NAME_POOL) / sizeof(SHEEP_NAME_POOL[0])));
}
}
void advance_cats(Prng& side, int count) {
for (int i = 0; i < count; ++i) {
const double margin = CAT_BODY_RADIUS + 8.0;
(void)prng_uniform(side, margin, Monitor1920 - margin);
(void)prng_uniform(side, CAT_WALK_SPEED_MIN, CAT_WALK_SPEED_MAX);
(void)prng_uniform(side, 0.0, 1.0);
(void)prng_next_u32(side);
(void)prng_uniform(side, CAT_WALK_DURATION_MIN, CAT_WALK_DURATION_MAX);
(void)prng_index(side, static_cast<uint32_t>(sizeof(CAT_NAME_POOL) / sizeof(CAT_NAME_POOL[0])));
(void)prng_index(side, static_cast<uint32_t>(CAT_COAT_VARIANT_COUNT));
}
}
void advance_bunnies(Prng& side, int count) {
for (int i = 0; i < count; ++i) {
(void)prng_uniform(side, 0.0, 1.0);
(void)prng_next_u64(side);
(void)prng_uniform(side, BUNNY_HOP_SPEED_MIN, BUNNY_HOP_SPEED_MAX);
(void)prng_index(side, static_cast<uint32_t>(sizeof(BUNNY_NAME_POOL) / sizeof(BUNNY_NAME_POOL[0])));
}
}
bool hedgehog_name_in_pool(const Entity& e) {
if (e.nameIndex >= sizeof(HEDGEHOG_NAME_POOL) / sizeof(HEDGEHOG_NAME_POOL[0])) return false;
const wchar_t* name = HEDGEHOG_NAME_POOL[e.nameIndex];
for (const wchar_t* candidate : HEDGEHOG_NAME_POOL) {
if (std::wcscmp(name, candidate) == 0) return true;
}
return false;
}
} // namespace
TEST_CASE("Hedgehog constants are pinned to spec values", "[hedgehog][constants]") {
REQUIRE(HEDGEHOG_COUNT_MIN == 0);
REQUIRE(HEDGEHOG_COUNT_MAX == 1);
REQUIRE(HEDGEHOG_COUNT_PROBABILITY == Approx(0.55));
REQUIRE(HEDGEHOG_WALK_SPEED_MIN == Approx(4.0));
REQUIRE(HEDGEHOG_WALK_SPEED_MAX == Approx(8.0));
REQUIRE(HEDGEHOG_BODY_RADIUS == Approx(9.0));
REQUIRE(HEDGEHOG_BODY_HEIGHT == Approx(5.5));
REQUIRE(HEDGEHOG_HEAD_RADIUS == Approx(3.6));
REQUIRE(HEDGEHOG_NOSE_RADIUS == Approx(0.8));
REQUIRE(HEDGEHOG_LEG_LENGTH == Approx(2.5));
REQUIRE(HEDGEHOG_SPIKE_COUNT == 14);
REQUIRE(HEDGEHOG_SPIKE_LENGTH == Approx(3.0));
REQUIRE(HEDGEHOG_SPIKE_WIDTH == Approx(1.4));
REQUIRE(HEDGEHOG_SPIKE_ARC_START_DEG == Approx(-20.0));
REQUIRE(HEDGEHOG_SPIKE_ARC_END_DEG == Approx(200.0));
REQUIRE(HEDGEHOG_BODY_COLOR == 0xFF5C4633u);
REQUIRE(HEDGEHOG_SPIKE_COLOR == 0xFF3A2A1Fu);
REQUIRE(HEDGEHOG_SPIKE_TIP_COLOR == 0xFF1E150Eu);
REQUIRE(HEDGEHOG_NOSE_COLOR == 0xFF1A1208u);
REQUIRE(HEDGEHOG_EYE_COLOR == 0xFF1A1208u);
REQUIRE(HEDGEHOG_STATE_WALKING == 0);
REQUIRE(HEDGEHOG_STATE_SNUFFLING == 1);
REQUIRE(HEDGEHOG_STATE_IDLE == 2);
REQUIRE(HEDGEHOG_STATE_SLEEPING == 3);
REQUIRE(HEDGEHOG_STATE_CURLED == 4);
REQUIRE(HEDGEHOG_WALK_DURATION_MIN == Approx(6.0));
REQUIRE(HEDGEHOG_WALK_DURATION_MAX == Approx(12.0));
REQUIRE(HEDGEHOG_SNUFFLE_DURATION_MIN == Approx(3.0));
REQUIRE(HEDGEHOG_SNUFFLE_DURATION_MAX == Approx(6.0));
REQUIRE(HEDGEHOG_IDLE_DURATION_MIN == Approx(1.5));
REQUIRE(HEDGEHOG_IDLE_DURATION_MAX == Approx(3.0));
REQUIRE(HEDGEHOG_SLEEP_DURATION_MIN == Approx(10.0));
REQUIRE(HEDGEHOG_SLEEP_DURATION_MAX == Approx(25.0));
REQUIRE(HEDGEHOG_CURL_DURATION_MIN == Approx(3.0));
REQUIRE(HEDGEHOG_CURL_DURATION_MAX == Approx(5.5));
REQUIRE(HEDGEHOG_SNUFFLE_PROBABILITY == Approx(0.55));
REQUIRE(HEDGEHOG_IDLE_PROBABILITY == Approx(0.30));
REQUIRE(HEDGEHOG_SLEEP_PROB == Approx(0.50));
REQUIRE(HEDGEHOG_STARTLE_RADIUS == Approx(70.0));
REQUIRE(HEDGEHOG_SNUFFLE_HEAD_FREQ == Approx(5.0));
REQUIRE(HEDGEHOG_SNUFFLE_HEAD_AMP == Approx(0.7));
REQUIRE(HEDGEHOG_WADDLE_FREQ == Approx(4.0));
REQUIRE(HEDGEHOG_WADDLE_AMP == Approx(0.8));
REQUIRE(HEDGEHOG_ZZZ_CYCLE_SEC == Approx(SHEEP_ZZZ_CYCLE_SEC));
REQUIRE(HEDGEHOG_ZZZ_RISE == Approx(SHEEP_ZZZ_RISE * 0.5));
REQUIRE(HEDGEHOG_ZZZ_SIZE_START == Approx(SHEEP_ZZZ_SIZE_START * 0.6));
REQUIRE(HEDGEHOG_ZZZ_SIZE_END == Approx(SHEEP_ZZZ_SIZE_END * 0.6));
REQUIRE(sizeof(HEDGEHOG_NAME_POOL) / sizeof(HEDGEHOG_NAME_POOL[0]) == 12);
REQUIRE(std::wcscmp(HEDGEHOG_NAME_POOL[0], L"Bristle") == 0);
REQUIRE(std::wcscmp(HEDGEHOG_NAME_POOL[11], L"Burdock") == 0);
}
TEST_CASE("Hedgehog count distribution is probabilistic rare sighting", "[hedgehog][gen]") {
constexpr int N = 1000;
int present = 0;
for (uint64_t i = 0; i < N; ++i) {
const uint64_t seed = CANONICAL_TEST_SEED + i * 0x9E3779B97F4A7C15ull;
Sim sim = build_grass_sim(seed);
const int count = count_kind(sim, EntityKind::Hedgehog);
REQUIRE(count >= HEDGEHOG_COUNT_MIN);
REQUIRE(count <= HEDGEHOG_COUNT_MAX);
present += count;
}
REQUIRE(static_cast<double>(present) / N == Approx(HEDGEHOG_COUNT_PROBABILITY).margin(0.05));
}
TEST_CASE("Hedgehogs are Grass scene only", "[hedgehog][scene]") {
Sim sim = build_sim();
sim_set_scene(sim, Scene::Desert);
REQUIRE(count_kind(sim, EntityKind::Hedgehog) == 0);
sim_set_scene(sim, Scene::Winter);
REQUIRE(count_kind(sim, EntityKind::Hedgehog) == 0);
}
TEST_CASE("Generated hedgehogs have speed range", "[hedgehog][gen]") {
bool sawHedgehog = false;
for (uint64_t i = 0; i < 128; ++i) {
Sim sim = build_grass_sim(CANONICAL_TEST_SEED + i * 0xD1B54A32D192ED03ull);
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Hedgehog) continue;
sawHedgehog = true;
REQUIRE(std::abs(e.vx) >= HEDGEHOG_WALK_SPEED_MIN);
REQUIRE(std::abs(e.vx) <= HEDGEHOG_WALK_SPEED_MAX);
REQUIRE(e.rotationSpeed == Approx(std::abs(e.vx)));
}
}
REQUIRE(sawHedgehog);
}
TEST_CASE("Generated hedgehogs have names in pool", "[hedgehog][gen]") {
bool sawHedgehog = false;
for (uint64_t i = 0; i < 128; ++i) {
Sim sim = build_grass_sim(CANONICAL_TEST_SEED + i * 0x94D049BB133111EBull);
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Hedgehog) continue;
sawHedgehog = true;
REQUIRE(hedgehog_name_in_pool(e));
}
}
REQUIRE(sawHedgehog);
}
TEST_CASE("Hedgehog PRNG draw order follows sheep cats and bunnies", "[hedgehog][prng]") {
Prng side;
prng_init(side, CANONICAL_TEST_SEED ^ CRITTER_PRNG_SALT);
Sim sim = build_grass_sim();
const int sheepCount = prng_count(side, SHEEP_COUNT_MIN, SHEEP_COUNT_MAX);
advance_sheep(side, sheepCount);
const int catCount = prng_count(side, CAT_COUNT_MIN, CAT_COUNT_MAX);
advance_cats(side, catCount);
const int bunnyCount = prng_count(side, BUNNY_COUNT_MIN, BUNNY_COUNT_MAX);
advance_bunnies(side, bunnyCount);
const double hasDraw = prng_uniform(side, 0.0, 1.0);
const int hedgehogCount = hasDraw < HEDGEHOG_COUNT_PROBABILITY ? 1 : 0;
REQUIRE(count_kind(sim, EntityKind::Hedgehog) == hedgehogCount);
int seen = 0;
for (const Entity& e : sim.entities) {
if (e.kind != EntityKind::Hedgehog) continue;
const double margin = HEDGEHOG_BODY_RADIUS + 8.0;
const double xFrac = prng_uniform(side, 0.0, 1.0);
const double expectedX = margin + xFrac * (Monitor1920 - 2.0 * margin);
const uint64_t vxSign = prng_next_u64(side) & 1ull;
const double expectedDir = vxSign != 0ull ? 1.0 : -1.0;
const double expectedSpeed = prng_uniform(side, HEDGEHOG_WALK_SPEED_MIN, HEDGEHOG_WALK_SPEED_MAX);
const uint8_t expectedName = static_cast<uint8_t>(prng_index(side,
static_cast<uint32_t>(sizeof(HEDGEHOG_NAME_POOL) / sizeof(HEDGEHOG_NAME_POOL[0]))));
REQUIRE(e.x == Approx(expectedX));
REQUIRE(e.vx == Approx(expectedDir * expectedSpeed));
REQUIRE(e.nameIndex == expectedName);
++seen;
}
REQUIRE(seen == hedgehogCount);
}
TEST_CASE("Hedgehog edge bounce flips direction", "[hedgehog][motion]") {
Sim sim = build_sim();
sim.currentScene = Scene::Desert;
sim.entities.clear();
Entity e = hedgehog_entity(Monitor1920 - (HEDGEHOG_BODY_RADIUS + 2.0) + 0.1, HEDGEHOG_WALK_SPEED_MIN);
e.stateTimer = 10.0;
sim.entities.push_back(e);
sim_tick_entities(sim, 0.016);
REQUIRE(sim.entities.front().vx < 0.0);
}
TEST_CASE("Hedgehog startle radius curls without flipping vx", "[hedgehog][click]") {
Sim sim = build_sim();
sim.entities.clear();
Entity e = hedgehog_entity(500.0, -HEDGEHOG_WALK_SPEED_MIN);
e.state = HEDGEHOG_STATE_WALKING;
e.stateTimer = 10.0;
sim.entities.push_back(e);
sim_apply_click(sim, click_event(e.x + 10.0, e.y));
REQUIRE(sim.entities.front().state == HEDGEHOG_STATE_CURLED);
REQUIRE(sim.entities.front().vx == Approx(-HEDGEHOG_WALK_SPEED_MIN));
REQUIRE(sim.entities.front().stateTimer >= HEDGEHOG_CURL_DURATION_MIN);
REQUIRE(sim.entities.front().stateTimer <= HEDGEHOG_CURL_DURATION_MAX);
Sim outside = build_sim();
outside.entities.clear();
Entity far = hedgehog_entity(500.0, HEDGEHOG_WALK_SPEED_MIN);
outside.entities.push_back(far);
sim_apply_click(outside, click_event(far.x + HEDGEHOG_STARTLE_RADIUS + 10.0, far.y));
REQUIRE(outside.entities.front().state == HEDGEHOG_STATE_WALKING);
REQUIRE(outside.entities.front().vx == Approx(HEDGEHOG_WALK_SPEED_MIN));
}
TEST_CASE("Hedgehog curl auto uncurls to previous state", "[hedgehog][state]") {
Sim sim = build_sim();
sim.entities.clear();
Entity e = hedgehog_entity(500.0, HEDGEHOG_WALK_SPEED_MIN);
e.state = HEDGEHOG_STATE_IDLE;
e.stateTimer = 2.5;
sim.entities.push_back(e);
sim_apply_click(sim, click_event(e.x, e.y));
REQUIRE(sim.entities.front().state == HEDGEHOG_STATE_CURLED);
sim_tick_entities(sim, HEDGEHOG_CURL_DURATION_MAX + 0.1);
REQUIRE(sim.entities.front().state == HEDGEHOG_STATE_IDLE);
REQUIRE(sim.entities.front().vx == Approx(HEDGEHOG_WALK_SPEED_MIN));
}
TEST_CASE("Hedgehog wakes from sleep on startle and does not resume sleep", "[hedgehog][click]") {
Sim sim = build_sim();
sim.entities.clear();
Entity e = hedgehog_entity(500.0, HEDGEHOG_WALK_SPEED_MIN);
e.state = HEDGEHOG_STATE_SLEEPING;
e.stateTimer = 10.0;
sim.entities.push_back(e);
sim_apply_click(sim, click_event(e.x + 10.0, e.y));
REQUIRE(sim.entities.front().state == HEDGEHOG_STATE_CURLED);
REQUIRE(sim.entities.front().state != HEDGEHOG_STATE_SLEEPING);
sim_tick_entities(sim, HEDGEHOG_CURL_DURATION_MAX + 0.1);
REQUIRE(sim.entities.front().state == HEDGEHOG_STATE_WALKING);
REQUIRE(sim.entities.front().state != HEDGEHOG_STATE_SLEEPING);
}
TEST_CASE("Hedgehog state transition probabilities are stable", "[hedgehog][state]") {
Prng p;
prng_init(p, CANONICAL_TEST_SEED ^ CRITTER_PRNG_SALT);
constexpr int N = 10000;
int snuffle = 0;
int idle = 0;
int sleep = 0;
for (int i = 0; i < N; ++i) {
const uint8_t state = hedgehog_choose_rest_state(p);
if (state == HEDGEHOG_STATE_SNUFFLING) ++snuffle;
else if (state == HEDGEHOG_STATE_IDLE) ++idle;
else if (state == HEDGEHOG_STATE_SLEEPING) ++sleep;
}
const double sleepProb = HEDGEHOG_SLEEP_PROB;
const double activeWeight = HEDGEHOG_SNUFFLE_PROBABILITY + HEDGEHOG_IDLE_PROBABILITY;
const double expectedSnuffle = (1.0 - sleepProb) * HEDGEHOG_SNUFFLE_PROBABILITY / activeWeight;
const double expectedIdle = (1.0 - sleepProb) * HEDGEHOG_IDLE_PROBABILITY / activeWeight;
REQUIRE(static_cast<double>(sleep) / N == Approx(sleepProb).margin(0.02));
REQUIRE(static_cast<double>(snuffle) / N == Approx(expectedSnuffle).margin(0.02));
REQUIRE(static_cast<double>(idle) / N == Approx(expectedIdle).margin(0.02));
}
TEST_CASE("Hedgehog sleep probability is stable", "[hedgehog][state]") {
constexpr int N = 20000;
Prng p;
prng_init(p, CANONICAL_TEST_SEED ^ 0x1234ull);
int sleep = 0;
for (int i = 0; i < N; ++i) {
if (hedgehog_choose_rest_state(p) == HEDGEHOG_STATE_SLEEPING) ++sleep;
}
REQUIRE(static_cast<double>(sleep) / N == Approx(HEDGEHOG_SLEEP_PROB).margin(0.02));
}
TEST_CASE("Hedgehog has no active interaction states", "[hedgehog][state]") {
Prng p;
prng_init(p, CANONICAL_TEST_SEED ^ 0xCAFEull);
for (int i = 0; i < 1000; ++i) {
const uint8_t state = hedgehog_choose_rest_state(p);
REQUIRE((state == HEDGEHOG_STATE_SNUFFLING
|| state == HEDGEHOG_STATE_IDLE
|| state == HEDGEHOG_STATE_SLEEPING));
}
Sim sim = build_sim();
sim.entities.clear();
Entity e = hedgehog_entity(500.0, HEDGEHOG_WALK_SPEED_MIN);
e.stateTimer = 10.0;
sim.entities.push_back(e);
sim_tick_entities(sim, 0.016);
REQUIRE(sim.entities.front().state == HEDGEHOG_STATE_WALKING);
REQUIRE(std::abs(sim.entities.front().vx) == Approx(HEDGEHOG_WALK_SPEED_MIN));
}

View File

@@ -0,0 +1,7 @@
// main.cpp
//
// Catch2 entry point. The Sim.cpp translation unit is also linked in via the
// vcxproj's source list so we can test it directly.
#define CATCH_CONFIG_MAIN
#include "../third_party/catch2/catch.hpp"

View File

@@ -0,0 +1,89 @@
// mushroom_tests.cpp
//
// Tests for §5 mushroom stream + §7 mushroom-render contract.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <algorithm>
#include <cmath>
#include <vector>
using namespace desktopgrass;
TEST_CASE("mushroom stream is deterministic for a given seed", "[mushrooms]") {
std::vector<Blade> a, b;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, a);
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, b);
REQUIRE(a.size() == b.size());
for (std::size_t i = 0; i < a.size(); ++i) {
REQUIRE(a[i].isMushroom == b[i].isMushroom);
REQUIRE(a[i].mushroomCapColorIdx == b[i].mushroomCapColorIdx);
REQUIRE(a[i].mushroomCapWidth == b[i].mushroomCapWidth);
REQUIRE(a[i].mushroomCapHeight == b[i].mushroomCapHeight);
REQUIRE(a[i].mushroomStemHeight == b[i].mushroomStemHeight);
REQUIRE(a[i].mushroomStemThickness == b[i].mushroomStemThickness);
}
}
TEST_CASE("mushroom count is within 3-sigma of MUSHROOM_PROBABILITY", "[mushrooms]") {
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
REQUIRE(blades.size() > 100);
std::size_t mushroomCount = 0;
for (const Blade& b : blades) if (b.isMushroom) ++mushroomCount;
const double n = static_cast<double>(blades.size());
const double p = MUSHROOM_PROBABILITY;
const double mu = n * p;
const double sd = std::sqrt(n * p * (1.0 - p));
// 3-sigma tolerance keeps this test stable across spec-conformant
// PRNG sequences. For seed=0x6B6173746F, n=321 we expect ~8.03 with
// sd≈2.80, so the inclusive 3-sigma range is roughly [0, 17].
const double lo = std::max(0.0, std::floor(mu - 3.0 * sd));
REQUIRE(mushroomCount >= static_cast<std::size_t>(lo));
REQUIRE(mushroomCount <= static_cast<std::size_t>(std::ceil(mu + 3.0 * sd)));
}
TEST_CASE("mushroom stream does not perturb the main stream", "[mushrooms][conformance]") {
// The mushroom stream is independent (seed ^ MUSHROOM_PRNG_SALT) so
// the main-stream first-blade values must still match the canonical.
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
REQUIRE(blades.size() > 0);
REQUIRE(blades[0].baseX == Approx(4.941073726820111).margin(1e-12));
REQUIRE(blades[0].height == Approx(24.469991818248864).margin(1e-12));
}
TEST_CASE("non-mushroom blades have zero mushroom fields", "[mushrooms]") {
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
for (const Blade& b : blades) {
if (!b.isMushroom) {
REQUIRE(b.mushroomCapColorIdx == 0);
REQUIRE(b.mushroomCapWidth == 0.0);
REQUIRE(b.mushroomCapHeight == 0.0);
REQUIRE(b.mushroomStemHeight == 0.0);
REQUIRE(b.mushroomStemThickness == 0.0);
}
}
}
TEST_CASE("mushroom field ranges respect spec", "[mushrooms]") {
std::vector<Blade> blades;
generate_blades(CANONICAL_TEST_SEED, 1920.0, 1.0, blades);
for (const Blade& b : blades) {
if (b.isMushroom) {
REQUIRE(b.mushroomCapColorIdx < MUSHROOM_PALETTE_SIZE);
REQUIRE(b.mushroomCapWidth >= MUSHROOM_CAP_WIDTH_MIN);
REQUIRE(b.mushroomCapWidth < MUSHROOM_CAP_WIDTH_MAX);
REQUIRE(b.mushroomCapHeight >= MUSHROOM_CAP_HEIGHT_MIN);
REQUIRE(b.mushroomCapHeight < MUSHROOM_CAP_HEIGHT_MAX);
REQUIRE(b.mushroomStemHeight >= MUSHROOM_STEM_HEIGHT_MIN);
REQUIRE(b.mushroomStemHeight < MUSHROOM_STEM_HEIGHT_MAX);
REQUIRE(b.mushroomStemThickness >= MUSHROOM_STEM_THICKNESS_MIN);
REQUIRE(b.mushroomStemThickness < MUSHROOM_STEM_THICKNESS_MAX);
}
}
}

View File

@@ -0,0 +1,114 @@
// ocean_tests.cpp
//
// Ocean scene tests (architecture.md §17). Mirror of the Win2D OceanTests so
// the coral blade variant, bubble emitter, and fish swimmers stay in lockstep
// across impls.
#include "../third_party/catch2/catch.hpp"
#include "Sim.h"
#include <algorithm>
using namespace desktopgrass;
namespace {
constexpr double kMonitor1920 = 1920.0;
Sim make_ocean_sim(uint64_t seed = CANONICAL_TEST_SEED,
double width = kMonitor1920,
double density = DEFAULT_DENSITY) {
Sim sim = sim_init(seed, width, density);
sim_set_scene(sim, Scene::Ocean);
return sim;
}
int count_kind(const Sim& sim, EntityKind kind) {
return static_cast<int>(std::count_if(sim.entities.begin(), sim.entities.end(),
[kind](const Entity& e) { return e.kind == kind; }));
}
} // namespace
TEST_CASE("Ocean scene generates at least one coral and keeps values in range",
"[ocean][coral]") {
Sim sim = make_ocean_sim();
int coralCount = 0;
for (const Blade& b : sim.blades) {
if (!b.isCoral) continue;
++coralCount;
REQUIRE_FALSE(b.isPine);
REQUIRE_FALSE(b.isCactus);
REQUIRE_FALSE(b.isMaple);
REQUIRE_FALSE(b.isFlower);
REQUIRE_FALSE(b.isMushroom);
REQUIRE(b.coralHeight >= CORAL_HEIGHT_MIN);
REQUIRE(b.coralHeight <= CORAL_HEIGHT_MAX);
REQUIRE(b.coralWidth >= CORAL_WIDTH_MIN);
REQUIRE(b.coralWidth <= CORAL_WIDTH_MAX);
REQUIRE(static_cast<int>(b.coralType) >= 0);
REQUIRE(static_cast<int>(b.coralType) <= CORAL_TYPE_COUNT - 1);
REQUIRE(static_cast<int>(b.coralColorIdx) >= 0);
REQUIRE(static_cast<int>(b.coralColorIdx) <= CORAL_COLOR_COUNT - 1);
}
REQUIRE(coralCount > 0);
}
TEST_CASE("Ocean scene spawns initial fish at or above the target minimum",
"[ocean][fish]") {
Sim sim = make_ocean_sim();
const int fishCount = count_kind(sim, EntityKind::Fish);
REQUIRE(fishCount >= FISH_COUNT_MIN);
REQUIRE(fishCount <= FISH_COUNT_MAX);
}
TEST_CASE("Ocean fish count rounds half-to-even deterministically",
"[ocean][fish]") {
// scaled = 2.5 * width / 1920. Widths chosen so scaled lands exactly on a
// .5 tie; round-half-to-even must pick the even neighbor (NOT half-up),
// matching C# Math.Round and independent of the FPU rounding mode.
Sim tie25 = make_ocean_sim(CANONICAL_TEST_SEED, 1920.0); // scaled 2.5 -> 2
REQUIRE(count_kind(tie25, EntityKind::Fish) == 2);
Sim tie45 = make_ocean_sim(CANONICAL_TEST_SEED, 3456.0); // scaled 4.5 -> 4
REQUIRE(count_kind(tie45, EntityKind::Fish) == 4);
}
TEST_CASE("Ocean tick emits bubbles over time", "[ocean][bubble]") {
Sim sim = make_ocean_sim();
const double dt = 1.0 / 60.0;
for (int i = 0; i < 600; ++i) {
sim.globalTime += dt;
sim_tick_entities(sim, dt);
}
REQUIRE(count_kind(sim, EntityKind::Bubble) > 0);
}
TEST_CASE("Switching from Ocean to Grass wipes bubbles and fish",
"[ocean][scene]") {
Sim sim = make_ocean_sim();
const double dt = 1.0 / 60.0;
for (int i = 0; i < 120; ++i) {
sim.globalTime += dt;
sim_tick_entities(sim, dt);
}
REQUIRE(count_kind(sim, EntityKind::Fish) > 0);
sim_set_scene(sim, Scene::Grass);
REQUIRE(count_kind(sim, EntityKind::Bubble) == 0);
REQUIRE(count_kind(sim, EntityKind::Fish) == 0);
REQUIRE(std::none_of(sim.blades.begin(), sim.blades.end(),
[](const Blade& b) { return b.isCoral; }));
}
TEST_CASE("Ocean palette is pinned in scene palettes", "[ocean][palette]") {
for (int i = 0; i < PALETTE_SIZE; ++i) {
REQUIRE(SCENE_PALETTES[static_cast<int>(Scene::Ocean)][i] == OCEAN_PALETTE[i]);
}
}

Some files were not shown because too many files have changed in this diff Show More