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.

Require truthful PowerShell 5.1 Windows lifecycle acceptance

pulse-triage[bot]bf562e27ca5b
diff --git a/.github/workflows/unified-agent-native.yml b/.github/workflows/unified-agent-native.yml
index 357674c43b..8e4ccef187 100644
--- a/.github/workflows/unified-agent-native.yml
+++ b/.github/workflows/unified-agent-native.yml
@@ -212,17 +212,9 @@ jobs:
- name: Exercise native Windows service lifecycle
if: ${{ !matrix.unix }}
- shell: pwsh
+ shell: powershell
timeout-minutes: 10
run: |
- if (Get-Service -Name 'PulseAgent' -ErrorAction SilentlyContinue) {
- throw 'PulseAgent is already installed; refusing to clear lifecycle state.'
- }
- $lifecycleStateDir = Join-Path $env:ProgramData 'Pulse'
- if (Test-Path $lifecycleStateDir) {
- Write-Host "Removing test-only Pulse state before clean lifecycle proof: $lifecycleStateDir"
- Remove-Item -Path $lifecycleStateDir -Recurse -Force
- }
go build -buildvcs=false -trimpath -ldflags="-s -w -X main.Version=6.0.5-ci.1" -o pulse-agent-windows-ci-1.exe ./cmd/pulse-agent
if ($LASTEXITCODE -ne 0) { throw "Windows lifecycle v1 build failed (exit $LASTEXITCODE)." }
go build -buildvcs=false -trimpath -ldflags="-s -w -X main.Version=6.0.5-ci.2" -o pulse-agent-windows-ci-2.exe ./cmd/pulse-agent
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 904601c4f9..3bb461323b 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -9260,3 +9260,28 @@ replaces that link, splitting the agent back out as unlink does. Agent
registration, enrolment, install, update, removal, report identity and
continuity are unchanged, and an agent's own declared node link still
ignores exclusions.
+
+### Windows installer acceptance engine and absence (8 October 2026)
+
+Native installer parsing, service-removal failure controls and actual lifecycle
+execution use Windows PowerShell 5.1, never a PowerShell 7 substitute. A missing
+or mismatched engine on Windows fails rather than skips. The dedicated runner
+rejects pre-existing or unknown service/state instead of deleting it before the
+proof. Both first and repeated uninstall require independent SCM, binary, state
+and listener absence; only the exact SCM not-found identity/category proves
+absence. Failed listener enumeration remains a failure. This changes validation,
+not installer authority, transport, enrolment or host containment.
+
+`TestWindowsAgentLifecycleRequiresExactEngineAndIndependentAbsence` rejects the
+complete supplied parent and eleven removed/changed controls. Native
+`TestWindowsAgentLifecycleObservationRuntime` executes the actual harness
+functions with fourteen no-mutation absence/failure/repeated-uninstall/owned-cleanup controls;
+the existing real lifecycle job then uses real SCM. Linux skips are explicit and
+do not establish a Windows parser, native runtime, reboot or installed result.
+
+Clean-runner admission checks service, binary, state and listener absence before
+machine-environment mutation. A rejected admission cannot clear a pre-existing
+machine setting. Cleanup restores only the captured prior setting, even when
+owned server teardown fails; an unconfirmed stop fails and retains the handle
+rather than reporting clean teardown. Real Windows execution and full terminal
+cleanup evidence still have to be returned by the existing native CI job.
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index 3ca57ac031..ec8ee091de 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -7281,3 +7281,28 @@ contract checks the helper staging, unchanged cache/graph inputs and bounded
command. These are offline command proofs, not a hosted Docker build, public
proxy recovery, E2E acceptance or installed customer result. The hosted checks
still have to build the image and execute the unchanged suites.
+
+### Windows installer acceptance engine and absence (8 October 2026)
+
+Native installer parsing, service-removal failure controls and actual lifecycle
+execution use Windows PowerShell 5.1, never a PowerShell 7 substitute. A missing
+or mismatched engine on Windows fails rather than skips. The dedicated runner
+rejects pre-existing or unknown service/state instead of deleting it before the
+proof. Both first and repeated uninstall require independent SCM, binary, state
+and listener absence; only the exact SCM not-found identity/category proves
+absence. Failed listener enumeration remains a failure. This changes validation,
+not installer authority, transport, enrolment or host containment.
+
+`TestWindowsAgentLifecycleRequiresExactEngineAndIndependentAbsence` rejects the
+complete supplied parent and eleven removed/changed controls. Native
+`TestWindowsAgentLifecycleObservationRuntime` executes the actual harness
+functions with fourteen no-mutation absence/failure/repeated-uninstall/owned-cleanup controls;
+the existing real lifecycle job then uses real SCM. Linux skips are explicit and
+do not establish a Windows parser, native runtime, reboot or installed result.
+
+Clean-runner admission checks service, binary, state and listener absence before
+machine-environment mutation. A rejected admission cannot clear a pre-existing
+machine setting. Cleanup restores only the captured prior setting, even when
+owned server teardown fails; an unconfirmed stop fails and retains the handle
+rather than reporting clean teardown. Real Windows execution and full terminal
+cleanup evidence still have to be returned by the existing native CI job.
diff --git a/scripts/installtests/install_ps1_test.go b/scripts/installtests/install_ps1_test.go
index 0d90ee9e8e..f36794eaaa 100644
--- a/scripts/installtests/install_ps1_test.go
+++ b/scripts/installtests/install_ps1_test.go
@@ -9,11 +9,35 @@ import (
"testing"
)
-func TestInstallPS1ParsesWithPowerShell(t *testing.T) {
- pwsh, err := exec.LookPath("pwsh")
+// Windows proof is specifically the supported legacy engine. Missing or newer
+// PowerShell must not silently skip (or stand in for) Windows PowerShell 5.1.
+func nativeInstallerPowerShell(t *testing.T) string {
+ t.Helper()
+ binary := "pwsh"
+ if runtime.GOOS == "windows" {
+ binary = "powershell.exe"
+ }
+ powerShell, err := exec.LookPath(binary)
if err != nil {
- t.Skip("pwsh not installed")
+ if runtime.GOOS == "windows" {
+ t.Fatal("native Windows installer proof requires Windows PowerShell 5.1")
+ }
+ t.Skip("PowerShell unavailable; native Windows installer proof remains unexecuted")
}
+ if runtime.GOOS == "windows" {
+ cmd := exec.Command(powerShell, "-NoLogo", "-NoProfile", "-NonInteractive", "-Command",
+ `if ($PSVersionTable.PSEdition -ne 'Desktop' -or $PSVersionTable.PSVersion.Major -ne 5 -or $PSVersionTable.PSVersion.Minor -ne 1) { throw 'Windows PowerShell 5.1 required' }; Write-Output $PSVersionTable.PSVersion.ToString()`)
+ output, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("Windows installer proof selected the wrong engine: %v\n%s", err, output)
+ }
+ t.Logf("Windows PowerShell %s", strings.TrimSpace(string(output)))
+ }
+ return powerShell
+}
+
+func TestInstallPS1ParsesWithPowerShell(t *testing.T) {
+ pwsh := nativeInstallerPowerShell(t)
scriptPath := repoFile("scripts", "install.ps1")
cmd := exec.Command(pwsh,
@@ -60,10 +84,7 @@ func TestInstallPS1KeepsTLS13OptionalOnLegacyWindowsPowerShell(t *testing.T) {
}
func TestWindowsAgentLifecycleHarnessParsesWithPowerShell(t *testing.T) {
- pwsh, err := exec.LookPath("pwsh")
- if err != nil {
- t.Skip("pwsh not installed")
- }
+ pwsh := nativeInstallerPowerShell(t)
scriptPath := repoFile("scripts", "installtests", "windows_agent_lifecycle.ps1")
cmd := exec.Command(pwsh,
@@ -117,15 +138,17 @@ func TestNativeWindowsSelfTestDoesNotPreseedLifecycleState(t *testing.T) {
`$selfTestStateDir = Join-Path $env:RUNNER_TEMP 'pulse-agent-self-test'`,
`$selfTestLogFile = Join-Path $selfTestStateDir 'pulse-agent.log'`,
`--self-test --state-dir $selfTestStateDir --log-file $selfTestLogFile`,
- `Get-Service -Name 'PulseAgent' -ErrorAction SilentlyContinue`,
- `$lifecycleStateDir = Join-Path $env:ProgramData 'Pulse'`,
- `Remove-Item -Path $lifecycleStateDir -Recurse -Force`,
}
for _, needle := range required {
if !strings.Contains(workflow, needle) {
t.Fatalf("native Windows workflow must keep its governed lifecycle proof intact: %s", needle)
}
}
+ if strings.Contains(workflow, "Remove-Item -Path $lifecycleStateDir") ||
+ strings.Contains(workflow, "Get-Service -Name 'PulseAgent' -ErrorAction SilentlyContinue") {
+ t.Fatal("native proof must reject pre-existing or unknown state, not erase it")
+ }
+
}
func TestNativeWindowsExecutesGeneratedInstallCommand(t *testing.T) {
@@ -611,14 +634,7 @@ func TestWindowsAgentLifecycleHarnessChecksEveryNativeExit(t *testing.T) {
// model. The Linux proof's missing runtime remains an explicit skip; the
// existing Windows native workflow selects these tests and uses PowerShell 5.1.
func TestInstallPS1ServiceRemovalRuntime(t *testing.T) {
- binary := "pwsh"
- if runtime.GOOS == "windows" {
- binary = "powershell.exe"
- }
- powerShell, err := exec.LookPath(binary)
- if err != nil {
- t.Skipf("%s not installed; native service-removal controls remain unexecuted", binary)
- }
+ powerShell := nativeInstallerPowerShell(t)
cmd := exec.Command(powerShell, "-NoLogo", "-NoProfile", "-NonInteractive", "-File",
repoFile("scripts", "installtests", "windows_service_removal_controls.ps1"),
"-InstallerPath", repoFile("scripts", "install.ps1"))
diff --git a/scripts/installtests/native_windows_exit_test.go b/scripts/installtests/native_windows_exit_test.go
index a21f193e4e..1ebcc3d00a 100644
--- a/scripts/installtests/native_windows_exit_test.go
+++ b/scripts/installtests/native_windows_exit_test.go
@@ -50,7 +50,11 @@ func nativeWindowsExitGuards(steps []nativeWindowsExitStep) ([]string, error) {
if !ok {
continue
}
- if step.If != "${{ !matrix.unix }}" || step.Shell != "pwsh" || step.ContinueOnError {
+ shell := "pwsh"
+ if step.Name == "Exercise native Windows service lifecycle" {
+ shell = "powershell"
+ }
+ if step.If != "${{ !matrix.unix }}" || step.Shell != shell || step.ContinueOnError {
return nil, fmt.Errorf("%s must be a required native Windows PowerShell step", step.Name)
}
found := 0
@@ -117,19 +121,7 @@ func nativeWindowsHarnessExitGuards(script string) ([]string, error) {
}
func TestWindowsAgentLifecycleNativeExitChecksStopFollowingCommands(t *testing.T) {
- shell := "pwsh"
- if runtime.GOOS == "windows" {
- // Prove the guards on Windows PowerShell 5.1 too, without installing an
- // agent or touching service state. The workflow uses pwsh.
- shell = "powershell.exe"
- }
- powerShell, err := exec.LookPath(shell)
- if err != nil {
- if runtime.GOOS == "windows" {
- t.Fatal("native Windows exit regression requires Windows PowerShell")
- }
- t.Skip("PowerShell unavailable; native exit execution remains a Windows CI obligation")
- }
+ powerShell := nativeInstallerPowerShell(t)
guards, err := nativeWindowsExitGuards(nativeWindowsExitSteps(t))
if err != nil {
t.Fatal(err)
diff --git a/scripts/installtests/windows_agent_lifecycle.ps1 b/scripts/installtests/windows_agent_lifecycle.ps1
index f135d64414..550f00c7bf 100644
--- a/scripts/installtests/windows_agent_lifecycle.ps1
+++ b/scripts/installtests/windows_agent_lifecycle.ps1
@@ -14,6 +14,10 @@ param (
)
$ErrorActionPreference = 'Stop'
+if ($PSVersionTable.PSEdition -ne 'Desktop' -or $PSVersionTable.PSVersion.Major -ne 5 -or $PSVersionTable.PSVersion.Minor -ne 1) {
+ throw 'Native Windows lifecycle proof requires Windows PowerShell 5.1.'
+}
+Write-Host "Lifecycle engine: Windows PowerShell $($PSVersionTable.PSVersion)"
$serviceName = 'PulseAgent'
$stateDir = Join-Path $env:ProgramData 'Pulse'
$logFile = Join-Path $stateDir 'pulse-agent.log'
@@ -21,7 +25,7 @@ $proofStatePath = Join-Path $stateDir 'windows-lifecycle-proof.json'
$baseUrl = "http://127.0.0.1:$Port"
$serverProcess = $null
$previousDisableAutoUpdate = $null
-$restoreAutoUpdateAtExit = $true
+$restoreAutoUpdateAtExit = $false
function Assert-Administrator {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
@@ -40,10 +44,14 @@ function Resolve-RequiredPath {
}
function Stop-LifecycleServer {
- if ($null -ne $script:serverProcess -and -not $script:serverProcess.HasExited) {
- Stop-Process -Id $script:serverProcess.Id -Force -ErrorAction SilentlyContinue
- $script:serverProcess.WaitForExit(5000) | Out-Null
+ if ($null -eq $script:serverProcess) { return }
+ if (-not $script:serverProcess.HasExited) {
+ Stop-Process -Id $script:serverProcess.Id -Force -ErrorAction Stop
+ if (-not $script:serverProcess.WaitForExit(5000)) {
+ throw 'Owned lifecycle server did not stop before the cleanup deadline.'
+ }
}
+ $script:serverProcess.Dispose()
$script:serverProcess = $null
}
@@ -159,10 +167,23 @@ function Assert-CrashRecovery {
throw 'PulseAgent did not recover after its process was terminated.'
}
-function Invoke-UninstallAndAssertClean {
- Invoke-Installer -Label 'uninstall' -Arguments '-Uninstall $true -NonInteractive $true'
- Start-Sleep -Seconds 2
- if ($null -ne (Get-Service $serviceName -ErrorAction SilentlyContinue)) {
+# Absence is a specific SCM result, not an empty/suppressed failed query.
+function Get-LifecycleService {
+ try {
+ return Get-Service -Name $serviceName -ErrorAction Stop
+ } catch {
+ if ($_.FullyQualifiedErrorId.Split(',')[0] -eq 'NoServiceFoundForGivenName' -and
+ $_.CategoryInfo.Category -eq [System.Management.Automation.ErrorCategory]::ObjectNotFound) {
+ return $null
+ }
+ throw
+ }
+}
+
+function Assert-LifecycleAgentAbsent {
+ $remaining = Get-LifecycleService
+ if ($null -ne $remaining) {
+ $remaining.Dispose()
throw 'PulseAgent service still exists after uninstall.'
}
if (Test-Path "$env:ProgramFiles\Pulse\pulse-agent.exe") {
@@ -171,11 +192,24 @@ function Invoke-UninstallAndAssertClean {
if (Test-Path $stateDir) {
throw 'Pulse Agent state directory still exists after uninstall.'
}
- if (Get-NetTCPConnection -LocalPort 9191 -State Listen -ErrorAction SilentlyContinue) {
+ # Enumerate first: a missing selected port must not turn access/query
+ # failure into apparently successful listener removal.
+ $listeners = @(Get-NetTCPConnection -ErrorAction Stop | Where-Object {
+ $_.LocalPort -eq 9191 -and $_.State -eq 'Listen'
+ })
+ if ($listeners.Count -ne 0) {
throw 'Pulse Agent readiness listener still exists after uninstall.'
}
}
+function Invoke-UninstallAndAssertClean {
+ foreach ($label in @('uninstall', 'repeated uninstall')) {
+ Invoke-Installer -Label $label -Arguments '-Uninstall $true -NonInteractive $true'
+ Assert-LifecycleAgentAbsent
+ Write-Host "${label}: independent SCM, binary, state and listener absence confirmed."
+ }
+}
+
Assert-Administrator
if (-not $ConfirmLifecycleMutation) {
throw 'Pass -ConfirmLifecycleMutation to acknowledge service installation, process termination, and uninstall on this dedicated Windows runner.'
@@ -202,14 +236,11 @@ try {
return
}
- if (Get-Service $serviceName -ErrorAction SilentlyContinue) {
- throw 'PulseAgent is already installed. Use a disposable runner or uninstall it before starting this proof.'
- }
- if (Test-Path $stateDir) {
- throw "Pulse state already exists at $stateDir. Use a clean disposable runner."
- }
-
+ # Fail closed on pre-existing state and observation errors before changing
+ # the machine environment or starting any test-owned process.
+ Assert-LifecycleAgentAbsent
$previousDisableAutoUpdate = [Environment]::GetEnvironmentVariable('PULSE_DISABLE_AUTO_UPDATE', 'Machine')
+ $restoreAutoUpdateAtExit = $true
[Environment]::SetEnvironmentVariable('PULSE_DISABLE_AUTO_UPDATE', 'true', 'Machine')
$versionV1 = Start-LifecycleServer -AgentPath $resolvedAgentV1
@@ -237,8 +268,11 @@ try {
Invoke-UninstallAndAssertClean
Write-Host 'Full Windows service lifecycle proof passed.' -ForegroundColor Green
} finally {
- Stop-LifecycleServer
- if ($restoreAutoUpdateAtExit) {
- [Environment]::SetEnvironmentVariable('PULSE_DISABLE_AUTO_UPDATE', $previousDisableAutoUpdate, 'Machine')
+ try {
+ Stop-LifecycleServer
+ } finally {
+ if ($restoreAutoUpdateAtExit) {
+ [Environment]::SetEnvironmentVariable('PULSE_DISABLE_AUTO_UPDATE', $previousDisableAutoUpdate, 'Machine')
+ }
}
}
diff --git a/scripts/installtests/windows_lifecycle_observation_controls.ps1 b/scripts/installtests/windows_lifecycle_observation_controls.ps1
new file mode 100644
index 0000000000..c8ecdfaf9d
--- /dev/null
+++ b/scripts/installtests/windows_lifecycle_observation_controls.ps1
@@ -0,0 +1,106 @@
+param([Parameter(Mandatory = $true)][string]$HarnessPath)
+$ErrorActionPreference = 'Stop'
+$serviceName = 'PulseAgent'
+$stateDir = 'test-only-state'
+$errors = $null
+$ast = [System.Management.Automation.Language.Parser]::ParseFile($HarnessPath, [ref]$null, [ref]$errors)
+if ($errors.Count) { throw "Harness parse failed: $errors" }
+# Only the actual observation functions run. No administrator check, actual SCM,
+# file deletion, listener mutation, or application install is admitted here.
+foreach ($name in @('Get-LifecycleService', 'Assert-LifecycleAgentAbsent', 'Invoke-UninstallAndAssertClean', 'Stop-LifecycleServer')) {
+ $functions = @($ast.FindAll({ param($node)
+ $node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -eq $name
+ }, $true))
+ if ($functions.Count -ne 1) { throw "Expected one lifecycle function: $name" }
+ Invoke-Expression $functions[0].Extent.Text
+}
+function Get-Service {
+ [CmdletBinding()]
+ param([string]$Name)
+ if ($Name -ne 'PulseAgent') { throw 'Different service selected' }
+ $script:reads++
+ if ($script:scenario -eq 'present') {
+ $controller = [PSCustomObject]@{}
+ $controller | Add-Member ScriptMethod Dispose { $script:disposed = $true }
+ return $controller
+ }
+ $id = 'NoServiceFoundForGivenName'
+ $category = [System.Management.Automation.ErrorCategory]::ObjectNotFound
+ if ($script:scenario -eq 'read-denied') { $category = [System.Management.Automation.ErrorCategory]::PermissionDenied }
+ if ($script:scenario -eq 'wrong-error-id') { $id = 'OtherNotFound' }
+ if ($script:scenario -eq 'wrong-category') { $category = [System.Management.Automation.ErrorCategory]::InvalidOperation }
+ $record = [System.Management.Automation.ErrorRecord]::new(
+ [System.InvalidOperationException]::new('test-only SCM result'), $id, $category, $Name)
+ $PSCmdlet.ThrowTerminatingError($record)
+}
+function Test-Path {
+ param([string]$Path)
+ if ($script:scenario -eq 'binary-present' -and $Path -eq "$env:ProgramFiles\Pulse\pulse-agent.exe") { return $true }
+ return $script:scenario -eq 'state-present' -and $Path -eq $stateDir
+}
+function Get-NetTCPConnection {
+ [CmdletBinding()]
+ param()
+ if ($script:scenario -eq 'listener-read-denied') { throw 'test-only listener read denied' }
+ if ($script:scenario -eq 'listener-present') { return [PSCustomObject]@{ LocalPort = 9191; State = 'Listen' } }
+ # Unrelated listeners and connected sockets do not prevent uninstall.
+ return @([PSCustomObject]@{ LocalPort = 80; State = 'Listen' },
+ [PSCustomObject]@{ LocalPort = 9191; State = 'Established' })
+}
+function Invoke-Installer {
+ param([string]$Arguments, [string]$Label)
+ if ($Arguments -ne '-Uninstall $true -NonInteractive $true') { throw 'Unexpected installer arguments' }
+ $script:labels.Add($Label)
+}
+$scenarios = @('absent', 'present', 'read-denied', 'wrong-error-id', 'wrong-category',
+ 'binary-present', 'state-present', 'listener-read-denied', 'listener-present')
+foreach ($script:scenario in $scenarios) {
+ $script:reads = 0
+ $script:disposed = $false
+ $failure = $null
+ try { Assert-LifecycleAgentAbsent } catch { $failure = $_ }
+ $success = $script:scenario -eq 'absent'
+ if (($null -eq $failure) -ne $success -or $script:reads -ne 1) {
+ throw "$script:scenario accepted uncertain state or did not independently query SCM: $failure"
+ }
+ if ($script:scenario -eq 'present' -and -not $script:disposed) { throw 'Controller handle not disposed' }
+ Write-Output "PASS $script:scenario"
+}
+$script:scenario = 'absent'
+$script:reads = 0
+$script:labels = [System.Collections.Generic.List[string]]::new()
+Invoke-UninstallAndAssertClean
+if (($script:labels -join ',') -ne 'uninstall,repeated uninstall' -or $script:reads -ne 2) {
+ throw 'Both uninstall attempts require their own independent SCM readback'
+}
+Write-Output 'PASS repeated uninstall with independent absence after each attempt'
+function Stop-Process {
+ [CmdletBinding()]
+ param([int]$Id, [switch]$Force)
+ if ($Id -ne 42 -or -not $Force) { throw 'Wrong owned process selected' }
+ $script:stops++
+ if ($script:scenario -eq 'server-stop-denied') { throw 'test-only stop denied' }
+}
+foreach ($script:scenario in @('server-already-exited', 'server-stopped', 'server-stop-denied', 'server-stop-timeout')) {
+ $script:stops = 0
+ $script:disposed = $false
+ $script:serverProcess = [PSCustomObject]@{ Id = 42; HasExited = ($script:scenario -eq 'server-already-exited') }
+ $script:serverProcess | Add-Member ScriptMethod WaitForExit {
+ param([int]$Timeout)
+ if ($Timeout -ne 5000) { throw 'Unbounded server cleanup' }
+ return $script:scenario -ne 'server-stop-timeout'
+ }
+ $script:serverProcess | Add-Member ScriptMethod Dispose { $script:disposed = $true }
+ $failure = $null
+ try { Stop-LifecycleServer } catch { $failure = $_ }
+ $success = $script:scenario -in @('server-already-exited', 'server-stopped')
+ if (($null -eq $failure) -ne $success -or $script:disposed -ne $success -or
+ ($null -eq $script:serverProcess) -ne $success) {
+ throw "$script:scenario lost owned cleanup uncertainty: $failure"
+ }
+ $expectedStops = 1
+ if ($script:scenario -eq 'server-already-exited') { $expectedStops = 0 }
+ if ($script:stops -ne $expectedStops) { throw 'Wrong cleanup stop count' }
+ Write-Output "PASS $script:scenario"
+}
+Write-Output 'PASS all 14 lifecycle observation controls; no actual SCM or file mutation'
diff --git a/scripts/installtests/windows_native_acceptance_test.go b/scripts/installtests/windows_native_acceptance_test.go
new file mode 100644
index 0000000000..f089edc763
--- /dev/null
+++ b/scripts/installtests/windows_native_acceptance_test.go
@@ -0,0 +1,124 @@
+package installtests
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "strings"
+ "testing"
+)
+
+func windowsNativeAcceptanceContract(harness string, steps []nativeWindowsExitStep) error {
+ for _, needle := range []string{
+ `$PSVersionTable.PSEdition -ne 'Desktop'`,
+ `$PSVersionTable.PSVersion.Major -ne 5`,
+ `$PSVersionTable.PSVersion.Minor -ne 1`,
+ `return Get-Service -Name $serviceName -ErrorAction Stop`,
+ `$_.FullyQualifiedErrorId.Split(',')[0] -eq 'NoServiceFoundForGivenName'`,
+ `$_.CategoryInfo.Category -eq [System.Management.Automation.ErrorCategory]::ObjectNotFound`,
+ `$remaining = Get-LifecycleService`,
+ "$previousDisableAutoUpdate = $null\n$restoreAutoUpdateAtExit = $false",
+ `Stop-Process -Id $script:serverProcess.Id -Force -ErrorAction Stop`,
+ `if (-not $script:serverProcess.WaitForExit(5000)) {`,
+ `$listeners = @(Get-NetTCPConnection -ErrorAction Stop | Where-Object {`,
+ `foreach ($label in @('uninstall', 'repeated uninstall')) {`,
+ `Invoke-Installer -Label $label -Arguments '-Uninstall $true -NonInteractive $true'`,
+ `Assert-LifecycleAgentAbsent`,
+ } {
+ if !strings.Contains(harness, needle) {
+ return fmt.Errorf("missing native acceptance boundary %q", needle)
+ }
+ }
+ if strings.Contains(harness, "Get-Service $serviceName -ErrorAction SilentlyContinue") ||
+ strings.Contains(harness, "Get-NetTCPConnection -LocalPort 9191") {
+ return fmt.Errorf("failed observation can stand in for absence")
+ }
+ preflight := "Assert-LifecycleAgentAbsent\n $previousDisableAutoUpdate = [Environment]::GetEnvironmentVariable"
+ if !strings.Contains(harness, preflight) {
+ return fmt.Errorf("machine state can change before independent clean-runner admission")
+ }
+
+ for _, step := range steps {
+ if step.Name == "Exercise native Windows service lifecycle" {
+ if step.Shell != "powershell" || step.ContinueOnError ||
+ strings.Contains(step.Run, "Remove-Item") || strings.Contains(step.Run, "SilentlyContinue") {
+ return fmt.Errorf("lifecycle must run in Windows PowerShell 5.1 without erasing pre-existing state")
+ }
+ return nil
+ }
+ }
+ return fmt.Errorf("native lifecycle step missing")
+}
+
+func TestWindowsAgentLifecycleRequiresExactEngineAndIndependentAbsence(t *testing.T) {
+ content, err := os.ReadFile(repoFile("scripts", "installtests", "windows_agent_lifecycle.ps1"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ harness := string(content)
+ steps := nativeWindowsExitSteps(t)
+ if err := windowsNativeAcceptanceContract(harness, steps); err != nil {
+ t.Fatal(err)
+ }
+ for _, needle := range []string{
+ `$PSVersionTable.PSVersion.Minor -ne 1`,
+ `return Get-Service -Name $serviceName -ErrorAction Stop`,
+ `$_.FullyQualifiedErrorId.Split(',')[0] -eq 'NoServiceFoundForGivenName'`,
+ `$_.CategoryInfo.Category -eq [System.Management.Automation.ErrorCategory]::ObjectNotFound`,
+ `$remaining = Get-LifecycleService`,
+ "$previousDisableAutoUpdate = $null\n$restoreAutoUpdateAtExit = $false",
+ `Stop-Process -Id $script:serverProcess.Id -Force -ErrorAction Stop`,
+ `if (-not $script:serverProcess.WaitForExit(5000)) {`,
+ `$listeners = @(Get-NetTCPConnection -ErrorAction Stop | Where-Object {`,
+ `foreach ($label in @('uninstall', 'repeated uninstall')) {`,
+ } {
+ t.Run(needle, func(t *testing.T) {
+ if err := windowsNativeAcceptanceContract(strings.Replace(harness, needle, "", 1), steps); err == nil {
+ t.Fatal("accepted removed engine, readback or repeated-uninstall boundary")
+ }
+ })
+ }
+ for _, mutation := range []string{"pwsh", "erase", "tolerate"} {
+ t.Run(mutation, func(t *testing.T) {
+ changed := append([]nativeWindowsExitStep(nil), steps...)
+ for i := range changed {
+ if changed[i].Name != "Exercise native Windows service lifecycle" {
+ continue
+ }
+ switch mutation {
+ case "pwsh":
+ changed[i].Shell = "pwsh"
+ case "erase":
+ changed[i].Run += "\nRemove-Item $lifecycleStateDir -Recurse -Force"
+ case "tolerate":
+ changed[i].ContinueOnError = true
+ }
+ }
+ if err := windowsNativeAcceptanceContract(harness, changed); err == nil {
+ t.Fatal("accepted unsafe native proof route")
+ }
+ })
+ }
+ if parentPath := os.Getenv("PULSE_WINDOWS_LIFECYCLE_PARENT"); parentPath != "" {
+ parent, err := os.ReadFile(parentPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := windowsNativeAcceptanceContract(string(parent), steps); err == nil {
+ t.Fatal("accepted original single-uninstall suppressed-read proof")
+ }
+ t.Log("rejected complete supplied parent lifecycle harness")
+ }
+}
+
+func TestWindowsAgentLifecycleObservationRuntime(t *testing.T) {
+ powerShell := nativeInstallerPowerShell(t)
+ cmd := exec.Command(powerShell, "-NoLogo", "-NoProfile", "-NonInteractive", "-File",
+ repoFile("scripts", "installtests", "windows_lifecycle_observation_controls.ps1"),
+ "-HarnessPath", repoFile("scripts", "installtests", "windows_agent_lifecycle.ps1"))
+ output, err := cmd.CombinedOutput()
+ if err != nil || !strings.Contains(string(output), "PASS all 14 lifecycle observation controls") {
+ t.Fatalf("actual lifecycle observation functions rejected their controls: %v\n%s", err, output)
+ }
+ t.Logf("%s", output)
+}