From 20669901812d125f8e4e24d84abf1ed3c7637c45 Mon Sep 17 00:00:00 2001 From: rebuildup Date: Sun, 29 Nov 2026 21:10:13 +0900 Subject: [PATCH] test(e2e): dismiss native host confirm dialogs on Windows via UI Automation UC-J02's preset delete confirm() left a modal Win32 dialog open on AE, blocking every later ae-session attach (J05/J06 BLOCKED cascade in results-final-205730). Add a win32 path that scans AfterFX top-level windows with UI Automation, prefers #32770 dialogs, excludes main windows, and invokes the localized Cancel/OK button. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- scripts/verify/e2e/host-dialog.ts | 94 ++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/scripts/verify/e2e/host-dialog.ts b/scripts/verify/e2e/host-dialog.ts index fcde4fae..8c41c21a 100644 --- a/scripts/verify/e2e/host-dialog.ts +++ b/scripts/verify/e2e/host-dialog.ts @@ -8,8 +8,10 @@ * app modal, so the runner dismisses it through OS-level UI automation — * CDP cannot reach it. * - * Only macOS is implemented (System Events). On other platforms the helper - * reports `dismissed: false` and callers keep the documented manual step. + * macOS dismisses through System Events; Windows walks the AE process's + * top-level windows with UI Automation and invokes the matching button. + * On other platforms the helper reports `dismissed: false` and callers + * keep the documented manual step. */ import { execFile } from "node:child_process"; import { readdir } from "node:fs/promises"; @@ -109,6 +111,74 @@ const clickDialogButton = async ( return clicked === "" ? undefined : clicked; }; +/** + * Windows counterpart of `clickDialogButton`: UI Automation over the + * AfterFX processes' top-level windows. ExtendScript `confirm()` shows a + * Win32 dialog (class `#32770`) owned by the AE process; we prefer that + * class and fall back to any non-main window so a different dialog class + * still resolves. The main window handle is excluded so palette buttons + * can never match. + */ +const clickDialogButtonWindows = async ( + buttonNames: string[], +): Promise => { + const namesJson = JSON.stringify(buttonNames); + const script = ` +$ErrorActionPreference = "SilentlyContinue" +Add-Type -AssemblyName UIAutomationClient, UIAutomationTypes +$names = ${namesJson} | ConvertFrom-Json +$procs = @(Get-Process AfterFX -ErrorAction SilentlyContinue) +if ($procs.Count -eq 0) { exit 1 } +$aePids = @($procs | ForEach-Object { $_.Id }) +$mainHandles = @($procs | ForEach-Object { $_.MainWindowHandle }) +$root = [System.Windows.Automation.AutomationElement]::RootElement +$winCond = New-Object System.Windows.Automation.PropertyCondition( + [System.Windows.Automation.AutomationElement]::ControlTypeProperty, + [System.Windows.Automation.ControlType]::Window) +$wins = $root.FindAll([System.Windows.Automation.TreeScope]::Children, $winCond) +$invoke = { + param($b) + try { + $p = $b.GetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern) + if ($p) { $p.Invoke(); return $true } + } catch {} + try { + $p = $b.GetCurrentPattern([System.Windows.Automation.LegacyIAccessiblePattern]::Pattern) + if ($p) { $p.DoDefaultAction(); return $true } + } catch {} + return $false +} +foreach ($pass in @('#32770', '*')) { + foreach ($w in $wins) { + if ($aePids -notcontains $w.Current.ProcessId) { continue } + if ($mainHandles -contains $w.Current.NativeWindowHandle) { continue } + if ($pass -eq '#32770' -and $w.Current.ClassName -ne '#32770') { continue } + $btnCond = New-Object System.Windows.Automation.PropertyCondition( + [System.Windows.Automation.AutomationElement]::ControlTypeProperty, + [System.Windows.Automation.ControlType]::Button) + $btns = $w.FindAll([System.Windows.Automation.TreeScope]::Descendants, $btnCond) + foreach ($b in $btns) { + if ($names -contains $b.Current.Name) { + if (& $invoke $b) { Write-Output $b.Current.Name; exit 0 } + } + } + } +} +exit 2 +`; + try { + const { stdout } = await execFileAsync( + "powershell.exe", + ["-NoProfile", "-NonInteractive", "-Command", script], + { timeout: 25_000 }, + ); + const name = stdout.trim(); + return name === "" ? undefined : name; + } catch { + return undefined; + } +}; + export type HostDialogDismissal = { dismissed: boolean; button?: string; @@ -124,10 +194,28 @@ export const dismissHostConfirmDialog = async ( ctx: E2EContext, { accept = false }: { accept?: boolean } = {}, ): Promise => { + if (process.platform === "win32") { + // The confirm() modal can take several seconds to appear after the + // destructive action; poll for it instead of checking once. + const deadline = Date.now() + 20_000; + const buttonNames = accept ? OK_BUTTONS : CANCEL_BUTTONS; + let lastError = "no matching dialog button found"; + while (Date.now() < deadline) { + const button = await clickDialogButtonWindows(buttonNames).catch( + (error: unknown) => { + lastError = String(error); + return undefined; + }, + ); + if (button) return { dismissed: true, button }; + await new Promise((resolve) => setTimeout(resolve, 1_000)); + } + return { dismissed: false, reason: lastError }; + } if (process.platform !== "darwin") { return { dismissed: false, - reason: "native dialog dismissal is macOS-only", + reason: "native dialog dismissal is unsupported on this platform", }; } const realRoot = ctx.options.realManagedRoot;