From 5a4ecbc13b21a79b7102cff858311f10be37172f Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Sat, 3 Oct 2026 16:29:15 +0800 Subject: [PATCH 1/5] feat(installer): preserve Explorer context menu selections --- .../2026-10-03-explorer-menu-selection.md | 79 ++++++++ scripts/installer-context-menu.iss | 158 ++++++++++++++++ scripts/installer-migration.iss | 42 ++--- scripts/installer.iss | 23 ++- .../tests/installer-context-menu-fixture.iss | 178 ++++++++++++++++++ .../tests/installer-context-menu.tests.ps1 | 121 ++++++++++++ scripts/tests/installer-migration.tests.ps1 | 1 + scripts/tests/installer.tests.ps1 | 36 ++-- 8 files changed, 592 insertions(+), 46 deletions(-) create mode 100644 architecture/notes/packaging/2026-10-03-explorer-menu-selection.md create mode 100644 scripts/installer-context-menu.iss create mode 100644 scripts/tests/installer-context-menu-fixture.iss create mode 100644 scripts/tests/installer-context-menu.tests.ps1 diff --git a/architecture/notes/packaging/2026-10-03-explorer-menu-selection.md b/architecture/notes/packaging/2026-10-03-explorer-menu-selection.md new file mode 100644 index 000000000..8f2992e3c --- /dev/null +++ b/architecture/notes/packaging/2026-10-03-explorer-menu-selection.md @@ -0,0 +1,79 @@ +# Preserve Explorer menu choices across installer runs + +## Status + +Implemented; pending review and remote validation. + +## Context + +Issue [#218](https://github.com/Kuddev/pebrel/issues/218) requests individual +Explorer entries and a master switch, available during installation or in +settings. The current installer owns both the ordinary entry and the existing +WSL cascade; it registers every discovered distribution on each installation. + +## Evidence + +[`installer.iss`](../../../scripts/installer.iss) previously wrote the ordinary +entry unconditionally. [`installer-migration.iss`](../../../scripts/installer-migration.iss) +already discovers distributions through Lxss, excludes Docker plumbing, and +protects WSL registration with executable ownership checks. The application +does not have an Explorer-registration settings adapter. + +## Decision + +Use one native installer checklist for the master switch, ordinary entry and +discovered WSL distributions. Re-running the installer edits the selection. +Keep the existing WSL cascade and commands. Persist DWORD choices under +`HKCU\Software\Pebrel\ExplorerMenu`, independently of application preferences. +The ordinary entry continues to launch the configured default shell. + +`Enabled` controls integration, `Default` controls the ordinary entry, and +`wsl:` records each distribution independently of enumeration +order. Absent choices inherit the existing all-enabled behavior until `Saved` +exists. Subsequently new distributions default to unchecked. Retain absent +distribution values so reinstalling a distribution restores its choice. Silent +upgrades read the same values. Turning the master off preserves individual values. + +Remove unconditional ordinary registry writes. Reconcile both Explorer roots +using exact ordinary command ownership and the existing WSL owner validation. +Keep foreign commands and unknown child subtrees; conflicting registration fails +visibly. Save the selection after the registrations succeed. + +## Rejected alternatives + +- A second registry adapter in the application duplicates installer ownership + and requires settings/startup coordination without being necessary for the + issue's installation option. +- Index-based preference names would attach choices to a different distribution + after enumeration changes. +- A new menu hierarchy is unnecessary: the existing WSL cascade is retained. +- Unconditionally writing menu keys during upgrades loses the user's selection. + +## Consequences + +These choices apply to the Inno installation channel, and take effect when the +installer completes. Changing them requires re-running the installer. This does +not add individual local-shell launch verbs, nor MSIX/Scoop integration. +Preferences survive uninstall, matching the retained user-configuration policy. +Legacy Inno uninstall logs may still contain the former ordinary entry's +`uninsdeletekey` action; this change does not rewrite historical uninstall logs. + +## Validation + +The maintained Inno fixture uses only `HKCU\Software\PebrelTestFixtures`. +It covers both cwd arguments, add/remove, master disable/restore, persistence, +enumeration changes, new distributions and foreign/edited keys. The Windows +input fixture drives the production checklist with mouse and keyboard events, +checks registered results and captures its states. Remote execution and visual +review are required; fixture compilation is not Explorer launch acceptance. + +## Supersedes + +The all-distributions registration policy in +[`2026-09-23-wsl-context-menu-cascade.md`](2026-09-23-wsl-context-menu-cascade.md). +The cascade layout and ownership policy remain. + +## Revisit when + +Users need to change integration without running the installer, or another +installation channel requires the same registration ownership. diff --git a/scripts/installer-context-menu.iss b/scripts/installer-context-menu.iss new file mode 100644 index 000000000..48c2f2398 --- /dev/null +++ b/scripts/installer-context-menu.iss @@ -0,0 +1,158 @@ +// Explorer choices belong to the installer, alongside its owned registrations. +var + ExplorerMenuPage: TInputOptionWizardPage; + ExplorerMenuDistros: TArrayOfString; + ExplorerMenuSettings: string; + +function ExplorerMenuChoice(Key, Name: string; Default: Boolean): Boolean; +var + Value: Cardinal; +begin + Result := Default; + if RegQueryDWordValue(HKCU, Key, Name, Value) then + Result := Value <> 0; +end; + +procedure ExplorerMenuSelectionChanged(Sender: TObject); +var + Index: Integer; +begin + for Index := 1 to ExplorerMenuPage.CheckListBox.Items.Count - 1 do + ExplorerMenuPage.CheckListBox.ItemEnabled[Index] := ExplorerMenuPage.Values[0]; +end; + +procedure CreateExplorerMenuPage(SettingsKey: string; Distros: TArrayOfString); +var + Index: Integer; + InitialSelection: Boolean; +begin + ExplorerMenuSettings := SettingsKey; + ExplorerMenuDistros := Distros; + InitialSelection := not RegValueExists(HKCU, SettingsKey, 'Saved'); + ExplorerMenuPage := CreateInputOptionPage(wpSelectDir, + CustomMessage('ExplorerMenuTitle'), CustomMessage('ExplorerMenuDescription'), + CustomMessage('ExplorerMenuHelp'), False, True); + ExplorerMenuPage.Add(CustomMessage('ExplorerMenuEnabled')); + ExplorerMenuPage.Values[0] := ExplorerMenuChoice(SettingsKey, 'Enabled', True); + ExplorerMenuPage.Add(CustomMessage('OpenInPebrel')); + ExplorerMenuPage.Values[1] := ExplorerMenuChoice(SettingsKey, 'Default', True); + for Index := 0 to GetArrayLength(Distros) - 1 do begin + ExplorerMenuPage.Add(CustomMessage('OpenInPebrel') + ' (' + Distros[Index] + ')'); + ExplorerMenuPage.Values[Index + 2] := + ExplorerMenuChoice(SettingsKey, 'wsl:' + Distros[Index], InitialSelection); + end; + ExplorerMenuPage.CheckListBox.OnClickCheck := @ExplorerMenuSelectionChanged; + ExplorerMenuSelectionChanged(nil); +end; + +procedure SaveExplorerMenuChoices; +var + Index: Integer; +begin + if not RegWriteDWordValue(HKCU, ExplorerMenuSettings, 'Enabled', + Ord(ExplorerMenuPage.Values[0])) or + not RegWriteDWordValue(HKCU, ExplorerMenuSettings, 'Default', + Ord(ExplorerMenuPage.Values[1])) then + RaiseException(CustomMessage('ExplorerMenuFailed')); + for Index := 0 to GetArrayLength(ExplorerMenuDistros) - 1 do + if not RegWriteDWordValue(HKCU, ExplorerMenuSettings, 'wsl:' + ExplorerMenuDistros[Index], + Ord(ExplorerMenuPage.Values[Index + 2])) then + RaiseException(CustomMessage('ExplorerMenuFailed')); + if not RegWriteDWordValue(HKCU, ExplorerMenuSettings, 'Saved', 1) then + RaiseException(CustomMessage('ExplorerMenuFailed')); +end; + +function SelectedExplorerMenuDistros: TArrayOfString; +var + Index, Count: Integer; +begin + SetArrayLength(Result, GetArrayLength(ExplorerMenuDistros)); + Count := 0; + if ExplorerMenuPage.Values[0] then + for Index := 0 to GetArrayLength(ExplorerMenuDistros) - 1 do + if ExplorerMenuPage.Values[Index + 2] then begin + Result[Count] := ExplorerMenuDistros[Index]; + Count := Count + 1; + end; + SetArrayLength(Result, Count); +end; + +function DefaultExplorerMenuCommand(Executable, DirectoryArgument: string): string; +begin + Result := '"' + Executable + '" --gpui --working-directory "' + DirectoryArgument + '"'; +end; + +function IsOwnedDefaultExplorerMenu(Key, Command: string): Boolean; +var + Existing: string; + Children: TArrayOfString; +begin + Result := RegQueryStringValue(HKCU, Key + '\command', '', Existing) and + (CompareText(Existing, Command) = 0) and + RegGetSubkeyNames(HKCU, Key, Children); + if Result then + Result := (GetArrayLength(Children) = 1) and + (CompareText(Children[0], 'command') = 0); + if Result then + Result := RegGetSubkeyNames(HKCU, Key + '\command', Children) and + (GetArrayLength(Children) = 0); +end; + +procedure UpdateDefaultExplorerMenuAt(Root, Executable, DirectoryArgument: string; + Enabled: Boolean); +var + Key, Command: string; +begin + Key := Root + '\Pebrel'; + Command := DefaultExplorerMenuCommand(Executable, DirectoryArgument); + if RegKeyExists(HKCU, Key) then begin + if not IsOwnedDefaultExplorerMenu(Key, Command) then begin + if Enabled then + RaiseException(FmtMessage(CustomMessage('ExplorerMenuConflict'), [Key])); + Exit; + end; + if not Enabled then begin + RemoveOwnedContextMenu(Key, Command); + Exit; + end; + end; + if not Enabled then + Exit; + if not RegWriteStringValue(HKCU, Key, 'MUIVerb', CustomMessage('OpenInPebrel')) or + not RegWriteStringValue(HKCU, Key, 'Icon', Executable + ',0') or + not RegWriteStringValue(HKCU, Key + '\command', '', Command) then + RaiseException(CustomMessage('ExplorerMenuFailed')); +end; + +procedure UpdateExplorerMenusAt(Root, Executable, DirectoryArgument: string); +var + Distros: TArrayOfString; +begin + Distros := SelectedExplorerMenuDistros; + if GetArrayLength(Distros) > 0 then + RegisterWslContextMenuAt(Root, Executable, DirectoryArgument, Distros) + else + RemoveOwnedWslContextMenusAt(Root, Executable); + UpdateDefaultExplorerMenuAt(Root, Executable, DirectoryArgument, + ExplorerMenuPage.Values[0] and ExplorerMenuPage.Values[1]); +end; + +procedure RegisterExplorerContextMenus; +var + Executable: string; +begin + Executable := ExpandConstant('{app}\pebrel.exe'); + UpdateExplorerMenusAt('Software\Classes\Directory\shell', Executable, '%1'); + UpdateExplorerMenusAt('Software\Classes\Directory\Background\shell', Executable, '%V'); + SaveExplorerMenuChoices; +end; + +procedure RemoveOwnedExplorerContextMenus; +var + Executable: string; +begin + Executable := ExpandConstant('{app}\pebrel.exe'); + RemoveOwnedWslContextMenus; + UpdateDefaultExplorerMenuAt('Software\Classes\Directory\shell', Executable, '%1', False); + UpdateDefaultExplorerMenuAt('Software\Classes\Directory\Background\shell', Executable, '%V', False); +end; diff --git a/scripts/installer-migration.iss b/scripts/installer-migration.iss index 07f0288de..da4cda952 100644 --- a/scripts/installer-migration.iss +++ b/scripts/installer-migration.iss @@ -102,18 +102,6 @@ begin ExpandConstant('{localappdata}\Programs\Pebrel')); end; -procedure InitializeWizard; -begin - { Reuse the registered directory for normal upgrades, so Inno recognizes it - as an existing installation. Keep the old-brand relocation suggestion and - an explicit /DIR selection intact. } - if (PreviousInstallDir <> '') and - (CompareText(ExtractFileName(NormalizedDirectory(PreviousInstallDir)), 'Nebula Terminal') = 0) and - (ExpandConstant('{param:DIR|}') = '') then - WizardForm.DirEdit.Text := SuggestedInstallDir(PreviousInstallDir, - ExpandConstant('{localappdata}\Programs\Pebrel')); -end; - procedure DiscoverLegacyInstallation; var Pending, UninstallCommand: string; @@ -410,17 +398,26 @@ begin end; end; -procedure RegisterWslContextMenus; -var - Distros: TArrayOfString; - Executable: string; +#include "installer-context-menu.iss" + +#ifndef MigrationFixture +procedure InitializeWizard; begin - Distros := WslDistroNames; - Executable := ExpandConstant('{app}\pebrel.exe'); - RegisterWslContextMenuAt('Software\Classes\Directory\shell', Executable, '%1', Distros); - RegisterWslContextMenuAt('Software\Classes\Directory\Background\shell', Executable, '%V', Distros); + { Reuse the registered directory for normal upgrades, so Inno recognizes it + as an existing installation. Keep the old-brand relocation suggestion and + an explicit /DIR selection intact. } + if (PreviousInstallDir <> '') and + (CompareText(ExtractFileName(NormalizedDirectory(PreviousInstallDir)), 'Nebula Terminal') = 0) and + (ExpandConstant('{param:DIR|}') = '') then + WizardForm.DirEdit.Text := SuggestedInstallDir(PreviousInstallDir, + ExpandConstant('{localappdata}\Programs\Pebrel')); + #ifndef AcceptanceFixture + CreateExplorerMenuPage(ProductSettingsKey + '\ExplorerMenu', WslDistroNames); + #endif end; +#endif + procedure MigrateLegacyIntegrations; var Executable, ExistingPath, Key: string; @@ -490,8 +487,9 @@ procedure CurStepChanged(CurStep: TSetupStep); begin if CurStep <> ssPostInstall then Exit; - { 与旧版迁移无关,装完就要做:菜单项取决于本机装了哪些 WSL 发行版。 } - RegisterWslContextMenus; + #ifndef AcceptanceFixture + RegisterExplorerContextMenus; + #endif if LegacyInstallDir = '' then Exit; try diff --git a/scripts/installer.iss b/scripts/installer.iss index a8d63eef6..f28406d18 100644 --- a/scripts/installer.iss +++ b/scripts/installer.iss @@ -109,6 +109,19 @@ chinesesimplified.MigrationFailed=Pebrel 已安装,但旧安装未能完全迁 chinesesimplified.MigrationPreflightFailed=无法检查旧安装:%1。尚未开始安装。 chinesesimplified.RemovePathFailed=无法从 PATH 中移除 Pebrel 安装目录。 +english.ExplorerMenuTitle=Explorer context menu +english.ExplorerMenuDescription=Choose which Pebrel entries appear in Explorer. +english.ExplorerMenuHelp=Run this installer again to change these choices. Upgrades keep your selection. New WSL distributions start unchecked after you save a selection. +english.ExplorerMenuEnabled=Enable Explorer context menu integration +english.ExplorerMenuConflict=An existing Pebrel context menu belongs to another installation or was edited, so it was preserved: %1. +english.ExplorerMenuFailed=Unable to update Explorer context menu entries or save your selection. +chinesesimplified.ExplorerMenuTitle=资源管理器右键菜单 +chinesesimplified.ExplorerMenuDescription=选择在资源管理器中显示哪些 Pebrel 入口。 +chinesesimplified.ExplorerMenuHelp=重新运行此安装器即可修改选项。升级会保留选择;保存选择后,新安装的 WSL 发行版默认不勾选。 +chinesesimplified.ExplorerMenuEnabled=启用资源管理器右键菜单集成 +chinesesimplified.ExplorerMenuConflict=现有 Pebrel 右键菜单属于其他安装或已被修改,因此已保留:%1。 +chinesesimplified.ExplorerMenuFailed=无法更新资源管理器右键菜单或保存选择。 + [Tasks] #ifndef AcceptanceFixture Name: "installfont"; Description: "{cm:InstallFont}" @@ -154,14 +167,6 @@ Root: HKCU; Subkey: "Software\Pebrel"; ValueType: dword; ValueName: "InstallerAd Root: HKCU; Subkey: "Environment"; ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"; Tasks: addtopath; Check: NeedsAddToPath; Flags: preservestringtype Root: HKCU; Subkey: "Software\Microsoft\Windows\CurrentVersion\App Paths\pebrel.exe"; ValueType: string; ValueName: ""; ValueData: "{app}\pebrel.exe"; Flags: uninsdeletekey Root: HKCU; Subkey: "Software\Microsoft\Windows\CurrentVersion\App Paths\pebrel.exe"; ValueType: string; ValueName: "Path"; ValueData: "{app}" -; 目录背景使用 %V,选中的目录对象使用 %1;两者必须由 Explorer 展开后再交给 CLI。 -; 每个动词使用独立的应用子键,卸载时只删除 Pebrel 自己注册的菜单。 -Root: HKCU; Subkey: "Software\Classes\Directory\Background\shell\Pebrel"; ValueType: string; ValueName: "MUIVerb"; ValueData: "{cm:OpenInPebrel}"; Flags: uninsdeletekey -Root: HKCU; Subkey: "Software\Classes\Directory\Background\shell\Pebrel"; ValueType: string; ValueName: "Icon"; ValueData: "{app}\pebrel.exe,0" -Root: HKCU; Subkey: "Software\Classes\Directory\Background\shell\Pebrel\command"; ValueType: string; ValueName: ""; ValueData: """{app}\pebrel.exe"" --gpui --working-directory ""%V""" -Root: HKCU; Subkey: "Software\Classes\Directory\shell\Pebrel"; ValueType: string; ValueName: "MUIVerb"; ValueData: "{cm:OpenInPebrel}"; Flags: uninsdeletekey -Root: HKCU; Subkey: "Software\Classes\Directory\shell\Pebrel"; ValueType: string; ValueName: "Icon"; ValueData: "{app}\pebrel.exe,0" -Root: HKCU; Subkey: "Software\Classes\Directory\shell\Pebrel\command"; ValueType: string; ValueName: ""; ValueData: """{app}\pebrel.exe"" --gpui --working-directory ""%1""" #endif [Run] @@ -196,7 +201,7 @@ begin { WSL 右键项是 [Code] 动态写的、没有 uninsdeletekey,必须自己认领删除; 这一步排在 PATH 那段的早退之前——两条互不依赖。 } - RemoveOwnedWslContextMenus; + RemoveOwnedExplorerContextMenus; if not RegValueExists(HKCU, 'Software\Pebrel', 'InstallerAddedToPath') then Exit; diff --git a/scripts/tests/installer-context-menu-fixture.iss b/scripts/tests/installer-context-menu-fixture.iss new file mode 100644 index 000000000..1359bd986 --- /dev/null +++ b/scripts/tests/installer-context-menu-fixture.iss @@ -0,0 +1,178 @@ +#ifndef FixtureRoot + #error FixtureRoot must point at an isolated test directory. +#endif +#define MigrationFixture + +[Setup] +AppId=PebrelExplorerMenuFixture +AppName=Pebrel Explorer Menu Fixture +AppVersion=0.0.0 +DefaultDirName={#FixtureRoot} +CreateAppDir=no +Uninstallable=no +PrivilegesRequired=lowest +OutputBaseFilename=installer-context-menu-fixture +Compression=none +DisableWelcomePage=yes +DisableDirPage=yes +DisableReadyPage=yes +DisableFinishedPage=yes + +[CustomMessages] +OpenInPebrel=Open in Pebrel +OpenInPebrelWsl=Open in Pebrel (WSL) +WslMenuConflict=Preserved an edited or foreign submenu: %1. +WslMenuRegistrationFailed=Unable to register the WSL context submenu. +ExplorerMenuTitle=Explorer context menu +ExplorerMenuDescription=Choose which Pebrel entries appear in Explorer. +ExplorerMenuHelp=Run this installer again to change these choices. Upgrades keep your selection. New WSL distributions start unchecked after you save a selection. +ExplorerMenuEnabled=Enable Explorer context menu integration +ExplorerMenuConflict=Preserved an edited or foreign context menu: %1. +ExplorerMenuFailed=Unable to update Explorer entries or save choices. + +[Code] +#include "..\installer-migration.iss" + +var + RegistryRoot, Executable: string; + Checks: Integer; + +procedure Check(Condition: Boolean; Name: string); +begin + if not Condition then + RaiseException(Name); + Checks := Checks + 1; +end; + +procedure CheckChoices; +var + Index: Integer; + Root, Argument, Value: string; + Names, Distros: TArrayOfString; + Failed: Boolean; +begin + Check(ExplorerMenuPage.Values[0] and ExplorerMenuPage.Values[1] and + ExplorerMenuPage.Values[2] and ExplorerMenuPage.Values[3], 'old configuration keeps all entries'); + for Index := 0 to 1 do begin + Root := RegistryRoot + '\root' + IntToStr(Index); + if Index = 0 then Argument := '%1' else Argument := '%V'; + UpdateExplorerMenusAt(Root, Executable, Argument); + Check(RegQueryStringValue(HKCU, Root + '\Pebrel\command', '', Value) and + (Value = DefaultExplorerMenuCommand(Executable, Argument)), 'ordinary entry keeps cwd argv'); + ExplorerMenuPage.Values[3] := False; + UpdateExplorerMenusAt(Root, Executable, Argument); + Check(RegGetSubkeyNames(HKCU, Root + '\PebrelWslMenu\shell', Names) and + (GetArrayLength(Names) = 1), 'deselected distro is removed'); + Check(RegQueryStringValue(HKCU, Root + '\PebrelWslMenu\shell\PebrelWsl0', + 'MUIVerb', Value) and (Value = 'Ubuntu Test'), 'selected distro remains'); + ExplorerMenuPage.Values[2] := False; + UpdateExplorerMenusAt(Root, Executable, Argument); + Check(not RegKeyExists(HKCU, Root + '\PebrelWslMenu') and + RegKeyExists(HKCU, Root + '\Pebrel'), 'zero selected distros removes only the cascade'); + ExplorerMenuPage.Values[2] := True; + ExplorerMenuPage.Values[1] := False; + UpdateExplorerMenusAt(Root, Executable, Argument); + Check(not RegKeyExists(HKCU, Root + '\Pebrel'), 'ordinary entry can be removed independently'); + ExplorerMenuPage.Values[1] := True; + ExplorerMenuPage.Values[3] := True; + UpdateExplorerMenusAt(Root, Executable, Argument); + Check(RegGetSubkeyNames(HKCU, Root + '\PebrelWslMenu\shell', Names) and + (GetArrayLength(Names) = 2), 'reselected distro is added'); + ExplorerMenuPage.Values[0] := False; + UpdateExplorerMenusAt(Root, Executable, Argument); + Check(not RegKeyExists(HKCU, Root + '\Pebrel') and + not RegKeyExists(HKCU, Root + '\PebrelWslMenu'), 'master removes owned entries'); + Check(ExplorerMenuPage.Values[2] and ExplorerMenuPage.Values[3], 'master preserves individual choices'); + ExplorerMenuPage.Values[0] := True; + UpdateExplorerMenusAt(Root, Executable, Argument); + Check(RegWriteStringValue(HKCU, Root + '\Pebrel\Custom', '', 'user data'), 'seed edited ordinary key'); + UpdateDefaultExplorerMenuAt(Root, Executable, Argument, False); + Check(RegKeyExists(HKCU, Root + '\Pebrel\Custom'), 'edited subtree survives removal'); + Failed := False; + try + UpdateDefaultExplorerMenuAt(Root, Executable, Argument, True); + except + Failed := True; + end; + Check(Failed, 'edited ordinary key fails visibly on registration'); + Check(RegDeleteKeyIncludingSubkeys(HKCU, Root + '\Pebrel'), 'clear fixture ordinary key'); + Check(RegWriteStringValue(HKCU, Root + '\Pebrel\command', '', 'foreign command'), 'seed foreign ordinary key'); + UpdateDefaultExplorerMenuAt(Root, Executable, Argument, False); + Check(RegQueryStringValue(HKCU, Root + '\Pebrel\command', '', Value) and + (Value = 'foreign command'), 'foreign ordinary command survives removal'); + Check(RegWriteStringValue(HKCU, Root + '\PebrelWslForeign\command', '', + '"D:\other\pebrel.exe" --gpui --shell "wsl:Foreign"'), 'seed foreign WSL key'); + ExplorerMenuPage.Values[0] := False; + UpdateExplorerMenusAt(Root, Executable, Argument); + Check(RegKeyExists(HKCU, Root + '\PebrelWslForeign'), 'master preserves foreign WSL entry'); + ExplorerMenuPage.Values[0] := True; + end; + ExplorerMenuPage.Values[0] := False; + ExplorerMenuPage.Values[1] := False; + ExplorerMenuPage.Values[3] := False; + SaveExplorerMenuChoices; + Distros := ExplorerMenuDistros; + SetArrayLength(Distros, 3); + Distros[0] := '开发环境'; + Distros[1] := 'Ubuntu Test'; + Distros[2] := 'New Distro'; + CreateExplorerMenuPage(ExplorerMenuSettings, Distros); + Check(not ExplorerMenuPage.Values[0] and not ExplorerMenuPage.Values[1], 'upgrade keeps master and ordinary choices'); + Check(not ExplorerMenuPage.Values[2] and ExplorerMenuPage.Values[3], 'distro names preserve choices across enumeration order changes'); + Check(not ExplorerMenuPage.Values[4], 'new distro starts unchecked after opt-in selection'); + Check(not ExplorerMenuPage.CheckListBox.ItemEnabled[3], 'master visibly disables rows'); + ExplorerMenuPage.Values[0] := True; + ExplorerMenuSelectionChanged(nil); + Check(ExplorerMenuPage.CheckListBox.ItemEnabled[3], 'master re-enables rows'); + SaveExplorerMenuChoices; + Check(ExplorerMenuChoice(ExplorerMenuSettings, 'Enabled', False) and + ExplorerMenuChoice(ExplorerMenuSettings, 'wsl:Ubuntu Test', False), 'selection roundtrip'); +end; + +procedure InitializeWizard; +var + Distros: TArrayOfString; + Report: string; +begin + RegistryRoot := 'Software\PebrelTestFixtures\' + ExtractFileName(ExpandConstant('{#FixtureRoot}')); + Executable := ExpandConstant('{#FixtureRoot}') + '\Program Files\pebrel.exe'; + SetArrayLength(Distros, 2); + Distros[0] := 'Ubuntu Test'; + Distros[1] := '开发环境'; + CreateExplorerMenuPage(RegistryRoot + '\Choices', Distros); + if ExpandConstant('{param:ExplorerUi|0}') = '1' then + Exit; + try + try + CheckChoices; + Report := 'PASS: ' + IntToStr(Checks) + ' Explorer selection checks'; + except + Report := 'FAIL: ' + GetExceptionMessage; + end; + SaveStringToFile(ExpandConstant('{#FixtureRoot}') + '\choices-result.txt', Report, False); + finally + RegDeleteKeyIncludingSubkeys(HKCU, RegistryRoot); + end; +end; + +procedure CurPageChanged(CurPageID: Integer); +var + Coordinates: string; +begin + if (ExpandConstant('{param:ExplorerUi|0}') = '1') and + (CurPageID = ExplorerMenuPage.ID) then begin + ExplorerMenuPage.CheckListBox.SetFocus; + Coordinates := IntToStr(ExplorerMenuPage.CheckListBox.Handle); + SaveStringToFile(ExpandConstant('{#FixtureRoot}') + '\ui-handle.txt', Coordinates, False); + end; +end; + +procedure CurStepChanged(CurStep: TSetupStep); +begin + if (ExpandConstant('{param:ExplorerUi|0}') = '1') and (CurStep = ssPostInstall) then begin + UpdateExplorerMenusAt(RegistryRoot + '\selected', Executable, '%1'); + UpdateExplorerMenusAt(RegistryRoot + '\background', Executable, '%V'); + SaveExplorerMenuChoices; + SaveStringToFile(ExpandConstant('{#FixtureRoot}') + '\ui-result.txt', 'PASS', False); + end; +end; diff --git a/scripts/tests/installer-context-menu.tests.ps1 b/scripts/tests/installer-context-menu.tests.ps1 new file mode 100644 index 000000000..d073182be --- /dev/null +++ b/scripts/tests/installer-context-menu.tests.ps1 @@ -0,0 +1,121 @@ +[CmdletBinding()] +param([Parameter(Mandatory)][string] $InnoCompiler) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version Latest +$repo = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path +$root = Join-Path $repo ('tmp\explorer-menu-' + [guid]::NewGuid().ToString('N')) +$registryRoot = 'Software\PebrelTestFixtures\' + (Split-Path $root -Leaf) +New-Item -ItemType Directory -Path $root | Out-Null +& $InnoCompiler '/Q' "/DFixtureRoot=$root" "/O$root" (Join-Path $PSScriptRoot 'installer-context-menu-fixture.iss') +if ($LASTEXITCODE -ne 0) { throw 'Explorer fixture compilation failed.' } +$executable = Join-Path $root 'installer-context-menu-fixture.exe' +$process = Start-Process $executable -ArgumentList '/VERYSILENT', '/SUPPRESSMSGBOXES' -Wait -PassThru +$report = Get-Content (Join-Path $root 'choices-result.txt') -Raw -Encoding UTF8 +if ($process.ExitCode -ne 0 -or -not $report.StartsWith('PASS: ')) { throw $report } +Write-Output $report + +Add-Type -AssemblyName System.Windows.Forms, System.Drawing +Add-Type @' +using System; +using System.Runtime.InteropServices; +public static class ExplorerFixtureInput { + [StructLayout(LayoutKind.Sequential)] public struct Rect { public int Left, Top, Right, Bottom; } + [StructLayout(LayoutKind.Sequential)] public struct Point { public int X, Y; } + [DllImport("user32.dll")] public static extern bool ClientToScreen(IntPtr hwnd, ref Point point); + [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hwnd, uint message, IntPtr row, ref Rect rect); + [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hwnd, out Rect rect); + [DllImport("user32.dll")] public static extern IntPtr GetAncestor(IntPtr hwnd, uint flags); + [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hwnd); + [DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y); + [DllImport("user32.dll")] public static extern void mouse_event(uint flags, uint x, uint y, uint data, UIntPtr extra); +} +'@ + +function Wait-ForFile([string] $path, $process) { + $deadline = [datetime]::UtcNow.AddSeconds(20) + while (-not (Test-Path $path)) { + if ($process.HasExited -or [datetime]::UtcNow -gt $deadline) { throw "Fixture did not reach $path" } + Start-Sleep -Milliseconds 100 + } +} + +function Click-Row([IntPtr] $handle, [int] $row) { + $rect = [ExplorerFixtureInput+Rect]::new() + if ([ExplorerFixtureInput]::SendMessage($handle, 0x198, [IntPtr]$row, [ref]$rect).ToInt64() -lt 0) { + throw "Cannot locate checkbox row $row" + } + $point = [ExplorerFixtureInput+Point]::new() + $point.X = 8 + $point.Y = ($rect.Top + $rect.Bottom) / 2 + [void][ExplorerFixtureInput]::ClientToScreen($handle, [ref]$point) + [void][ExplorerFixtureInput]::SetCursorPos($point.X, $point.Y) + [ExplorerFixtureInput]::mouse_event(2, 0, 0, 0, [UIntPtr]::Zero) + [ExplorerFixtureInput]::mouse_event(4, 0, 0, 0, [UIntPtr]::Zero) + Start-Sleep -Milliseconds 100 +} + +function Save-Window([IntPtr] $windowHandle, [string] $name) { + $rect = [ExplorerFixtureInput+Rect]::new() + [void][ExplorerFixtureInput]::GetWindowRect($windowHandle, [ref]$rect) + $bitmap = [Drawing.Bitmap]::new($rect.Right - $rect.Left, $rect.Bottom - $rect.Top) + $graphics = [Drawing.Graphics]::FromImage($bitmap) + try { + $graphics.CopyFromScreen($rect.Left, $rect.Top, 0, 0, $bitmap.Size) + $bitmap.Save((Join-Path $root "$name.png")) + } finally { + $graphics.Dispose() + $bitmap.Dispose() + } +} + +function Run-Ui([string] $phase, [scriptblock] $actions) { + Remove-Item (Join-Path $root 'ui-handle.txt'), (Join-Path $root 'ui-result.txt') -ErrorAction SilentlyContinue + $process = Start-Process $executable -ArgumentList '/ExplorerUi=1' -PassThru + try { + Wait-ForFile (Join-Path $root 'ui-handle.txt') $process + $handle = [IntPtr][long](Get-Content (Join-Path $root 'ui-handle.txt') -Raw) + $windowHandle = [ExplorerFixtureInput]::GetAncestor($handle, 2) + [void][ExplorerFixtureInput]::SetForegroundWindow($windowHandle) + Save-Window $windowHandle "$phase-before" + & $actions $handle + Save-Window $windowHandle "$phase-after" + [Windows.Forms.SendKeys]::SendWait('%n') + Wait-ForFile (Join-Path $root 'ui-result.txt') $process + if (-not $process.WaitForExit(20000) -or $process.ExitCode -ne 0) { throw 'UI fixture failed to finish.' } + } finally { + if (-not $process.HasExited) { $process.Kill() } + } +} + +try { + Run-Ui 'choose' { param($handle) Click-Row $handle 3 } + $choices = Get-ItemProperty "HKCU:\$registryRoot\Choices" + if ($choices.Enabled -ne 1 -or $choices.Default -ne 1 -or + $choices.'wsl:Ubuntu Test' -ne 1 -or $choices.'wsl:开发环境' -ne 0) { throw 'Mouse checkbox selection was not saved.' } + foreach ($scope in @('selected', 'background')) { + $children = @(Get-ChildItem "HKCU:\$registryRoot\$scope\PebrelWslMenu\shell") + if ($children.Count -ne 1) { throw 'UI did not remove the deselected distribution.' } + } + Run-Ui 'disable' { param($handle) + # Keyboard operates the actual focused checklist, including the master switch. + [Windows.Forms.SendKeys]::SendWait('{HOME} ') + Click-Row $handle 2 + } + $choices = Get-ItemProperty "HKCU:\$registryRoot\Choices" + if ($choices.Enabled -ne 0 -or $choices.'wsl:Ubuntu Test' -ne 1) { throw 'Master toggle lost or changed a disabled choice.' } + foreach ($scope in @('selected', 'background')) { + if (Test-Path "HKCU:\$registryRoot\$scope\Pebrel") { throw 'Disabled ordinary entry remained.' } + if (Test-Path "HKCU:\$registryRoot\$scope\PebrelWslMenu") { throw 'Disabled WSL entry remained.' } + } + Run-Ui 'restore' { param($handle) Click-Row $handle 0 } + $choices = Get-ItemProperty "HKCU:\$registryRoot\Choices" + if ($choices.Enabled -ne 1 -or $choices.'wsl:开发环境' -ne 0) { throw 'Upgrade changed the stored selection.' } + foreach ($scope in @('selected', 'background')) { + if (@(Get-ChildItem "HKCU:\$registryRoot\$scope\PebrelWslMenu\shell").Count -ne 1) { throw 'Re-enable did not restore only the selected distribution.' } + } + Write-Output 'PASS: native installer mouse selection, keyboard master toggle, disabled input, persistence and restore' + Write-Output "Fixture evidence: $root" +} finally { + Remove-Item "HKCU:\$registryRoot" -Recurse -Force -ErrorAction SilentlyContinue +} diff --git a/scripts/tests/installer-migration.tests.ps1 b/scripts/tests/installer-migration.tests.ps1 index 6202533a6..439acd247 100644 --- a/scripts/tests/installer-migration.tests.ps1 +++ b/scripts/tests/installer-migration.tests.ps1 @@ -50,6 +50,7 @@ try { (Join-Path $repo 'scripts\installer.iss') if ($LASTEXITCODE -ne 0) { throw 'Full installer syntax compilation failed.' } Write-Output 'installer-migration.tests.ps1: full installer compilation PASS (not executed)' + & (Join-Path $PSScriptRoot 'installer-context-menu.tests.ps1') -InnoCompiler $InnoCompiler Write-Output "Fixture evidence: $root" } finally { $env:TEMP = $previousTemp diff --git a/scripts/tests/installer.tests.ps1 b/scripts/tests/installer.tests.ps1 index 9d42c6967..315585356 100644 --- a/scripts/tests/installer.tests.ps1 +++ b/scripts/tests/installer.tests.ps1 @@ -11,6 +11,7 @@ $builderPath = Join-Path $repo 'scripts\build-installer.ps1' $installer = Get-Content -LiteralPath $installerPath -Raw -Encoding UTF8 $migration = Get-Content -LiteralPath $migrationPath -Raw -Encoding UTF8 +$contextMenu = Get-Content -LiteralPath (Join-Path $repo 'scripts\installer-context-menu.iss') -Raw -Encoding UTF8 $requiredPatterns = [ordered]@{ 'migration-aware installation directory' = 'DefaultDirName=\{code:DefaultInstallDir\}' 'registered previous-directory reuse' = 'UsePreviousAppDir=yes' @@ -39,12 +40,9 @@ $requiredPatterns = [ordered]@{ 'localized Chinese context menu label' = 'chinesesimplified\.OpenInPebrel=\S.+' 'localized WSL context menu label' = 'english\.OpenInPebrelWsl=Open in Pebrel' 'localized Chinese WSL context menu label' = 'chinesesimplified\.OpenInPebrelWsl=\S.+' - 'WSL context menu uninstall cleanup' = 'RemoveOwnedWslContextMenus;' - 'directory background context menu' = 'Software\\Classes\\Directory\\Background\\shell\\Pebrel' - 'selected directory context menu' = 'Software\\Classes\\Directory\\shell\\Pebrel' - 'context menu executable icon' = 'ValueName: "Icon"; ValueData: "\{app\}\\pebrel\.exe,0"' - 'background working-directory command' = '--gpui --working-directory ""%V""' - 'selected directory working-directory command' = '--gpui --working-directory ""%1""' + 'owned context menu uninstall cleanup' = 'RemoveOwnedExplorerContextMenus;' + 'localized Explorer menu master switch' = 'english\.ExplorerMenuEnabled=Enable Explorer context menu integration' + 'localized Chinese Explorer menu master switch' = 'chinesesimplified\.ExplorerMenuEnabled=\S.+' 'PATH task' = 'Name: "addtopath"; Description: "\{cm:AddToPath\}"' 'PATH registry entry' = 'Subkey: "Environment"; ValueType: expandsz; ValueName: "Path"' 'PATH ownership marker' = 'ValueName: "InstallerAddedToPath"' @@ -85,16 +83,24 @@ if ($uninstallRun -lt 0 -or $cleanup -lt $uninstallRun) { throw 'Hook cleanup must be an [UninstallRun] action so it executes before installed files are deleted.' } -$contextMenuRoots = @( - 'Software\Classes\Directory\Background\shell\Pebrel' - 'Software\Classes\Directory\shell\Pebrel' -) -foreach ($root in $contextMenuRoots) { - $escapedRoot = [regex]::Escape($root) - if ($installer -notmatch "Subkey: `"$escapedRoot`";.*Flags: uninsdeletekey") { - throw "Context-menu key must be removed during uninstall: $root" +$contextMenuPatterns = [ordered]@{ + 'directory background root' = 'Software\\Classes\\Directory\\Background\\shell' + 'selected directory root' = 'Software\\Classes\\Directory\\shell' + 'working-directory command' = '--gpui --working-directory' + 'executable icon' = "'Icon', Executable \+ ',0'" + 'master switch' = 'ExplorerMenuPage.Values\[0\]' + 'saved choices' = 'SaveExplorerMenuChoices;' + 'exact ordinary command ownership' = 'CompareText\(Existing, Command\) = 0' + 'owned ordinary uninstall cleanup' = 'UpdateDefaultExplorerMenuAt.*False\);' +} +foreach ($entry in $contextMenuPatterns.GetEnumerator()) { + if ($contextMenu -notmatch $entry.Value) { + throw "Explorer context-menu implementation is missing $($entry.Key): $($entry.Value)" } } +if ($installer -match 'Subkey: "Software\\Classes\\Directory.*shell\\Pebrel') { + throw 'Unconditional registry entries would overwrite the saved Explorer selection.' +} $migrationPatterns = [ordered]@{ 'per-user Pebrel default' = '\{localappdata\}\\Programs\\Pebrel' @@ -123,7 +129,7 @@ $wslPatterns = [ordered]@{ 'WSL distribution registry' = 'Software\\Microsoft\\Windows\\CurrentVersion\\Lxss' 'plumbing distros are skipped' = "Pos\('docker-desktop'" 'distinct verb namespace' = "'PebrelWsl' \+ IntToStr\(Index\)" - 'registration runs at post-install' = 'RegisterWslContextMenus;' + 'registration runs at post-install' = 'RegisterExplorerContextMenus;' 'owned keys are reclaimed by prefix and command' = "Pos\('PebrelWsl', Names\[NameIndex\]\) = 1" 'uninstall sweeps both roots' = "Directory\\Background\\shell'" } From a80783a593014ce01fdcc98e6959d0a9a554d213 Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Sat, 3 Oct 2026 16:33:20 +0800 Subject: [PATCH 2/5] test(installer): adapt identity and native checklist checks --- scripts/tests/installer-context-menu-fixture.iss | 2 +- scripts/tests/test_pebrel_branding.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/tests/installer-context-menu-fixture.iss b/scripts/tests/installer-context-menu-fixture.iss index 1359bd986..992ebac3f 100644 --- a/scripts/tests/installer-context-menu-fixture.iss +++ b/scripts/tests/installer-context-menu-fixture.iss @@ -161,7 +161,7 @@ var begin if (ExpandConstant('{param:ExplorerUi|0}') = '1') and (CurPageID = ExplorerMenuPage.ID) then begin - ExplorerMenuPage.CheckListBox.SetFocus; + WizardForm.ActiveControl := ExplorerMenuPage.CheckListBox; Coordinates := IntToStr(ExplorerMenuPage.CheckListBox.Handle); SaveStringToFile(ExpandConstant('{#FixtureRoot}') + '\ui-handle.txt', Coordinates, False); end; diff --git a/scripts/tests/test_pebrel_branding.py b/scripts/tests/test_pebrel_branding.py index fd9332731..529766125 100644 --- a/scripts/tests/test_pebrel_branding.py +++ b/scripts/tests/test_pebrel_branding.py @@ -49,7 +49,6 @@ def test_installer_migrates_names_and_keeps_upgrade_identity(self): "UsePreviousAppDir=yes", r"Software\Pebrel", r"App Paths\pebrel.exe", - r"shell\Pebrel", r'Source: "{#BuildRoot}\pebrel.exe";', r'Source: "{#BuildRoot}\pebrel-hook.exe";', 'RunOnceId: "RemovePebrelAiHooks"', @@ -62,6 +61,12 @@ def test_installer_migrates_names_and_keeps_upgrade_identity(self): migration = self.source("scripts/installer-migration.iss") self.assertIn(r"{localappdata}\Programs\Pebrel", migration) self.assertIn(r"Software\Nebula Terminal", migration) + self.assertIn('#include "installer-context-menu.iss"', migration) + context_menu = self.source("scripts/installer-context-menu.iss") + self.assertIn(r"Key := Root + '\Pebrel';", context_menu) + for root in (r"Software\Classes\Directory\shell", r"Software\Classes\Directory\Background\shell"): + with self.subTest(root=root): + self.assertIn(f"UpdateExplorerMenusAt('{root}', Executable,", context_menu) def test_pebrel_assets_are_default_and_keep_explicit_legacy_alias(self): for path in ("scripts/package-release.ps1", "scripts/build-installer.ps1"): From d74d66b1f70ad843b24eb4813ee1e10880f7e31e Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Sat, 3 Oct 2026 16:45:14 +0800 Subject: [PATCH 3/5] test(installer): capture painted native checklist states --- scripts/tests/installer-context-menu.tests.ps1 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/tests/installer-context-menu.tests.ps1 b/scripts/tests/installer-context-menu.tests.ps1 index d073182be..f234cc5a0 100644 --- a/scripts/tests/installer-context-menu.tests.ps1 +++ b/scripts/tests/installer-context-menu.tests.ps1 @@ -26,6 +26,9 @@ public static class ExplorerFixtureInput { [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hwnd, uint message, IntPtr row, ref Rect rect); [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hwnd, out Rect rect); [DllImport("user32.dll")] public static extern IntPtr GetAncestor(IntPtr hwnd, uint flags); + [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint processId); + [DllImport("user32.dll")] public static extern bool RedrawWindow(IntPtr hwnd, IntPtr rect, IntPtr region, uint flags); + [DllImport("dwmapi.dll")] public static extern int DwmFlush(); [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hwnd); [DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y); [DllImport("user32.dll")] public static extern void mouse_event(uint flags, uint x, uint y, uint data, UIntPtr extra); @@ -56,6 +59,8 @@ function Click-Row([IntPtr] $handle, [int] $row) { } function Save-Window([IntPtr] $windowHandle, [string] $name) { + [void][ExplorerFixtureInput]::RedrawWindow($windowHandle, [IntPtr]::Zero, [IntPtr]::Zero, 0x181) + [void][ExplorerFixtureInput]::DwmFlush() $rect = [ExplorerFixtureInput+Rect]::new() [void][ExplorerFixtureInput]::GetWindowRect($windowHandle, [ref]$rect) $bitmap = [Drawing.Bitmap]::new($rect.Right - $rect.Left, $rect.Bottom - $rect.Top) @@ -76,6 +81,11 @@ function Run-Ui([string] $phase, [scriptblock] $actions) { Wait-ForFile (Join-Path $root 'ui-handle.txt') $process $handle = [IntPtr][long](Get-Content (Join-Path $root 'ui-handle.txt') -Raw) $windowHandle = [ExplorerFixtureInput]::GetAncestor($handle, 2) + $windowProcessId = [uint32]0 + [void][ExplorerFixtureInput]::GetWindowThreadProcessId($windowHandle, [ref]$windowProcessId) + if (-not [Diagnostics.Process]::GetProcessById($windowProcessId).WaitForInputIdle(20000)) { + throw 'Installer did not complete its initial UI rendering.' + } [void][ExplorerFixtureInput]::SetForegroundWindow($windowHandle) Save-Window $windowHandle "$phase-before" & $actions $handle From f559d14032050adbdce60b796037af1852acdebd Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Sat, 3 Oct 2026 17:24:06 +0800 Subject: [PATCH 4/5] fix(installer): preserve unknown WSL verb descendants --- .../2026-10-03-explorer-menu-selection.md | 8 +++ scripts/installer-context-menu.iss | 13 +--- scripts/installer-migration.iss | 34 +++++++--- .../tests/installer-context-menu-fixture.iss | 65 +++++++++++++++++++ 4 files changed, 102 insertions(+), 18 deletions(-) diff --git a/architecture/notes/packaging/2026-10-03-explorer-menu-selection.md b/architecture/notes/packaging/2026-10-03-explorer-menu-selection.md index 8f2992e3c..45f61b4e6 100644 --- a/architecture/notes/packaging/2026-10-03-explorer-menu-selection.md +++ b/architecture/notes/packaging/2026-10-03-explorer-menu-selection.md @@ -39,6 +39,12 @@ using exact ordinary command ownership and the existing WSL owner validation. Keep foreign commands and unknown child subtrees; conflicting registration fails visibly. Save the selection after the registrations succeed. +Executable ownership alone cannot authorize recursive deletion: the previous +WSL check accepted a verb whose command still belonged to Pebrel even when a +user added descendants below the verb or its `command` key. A shared structural +check now requires one `command` child and no descendants below it for ordinary, +WSL cascade and legacy flat verbs. Unknown descendants preserve the whole menu. + ## Rejected alternatives - A second registry adapter in the application duplicates installer ownership @@ -66,6 +72,8 @@ enumeration changes, new distributions and foreign/edited keys. The Windows input fixture drives the production checklist with mouse and keyboard events, checks registered results and captures its states. Remote execution and visual review are required; fixture compilation is not Explorer launch acceptance. +The unknown-descendant regression covers both verb/command levels in both roots, +for all-WSL deselection, master disable, legacy flat removal and submenu rebuild. ## Supersedes diff --git a/scripts/installer-context-menu.iss b/scripts/installer-context-menu.iss index 48c2f2398..2cd21e78e 100644 --- a/scripts/installer-context-menu.iss +++ b/scripts/installer-context-menu.iss @@ -85,17 +85,10 @@ end; function IsOwnedDefaultExplorerMenu(Key, Command: string): Boolean; var Existing: string; - Children: TArrayOfString; begin - Result := RegQueryStringValue(HKCU, Key + '\command', '', Existing) and - (CompareText(Existing, Command) = 0) and - RegGetSubkeyNames(HKCU, Key, Children); - if Result then - Result := (GetArrayLength(Children) = 1) and - (CompareText(Children[0], 'command') = 0); - if Result then - Result := RegGetSubkeyNames(HKCU, Key + '\command', Children) and - (GetArrayLength(Children) = 0); + Result := IsSingleCommandVerb(Key) and + RegQueryStringValue(HKCU, Key + '\command', '', Existing) and + (CompareText(Existing, Command) = 0); end; procedure UpdateDefaultExplorerMenuAt(Root, Executable, DirectoryArgument: string; diff --git a/scripts/installer-migration.iss b/scripts/installer-migration.iss index da4cda952..c6ee9c3ec 100644 --- a/scripts/installer-migration.iss +++ b/scripts/installer-migration.iss @@ -306,9 +306,31 @@ begin Result := CompareText(Copy(Command, 1, Length(Prefix)), Prefix) = 0; end; +function IsSingleCommandVerb(Key: string): Boolean; +var + Children: TArrayOfString; +begin + Result := RegGetSubkeyNames(HKCU, Key, Children); + if Result then + Result := (GetArrayLength(Children) = 1) and + (CompareText(Children[0], 'command') = 0); + if Result then + Result := RegGetSubkeyNames(HKCU, Key + '\command', Children) and + (GetArrayLength(Children) = 0); +end; + +function IsOwnedWslVerb(Key, Executable: string): Boolean; +var + Command: string; +begin + Result := IsSingleCommandVerb(Key) and + RegQueryStringValue(HKCU, Key + '\command', '', Command) and + IsOwnedWslCommand(Command, Executable); +end; + function IsOwnedWslMenu(Key, Executable: string): Boolean; var - Owner, Command: string; + Owner: string; Children, Subkeys: TArrayOfString; Index: Integer; begin @@ -325,8 +347,7 @@ begin if not RegGetSubkeyNames(HKCU, Key + '\shell', Children) then Exit; for Index := 0 to GetArrayLength(Children) - 1 do begin - if not RegQueryStringValue(HKCU, Key + '\shell\' + Children[Index] + '\command', '', Command) or - not IsOwnedWslCommand(Command, Executable) then + if not IsOwnedWslVerb(Key + '\shell\' + Children[Index], Executable) then Exit; end; end; @@ -335,7 +356,7 @@ end; procedure RemoveOwnedWslContextMenusAt(Root, Executable: string); var - Key, Command: string; + Key: string; Names: TArrayOfString; NameIndex: Integer; begin @@ -343,10 +364,7 @@ begin for NameIndex := 0 to GetArrayLength(Names) - 1 do if Pos('PebrelWsl', Names[NameIndex]) = 1 then begin Key := Root + '\' + Names[NameIndex]; - Command := ''; - if IsOwnedWslMenu(Key, Executable) or - (RegQueryStringValue(HKCU, Key + '\command', '', Command) and - IsOwnedWslCommand(Command, Executable)) then + if IsOwnedWslMenu(Key, Executable) or IsOwnedWslVerb(Key, Executable) then if not RegDeleteKeyIncludingSubkeys(HKCU, Key) then RaiseException('Unable to remove an owned WSL context menu: ' + Key); end; diff --git a/scripts/tests/installer-context-menu-fixture.iss b/scripts/tests/installer-context-menu-fixture.iss index 992ebac3f..5d4d178e2 100644 --- a/scripts/tests/installer-context-menu-fixture.iss +++ b/scripts/tests/installer-context-menu-fixture.iss @@ -44,6 +44,70 @@ begin Checks := Checks + 1; end; +procedure CheckEditedWslSubtrees; +var + Root, Argument, Verb, Custom, Value, Report: string; + RootIndex, Depth, Mode, Failures: Integer; + Failed, Preserved: Boolean; +begin + Report := ''; + Failures := 0; + for RootIndex := 0 to 1 do + for Depth := 0 to 1 do + for Mode := 0 to 3 do begin + Root := RegistryRoot + '\structure' + IntToStr(RootIndex); + if RootIndex = 0 then Argument := '%1' else Argument := '%V'; + RegDeleteKeyIncludingSubkeys(HKCU, Root); + ExplorerMenuPage.Values[0] := True; + ExplorerMenuPage.Values[2] := True; + ExplorerMenuPage.Values[3] := True; + if Mode = 2 then begin + Verb := Root + '\PebrelWsl0'; + Check(RegWriteStringValue(HKCU, Verb + '\command', '', + '"' + Executable + '" --gpui --shell "wsl:Ubuntu Test" --working-directory "' + Argument + '"'), + 'seed owned legacy flat verb'); + end else begin + UpdateExplorerMenusAt(Root, Executable, Argument); + Verb := Root + '\PebrelWslMenu\shell\PebrelWsl0'; + end; + Custom := Verb; + if Depth = 1 then Custom := Custom + '\command'; + Custom := Custom + '\Custom'; + Check(RegWriteStringValue(HKCU, Custom, '', 'user data'), 'seed unknown WSL descendant'); + Failed := False; + if Mode = 2 then + RemoveOwnedWslContextMenusAt(Root, Executable) + else begin + if Mode = 0 then begin + ExplorerMenuPage.Values[2] := False; + ExplorerMenuPage.Values[3] := False; + end else if Mode = 1 then + ExplorerMenuPage.Values[0] := False + else + ExplorerMenuPage.Values[3] := False; + try + UpdateExplorerMenusAt(Root, Executable, Argument); + except + Failed := True; + end; + end; + Preserved := RegQueryStringValue(HKCU, Custom, '', Value) and (Value = 'user data'); + if Mode = 3 then Preserved := Preserved and Failed + else Preserved := Preserved and not Failed; + if Preserved then Report := Report + 'PASS: ' else begin + Report := Report + 'FAIL: '; + Failures := Failures + 1; + end; + Report := Report + 'root=' + IntToStr(RootIndex) + ' depth=' + IntToStr(Depth) + + ' mode=' + IntToStr(Mode) + #13#10; + end; + SaveStringToFile(ExpandConstant('{#FixtureRoot}') + '\wsl-structure-result.txt', Report, False); + ExplorerMenuPage.Values[0] := True; + ExplorerMenuPage.Values[2] := True; + ExplorerMenuPage.Values[3] := True; + Check(Failures = 0, 'unknown WSL verb/command descendants were deleted or overwritten'); +end; + procedure CheckChoices; var Index: Integer; @@ -144,6 +208,7 @@ begin Exit; try try + CheckEditedWslSubtrees; CheckChoices; Report := 'PASS: ' + IntToStr(Checks) + ' Explorer selection checks'; except From c2815907b027074bda36d9f215691200e4511681 Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Tue, 6 Oct 2026 23:20:06 +0800 Subject: [PATCH 5/5] ci: rerun native tests after unrelated flaky failure