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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Repair native installer CI portability without weakening safety
pulse-triage[bot]d81401f29b9b
diff --git a/.github/workflows/unified-agent-native.yml b/.github/workflows/unified-agent-native.ymlindex 8e4ccef187..233e3b4be8 100644--- a/.github/workflows/unified-agent-native.yml+++ b/.github/workflows/unified-agent-native.yml@@ -162,9 +162,38 @@ jobs:if: runner.os == 'Linux'run: go build -o pulse-agent-helper-native ./cmd/pulse-agent-helper+ # Server/LXC fixtures execute Linux-only scripts, not a macOS installer.+ # Keep their supported Bash/GNU metadata semantics local to that step;+ # native macOS agent/runtime tests still use the runner's own utilities.+ - name: Supply Linux server installer fixture tools on macOS+ if: runner.os == 'macOS'+ shell: bash+ run: |+ set -euo pipefail+ brew install bash+ linux_bash="$(brew --prefix bash)/bin/bash"+ test -x "$linux_bash"+ "$linux_bash" -c '(( BASH_VERSINFO[0] >= 5 ))'+ coreutils_bin="$(brew --prefix coreutils)/bin"+ fixture_bin="$(mktemp -d "$RUNNER_TEMP/pulse-installer-fixture-tools.XXXXXX")"+ ln -s "$linux_bash" "$fixture_bin/bash"+ for tool in stat chmod chown; do+ executable="$coreutils_bin/g$tool"+ test -x "$executable"+ "$executable" --version | grep -q 'GNU coreutils'+ ln -s "$executable" "$fixture_bin/$tool"+ done+ printf 'PULSE_INSTALLER_FIXTURE_BIN=%s\n' "$fixture_bin" >> "$GITHUB_ENV"+- name: Test native Unix installer contractsif: matrix.unix- run: go test ./scripts/installtests+ shell: bash+ run: |+ set -euo pipefail+ if [[ -n "${PULSE_INSTALLER_FIXTURE_BIN:-}" ]]; then+ export PATH="$PULSE_INSTALLER_FIXTURE_BIN:$PATH"+ fi+ python3 scripts/installtests/run_unix_contracts.py- name: Test native Windows installer contractsif: ${{ !matrix.unix }}diff --git a/scripts/installtests/install_ps1_test.go b/scripts/installtests/install_ps1_test.goindex f36794eaaa..c39bb3490f 100644--- a/scripts/installtests/install_ps1_test.go+++ b/scripts/installtests/install_ps1_test.go@@ -639,12 +639,50 @@ func TestInstallPS1ServiceRemovalRuntime(t *testing.T) {repoFile("scripts", "installtests", "windows_service_removal_controls.ps1"),"-InstallerPath", repoFile("scripts", "install.ps1"))output, err := cmd.CombinedOutput()- if err != nil {+ if err != nil || !strings.Contains(string(output), "PASS all 13 production service-removal controls") {t.Fatalf("production service-removal controls failed: %v\n%s", err, output)}t.Logf("%s", output)}+func windowsRemovalFixtureContract(fixture string) error {+ load := strings.Index(fixture, "Add-Type -AssemblyName System.ServiceProcess")+ extract := strings.Index(fixture, "foreach ($name in @('Get-PulseService', 'Remove-PulseService'))")+ if load < 0 || extract <= load ||+ !strings.Contains(fixture, "$ExpectedStatus -is [System.ServiceProcess.ServiceControllerStatus]") {+ return fmt.Errorf("SCM double must load and check the real service-status enum before production controls")+ }+ return nil+}++func TestInstallPS1ServiceRemovalFixtureLoadsRealControllerEnum(t *testing.T) {+ content, err := os.ReadFile(repoFile("scripts", "installtests", "windows_service_removal_controls.ps1"))+ if err != nil {+ t.Fatal(err)+ }+ fixture := string(content)+ if err := windowsRemovalFixtureContract(fixture); err != nil {+ t.Fatal(err)+ }+ for _, boundary := range []string{"Add-Type -AssemblyName System.ServiceProcess", "$ExpectedStatus -is [System.ServiceProcess.ServiceControllerStatus]"} {+ t.Run(boundary, func(t *testing.T) {+ if err := windowsRemovalFixtureContract(strings.Replace(fixture, boundary, "", 1)); err == nil {+ t.Fatal("accepted an unloaded or simulated enum")+ }+ })+ }+ if parentPath := os.Getenv("PULSE_WINDOWS_REMOVAL_FIXTURE_PARENT"); parentPath != "" {+ parent, err := os.ReadFile(parentPath)+ if err != nil {+ t.Fatal(err)+ }+ if err := windowsRemovalFixtureContract(string(parent)); err == nil {+ t.Fatal("accepted the exact parent's missing assembly precondition")+ }+ t.Log("rejected supplied parent fixture without the real enum precondition")+ }+}+func windowsRemovalContract(script string) error {for _, needle := range []string{`return Get-Service -Name $AgentName -ErrorAction Stop`,diff --git a/scripts/installtests/native_installer_fixture_tools_test.go b/scripts/installtests/native_installer_fixture_tools_test.gonew file mode 100644index 0000000000..67e6d96c9a--- /dev/null+++ b/scripts/installtests/native_installer_fixture_tools_test.go@@ -0,0 +1,185 @@+//go:build !windows++package installtests++import (+ "context"+ "os"+ "os/exec"+ "path/filepath"+ "strings"+ "testing"+ "time"++ "gopkg.in/yaml.v3"+)++func nativeInstallerFixtureSteps(t *testing.T) (nativeGuidanceStep, nativeGuidanceStep) {+ t.Helper()+ content, err := os.ReadFile(repoFile(".github", "workflows", "unified-agent-native.yml"))+ if err != nil {+ t.Fatal(err)+ }+ var workflow struct {+ Jobs map[string]struct{ Steps []nativeGuidanceStep }+ }+ if err := yaml.Unmarshal(content, &workflow); err != nil {+ t.Fatal(err)+ }+ steps := workflow.Jobs["native-agent"].Steps+ runtimeAt, supplyAt, installerAt := -1, -1, -1+ for i, step := range steps {+ switch step.Name {+ case "Test native agent runtime":+ runtimeAt = i+ case "Supply Linux server installer fixture tools on macOS":+ supplyAt = i+ case "Test native Unix installer contracts":+ installerAt = i+ }+ }+ if runtimeAt < 0 || supplyAt <= runtimeAt || installerAt <= supplyAt {+ t.Fatal("Linux fixture tool supply must follow native runtime testing and precede Unix installer checks")+ }+ supply, installer := steps[supplyAt], steps[installerAt]+ if supply.If != "runner.os == 'macOS'" || supply.Shell != "bash" || installer.If != "matrix.unix" || installer.Shell != "bash" ||+ strings.Contains(supply.Run, "GITHUB_PATH") || !strings.Contains(installer.Run, `export PATH="$PULSE_INSTALLER_FIXTURE_BIN:$PATH"`) ||+ !strings.Contains(installer.Run, "python3 scripts/installtests/run_unix_contracts.py") {+ t.Fatal("Linux tools must stay local to complete Unix installer qualification")+ }+ return supply, installer+}++func TestNativeInstallerFixtureToolsAreRealAndStepLocal(t *testing.T) {+ supply, installer := nativeInstallerFixtureSteps(t)+ for _, scenario := range []string{"real tools", "install failure", "missing bash", "legacy bash", "missing stat", "non-GNU chmod"} {+ t.Run(scenario, func(t *testing.T) {+ root := t.TempDir()+ bin, prefix, runnerTemp := filepath.Join(root, "bin"), filepath.Join(root, "brew with spaces"), filepath.Join(root, "runner temp")+ for _, path := range []string{bin, filepath.Join(prefix, "bin"), runnerTemp} {+ if err := os.MkdirAll(path, 0700); err != nil {+ t.Fatal(err)+ }+ }+ brew := `#!/bin/sh+printf '%s\n' "$*" >> "$BREW_CALLS"+case "$*" in+ 'install bash') exit "${BREW_EXIT:-0}" ;;+ '--prefix bash'|'--prefix coreutils') printf '%s\n' "$TOOLS_PREFIX" ;;+ *) exit 64 ;;+esac+`+ if err := os.WriteFile(filepath.Join(bin, "brew"), []byte(brew), 0700); err != nil {+ t.Fatal(err)+ }+ for _, name := range []string{"bash", "stat", "chmod", "chown"} {+ if scenario == "missing "+name {+ continue+ }+ leaf := name+ if name != "bash" {+ leaf = "g" + name+ }+ path := filepath.Join(prefix, "bin", leaf)+ if (scenario == "legacy bash" && name == "bash") || (scenario == "non-GNU chmod" && name == "chmod") {+ fake := "#!/bin/sh\nprintf 'BSD utility\\n'\n"+ if name == "bash" {+ fake = "#!/bin/sh\nexit 1\n"+ }+ if err := os.WriteFile(path, []byte(fake), 0700); err != nil {+ t.Fatal(err)+ }+ } else {+ realTool, err := exec.LookPath(name)+ if err != nil {+ t.Fatal(err)+ }+ if err := os.Symlink(realTool, path); err != nil {+ t.Fatal(err)+ }+ }+ }+ envFile, calls := filepath.Join(root, "github-env"), filepath.Join(root, "brew-calls")+ installExit := "0"+ if scenario == "install failure" {+ installExit = "23"+ }+ env := append(os.Environ(), "PATH="+bin+":"+os.Getenv("PATH"), "TOOLS_PREFIX="+prefix,+ "BREW_CALLS="+calls, "BREW_EXIT="+installExit, "RUNNER_TEMP="+runnerTemp, "GITHUB_ENV="+envFile)+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)+ defer cancel()+ cmd := exec.CommandContext(ctx, "bash", "-c", supply.Run)+ cmd.Env = env+ output, runErr := cmd.CombinedOutput()+ if ctx.Err() != nil {+ t.Fatalf("fixture prerequisite deadline: %v", ctx.Err())+ }+ if scenario != "real tools" {+ want := 1+ if scenario == "install failure" {+ want = 23+ }+ exit, ok := runErr.(*exec.ExitError)+ if !ok || exit.ExitCode() != want {+ t.Fatalf("prerequisite exit %v, want %d: %s", runErr, want, output)+ }+ if _, err := os.Stat(envFile); !os.IsNotExist(err) {+ t.Fatal("failed prerequisite exported an executable path")+ }+ return+ }+ if runErr != nil {+ t.Fatalf("real tool supply: %v: %s", runErr, output)+ }+ data, err := os.ReadFile(envFile)+ if err != nil {+ t.Fatal(err)+ }+ fixtureBin := strings.TrimSuffix(strings.TrimPrefix(string(data), "PULSE_INSTALLER_FIXTURE_BIN="), "\n")+ if filepath.Dir(fixtureBin) != runnerTemp {+ t.Fatal("fixture tools escaped the owned runner directory")+ }+ entries, err := os.ReadDir(fixtureBin)+ if err != nil || len(entries) != 4 {+ t.Fatal("fixture supply must select only Bash/stat/chmod/chown")+ }+ for _, name := range []string{"bash", "stat", "chmod", "chown"} {+ leaf := name+ if name != "bash" {+ leaf = "g" + name+ }+ if target, err := os.Readlink(filepath.Join(fixtureBin, name)); err != nil || target != filepath.Join(prefix, "bin", leaf) {+ t.Fatalf("%s did not bind the verified installed executable", name)+ }+ }+ if data, err := os.ReadFile(calls); err != nil || string(data) != "install bash\n--prefix bash\n--prefix coreutils\n" {+ t.Fatal("fixture supply changed its fixed package/resource selection")+ }+ // Exercise the actual workflow step's local PATH boundary, replacing+ // only Python's containing suite to avoid recursively starting Go.+ probe := `#!/bin/sh+test "$*" = 'scripts/installtests/run_unix_contracts.py' || exit 91+test "$(command -v bash)" = "$PULSE_INSTALLER_FIXTURE_BIN/bash" || exit 92+for tool in stat chmod chown; do+ test "$(command -v "$tool")" = "$PULSE_INSTALLER_FIXTURE_BIN/$tool" || exit 93+done+exit "${SUITE_EXIT:-0}"+`+ if err := os.WriteFile(filepath.Join(bin, "python3"), []byte(probe), 0700); err != nil {+ t.Fatal(err)+ }+ for _, code := range []string{"0", "23"} {+ cmd := exec.CommandContext(ctx, "bash", "-c", installer.Run)+ cmd.Env = append(env, "PULSE_INSTALLER_FIXTURE_BIN="+fixtureBin, "SUITE_EXIT="+code)+ output, err := cmd.CombinedOutput()+ if code == "0" && err != nil {+ t.Fatalf("fixture-local path did not reach the suite: %v: %s", err, output)+ } else if code == "23" {+ if exit, ok := err.(*exec.ExitError); !ok || exit.ExitCode() != 23 {+ t.Fatalf("containing suite failure hidden: %v: %s", err, output)+ }+ }+ }+ })+ }+}diff --git a/scripts/installtests/run_unix_contracts.py b/scripts/installtests/run_unix_contracts.pynew file mode 100644index 0000000000..372a4f6a6e--- /dev/null+++ b/scripts/installtests/run_unix_contracts.py@@ -0,0 +1,46 @@+#!/usr/bin/env python3+"""Keep the expanded reset matrix separate without dropping installer checks.++Each Go invocation retains the existing ten-minute package deadline; individual+fixture, transport and cleanup deadlines are unchanged. Discover the actual+package inventory so future tests, examples and fuzz seeds remain included.+"""++from pathlib import Path+import subprocess+++ROOT = Path(__file__).resolve().parents[2]+PACKAGE = "./scripts/installtests"+++def partition(output):+ general, reset = [], []+ seen = set()+ for name in output.splitlines():+ if not name.startswith(("Test", "Example", "Fuzz")):+ continue+ if not name.isidentifier() or name in seen:+ raise ValueError("invalid or repeated Go test identity")+ seen.add(name)+ (reset if name.startswith("TestRootInstallReset") else general).append(name)+ if not general or not reset:+ raise ValueError("missing general or reset installer inventory")+ return general, reset+++def main():+ inventory = subprocess.run(+ ["go", "test", "-list", ".", PACKAGE], cwd=ROOT,+ check=True, capture_output=True, text=True,+ )+ for group, names in zip(("general", "reset"), partition(inventory.stdout)):+ print(f"Native Unix installer {group}: {len(names)} discovered checks", flush=True)+ subprocess.run(+ ["go", "test", "-count=1", "-timeout", "10m", "-run", "^(" + "|".join(names) + ")$", PACKAGE],+ cwd=ROOT, check=True,+ )+++if __name__ == "__main__":+ main()diff --git a/scripts/installtests/windows_native_acceptance_test.go b/scripts/installtests/windows_native_acceptance_test.goindex 30be380bf0..e4fd926e01 100644--- a/scripts/installtests/windows_native_acceptance_test.go+++ b/scripts/installtests/windows_native_acceptance_test.go@@ -9,6 +9,9 @@ import ()func windowsNativeAcceptanceContract(harness string, steps []nativeWindowsExitStep) error {+ // Git's native Windows checkout can use CRLF. Check the same statements+ // and ordering, rather than mistaking a line terminator for a missing gate.+ harness = strings.ReplaceAll(harness, "\r\n", "\n")for _, needle := range []string{`$PSVersionTable.PSEdition -ne 'Desktop'`,`$PSVersionTable.PSVersion.Major -ne 5`,@@ -55,7 +58,7 @@ func TestWindowsAgentLifecycleRequiresExactEngineAndIndependentAbsence(t *testinif err != nil {t.Fatal(err)}- harness := string(content)+ harness := strings.ReplaceAll(string(content), "\r\n", "\n")steps := nativeWindowsExitSteps(t)if err := windowsNativeAcceptanceContract(harness, steps); err != nil {t.Fatal(err)@@ -74,8 +77,12 @@ func TestWindowsAgentLifecycleRequiresExactEngineAndIndependentAbsence(t *testin"Assert-LifecycleAgentAbsent\n $previousDisableAutoUpdate = [Environment]::GetEnvironmentVariable",} {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 _, ending := range []string{"\n", "\r\n"} {+ changed := strings.Replace(harness, needle, "", 1)+ changed = strings.ReplaceAll(changed, "\n", ending)+ if err := windowsNativeAcceptanceContract(changed, steps); err == nil {+ t.Fatal("accepted removed engine, readback or repeated-uninstall boundary")+ }}})}@@ -112,6 +119,33 @@ func TestWindowsAgentLifecycleRequiresExactEngineAndIndependentAbsence(t *testin}}+func TestWindowsAgentLifecycleAcceptancePreservesBoundariesWithCRLF(t *testing.T) {+ content, err := os.ReadFile(repoFile("scripts", "installtests", "windows_agent_lifecycle.ps1"))+ if err != nil {+ t.Fatal(err)+ }+ harness := strings.ReplaceAll(string(content), "\r\n", "\n")+ steps := nativeWindowsExitSteps(t)+ for name, ending := range map[string]string{"LF": "\n", "CRLF": "\r\n"} {+ t.Run(name, func(t *testing.T) {+ if err := windowsNativeAcceptanceContract(strings.ReplaceAll(harness, "\n", ending), steps); err != nil {+ t.Fatal(err)+ }+ // Normalisation must not collapse statements or forgive a missing+ // preflight/reset. Both multi-line gates stay independently required.+ for _, needle := range []string{+ "$restoreAutoUpdateAtExit = $false",+ "Assert-LifecycleAgentAbsent\n $previousDisableAutoUpdate",+ } {+ changed := strings.Replace(harness, needle, "", 1)+ if err := windowsNativeAcceptanceContract(strings.ReplaceAll(changed, "\n", ending), steps); err == nil {+ t.Fatal("line-ending handling erased a safety boundary")+ }+ }+ })+ }+}+func TestWindowsAgentLifecycleObservationRuntime(t *testing.T) {powerShell := nativeInstallerPowerShell(t)cmd := exec.Command(powerShell, "-NoLogo", "-NoProfile", "-NonInteractive", "-File",diff --git a/scripts/installtests/windows_service_removal_controls.ps1 b/scripts/installtests/windows_service_removal_controls.ps1index 7078e95762..246a080231 100644--- a/scripts/installtests/windows_service_removal_controls.ps1+++ b/scripts/installtests/windows_service_removal_controls.ps1@@ -3,6 +3,10 @@ param([Parameter(Mandatory = $true)][string]$InstallerPath)$ErrorActionPreference = 'Stop'$AgentName = 'PulseAgent'+# Real Get-Service loads this assembly before returning a ServiceController.+# Our SCM double must supply the same enum without making a real service read.+Add-Type -AssemblyName System.ServiceProcess+# Load only the production boundary. No administrator check, download, real# SCM call or installer mutation runs in this failure-control harness.$errors = $null@@ -89,6 +93,7 @@ foreach ($script:scenario in $scenarios) {$script:controller | Add-Member ScriptMethod WaitForStatus {param($ExpectedStatus, [TimeSpan]$Timeout)$script:events.Add('wait')+ Assert-Control ($ExpectedStatus -is [System.ServiceProcess.ServiceControllerStatus]) 'wait did not receive the real service-status enum'Assert-Control ($ExpectedStatus.ToString() -eq 'Stopped') 'waited for a non-stopped state'$expectedTimeout = 30if ($script:scenario -eq 'delete-pending') { $expectedTimeout = 0 }diff --git a/scripts/tests/test_native_installer_contract_runner.py b/scripts/tests/test_native_installer_contract_runner.pynew file mode 100644index 0000000000..8d440513a1--- /dev/null+++ b/scripts/tests/test_native_installer_contract_runner.py@@ -0,0 +1,80 @@+#!/usr/bin/env python3+"""Exercise the actual inventory partition and fail-closed Go invocations."""++import importlib.util+from pathlib import Path+import subprocess+import unittest+from unittest import mock+++ROOT = Path(__file__).resolve().parents[2]+spec = importlib.util.spec_from_file_location(+ "runner", ROOT / "scripts/installtests/run_unix_contracts.py")+runner = importlib.util.module_from_spec(spec)+spec.loader.exec_module(runner)+++class NativeInstallerRunnerTest(unittest.TestCase):+ inventory = "TestInstaller\nTestRootInstallResetSafety\nExample\nFuzzInput\nTestFuture\nTestRootInstallResetFuture\nok\tpackage\n"++ def test_every_discovered_check_runs_once_in_one_group(self):+ general, reset = runner.partition(self.inventory)+ self.assertEqual(general, ["TestInstaller", "Example", "FuzzInput", "TestFuture"])+ self.assertEqual(reset, ["TestRootInstallResetSafety", "TestRootInstallResetFuture"])+ self.assertEqual(len(set(general + reset)), 6)++ def test_missing_inventory_is_not_a_passing_empty_run(self):+ for inventory in ("", "ok\tpackage\n", "TestInstaller\n", "TestRootInstallResetSafety\n"):+ with self.subTest(inventory=inventory), self.assertRaises(ValueError):+ runner.partition(inventory)++ def test_repeated_or_invalid_identity_stops(self):+ for name in ("TestInstaller", "TestX|.*", "Test(name)", "TestX --skip TestY"):+ with self.subTest(name=name), self.assertRaises(ValueError):+ runner.partition(self.inventory + name + "\n")++ def test_unicode_go_identifiers_remain_included(self):+ general, _ = runner.partition(self.inventory + "TestΣ\n")+ self.assertIn("TestΣ", general)++ def run_main(self, fault=None):+ calls = []++ def run(command, **kwargs):+ calls.append((command, kwargs))+ if fault == len(calls):+ raise subprocess.CalledProcessError(23, command)+ return subprocess.CompletedProcess(command, 0, stdout=self.inventory)++ with mock.patch.object(runner.subprocess, "run", side_effect=run), mock.patch("builtins.print"):+ if fault:+ with self.assertRaises(subprocess.CalledProcessError) as raised:+ runner.main()+ self.assertEqual(raised.exception.returncode, 23)+ else:+ runner.main()+ return calls++ def test_actual_commands_preserve_deadlines_count_and_complete_selection(self):+ calls = self.run_main()+ self.assertEqual(calls[0][0], ["go", "test", "-list", ".", runner.PACKAGE])+ general, reset = runner.partition(self.inventory)+ for (command, kwargs), names in zip(calls[1:], (general, reset)):+ self.assertEqual(command, ["go", "test", "-count=1", "-timeout", "10m", "-run", "^(" + "|".join(names) + ")$", runner.PACKAGE])+ self.assertTrue(kwargs["check"])+ self.assertEqual(kwargs["cwd"], ROOT)+ self.assertEqual(len(calls), 3)++ def test_inventory_failure_does_not_run_any_group(self):+ self.assertEqual(len(self.run_main(1)), 1)++ def test_first_failure_cannot_be_hidden_by_second_group(self):+ self.assertEqual(len(self.run_main(2)), 2)++ def test_second_group_failure_remains_terminal(self):+ self.assertEqual(len(self.run_main(3)), 3)+++if __name__ == "__main__":+ unittest.main()