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.

Aggregate simplify-review cleanups (no behavior change)

rcourtman93c62e691a9f
diff --git a/.github/workflows/install-sh-smoke.yml b/.github/workflows/install-sh-smoke.yml
index b8528e7757..38b7ce17b6 100644
--- a/.github/workflows/install-sh-smoke.yml
+++ b/.github/workflows/install-sh-smoke.yml
@@ -228,19 +228,13 @@ jobs:
done
echo "✓ pulse.service is active"
- echo "Hitting /api/health..."
- for i in $(seq 1 30); do
- if docker exec "${container_name}" curl -fsS http://127.0.0.1:7655/api/health >/dev/null 2>&1; then
- break
- fi
- if [ "$i" -eq 30 ]; then
- docker exec "${container_name}" systemctl status pulse --no-pager || true
- docker exec "${container_name}" journalctl -u pulse --no-pager --lines=80 || true
- echo "::error::/api/health did not respond within 60 seconds of service activation"
- exit 1
- fi
- sleep 2
- done
+ echo "Hitting /api/health (curl --retry handles the poll loop)..."
+ if ! docker exec "${container_name}" curl -fsS --retry 30 --retry-delay 2 --retry-connrefused --retry-all-errors http://127.0.0.1:7655/api/health >/dev/null; then
+ docker exec "${container_name}" systemctl status pulse --no-pager || true
+ docker exec "${container_name}" journalctl -u pulse --no-pager --lines=80 || true
+ echo "::error::/api/health did not respond within 60 seconds of service activation"
+ exit 1
+ fi
echo "✓ /api/health responded 200"
echo "Confirming installed version matches ${VERSION} via /api/version..."
diff --git a/internal/config/persistence_relay.go b/internal/config/persistence_relay.go
index 0e611f63c0..79d7c1c1c4 100644
--- a/internal/config/persistence_relay.go
+++ b/internal/config/persistence_relay.go
@@ -25,14 +25,11 @@ func (c *ConfigPersistence) SaveRelayConfig(cfg relay.Config) error {
func (c *ConfigPersistence) LoadRelayConfig() (*relay.Config, error) {
cfg := relay.DefaultConfig()
if err := loadJSON(c, c.relayFile, true, cfg); err != nil {
- if errors.Is(err, fs.ErrNotExist) || os.IsNotExist(err) {
- cfg = relay.DefaultConfig()
- relay.ApplyEnvOverrides(cfg)
- return cfg, nil
+ if !errors.Is(err, fs.ErrNotExist) && !os.IsNotExist(err) {
+ return nil, err
}
- return nil, err
+ // File absent: cfg is already the default; fall through to env overrides.
}
-
relay.ApplyEnvOverrides(cfg)
return cfg, nil
}
diff --git a/internal/relay/config_env.go b/internal/relay/config_env.go
index fc46b431f4..46d3a09d14 100644
--- a/internal/relay/config_env.go
+++ b/internal/relay/config_env.go
@@ -1,32 +1,30 @@
package relay
import (
- "os"
"strings"
+ "github.com/rcourtman/pulse-go-rewrite/internal/utils"
"github.com/rs/zerolog/log"
)
-// Env vars for headless / container deployments that need to bootstrap relay
-// without going through Settings → Relay. They override the persisted file
-// config; if you set them you accept that UI changes will be re-overridden on
-// next start.
+// Env vars for headless / container deployments that bootstrap relay without
+// going through Settings → Relay. Saving from the UI after an override is
+// active persists the env-effective state to disk, so clearing the env alone
+// does not revert.
const (
EnvRelayEnabled = "PULSE_RELAY_ENABLED"
EnvRelayServerURL = "PULSE_RELAY_SERVER"
)
// ApplyEnvOverrides mutates cfg in place to reflect PULSE_RELAY_* environment
-// overrides. Unset / empty / unparseable env vars do not override; the file
-// (or default) value remains. Invalid server URLs are logged and ignored —
-// the override silently falls back rather than leaving relay wedged on a
-// malformed endpoint.
+// overrides. Unset / empty / unparseable env vars leave the file value
+// untouched; invalid server URLs are logged and ignored.
func ApplyEnvOverrides(cfg *Config) {
if cfg == nil {
return
}
- if rawEnabled := strings.TrimSpace(os.Getenv(EnvRelayEnabled)); rawEnabled != "" {
+ if rawEnabled := utils.GetenvTrim(EnvRelayEnabled); rawEnabled != "" {
if parsed, ok := parseEnvBool(rawEnabled); ok {
cfg.Enabled = parsed
log.Info().
@@ -41,7 +39,7 @@ func ApplyEnvOverrides(cfg *Config) {
}
}
- if rawURL := strings.TrimSpace(os.Getenv(EnvRelayServerURL)); rawURL != "" {
+ if rawURL := utils.GetenvTrim(EnvRelayServerURL); rawURL != "" {
if err := validateRelayServerURL(rawURL); err != nil {
log.Warn().
Str("env_var", EnvRelayServerURL).
@@ -58,10 +56,8 @@ func ApplyEnvOverrides(cfg *Config) {
}
}
-// parseEnvBool returns (value, ok). ok=false means the input was not a
-// recognizable boolean and the caller should leave the config field alone.
-// Distinct from utils.ParseBool which silently coerces everything unknown to
-// false; for env overrides we need to tell "unset" from "explicit false".
+// parseEnvBool distinguishes "unset" from "explicit false"; utils.ParseBool
+// can't (it coerces everything unrecognized to false).
func parseEnvBool(rawValue string) (value bool, ok bool) {
switch strings.ToLower(strings.TrimSpace(rawValue)) {
case "1", "true", "yes", "y", "on":
diff --git a/internal/relay/config_env_test.go b/internal/relay/config_env_test.go
index 38afb95b88..c78fd1b9a1 100644
--- a/internal/relay/config_env_test.go
+++ b/internal/relay/config_env_test.go
@@ -2,90 +2,82 @@ package relay
import "testing"
-func TestApplyEnvOverridesUnsetLeavesConfigAlone(t *testing.T) {
- t.Setenv(EnvRelayEnabled, "")
- t.Setenv(EnvRelayServerURL, "")
-
- cfg := &Config{Enabled: true, ServerURL: "wss://file.example/ws/instance"}
- ApplyEnvOverrides(cfg)
-
- if !cfg.Enabled {
- t.Fatalf("Enabled = false, want true (file value preserved when env unset)")
- }
- if cfg.ServerURL != "wss://file.example/ws/instance" {
- t.Fatalf("ServerURL = %q, want file value preserved", cfg.ServerURL)
- }
-}
-
-func TestApplyEnvOverridesEnabledTrueOverridesFile(t *testing.T) {
- t.Setenv(EnvRelayEnabled, "true")
- t.Setenv(EnvRelayServerURL, "")
-
- cfg := &Config{Enabled: false, ServerURL: DefaultServerURL}
- ApplyEnvOverrides(cfg)
-
- if !cfg.Enabled {
- t.Fatalf("Enabled = false, want true (env override true)")
- }
-}
-
-func TestApplyEnvOverridesEnabledFalseOverridesFile(t *testing.T) {
- t.Setenv(EnvRelayEnabled, "false")
- t.Setenv(EnvRelayServerURL, "")
-
- cfg := &Config{Enabled: true, ServerURL: DefaultServerURL}
- ApplyEnvOverrides(cfg)
-
- if cfg.Enabled {
- t.Fatalf("Enabled = true, want false (env override false should disable a file-enabled relay)")
- }
-}
-
-func TestApplyEnvOverridesGarbageBoolIgnored(t *testing.T) {
- t.Setenv(EnvRelayEnabled, "maybe")
- t.Setenv(EnvRelayServerURL, "")
-
- cfg := &Config{Enabled: true, ServerURL: DefaultServerURL}
- ApplyEnvOverrides(cfg)
-
- if !cfg.Enabled {
- t.Fatalf("Enabled = false, want true (garbage bool should not override)")
+const fileServerURL = "wss://file.example/ws/instance"
+
+func TestApplyEnvOverridesTable(t *testing.T) {
+ cases := []struct {
+ name string
+ envEnabled string
+ envURL string
+ in Config
+ want Config
+ }{
+ {
+ name: "unset leaves config alone",
+ envEnabled: "",
+ envURL: "",
+ in: Config{Enabled: true, ServerURL: fileServerURL},
+ want: Config{Enabled: true, ServerURL: fileServerURL},
+ },
+ {
+ name: "enabled true overrides file",
+ envEnabled: "true",
+ envURL: "",
+ in: Config{Enabled: false, ServerURL: DefaultServerURL},
+ want: Config{Enabled: true, ServerURL: DefaultServerURL},
+ },
+ {
+ name: "enabled false overrides file-enabled relay",
+ envEnabled: "false",
+ envURL: "",
+ in: Config{Enabled: true, ServerURL: DefaultServerURL},
+ want: Config{Enabled: false, ServerURL: DefaultServerURL},
+ },
+ {
+ name: "garbage bool does not override",
+ envEnabled: "maybe",
+ envURL: "",
+ in: Config{Enabled: true, ServerURL: DefaultServerURL},
+ want: Config{Enabled: true, ServerURL: DefaultServerURL},
+ },
+ {
+ name: "valid server URL overrides file",
+ envEnabled: "",
+ envURL: "wss://relay.test.example/ws/instance",
+ in: Config{Enabled: true, ServerURL: DefaultServerURL},
+ want: Config{Enabled: true, ServerURL: "wss://relay.test.example/ws/instance"},
+ },
+ {
+ name: "invalid server URL keeps file value",
+ envEnabled: "",
+ envURL: "http://wrong-scheme.example/",
+ in: Config{Enabled: true, ServerURL: fileServerURL},
+ want: Config{Enabled: true, ServerURL: fileServerURL},
+ },
+ {
+ name: "both overrides apply together",
+ envEnabled: "yes",
+ envURL: "wss://relay.test.example/ws/instance",
+ in: Config{Enabled: false, ServerURL: DefaultServerURL},
+ want: Config{Enabled: true, ServerURL: "wss://relay.test.example/ws/instance"},
+ },
}
-}
-
-func TestApplyEnvOverridesValidServerURLOverridesFile(t *testing.T) {
- t.Setenv(EnvRelayEnabled, "")
- t.Setenv(EnvRelayServerURL, "wss://relay.test.example/ws/instance")
-
- cfg := &Config{Enabled: true, ServerURL: DefaultServerURL}
- ApplyEnvOverrides(cfg)
-
- if cfg.ServerURL != "wss://relay.test.example/ws/instance" {
- t.Fatalf("ServerURL = %q, want env override", cfg.ServerURL)
- }
-}
-
-func TestApplyEnvOverridesInvalidServerURLKeepsFile(t *testing.T) {
- t.Setenv(EnvRelayEnabled, "")
- t.Setenv(EnvRelayServerURL, "http://wrong-scheme.example/")
-
- cfg := &Config{Enabled: true, ServerURL: "wss://file.example/ws/instance"}
- ApplyEnvOverrides(cfg)
-
- if cfg.ServerURL != "wss://file.example/ws/instance" {
- t.Fatalf("ServerURL = %q, want file value preserved (invalid env URL should not override)", cfg.ServerURL)
- }
-}
-
-func TestApplyEnvOverridesBothApplyTogether(t *testing.T) {
- t.Setenv(EnvRelayEnabled, "yes")
- t.Setenv(EnvRelayServerURL, "wss://relay.test.example/ws/instance")
-
- cfg := &Config{Enabled: false, ServerURL: DefaultServerURL}
- ApplyEnvOverrides(cfg)
- if !cfg.Enabled || cfg.ServerURL != "wss://relay.test.example/ws/instance" {
- t.Fatalf("ApplyEnvOverrides did not apply both overrides: %+v", cfg)
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Setenv(EnvRelayEnabled, tc.envEnabled)
+ t.Setenv(EnvRelayServerURL, tc.envURL)
+
+ cfg := tc.in
+ ApplyEnvOverrides(&cfg)
+
+ if cfg.Enabled != tc.want.Enabled {
+ t.Errorf("Enabled = %v, want %v", cfg.Enabled, tc.want.Enabled)
+ }
+ if cfg.ServerURL != tc.want.ServerURL {
+ t.Errorf("ServerURL = %q, want %q", cfg.ServerURL, tc.want.ServerURL)
+ }
+ })
}
}
diff --git a/scripts/installtests/build_release_assets_test.go b/scripts/installtests/build_release_assets_test.go
index df7302703f..9b0be6542e 100644
--- a/scripts/installtests/build_release_assets_test.go
+++ b/scripts/installtests/build_release_assets_test.go
@@ -926,20 +926,17 @@ func TestBuildReleasePackagesPulseMcpForAllPlatforms(t *testing.T) {
}
}
+// The three release-pipeline downstream workflows (install-sh-smoke,
+// promote-floating-tags, publish-helm-chart) all share the same root cause:
+// v6 rc.1 → rc.5 silently broke because GitHub's `release: published` webhook
+// doesn't fire when create-release.yml's draft → PATCH(draft=false) promotion
+// path is used, and `workflow_run` chains don't fire when their upstream
+// fails. The fix in each case is a workflow_call entry from create-release.yml
+// after validate_release_assets succeeds. The tests below pin the trigger
+// declarations and resolver logic so the regression class can't return.
+
func TestInstallShSmokeWorkflowPresent(t *testing.T) {
- // End-to-end install.sh smoke gate. validate-release.sh catches asset-
- // identity drift at build time (right banner / right --version handler /
- // right signature key). This workflow proves the documented secure-install
- // commands actually install and boot Pulse end-to-end against the
- // published GitHub Release, which is the surface that broke silently
- // across v6 rc.1 → rc.5. Removing or weakening any of these assertions
- // reopens that regression class.
- workflowBytes, err := os.ReadFile(repoFile(".github", "workflows", "install-sh-smoke.yml"))
- if err != nil {
- t.Fatalf("read install-sh-smoke.yml: %v", err)
- }
- workflow := string(workflowBytes)
- required := []string{
+ assertFileContainsAll(t, repoFile(".github", "workflows", "install-sh-smoke.yml"),
// Inputs and triggers.
`name: install.sh Smoke (Published Release)`,
`workflow_call:`,
@@ -948,8 +945,7 @@ func TestInstallShSmokeWorkflowPresent(t *testing.T) {
`releases/download/${TAG}`,
`install.sh.sshsig`,
`pulse-${TAG}-linux-amd64.tar.gz`,
- // README key extraction + actual ssh-keygen verify against the
- // downloaded asset.
+ // README key extraction + ssh-keygen verify against the asset.
`grep -oE 'ssh-ed25519 [A-Za-z0-9+/=]+ pulse-installer' README.md`,
`ssh-keygen -Y verify \`,
`-I pulse-installer \`,
@@ -963,33 +959,16 @@ func TestInstallShSmokeWorkflowPresent(t *testing.T) {
`jrei/systemd-debian:12`,
`bash install.sh --archive /smoke/${tarball} --disable-auto-updates`,
`systemctl is-active pulse`,
- `curl -fsS http://127.0.0.1:7655/api/health`,
+ // curl --retry handles its own poll loop instead of a bash for-loop.
+ `--retry 30 --retry-delay 2 --retry-connrefused --retry-all-errors http://127.0.0.1:7655/api/health`,
// Authoritative version check via /api/version (not /api/health).
`curl -fsS http://127.0.0.1:7655/api/version`,
`Installed version mismatch. Expected`,
- }
- for _, needle := range required {
- if !strings.Contains(workflow, needle) {
- t.Fatalf("install-sh-smoke.yml missing required smoke step: %s", needle)
- }
- }
+ )
}
func TestPromoteFloatingTagsReachableViaWorkflowCall(t *testing.T) {
- // promote-floating-tags.yml's `workflow_run` chain off publish-docker
- // silently stops working when publish-docker fails (rc.3 → rc.5 all
- // failed at the now-removed pulse-agent push step). Without the
- // floating tags promoted, customers pulling rcourtman/pulse:latest
- // stay on the previous release tag. Adding workflow_call so
- // create-release.yml can drive promotion explicitly after
- // validate_release_assets succeeds — same defensive shape as
- // publish-helm-chart and install-sh-smoke.
- workflowBytes, err := os.ReadFile(repoFile(".github", "workflows", "promote-floating-tags.yml"))
- if err != nil {
- t.Fatalf("read promote-floating-tags.yml: %v", err)
- }
- workflow := string(workflowBytes)
- required := []string{
+ assertFileContainsAll(t, repoFile(".github", "workflows", "promote-floating-tags.yml"),
`workflow_call:`,
`tag:`,
`description: "Release tag (e.g., v6.0.0). Required for workflow_call."`,
@@ -997,50 +976,24 @@ func TestPromoteFloatingTagsReachableViaWorkflowCall(t *testing.T) {
`type: boolean`,
// Job condition must accept workflow_call alongside workflow_dispatch.
`github.event_name == 'workflow_call'`,
- // Tag resolver must prefer inputs over the workflow_run derivation
- // when running through workflow_call / workflow_dispatch.
+ // Tag resolver must prefer inputs over the workflow_run derivation.
`if [ -n "${INPUT_TAG}" ]; then`,
`TAG="${INPUT_TAG}"`,
- }
- for _, needle := range required {
- if !strings.Contains(workflow, needle) {
- t.Fatalf("promote-floating-tags.yml missing required workflow_call wiring: %s", needle)
- }
- }
+ )
}
func TestPublishHelmChartReachableViaWorkflowCall(t *testing.T) {
- // v6 rc.1 → rc.5 published successfully but never published a Helm
- // chart because `release: published` does not fire when a release is
- // created as draft and later PATCHed to draft=false (the path
- // create-release.yml uses). The fix is an explicit workflow_call from
- // create-release.yml — wired in `publish_helm_chart` job — that runs
- // after validate_release_assets succeeds. Both the trigger declaration
- // on publish-helm-chart.yml and the wiring in create-release.yml must
- // be present; reverting either reopens the chart-not-published gap.
- workflowBytes, err := os.ReadFile(repoFile(".github", "workflows", "publish-helm-chart.yml"))
- if err != nil {
- t.Fatalf("read publish-helm-chart.yml: %v", err)
- }
- workflow := string(workflowBytes)
- required := []string{
+ assertFileContainsAll(t, repoFile(".github", "workflows", "publish-helm-chart.yml"),
`workflow_call:`,
`chart_version:`,
`description: "Chart version (e.g., 6.0.0-rc.5). Required for workflow_call."`,
`required: true`,
`type: string`,
`app_version:`,
- // The chart-version resolver must accept inputs from both
- // workflow_call and workflow_dispatch, falling back to the
- // release-event tag only when no inputs are present.
+ // Chart-version resolver prefers inputs over release-event tag.
`if [ -n "${INPUT_CHART_VERSION}" ]; then`,
`RELEASE_TAG="${RELEASE_TAG_NAME}"`,
- }
- for _, needle := range required {
- if !strings.Contains(workflow, needle) {
- t.Fatalf("publish-helm-chart.yml missing required workflow_call wiring: %s", needle)
- }
- }
+ )
}
func TestHelmAgentRuntimePointsAtRealImage(t *testing.T) {
@@ -1085,37 +1038,17 @@ func TestHelmAgentRuntimePointsAtRealImage(t *testing.T) {
t.Fatal("agent.yaml template must render command via toYaml so list values pass through correctly")
}
- dockerfile, err := os.ReadFile(repoFile("Dockerfile"))
- if err != nil {
- t.Fatalf("read Dockerfile: %v", err)
- }
- dockerfileStr := string(dockerfile)
- dockerfileRequired := []string{
+ assertFileContainsAll(t, repoFile("Dockerfile"),
`ln -s /opt/pulse/bin/pulse-agent-linux-arm64 /usr/local/bin/pulse-agent`,
`ln -s /opt/pulse/bin/pulse-agent-linux-armv7 /usr/local/bin/pulse-agent`,
`ln -s /opt/pulse/bin/pulse-agent-linux-amd64 /usr/local/bin/pulse-agent`,
- }
- for _, needle := range dockerfileRequired {
- if !strings.Contains(dockerfileStr, needle) {
- t.Fatalf("Dockerfile runtime stage missing arch-resolved pulse-agent symlink: %s", needle)
- }
- }
+ )
- validateScript, err := os.ReadFile(repoFile("scripts", "validate-release.sh"))
- if err != nil {
- t.Fatalf("read validate-release.sh: %v", err)
- }
- validate := string(validateScript)
- validateRequired := []string{
+ assertFileContainsAll(t, repoFile("scripts", "validate-release.sh"),
`Validating /usr/local/bin/pulse-agent arch-resolved symlink`,
`[ -L /usr/local/bin/pulse-agent ]`,
`/usr/local/bin/pulse-agent target is not executable`,
- }
- for _, needle := range validateRequired {
- if !strings.Contains(validate, needle) {
- t.Fatalf("validate-release.sh missing pulse-agent symlink guard: %s", needle)
- }
- }
+ )
}
func repoFile(parts ...string) string {
@@ -1124,6 +1057,23 @@ func repoFile(parts ...string) string {
return filepath.Join(segments...)
}
+// assertFileContainsAll reads the file at path and fails the test if any of
+// the required substrings is missing. The standard pinning-test shape in
+// this package.
+func assertFileContainsAll(t *testing.T, path string, required ...string) {
+ t.Helper()
+ content, err := os.ReadFile(path)
+ if err != nil {
+ t.Fatalf("read %s: %v", path, err)
+ }
+ s := string(content)
+ for _, needle := range required {
+ if !strings.Contains(s, needle) {
+ t.Fatalf("%s missing required substring: %s", path, needle)
+ }
+ }
+}
+
func workflowJobBlock(t *testing.T, workflow, job string) string {
t.Helper()