From f0d207b4201856de81bf0223f3bb98ce0a80a079 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 26 Jun 2026 07:26:54 +0000 Subject: [PATCH] fix: capture gateway apply native warnings --- scripts/src/hwlab-node-hwpod-preinstall.ts | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/scripts/src/hwlab-node-hwpod-preinstall.ts b/scripts/src/hwlab-node-hwpod-preinstall.ts index c230df99..ee5d2a07 100644 --- a/scripts/src/hwlab-node-hwpod-preinstall.ts +++ b/scripts/src/hwlab-node-hwpod-preinstall.ts @@ -1147,11 +1147,25 @@ $EnsureVbs = Join-Path $Root 'ensure-node-ws.vbs' $RunTask = 'wscript.exe //B //Nologo "' + $RunVbs + '"' $EnsureTask = 'wscript.exe //B //Nologo "' + $EnsureVbs + '"' New-Item -ItemType Directory -Force -Path $Root, (Join-Path $Root 'logs'), (Join-Path $Root '.state'), (Join-Path $Root 'tools'), (Join-Path $Root 'tools\\src') | Out-Null +function RunNativeCapture([scriptblock]$Block) { + $previous = $ErrorActionPreference + $ErrorActionPreference = 'Continue' + try { + $output = @(& $Block 2>&1) + $exitCode = $global:LASTEXITCODE + return [pscustomobject]@{ + exitCode = [int]$exitCode + output = (($output | ForEach-Object { [string]$_ }) -join "\`n") + } + } finally { + $ErrorActionPreference = $previous + } +} function EndTaskIfPresent([string]$Name) { $task = Get-ScheduledTask -TaskName $Name -ErrorAction SilentlyContinue if ($null -eq $task) { return } if ([string]$task.State -eq 'Running') { - $null = schtasks /End /TN $Name 2>&1 + $null = RunNativeCapture { schtasks /End /TN $Name } Start-Sleep -Seconds 2 } } @@ -1176,14 +1190,14 @@ foreach ($proc in $processes) { $written = @() foreach ($item in @($payload.sourceFiles)) { $written += WritePayloadFile $item } foreach ($item in @($payload.runnerFiles)) { $written += WritePayloadFile $item } -$runCreate = schtasks /Create /TN $TaskName /SC ONCE /ST 00:00 /TR $RunTask /F 2>&1 -if ($LASTEXITCODE -ne 0) { throw "run task create failed: $runCreate" } -$periodicCreate = schtasks /Create /TN $PeriodicTaskName /SC MINUTE /MO 5 /TR $EnsureTask /F 2>&1 -if ($LASTEXITCODE -ne 0) { throw "periodic task create failed: $periodicCreate" } -$runKey = reg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /v $RunKeyName /t REG_SZ /d $EnsureTask /f 2>&1 -if ($LASTEXITCODE -ne 0) { throw "HKCU Run update failed: $runKey" } -$runOut = schtasks /Run /TN $TaskName 2>&1 -$runExit = $LASTEXITCODE +$runCreate = RunNativeCapture { schtasks /Create /TN $TaskName /SC ONCE /ST 00:00 /TR $RunTask /F } +if ($runCreate.exitCode -ne 0) { throw "run task create failed: $($runCreate.output)" } +$periodicCreate = RunNativeCapture { schtasks /Create /TN $PeriodicTaskName /SC MINUTE /MO 5 /TR $EnsureTask /F } +if ($periodicCreate.exitCode -ne 0) { throw "periodic task create failed: $($periodicCreate.output)" } +$runKey = RunNativeCapture { reg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /v $RunKeyName /t REG_SZ /d $EnsureTask /f } +if ($runKey.exitCode -ne 0) { throw "HKCU Run update failed: $($runKey.output)" } +$runOut = RunNativeCapture { schtasks /Run /TN $TaskName } +$runExit = $runOut.exitCode Start-Sleep -Seconds 3 $expected = @(Get-CimInstance Win32_Process -Filter "Name='bun.exe'" | Where-Object { ($_.CommandLine -match 'hwpod-node\\.ts\\s+connect') -and ($_.CommandLine -match [regex]::Escape($NodeId)) -and ($_.CommandLine -match [regex]::Escape($CloudUrl)) -and ($_.CommandLine -match [regex]::Escape($WsUrl)) }) $result = [ordered]@{ @@ -1194,6 +1208,7 @@ $result = [ordered]@{ taskName = $TaskName periodicTaskName = $PeriodicTaskName runTaskExitCode = $runExit + failureDetail = $(if (($runExit -eq 0) -and ($expected.Count -gt 0)) { $null } else { "runOutput=$($runOut.output)" }) valuesRedacted = $true } $result | ConvertTo-Json -Compress -Depth 8