diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index daaf28f24..39006ce6b 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -202,6 +202,7 @@ jobs: } & ./scripts/cowork-inference/test-diagnostics.ps1 & ./scripts/cowork-inference/test-prepare-task.ps1 + & ./scripts/cowork-inference/test-task-waits.ps1 - name: Download and verify the approved Claude installer shell: pwsh run: ./scripts/cowork-inference/download-desktop.ps1 diff --git a/scripts/cowork-inference/README.md b/scripts/cowork-inference/README.md index a17ca2102..f2ea5edff 100644 --- a/scripts/cowork-inference/README.md +++ b/scripts/cowork-inference/README.md @@ -19,6 +19,15 @@ through Windows UI Automation. `--force-renderer-accessibility` exposes the app' accessible controls. Controls are polled until enabled and visible, with a 60-second deadline per transition. No preliminary launch or virtualization check is needed. +On a Windows task control timeout, `result.json` includes `waitFailure`: the requested +labels, wait budget, scan count, and elapsed milliseconds before and after the failure +snapshot. `wait-failed.json` captures the actual subtree searched, including native folder +dialogs. Compare those timings with the snapshot when an expected control appears there; +its presence after the wait alone does not establish when it became available. +If snapshot collection fails, `snapshotError` records its exception class and the original +control timeout remains the failure. `test-task-waits.ps1` checks ready controls, missing +controls, and failed snapshots with only the UI Automation boundary substituted. + The test installs UG from the checkout, runs `ug configure` with the existing `UCODE_TEST_WORKSPACE` and `DATABRICKS_BEARER` CI secrets, and checks the generated gateway profile. UG detects the installed Windows MSIX package and executable, diff --git a/scripts/cowork-inference/test-task-waits.ps1 b/scripts/cowork-inference/test-task-waits.ps1 new file mode 100644 index 000000000..2723d399b --- /dev/null +++ b/scripts/cowork-inference/test-task-waits.ps1 @@ -0,0 +1,46 @@ +$ErrorActionPreference = 'Stop' +$tokens = $null +$errors = $null +$source = [System.Management.Automation.Language.Parser]::ParseFile( + (Join-Path $PSScriptRoot 'test-task.ps1'), [ref]$tokens, [ref]$errors) +if ($errors.Count) { throw ($errors | Out-String) } +$definition = $source.Find({ + param($node) + $node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -eq 'Wait-Control' +}, $true) +Invoke-Expression $definition.Extent.Text + +# UI Automation is the external boundary; execute the real wait and evidence handling. +function Find-Control { param($Names, $Root) return $script:control } +function Save-UI { + param($Name, $Root) + if ($Name -ne 'wait-failed' -or -not [object]::ReferenceEquals($Root, $script:expectedRoot)) { + throw 'Wrong snapshot subtree' + } + if ($script:failSnapshot) { throw [InvalidOperationException]::new('Closed UI root') } + $script:snapshotSaved = $true +} + +$script:control = [pscustomobject]@{ Name = 'ready' } +$report = [ordered]@{} +if ((Wait-Control -Names @('ready') -Seconds 0) -ne $script:control -or $report.Contains('waitFailure')) { + throw 'Ready control did not return without failure evidence' +} +$script:control = $null +$script:expectedRoot = [pscustomobject]@{ Name = 'native folder dialog' } +foreach ($script:failSnapshot in @($false, $true)) { + $report = [ordered]@{} + $script:snapshotSaved = $false + $message = '' + try { Wait-Control -Names @('missing') -Seconds 0 -Root $script:expectedRoot } + catch { $message = $_.Exception.Message } + if ($message -ne 'Control not ready: missing') { throw "Timeout replaced by: $message" } + $failure = ($report | ConvertTo-Json -Depth 8 | ConvertFrom-Json).waitFailure + if ($failure.names[0] -ne 'missing' -or $failure.budgetSeconds -ne 0 -or $failure.scans -ne 1 -or + $failure.elapsedMilliseconds -lt 0 -or $failure.snapshotCompletedMilliseconds -lt $failure.elapsedMilliseconds) { + throw 'Missing or inconsistent wait evidence' + } + if ($script:failSnapshot) { + if ($failure.snapshotError -ne 'InvalidOperationException') { throw 'Missing snapshot error class' } + } elseif (-not $script:snapshotSaved) { throw 'Failure snapshot was not saved' } +} diff --git a/scripts/cowork-inference/test-task.ps1 b/scripts/cowork-inference/test-task.ps1 index 6f26a0bfd..34015bd54 100644 --- a/scripts/cowork-inference/test-task.ps1 +++ b/scripts/cowork-inference/test-task.ps1 @@ -41,12 +41,23 @@ function Find-Control { function Wait-Control { param([string[]]$Names, [int]$Seconds = 60, $Root = $script:window) $deadline = [DateTime]::UtcNow.AddSeconds($Seconds) + $timer = [Diagnostics.Stopwatch]::StartNew() + $scans = 0 do { + $scans++ $control = Find-Control -Names $Names -Root $Root if ($control) { return $control } Start-Sleep -Milliseconds 500 } until ([DateTime]::UtcNow -ge $deadline) - Save-UI 'wait-failed' + $report.waitFailure = [ordered]@{ + names = $Names + budgetSeconds = $Seconds + scans = $scans + elapsedMilliseconds = $timer.ElapsedMilliseconds + } + try { Save-UI 'wait-failed' -Root $Root } + catch { $report.waitFailure.snapshotError = $_.Exception.GetType().Name } + $report.waitFailure.snapshotCompletedMilliseconds = $timer.ElapsedMilliseconds throw "Control not ready: $($Names -join ', ')" }