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 incompatible Go test fixtures before backend CI fan-out

pulse-triage[bot]450a551cf5e8
diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml
index 46bee9ebbe..ebf7ad04b4 100644
--- a/.github/workflows/build-and-test.yml
+++ b/.github/workflows/build-and-test.yml
@@ -72,6 +72,7 @@ jobs:
outputs:
code: ${{ steps.filter.outputs.code }}
frontend_deps: ${{ steps.filter.outputs.frontend_deps }}
+ go_compile: ${{ steps.filter.outputs.go_compile }}
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -97,6 +98,7 @@ jobs:
echo "Base commit unavailable; assuming code and dependencies changed."
echo "code=true" >> "$GITHUB_OUTPUT"
echo "frontend_deps=true" >> "$GITHUB_OUTPUT"
+ echo "go_compile=true" >> "$GITHUB_OUTPUT"
exit 0
fi
changed=$(git diff --name-only "$base" "${{ github.sha }}")
@@ -109,6 +111,14 @@ jobs:
code=false
fi
echo "code=$code" >> "$GITHUB_OUTPUT"
+ # A full race-test compilation cost 386 seconds in a cold offline
+ # guest. Reserve that admission for Go source/graph/backend embeds
+ # and its own control path, not the much more frequent UI changes.
+ go_compile=false
+ if [ "$code" = true ]; then
+ go_compile=$(printf '%s\n' "$changed" | bash scripts/go-test-compile-required.sh)
+ fi
+ echo "go_compile=$go_compile" >> "$GITHUB_OUTPUT"
# Whether this change moves the frontend dependency graph. It decides
# whether the audit blocks it: a change that moves the graph answers
# for any finding and for an unreachable endpoint, while one that
@@ -268,9 +278,39 @@ jobs:
exit 1
fi
+ # Reject cross-package test/API incompatibilities before spending seven
+ # runners on race tests. This links test binaries but never executes them;
+ # the existing required checks below still own runtime and vet verdicts.
+ test-compile:
+ name: Compile backend race tests (no execution)
+ needs: changes
+ if: needs.changes.outputs.go_compile == 'true'
+ runs-on: ubuntu-24.04
+ timeout-minutes: 15
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
+ - name: Set up Go
+ uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
+ with:
+ go-version-file: go.mod
+ cache: true
+
+ - name: Provide frontend test embed stub
+ run: bash scripts/ensure_test_assets.sh
+
+ - name: Compile every Go race-test binary without executing it
+ run: bash scripts/compile-go-tests.sh
+
backend:
name: Backend tests (${{ matrix.shard }})
- needs: changes
+ needs: [changes, test-compile]
+ # Expand the unchanged required checks even when compilation fails. A
+ # skipped dependency must not turn a broken source into a green check.
+ if: ${{ !cancelled() && needs.changes.result == 'success' }}
# Expand every required shard even for documentation-only changes. A
# job-level condition skips expansion and leaves the named checks pending.
runs-on: ubuntu-24.04
@@ -283,6 +323,16 @@ jobs:
shard: [rest-0, rest-1]
steps:
+ - name: Require compiled backend tests
+ env:
+ COMPILE_REQUIRED: ${{ needs.changes.outputs.go_compile }}
+ COMPILE_RESULT: ${{ needs.test-compile.result }}
+ run: |
+ if [ "$COMPILE_REQUIRED" = true ] && [ "$COMPILE_RESULT" != success ]; then
+ echo "::error::Backend test compilation did not pass (result: ${COMPILE_RESULT:-unknown}); no runtime tests started."
+ exit 1
+ fi
+
- name: Report documentation-only change
if: needs.changes.outputs.code != 'true'
run: echo "No backend code changed. Tests are not required for this shard."
@@ -344,7 +394,10 @@ jobs:
# name by passing only when every shard passed.
backend-api:
name: Backend tests (api-${{ matrix.index }})
- needs: changes
+ needs: [changes, test-compile]
+ # Expand the unchanged required checks even when compilation fails. A
+ # skipped dependency must not turn a broken source into a green check.
+ if: ${{ !cancelled() && needs.changes.result == 'success' }}
# Like the rest shards, expand even for documentation-only changes so the
# verdict job sees real shard results rather than skipped jobs.
runs-on: ubuntu-24.04
@@ -358,6 +411,16 @@ jobs:
API_SHARD_COUNT: 5
steps:
+ - name: Require compiled backend tests
+ env:
+ COMPILE_REQUIRED: ${{ needs.changes.outputs.go_compile }}
+ COMPILE_RESULT: ${{ needs.test-compile.result }}
+ run: |
+ if [ "$COMPILE_REQUIRED" = true ] && [ "$COMPILE_RESULT" != success ]; then
+ echo "::error::Backend test compilation did not pass (result: ${COMPILE_RESULT:-unknown}); no runtime tests started."
+ exit 1
+ fi
+
- name: Report documentation-only change
if: needs.changes.outputs.code != 'true'
run: echo "No backend code changed. Tests are not required for this shard."
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index a8dbfbd5f0..3fd5d9ee8d 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -6786,6 +6786,39 @@ helper and `npm-audit-retry.sh` against the 1 October 2026 heads selected
`release/v6.4` (`GHSA-p98j-92pf-mc4p`) and `release/v6.5`
(`brace-expansion` and DOMPurify advisories). The hosted run is not yet claimed.
+
+### Backend test compilation before CI fan-out
+
+Build and Test links every Linux Go test binary with the same race instrumentation
+as its backend shards before those shards start runtime work. The compile-only
+job uses the declared Go toolchain, credential-free checkout and a test embed
+stub. `scripts/compile-go-tests.sh` replaces binary execution with `/bin/true`;
+it must not run package initialisers, TestMain, tests or examples. Its success
+is compilation evidence only, never a runtime, vet, real-frontend or installed
+acceptance verdict. Full required race-test shards retain those responsibilities.
+
+The diff classifier reserves this admission for Go source/manifests, backend
+embedded files and its own workflow/scripts. Unavailable diffs fail open into
+full compilation. Frontend-only changes do not pay for this Go-only preflight
+(the measured cold VM pass took 386 seconds); their existing backend runtime
+checks still run. `scripts/go-test-compile-required.sh` consumes the complete
+file list without an early-close/SIGPIPE path.
+
+A failed, cancelled, skipped or unknown compile result when compilation is required must
+fail the unchanged required backend check names, not let dependency skipping
+report success. Documentation-only changes still expand those named checks and
+accept the deliberately skipped compiler, as do changes outside Go compilation. Frontend and independent secret-scan
+work do not wait for compilation; their existing audit rules remain unchanged.
+
+`scripts/tests/test_go_test_compilation.py` exercises the actual compiler on
+inert multi-package fixtures, rejects a test-only removed API and a normal-source
+compile defect, and proves init/TestMain/test/example code is never executed.
+It executes both matrix prerequisite scripts against successful and adverse
+results and the documentation-only skip. `TestCITestCompilationPreservesChecks`
+retains the required names, full race execution and separate dependency audit.
+These proofs establish CI source admission, not hosted queue-time relief.
+
+
## Release-body updater ownership (30 September 2026)
Each executable `/bin/update --version` example in a published body must carry
diff --git a/scripts/compile-go-tests.sh b/scripts/compile-go-tests.sh
new file mode 100644
index 0000000000..efc363f1e5
--- /dev/null
+++ b/scripts/compile-go-tests.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+# Compile the same Linux race-test binaries as CI, without running package
+# initialisers, TestMain, tests or examples. This is not a test verdict.
+set -euo pipefail
+
+echo 'Compiling all Go race-test binaries; no test binary will execute.'
+# -exec replaces execution of each successfully linked binary. In contrast,
+# -run '^$' alone still runs init and TestMain. Vet and real test execution
+# remain in the existing required backend shards. Disable result caching so
+# the output cannot be mistaken for a previously executed test result.
+go test -race -vet=off -count=1 -exec /bin/true ./...
+echo 'All Go race-test binaries compiled; runtime tests remain required.'
diff --git a/scripts/go-test-compile-required.sh b/scripts/go-test-compile-required.sh
new file mode 100644
index 0000000000..5b597f208b
--- /dev/null
+++ b/scripts/go-test-compile-required.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+# Read the entire changed-file list. Source/manifests, embedded backend files
+# and this admission path can affect the root Go module; frontend-only changes
+# cannot invalidate its test API. An unavailable diff is handled as true by CI.
+set -euo pipefail
+
+if grep -E '^go\.(mod|sum)$|^(internal|cmd|pkg)/|^scripts/(compile-go-tests|go-test-compile-required|ensure_test_assets)\.sh$|^\.github/workflows/build-and-test\.yml$|\.(go|c|cc|cpp|h|s|S|syso)$' >/dev/null; then
+ printf 'true\n'
+else
+ printf 'false\n'
+fi
diff --git a/scripts/installtests/build_release_assets_test.go b/scripts/installtests/build_release_assets_test.go
index da492f2c72..1437275da1 100644
--- a/scripts/installtests/build_release_assets_test.go
+++ b/scripts/installtests/build_release_assets_test.go
@@ -5275,3 +5275,37 @@ func TestNpmAuditReportCleanupRemainsParentOwned(t *testing.T) {
})
}
}
+
+func TestCITestCompilationPreservesChecks(t *testing.T) {
+ workflowBytes, err := os.ReadFile(repoFile(".github", "workflows", "build-and-test.yml"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ workflow := string(workflowBytes)
+ for _, required := range []string{
+ "name: Compile backend race tests (no execution)",
+ "run: bash scripts/compile-go-tests.sh",
+ "name: Backend tests (${{ matrix.shard }})",
+ "name: Backend tests (api)",
+ "shard: [rest-0, rest-1]",
+ "index: [0, 1, 2, 3, 4]",
+ "go test -race -timeout 50m",
+ "name: Require frontend dependency audit",
+ "NPM_AUDIT_REQUIRE_RESULT: ${{ needs.changes.outputs.frontend_deps }}",
+ } {
+ if !strings.Contains(workflow, required) {
+ t.Fatalf("compile admission removed independent CI requirement: %s", required)
+ }
+ }
+ if strings.Count(workflow, "name: Require compiled backend tests") != 2 {
+ t.Fatal("both required backend matrices must report compilation failures")
+ }
+ for _, path := range []string{
+ repoFile("scripts", "compile-go-tests.sh"),
+ repoFile("scripts", "tests", "test_go_test_compilation.py"),
+ } {
+ if _, err := os.Stat(path); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
diff --git a/scripts/tests/test_go_test_compilation.py b/scripts/tests/test_go_test_compilation.py
new file mode 100644
index 0000000000..b8af39061e
--- /dev/null
+++ b/scripts/tests/test_go_test_compilation.py
@@ -0,0 +1,161 @@
+#!/usr/bin/env python3
+"""Compilation admission must reject broken fixtures without executing tests."""
+
+import os
+from pathlib import Path
+import re
+import subprocess
+import tempfile
+import unittest
+
+
+ROOT = Path(__file__).resolve().parents[2]
+COMPILER = ROOT / "scripts/compile-go-tests.sh"
+WORKFLOW = ROOT / ".github/workflows/build-and-test.yml"
+
+
+def job(source, name):
+ match = re.search(rf"^ {re.escape(name)}:\n(.*?)(?=^ [\w-]+:\n|\Z)", source, re.M | re.S)
+ if match is None:
+ raise AssertionError(f"missing workflow job {name}")
+ return match.group(1)
+
+
+def prerequisite_script(source):
+ match = re.search(
+ r" - name: Require compiled backend tests\n[\s\S]*? run: \|\n((?: [^\n]*\n|\n)+)",
+ source,
+ )
+ if match is None:
+ raise AssertionError("missing compilation prerequisite")
+ return "\n".join(line[10:] for line in match.group(1).splitlines())
+
+
+class GoTestCompilationTest(unittest.TestCase):
+ def compile_fixture(self, files):
+ with tempfile.TemporaryDirectory() as directory:
+ root = Path(directory)
+ (root / "go.mod").write_text("module example.invalid/compileproof\n\ngo 1.24\n")
+ for name, content in files.items():
+ path = root / name
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(content)
+ sentinel = root / "executed"
+ result = subprocess.run(
+ ["bash", str(COMPILER)], cwd=root,
+ env={**os.environ, "GOWORK": "off", "GOPROXY": "off", "CI_COMPILE_SENTINEL": str(sentinel)},
+ capture_output=True, text=True, timeout=120,
+ )
+ self.assertFalse(sentinel.exists(), "compile-only admission executed fixture code")
+ return result
+
+ def test_links_all_packages_without_init_testmain_tests_or_examples(self):
+ result = self.compile_fixture({
+ "proof_test.go": '''package compileproof
+import ("os"; "testing")
+func record() { os.WriteFile(os.Getenv("CI_COMPILE_SENTINEL"), []byte("executed"), 0600) }
+func init() { record(); panic("initialiser must not execute") }
+func TestMain(m *testing.M) { record(); os.Exit(99) }
+func TestMustNotExecute(t *testing.T) { record(); t.Fatal("test must not execute") }
+func ExampleMustNotExecute() { record(); panic("example must not execute") }
+''',
+ "child/proof_test.go": '''package child
+import "testing"
+func TestMustNotExecute(t *testing.T) { t.Fatal("child test must not execute") }
+''',
+ })
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("example.invalid/compileproof/child", result.stdout)
+ self.assertIn("runtime tests remain required", result.stdout)
+
+ def test_rejects_a_test_only_removed_api_before_runtime(self):
+ result = self.compile_fixture({
+ "api.go": "package compileproof\ntype Resource struct { ActiveAlerts []string }\n",
+ "child/stale_test.go": '''package child
+import ("testing"; api "example.invalid/compileproof")
+func TestStaleFixture(t *testing.T) { _ = api.Resource{Alerts: []api.ResourceAlertFrontend{}} }
+''',
+ })
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("ResourceAlertFrontend", result.stderr)
+ self.assertNotIn("runtime tests remain required", result.stdout)
+
+ def test_rejects_a_non_test_compilation_error(self):
+ result = self.compile_fixture({"broken.go": "package compileproof\nvar _ = removedAPI\n"})
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("removedAPI", result.stderr)
+
+ def test_admission_is_reserved_for_go_affecting_source_and_control(self):
+ required = ["internal/api/server.go", "pkg/model_test.go", "scripts/installtests/contract_test.go",
+ "go.mod", "go.sum", "internal/api/embed.json", "cmd/pulse/main.go",
+ "pkg/native/helper.c", "scripts/compile-go-tests.sh",
+ "scripts/go-test-compile-required.sh", "scripts/ensure_test_assets.sh",
+ ".github/workflows/build-and-test.yml"]
+ irrelevant = ["frontend-modern/src/index.tsx", "frontend-modern/package-lock.json",
+ "docs/guide.md", "README.md", "scripts/unrelated.sh"]
+ for paths, expected in [(required, "true"), (irrelevant, "false"), ([], "false")]:
+ for path in paths or [""]:
+ with self.subTest(path=path):
+ result = subprocess.run(["bash", str(ROOT / "scripts/go-test-compile-required.sh")],
+ input=path + "\n", capture_output=True, text=True)
+ self.assertEqual(result.returncode, 0, result.stderr)
+ self.assertEqual(result.stdout.strip(), expected)
+ # Do not use grep -q: under pipefail an early match in a large source
+ # update must not kill the writer with SIGPIPE and lose admission.
+ script = 'set -euo pipefail; printf "%s\n" "$CHANGED" | bash scripts/go-test-compile-required.sh'
+ result = subprocess.run(["bash", "-c", script], cwd=ROOT,
+ env={**os.environ, "CHANGED": "go.mod\n" + "frontend-modern/src/long.tsx\n" * 2000},
+ capture_output=True, text=True)
+ self.assertEqual(result.returncode, 0, result.stderr)
+ self.assertEqual(result.stdout.strip(), "true")
+ changes = job(WORKFLOW.read_text(), "changes")
+ self.assertIn('echo "go_compile=true" >> "$GITHUB_OUTPUT"', changes)
+ self.assertIn('go_compile=$(printf', changes)
+ self.assertIn('echo "go_compile=$go_compile" >> "$GITHUB_OUTPUT"', changes)
+ self.assertIn('go_compile=false', changes)
+
+ def test_gate_keeps_source_toolchain_embed_and_no_runtime_contract(self):
+ source = WORKFLOW.read_text()
+ compile_job = job(source, "test-compile")
+ for expected in (
+ "needs: changes", "if: needs.changes.outputs.go_compile == 'true'",
+ "runs-on: ubuntu-24.04", "timeout-minutes: 15",
+ "persist-credentials: false", "go-version-file: go.mod",
+ "run: bash scripts/ensure_test_assets.sh", "run: bash scripts/compile-go-tests.sh",
+ ):
+ self.assertIn(expected, compile_job)
+ self.assertLess(compile_job.index("ensure_test_assets.sh"), compile_job.index("compile-go-tests.sh"))
+ self.assertNotIn("continue-on-error:", compile_job)
+ self.assertIn("go test -race -vet=off -count=1 -exec /bin/true ./...", COMPILER.read_text())
+ # Frontend work does not wait for the Go-only gate.
+ self.assertIn("needs: changes", job(source, "frontend"))
+
+ def test_required_checks_fail_on_bad_compile_and_pass_docs_only_skip(self):
+ source = WORKFLOW.read_text()
+ for name in ("backend", "backend-api"):
+ section = job(source, name)
+ self.assertIn("needs: [changes, test-compile]", section)
+ self.assertIn("if: ${{ !cancelled() && needs.changes.result == 'success' }}", section)
+ self.assertIn("COMPILE_RESULT: ${{ needs.test-compile.result }}", section)
+ self.assertLess(section.index("Require compiled backend tests"), section.index("Checkout repository"))
+ script = prerequisite_script(section)
+ for code in ("true", "false"):
+ for result in ("success", "failure", "cancelled", "skipped", ""):
+ with self.subTest(job=name, code=code, result=result):
+ observed = subprocess.run(
+ ["bash", "-euo", "pipefail", "-c", script],
+ env={**os.environ, "COMPILE_REQUIRED": code, "COMPILE_RESULT": result},
+ capture_output=True, text=True,
+ )
+ expected = 0 if code == "false" or result == "success" else 1
+ self.assertEqual(observed.returncode, expected, observed.stdout + observed.stderr)
+ # Compile-only success cannot replace these full race/vet runs.
+ self.assertIn("go test -race -timeout 50m", section)
+ self.assertIn("shard: [rest-0, rest-1]", job(source, "backend"))
+ self.assertIn("index: [0, 1, 2, 3, 4]", job(source, "backend-api"))
+ self.assertIn("name: Backend tests (api)", job(source, "backend-api-verdict"))
+ self.assertIn("if: always()", job(source, "backend-api-verdict"))
+
+
+if __name__ == "__main__":
+ unittest.main()