|
38 | 38 | default: false |
39 | 39 | type: boolean |
40 | 40 | run_windows_ci: |
41 | | - description: "Run the focused Windows-native CI test shard after probing" |
| 41 | + description: "Run the focused Windows CI shard and native Scheduled Task proof" |
42 | 42 | required: false |
43 | 43 | default: false |
44 | 44 | type: boolean |
@@ -281,6 +281,165 @@ jobs: |
281 | 281 | export PATH="$NODE_BIN:$PATH" |
282 | 282 | pnpm test:windows:ci |
283 | 283 |
|
| 284 | + - name: Preflight native Scheduled Task session |
| 285 | + if: ${{ inputs.run_windows_ci }} |
| 286 | + shell: pwsh |
| 287 | + run: | |
| 288 | + $ErrorActionPreference = "Stop" |
| 289 | + $identity = [Security.Principal.WindowsIdentity]::GetCurrent() |
| 290 | + $principal = [Security.Principal.WindowsPrincipal]::new($identity) |
| 291 | + $isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) |
| 292 | + $sessionId = (Get-Process -Id $PID).SessionId |
| 293 | + Write-Host "identity=$($identity.Name)" |
| 294 | + Write-Host "session_id=$sessionId" |
| 295 | + Write-Host "user_interactive=$([Environment]::UserInteractive)" |
| 296 | + Write-Host "administrator=$isAdmin" |
| 297 | + query user 2>&1 | Write-Host |
| 298 | + if (-not [Environment]::UserInteractive) { |
| 299 | + throw "Native Scheduled Task proof requires an interactive Windows runner session." |
| 300 | + } |
| 301 | +
|
| 302 | + - name: Run native Scheduled Task lifecycle proof |
| 303 | + id: native_schtasks |
| 304 | + if: ${{ inputs.run_windows_ci }} |
| 305 | + timeout-minutes: 5 |
| 306 | + shell: bash |
| 307 | + env: |
| 308 | + CI_WINDOWS_SCHTASKS_PROOF_PATH: ${{ github.workspace }}\.artifacts\windows-schtasks\proof.json |
| 309 | + CI_WINDOWS_SCHTASKS_ROOT: ${{ runner.temp }}\openclaw-schtasks-${{ github.run_id }}-${{ github.run_attempt }} |
| 310 | + CI_WINDOWS_SCHTASKS_TEST_ID: ${{ github.run_id }}-${{ github.run_attempt }} |
| 311 | + EXPECTED_HEAD: ${{ inputs.target_ref }} |
| 312 | + run: | |
| 313 | + set -euo pipefail |
| 314 | + export PATH="$NODE_BIN:$PATH" |
| 315 | + if [[ ! "$EXPECTED_HEAD" =~ ^[0-9a-f]{40}$ ]]; then |
| 316 | + echo "Native Scheduled Task proof requires target_ref to be an exact 40-character commit SHA." >&2 |
| 317 | + exit 1 |
| 318 | + fi |
| 319 | + CI_WINDOWS_SCHTASKS_HEAD="$(git rev-parse HEAD)" |
| 320 | + if [[ "$CI_WINDOWS_SCHTASKS_HEAD" != "$EXPECTED_HEAD" ]]; then |
| 321 | + echo "Checked out $CI_WINDOWS_SCHTASKS_HEAD, expected frozen target $EXPECTED_HEAD." >&2 |
| 322 | + exit 1 |
| 323 | + fi |
| 324 | + export CI_WINDOWS_SCHTASKS_HEAD |
| 325 | + mkdir -p .artifacts/windows-schtasks |
| 326 | + pnpm test:windows:schtasks:integration |
| 327 | +
|
| 328 | + - name: Clean native Scheduled Task residue |
| 329 | + id: native_cleanup |
| 330 | + if: ${{ always() && inputs.run_windows_ci }} |
| 331 | + shell: pwsh |
| 332 | + env: |
| 333 | + TEST_ID: ${{ github.run_id }}-${{ github.run_attempt }} |
| 334 | + TEST_ROOT: ${{ runner.temp }}\openclaw-schtasks-${{ github.run_id }}-${{ github.run_attempt }} |
| 335 | + run: | |
| 336 | + $ErrorActionPreference = "Continue" |
| 337 | + $cleanupErrors = @() |
| 338 | + $profile = "schtasks-int-$env:TEST_ID" |
| 339 | + $taskName = "OpenClaw Gateway ($profile)" |
| 340 | + $stateDir = Join-Path $env:USERPROFILE ".openclaw-$profile" |
| 341 | + New-Item -ItemType Directory -Force -Path $env:TEST_ROOT | Out-Null |
| 342 | + schtasks.exe /End /TN $taskName 2>$null |
| 343 | + Start-Sleep -Milliseconds 200 |
| 344 | + $activePidPath = Join-Path $env:TEST_ROOT "active-pid.txt" |
| 345 | + if (Test-Path -LiteralPath $activePidPath) { |
| 346 | + try { |
| 347 | + $probePid = 0 |
| 348 | + $activePid = (Get-Content -LiteralPath $activePidPath -Raw).Trim() |
| 349 | + if (-not [int]::TryParse($activePid, [ref]$probePid) -or $probePid -le 1) { |
| 350 | + throw "Invalid Scheduled Task active process id: $activePid" |
| 351 | + } |
| 352 | + $processQueryError = @() |
| 353 | + $process = Get-CimInstance Win32_Process -Filter "ProcessId = $probePid" -ErrorAction SilentlyContinue -ErrorVariable processQueryError |
| 354 | + if ($processQueryError.Count -gt 0) { |
| 355 | + throw "Could not inspect Scheduled Task probe process $probePid." |
| 356 | + } |
| 357 | + if ($process) { |
| 358 | + $probePath = Join-Path $env:TEST_ROOT "probe.cjs" |
| 359 | + $eventsPath = Join-Path $env:TEST_ROOT "runs.txt" |
| 360 | + if ( |
| 361 | + $process.CommandLine -like "*$probePath*" -and |
| 362 | + $process.CommandLine -like "*$eventsPath*" |
| 363 | + ) { |
| 364 | + taskkill.exe /F /T /PID $probePid 2>$null |
| 365 | + $deadline = [DateTime]::UtcNow.AddSeconds(30) |
| 366 | + do { |
| 367 | + Start-Sleep -Milliseconds 200 |
| 368 | + $processQueryError = @() |
| 369 | + $process = Get-CimInstance Win32_Process -Filter "ProcessId = $probePid" -ErrorAction SilentlyContinue -ErrorVariable processQueryError |
| 370 | + if ($processQueryError.Count -gt 0) { |
| 371 | + throw "Could not verify Scheduled Task probe process $probePid exited." |
| 372 | + } |
| 373 | + } while ($process -and [DateTime]::UtcNow -lt $deadline) |
| 374 | + if ($process) { |
| 375 | + throw "Scheduled Task probe process $probePid survived cleanup." |
| 376 | + } |
| 377 | + } else { |
| 378 | + throw "Refusing to kill reused or unverifiable process id $probePid." |
| 379 | + } |
| 380 | + } |
| 381 | + } catch { |
| 382 | + $cleanupErrors += $_.Exception.Message |
| 383 | + } |
| 384 | + } |
| 385 | + schtasks.exe /Delete /F /TN $taskName 2>$null |
| 386 | + $deleteExit = $LASTEXITCODE |
| 387 | + try { |
| 388 | + $service = New-Object -ComObject "Schedule.Service" |
| 389 | + $service.Connect() |
| 390 | + $null = $service.GetFolder("\").GetTask($taskName) |
| 391 | + $taskExists = $true |
| 392 | + } catch { |
| 393 | + $exception = $_.Exception |
| 394 | + while ($null -ne $exception.InnerException) { |
| 395 | + $exception = $exception.InnerException |
| 396 | + } |
| 397 | + if ($exception.HResult -eq -2147024894 -or $exception.HResult -eq -2147024893) { |
| 398 | + $taskExists = $false |
| 399 | + } else { |
| 400 | + $cleanupErrors += "Could not verify Scheduled Task cleanup for $taskName (HRESULT $($exception.HResult))." |
| 401 | + $taskExists = $null |
| 402 | + } |
| 403 | + } |
| 404 | + if ($taskExists -eq $true) { |
| 405 | + $cleanupErrors += "Scheduled Task cleanup left $taskName registered (delete exit $deleteExit)." |
| 406 | + } |
| 407 | + @( |
| 408 | + "task_name=$taskName" |
| 409 | + "delete_exit=$deleteExit" |
| 410 | + "task_exists=$taskExists" |
| 411 | + "proof_outcome=${{ steps.native_schtasks.outcome }}" |
| 412 | + "cleanup_errors=$($cleanupErrors -join ' ')" |
| 413 | + ) | Set-Content -LiteralPath (Join-Path $env:TEST_ROOT "cleanup-summary.txt") |
| 414 | + if ($cleanupErrors.Count -gt 0) { |
| 415 | + throw ($cleanupErrors -join " ") |
| 416 | + } |
| 417 | + exit 0 |
| 418 | +
|
| 419 | + - name: Upload native Scheduled Task proof |
| 420 | + id: native_proof_upload |
| 421 | + if: ${{ always() && inputs.run_windows_ci }} |
| 422 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 |
| 423 | + with: |
| 424 | + name: windows-schtasks-proof-${{ github.run_id }}-${{ github.run_attempt }} |
| 425 | + path: | |
| 426 | + .artifacts/windows-schtasks/proof.json |
| 427 | + ${{ runner.temp }}\openclaw-schtasks-${{ github.run_id }}-${{ github.run_attempt }}\failure-diagnostics.json |
| 428 | + ${{ runner.temp }}\openclaw-schtasks-${{ github.run_id }}-${{ github.run_attempt }}\cleanup-summary.txt |
| 429 | + if-no-files-found: warn |
| 430 | + retention-days: 7 |
| 431 | + |
| 432 | + - name: Remove retained native Scheduled Task evidence |
| 433 | + if: ${{ always() && inputs.run_windows_ci && steps.native_cleanup.outcome == 'success' && steps.native_proof_upload.outcome == 'success' }} |
| 434 | + shell: pwsh |
| 435 | + env: |
| 436 | + TEST_ID: ${{ github.run_id }}-${{ github.run_attempt }} |
| 437 | + TEST_ROOT: ${{ runner.temp }}\openclaw-schtasks-${{ github.run_id }}-${{ github.run_attempt }} |
| 438 | + run: | |
| 439 | + $profile = "schtasks-int-$env:TEST_ID" |
| 440 | + Remove-Item -LiteralPath (Join-Path $env:USERPROFILE ".openclaw-$profile") -Recurse -Force -ErrorAction SilentlyContinue |
| 441 | + Remove-Item -LiteralPath $env:TEST_ROOT -Recurse -Force -ErrorAction SilentlyContinue |
| 442 | +
|
284 | 443 | - name: Keep runner alive for SSH inspection |
285 | 444 | if: ${{ always() && !cancelled() }} |
286 | 445 | env: |
|
0 commit comments