Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 91 additions & 3 deletions scripts/verify/e2e/host-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string | undefined> => {
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;
Expand All @@ -124,10 +194,28 @@ export const dismissHostConfirmDialog = async (
ctx: E2EContext,
{ accept = false }: { accept?: boolean } = {},
): Promise<HostDialogDismissal> => {
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;
Expand Down
Loading