Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Reject failed observations inside Windows lifecycle proof

pulse-triage[bot]3dfef8cffa3f
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index db330778f6..6bf6821634 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -6800,7 +6800,9 @@ request and does not clear an existing advisory or establish hosted acceptance.
The native agent and service-lifecycle workflow checks each build, version,
self-test and lifecycle command immediately. PowerShell's final exit handling
alone can hide an earlier native failure behind a later successful command.
-The exit regressions cover all seven boundaries and reject tolerant steps;
+The service harness also checks captured version and service-query exits before
+accepting their text. Exit regressions cover all twelve boundaries (seven
+workflow commands and five harness commands) and reject tolerant steps;
Windows CI also executes the actual guards against failed and successful native
processes, including the unguarded masking control. An unavailable local
PowerShell is an explicit skip, not native acceptance. Installer behaviour,
diff --git a/scripts/installtests/native_windows_exit_test.go b/scripts/installtests/native_windows_exit_test.go
index 554ae49523..33ddfcaadd 100644
--- a/scripts/installtests/native_windows_exit_test.go
+++ b/scripts/installtests/native_windows_exit_test.go
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
+ "regexp"
"runtime"
"strings"
"testing"
@@ -120,6 +121,53 @@ func TestWindowsAgentLifecycleWorkflowChecksEveryNativeExit(t *testing.T) {
}
}
+func nativeWindowsHarnessExitGuards(script string) ([]string, error) {
+ commands := []string{
+ `$version = ((& $AgentPath --version`,
+ `& $script:powerShellPath -NoLogo`,
+ `$installedVersion = ((& "$env:ProgramFiles\Pulse\pulse-agent.exe" --version`,
+ `$recovery = (& sc.exe qfailure `,
+ `$failureFlag = (& sc.exe qfailureflag `,
+ }
+ guardPattern := regexp.MustCompile(`^\s*if \(\$LASTEXITCODE -ne 0\) \{\s*throw "[^"\n]*\$LASTEXITCODE[^"\n]*"\s*\}`)
+ var guards []string
+ for _, command := range commands {
+ i := strings.Index(script, command)
+ if i < 0 {
+ return nil, fmt.Errorf("missing lifecycle native command %s", command)
+ }
+ newline := strings.IndexByte(script[i:], '\n')
+ if newline < 0 {
+ return nil, fmt.Errorf("lifecycle command %s has no exit check", command)
+ }
+ guard := guardPattern.FindString(script[i+newline+1:])
+ if guard == "" {
+ return nil, fmt.Errorf("lifecycle command %s must fail before interpreting its output", command)
+ }
+ guards = append(guards, strings.TrimSpace(guard))
+ }
+ return guards, nil
+}
+
+func TestWindowsAgentLifecycleHarnessChecksEveryNativeExit(t *testing.T) {
+ content, err := os.ReadFile(repoFile("scripts", "installtests", "windows_agent_lifecycle.ps1"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ guards, err := nativeWindowsHarnessExitGuards(string(content))
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, guard := range guards {
+ t.Run(guard, func(t *testing.T) {
+ changed := strings.Replace(string(content), guard, "", 1)
+ if _, err := nativeWindowsHarnessExitGuards(changed); err == nil {
+ t.Fatal("accepted failed version/installer/service query evidence")
+ }
+ })
+ }
+}
+
func TestWindowsAgentLifecycleNativeExitChecksStopFollowingCommands(t *testing.T) {
shell := "pwsh"
if runtime.GOOS == "windows" {
@@ -138,6 +186,15 @@ func TestWindowsAgentLifecycleNativeExitChecksStopFollowingCommands(t *testing.T
if err != nil {
t.Fatal(err)
}
+ harness, err := os.ReadFile(repoFile("scripts", "installtests", "windows_agent_lifecycle.ps1"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ harnessGuards, err := nativeWindowsHarnessExitGuards(string(harness))
+ if err != nil {
+ t.Fatal(err)
+ }
+ guards = append(guards, harnessGuards...)
nativeExit := func(code int) string {
if runtime.GOOS == "windows" {
return fmt.Sprintf(`cmd.exe /d /c "exit /b %d"`, code)
@@ -148,7 +205,7 @@ func TestWindowsAgentLifecycleNativeExitChecksStopFollowingCommands(t *testing.T
t.Helper()
// Match Actions' error preference and final native exit propagation.
// The second successful native command reproduces the masking case.
- script := "$ErrorActionPreference = 'Stop'\n" + nativeExit(code) + "\n" + guard + "\n" +
+ script := "$ErrorActionPreference = 'Stop'\n$Label = 'Controlled installer'\n" + nativeExit(code) + "\n" + guard + "\n" +
nativeExit(0) + "\nWrite-Output 'FOLLOWING_COMMAND_RAN'\nexit $LASTEXITCODE\n"
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
@@ -164,7 +221,8 @@ func TestWindowsAgentLifecycleNativeExitChecksStopFollowingCommands(t *testing.T
for i, guard := range guards {
t.Run(fmt.Sprintf("command %d", i+1), func(t *testing.T) {
output, err := run(t, guard, 23)
- if err == nil || strings.Contains(string(output), "FOLLOWING_COMMAND_RAN") || !strings.Contains(string(output), "exit 23") {
+ if err == nil || strings.Contains(string(output), "FOLLOWING_COMMAND_RAN") ||
+ (!strings.Contains(string(output), "exit 23") && !strings.Contains(string(output), "exit code 23")) {
t.Fatalf("failed native command must stop immediately and retain its exit: %v\n%s", err, output)
}
output, err = run(t, guard, 0)
diff --git a/scripts/installtests/windows_agent_lifecycle.ps1 b/scripts/installtests/windows_agent_lifecycle.ps1
index 33261abf4d..f135d64414 100644
--- a/scripts/installtests/windows_agent_lifecycle.ps1
+++ b/scripts/installtests/windows_agent_lifecycle.ps1
@@ -51,6 +51,7 @@ function Start-LifecycleServer {
param([string]$AgentPath)
Stop-LifecycleServer
$version = ((& $AgentPath --version 2>$null) | Select-Object -First 1).Trim()
+ if ($LASTEXITCODE -ne 0) { throw "Lifecycle input version check failed (exit $LASTEXITCODE)." }
if ([string]::IsNullOrWhiteSpace($version)) {
throw "Could not read agent version from $AgentPath"
}
@@ -111,6 +112,7 @@ function Assert-AgentRuntime {
throw "Unexpected service state: $($service | ConvertTo-Json -Compress)"
}
$installedVersion = ((& "$env:ProgramFiles\Pulse\pulse-agent.exe" --version 2>$null) | Select-Object -First 1).Trim()
+ if ($LASTEXITCODE -ne 0) { throw "Installed agent version check failed (exit $LASTEXITCODE)." }
if ($installedVersion -ne $ExpectedVersion) {
throw "Installed version is $installedVersion; expected $ExpectedVersion."
}
@@ -126,10 +128,12 @@ function Assert-AgentRuntime {
throw "Agent log does not contain startup evidence for $ExpectedVersion."
}
$recovery = (& sc.exe qfailure $serviceName 2>&1 | Out-String)
+ if ($LASTEXITCODE -ne 0) { throw "Service recovery query failed (exit $LASTEXITCODE)." }
if ([regex]::Matches($recovery, 'RESTART').Count -lt 3) {
throw "Service recovery actions are incomplete: $recovery"
}
$failureFlag = (& sc.exe qfailureflag $serviceName 2>&1 | Out-String)
+ if ($LASTEXITCODE -ne 0) { throw "Service failure-flag query failed (exit $LASTEXITCODE)." }
if ($failureFlag -notmatch 'TRUE|1') {
throw "Service non-crash recovery flag is not enabled: $failureFlag"
}