From 9d9375a184aa54d3efe39e6c52c618b8be68bf16 Mon Sep 17 00:00:00 2001 From: Colin Neilens Date: Thu, 12 Nov 2026 18:18:55 -0700 Subject: [PATCH] Verify Delete Loop modal identity Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Signed-off-by: Colin Neilens --- .../Tests/CanvasCardContextMenu.Tests.ps1 | 12 +++++++++ .../windows/Tests/ValidationRunner.Tests.ps1 | 26 ++++++++++++++----- Tools/windows/Tests/WindowsShell.Tests.ps1 | 4 +-- .../Ui/UiDerivedContracts.ps1 | 13 +++++++--- Tools/windows/uia-live-gate.ps1 | 15 ++++++++--- 5 files changed, 55 insertions(+), 15 deletions(-) diff --git a/Tools/windows/Tests/CanvasCardContextMenu.Tests.ps1 b/Tools/windows/Tests/CanvasCardContextMenu.Tests.ps1 index e17c14f2..df48bc83 100644 --- a/Tools/windows/Tests/CanvasCardContextMenu.Tests.ps1 +++ b/Tools/windows/Tests/CanvasCardContextMenu.Tests.ps1 @@ -141,4 +141,16 @@ Describe "Stable canvas card context menu (managed mocks only)" { $source | Should -Match '\$deleteLoopPopup = Open-CanvasCardContextMenu \$process \$root \$shellWindow' $source | Should -Not -Match 'PostContextMenu\(\$shellWindow, 3\)\)\s*`\s*"Delete Loop' } + It "requires an exact owned modal completion for the Delete Loop command" { + $source | Should -Match '\[GraphCodeUiaGateState\]::ClickPopupMenuItemForModal\(' + $source | Should -Match '(?s)ClickPopupMenuItemForModal\(\s*\$deleteLoopPopup, \$shellWindow, \[int\]\$deleteLoopItem\.Position, \[int\]\$deleteLoopItem\.Id,\s*\[uint32\]\$process\.Id, \$deleteLoopTitle' + $source | Should -Match '\$deleteLoopClick\.Completion\.ToString\(\) -ceq "ExpectedOwnedModal"' + $source | Should -Match '\$deleteLoopClick\.ModalWindow -ne \[IntPtr\]::Zero' + $identityRequirement = '\[IntPtr\]\$deleteLoopDialog\.Current\.NativeWindowHandle -eq \$deleteLoopClick\.ModalWindow' + $source | Should -Match $identityRequirement + $source.Replace( + '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle -eq $deleteLoopClick.ModalWindow', + '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle -ne $deleteLoopClick.ModalWindow' + ) | Should -Not -Match $identityRequirement + } } diff --git a/Tools/windows/Tests/ValidationRunner.Tests.ps1 b/Tools/windows/Tests/ValidationRunner.Tests.ps1 index bd48a84f..3c3d0379 100644 --- a/Tools/windows/Tests/ValidationRunner.Tests.ps1 +++ b/Tools/windows/Tests/ValidationRunner.Tests.ps1 @@ -4518,15 +4518,19 @@ Start-Sleep -Seconds 60 '$deleteTargetSelection.Select()', 'Require $deleteTargetSelection.Current.IsSelected', 'UIA_DELETE_LOOP_TARGET', - '[GraphCodeUiaGateState]::PostContextMenu($shellWindow, 3)', - '$deleteLoopPopup = Wait-ForPopupMenu $process $shellWindow "Delete Loop"', + '$deleteLoopPopup = Open-CanvasCardContextMenu $process $root $shellWindow', '$deleteLoopItems = @(Get-PopupMenuItems $deleteLoopPopup)', '$_.Id -eq 5103 -and $_.Enabled', 'Require ($null -ne $deleteLoopItem)', + '[GraphCodeUiaGateState]::ClickPopupMenuItemForModal(', '$deleteLoopPopup, $shellWindow, [int]$deleteLoopItem.Position, [int]$deleteLoopItem.Id', - 'Require ($null -ne $deleteLoopClick)', + '$process.Id, $deleteLoopTitle', + 'Require ($null -ne $deleteLoopClick', + '$deleteLoopClick.Completion.ToString() -ceq "ExpectedOwnedModal"', + '$deleteLoopClick.ModalWindow -ne [IntPtr]::Zero', 'UIA_DELETE_LOOP_MENU', '"GraphCodeWindowsDialogContent" $deleteLoopTitle "Delete Loop custom sheet"', + '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle -eq $deleteLoopClick.ModalWindow', '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle, 9808', 'Wait-UiaOwnedSheetGoneByContentClass $process.Id $shellWindow ` "GraphCodeWindowsDialogContent") "Delete Loop custom sheet remained open after Cancel"' ) @@ -4539,7 +4543,7 @@ Start-Sleep -Seconds 60 return $true } $directDeleteMutant = $uiaLiveGateSource.Replace( - '[GraphCodeUiaGateState]::PostContextMenu($shellWindow, 3)', + 'Open-CanvasCardContextMenu $process $root $shellWindow', '[GraphCodeUiaGateState]::SendCommand($shellWindow, 5103)' ) $missingItemAssertionMutant = $uiaLiveGateSource.Replace( @@ -4547,8 +4551,16 @@ Start-Sleep -Seconds 60 '$null = ($null -ne $deleteLoopItem)' ) $wrongClickMutant = $uiaLiveGateSource.Replace( - '$deleteLoopPopup, $shellWindow, [int]$deleteLoopItem.Position, [int]$deleteLoopItem.Id', - '$deleteLoopPopup, $shellWindow, 0, 5103' + '$process.Id, $deleteLoopTitle', + '$process.Id, "Wrong Delete Loop title"' + ) + $missingModalReceiptMutant = $uiaLiveGateSource.Replace( + '$deleteLoopClick.Completion.ToString() -ceq "ExpectedOwnedModal"', + '$deleteLoopClick.Completion.ToString() -ceq "PopupClosed"' + ) + $replacedModalMutant = $uiaLiveGateSource.Replace( + '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle -eq $deleteLoopClick.ModalWindow', + '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle -ne $deleteLoopClick.ModalWindow' ) $wrongCancelMutant = $uiaLiveGateSource.Replace( '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle, 9808', @@ -4562,6 +4574,8 @@ Start-Sleep -Seconds 60 (Test-DeleteLoopContextSource $directDeleteMutant) -or (Test-DeleteLoopContextSource $missingItemAssertionMutant) -or (Test-DeleteLoopContextSource $wrongClickMutant) -or + (Test-DeleteLoopContextSource $missingModalReceiptMutant) -or + (Test-DeleteLoopContextSource $replacedModalMutant) -or (Test-DeleteLoopContextSource $wrongCancelMutant) -or (Test-DeleteLoopContextSource $missingTeardownMutant)) { throw "RED: UIA Delete Loop invocation does not re-establish the stable fixture selection after Rename" diff --git a/Tools/windows/Tests/WindowsShell.Tests.ps1 b/Tools/windows/Tests/WindowsShell.Tests.ps1 index 51feafc5..1f95d516 100644 --- a/Tools/windows/Tests/WindowsShell.Tests.ps1 +++ b/Tools/windows/Tests/WindowsShell.Tests.ps1 @@ -717,10 +717,10 @@ Invoke-Native "Shell process ownership mock contracts" { Invoke-Native "Stable canvas card context menu mock contracts" { . (Join-Path $PSScriptRoot "..\Import-PinnedPester.ps1") $cardMenuResults = Invoke-Pester -Path (Join-Path $PSScriptRoot "CanvasCardContextMenu.Tests.ps1") -PassThru - if ($cardMenuResults.TotalCount -ne 16 -or $cardMenuResults.PassedCount -ne 16 -or + if ($cardMenuResults.TotalCount -ne 17 -or $cardMenuResults.PassedCount -ne 17 -or $cardMenuResults.FailedCount -ne 0 -or $cardMenuResults.SkippedCount -ne 0 -or $cardMenuResults.NotRunCount -ne 0) { - throw "Stable canvas card context menu mock contracts did not pass all 16 unskipped cases" + throw "Stable canvas card context menu mock contracts did not pass all 17 unskipped cases" } Write-Host "CANVAS_CARD_CONTEXT_MENU_MOCK_CASES=$($cardMenuResults.TotalCount)" $global:LASTEXITCODE = 0 diff --git a/Tools/windows/ValidationRunner/Ui/UiDerivedContracts.ps1 b/Tools/windows/ValidationRunner/Ui/UiDerivedContracts.ps1 index 289fc66b..9bdc9a17 100644 --- a/Tools/windows/ValidationRunner/Ui/UiDerivedContracts.ps1 +++ b/Tools/windows/ValidationRunner/Ui/UiDerivedContracts.ps1 @@ -137,8 +137,13 @@ function Confirm-DeleteContext([string] $Gate) { '$deleteLoopPopup = Open-CanvasCardContextMenu $process $root $shellWindow ` $renameGraphIdentity $rawWalker "Delete Loop"', '$deleteLoopItems = @(Get-PopupMenuItems $deleteLoopPopup)', '$_.Id -eq 5103 -and $_.Enabled', 'Require ($null -ne $deleteLoopItem)', - '$deleteLoopPopup, $shellWindow, [int]$deleteLoopItem.Position, [int]$deleteLoopItem.Id', 'Require ($null -ne $deleteLoopClick)', + '[GraphCodeUiaGateState]::ClickPopupMenuItemForModal(', + '$deleteLoopPopup, $shellWindow, [int]$deleteLoopItem.Position, [int]$deleteLoopItem.Id', '$process.Id, $deleteLoopTitle', + 'Require ($null -ne $deleteLoopClick', + '$deleteLoopClick.Completion.ToString() -ceq "ExpectedOwnedModal"', + '$deleteLoopClick.ModalWindow -ne [IntPtr]::Zero', 'UIA_DELETE_LOOP_MENU', '"GraphCodeWindowsDialogContent" $deleteLoopTitle "Delete Loop custom sheet"', + '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle -eq $deleteLoopClick.ModalWindow', '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle, 9808', 'Wait-UiaOwnedSheetGoneByContentClass $process.Id $shellWindow ` "GraphCodeWindowsDialogContent") "Delete Loop custom sheet remained open after Cancel"') } @@ -157,7 +162,9 @@ Invoke-Derived 'ui.root.source.line-6157' { $mutants = @( @('Open-CanvasCardContextMenu $process $root $shellWindow', '[GraphCodeUiaGateState]::SendCommand($shellWindow, 5103)'), @('Require ($null -ne $deleteLoopItem)', '$null = ($null -ne $deleteLoopItem)'), - @('$deleteLoopPopup, $shellWindow, [int]$deleteLoopItem.Position, [int]$deleteLoopItem.Id', '$deleteLoopPopup, $shellWindow, 0, 5103'), + @('$process.Id, $deleteLoopTitle', '$process.Id, "Wrong Delete Loop title"'), + @('$deleteLoopClick.Completion.ToString() -ceq "ExpectedOwnedModal"', '$deleteLoopClick.Completion.ToString() -ceq "PopupClosed"'), + @('[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle -eq $deleteLoopClick.ModalWindow', '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle -ne $deleteLoopClick.ModalWindow'), @('[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle, 9808', '[IntPtr]$deleteLoopDialog.Current.NativeWindowHandle, 7'), @('Wait-UiaOwnedSheetGoneByContentClass $process.Id $shellWindow', 'Wait-UiaOwnedSheetGoneDisabled $process.Id $shellWindow') ) @@ -167,7 +174,7 @@ Invoke-Derived 'ui.root.source.line-6157' { Assert-Derived (-not (Confirm-DeleteContext ($source.Replace($mutant[0], $mutant[1])))) 'Delete context mutant accepted' $checked++ } - Assert-Derived ($checked -eq 5) 'Delete context mutation count changed' + Assert-Derived ($checked -eq 7) 'Delete context mutation count changed' } Invoke-Derived 'ui.root.source.line-6182' { foreach ($pattern in @('UIA_RENAME_DISPATCH', 'UIA_RENAME_INPUT', 'UIA_RENAME_OUTCOME', 'SetEditTextById', diff --git a/Tools/windows/uia-live-gate.ps1 b/Tools/windows/uia-live-gate.ps1 index 25324294..68baae7e 100644 --- a/Tools/windows/uia-live-gate.ps1 +++ b/Tools/windows/uia-live-gate.ps1 @@ -9464,15 +9464,22 @@ try { }) | Select-Object -First 1 Require ($null -ne $deleteLoopItem) ` "Delete Loop context menu omitted its enabled Delete action: $(Format-PopupMenuItems $deleteLoopItems)" - $deleteLoopClick = [GraphCodeUiaGateState]::ClickPopupMenuItem( - $deleteLoopPopup, $shellWindow, [int]$deleteLoopItem.Position, [int]$deleteLoopItem.Id, [uint32]$process.Id + $deleteLoopClick = [GraphCodeUiaGateState]::ClickPopupMenuItemForModal( + $deleteLoopPopup, $shellWindow, [int]$deleteLoopItem.Position, [int]$deleteLoopItem.Id, + [uint32]$process.Id, $deleteLoopTitle ) - Require ($null -ne $deleteLoopClick) "Delete Loop context-menu action could not be clicked" + Require ($null -ne $deleteLoopClick -and + $deleteLoopClick.Completion.ToString() -ceq "ExpectedOwnedModal" -and + $deleteLoopClick.ModalWindow -ne [IntPtr]::Zero) ` + "Delete Loop context-menu action did not produce an exact owned modal" Write-Host ("UIA_DELETE_LOOP_MENU command=$($deleteLoopItem.Id) " + - "hilite=$($deleteLoopClick.Hilite) keyboardFallback=$($deleteLoopClick.UsedKeyboardFallback)") + "hilite=$($deleteLoopClick.Hilite) keyboardFallback=$($deleteLoopClick.UsedKeyboardFallback) " + + "completion=$($deleteLoopClick.Completion) modal=$($deleteLoopClick.ModalWindow)") $deleteLoopDialog = Wait-UiaOwnedSheetByContentClass $process.Id $shellWindow ` "GraphCodeWindowsDialogContent" $deleteLoopTitle "Delete Loop custom sheet" Require ($null -ne $deleteLoopDialog) "Delete Loop did not open its custom sheet" + Require ([IntPtr]$deleteLoopDialog.Current.NativeWindowHandle -eq $deleteLoopClick.ModalWindow) ` + "Delete Loop custom sheet identity differs from the popup modal completion" $deleteLoopIdentity = Assert-UiaOwnedSheet $deleteLoopDialog $process.Id $shellWindow ` $deleteLoopTitle "GraphCodeWindowsDialogContent" "Delete Loop custom sheet" $null = Write-UiaDialogSheet768Observation $deleteLoopDialog $process.Id $shellWindow `