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.

Fail closed when local pre-push source reads fail

pulse-triage[bot]21a32dbf86fd
diff --git a/scripts/dev-prepush.sh b/scripts/dev-prepush.sh
index e2520fe82f..2a9ec8d471 100755
--- a/scripts/dev-prepush.sh
+++ b/scripts/dev-prepush.sh
@@ -26,18 +26,37 @@ FAILURES=0
step() { printf '\n=== %s ===\n' "$1"; }
fail() { printf 'FAIL: %s\n' "$1"; FAILURES=$((FAILURES + 1)); }
+source_read_failed() {
+ printf 'Cannot %s (git exit %s); no passing pre-push verdict is available.\n' "$2" "$1" >&2
+ exit 2
+}
if ! BASE_SHA=$(git rev-parse --verify --quiet "${BASE}^{commit}"); then
echo "Base ref $BASE not found; run git fetch origin first." >&2
exit 2
fi
-if ! git diff --quiet || ! git diff --cached --quiet; then
+DIRTY=false
+status=0
+git diff --quiet || status=$?
+case "$status" in
+ 0) ;;
+ 1) DIRTY=true ;;
+ *) source_read_failed "$status" "inspect unstaged changes" ;;
+esac
+status=0
+git diff --cached --quiet || status=$?
+case "$status" in
+ 0) ;;
+ 1) DIRTY=true ;;
+ *) source_read_failed "$status" "inspect staged changes" ;;
+esac
+if [ "$DIRTY" = true ]; then
echo "Note: working tree has uncommitted changes; only committed work is checked."
fi
-HEAD_SHA=$(git rev-parse --verify HEAD)
-AHEAD=$(git rev-list --count "$BASE_SHA".."$HEAD_SHA")
+HEAD_SHA=$(git rev-parse --verify HEAD) || source_read_failed "$?" "resolve HEAD"
+AHEAD=$(git rev-list --count "$BASE_SHA".."$HEAD_SHA") || source_read_failed "$?" "count outgoing commits"
if [ "$AHEAD" -eq 0 ]; then
echo "No commits ahead of $BASE; nothing to check."
exit 0
@@ -49,8 +68,11 @@ if ! RANGE_BASE=$(git merge-base "$BASE_SHA" "$HEAD_SHA"); then
echo "Base ref $BASE has no common ancestor with HEAD; choose a base in this history." >&2
exit 2
fi
-CHANGED=$(git diff --name-only "$RANGE_BASE" "$HEAD_SHA")
+CHANGED=$(git diff --name-only "$RANGE_BASE" "$HEAD_SHA") || source_read_failed "$?" "list changed files"
CHANGED_GO=$(printf '%s\n' "$CHANGED" | grep -E '\.go$' || true)
+# Admit the whole commit/parent inventory before interpreting it. A process
+# substitution hides rev-list's exit and can silently omit required guards.
+COMMITS=$(git rev-list --reverse --no-merges --parents "$BASE_SHA".."$HEAD_SHA") || source_read_failed "$?" "list outgoing commits"
# Match Build and Test's strict audit paths. A known-rejected graph should not
# wait for the expensive source checks, or get a local passing verdict instead.
@@ -66,11 +88,11 @@ if printf '%s\n' "$CHANGED" | grep -E '^frontend-modern/package(-lock)?\.json$|^
fi
step "Canonical completion guard (per commit, CI mode)"
-while IFS= read -r commit; do
+while read -r commit parents; do
if [ -z "$commit" ]; then
continue
fi
- if ! git rev-parse --verify --quiet "${commit}^" >/dev/null; then
+ if [ -z "$parents" ]; then
echo "Skipping root commit $commit (no parent to diff against)."
continue
fi
@@ -78,15 +100,21 @@ while IFS= read -r commit; do
# Match canonical-governance.yml exactly: the prepare-commit-msg hook
# persists an intentional local bypass as a trailer, so recover that
# reason when validating already-created commits before push.
- reason=$(git log -1 --format='%(trailers:key=Contract-Neutral,valueonly,separator=; )' "$commit" | tr '\n' ' ')
+ reason=$(git log -1 --format='%(trailers:key=Contract-Neutral,valueonly,separator=; )' "$commit" | tr '\n' ' ') || source_read_failed "$?" "read Contract-Neutral trailer for $commit"
+ files=$(git diff-tree --no-commit-id --name-only -r "$commit") || source_read_failed "$?" "list changed files for $commit"
echo "Checking $commit"
- if ! git diff-tree --no-commit-id --name-only -r "$commit" | \
+ if ! printf '%s\n' "$files" | \
PULSE_ALLOW_CONTRACT_NEUTRAL_COMMIT="$reason" \
python3 scripts/release_control/canonical_completion_guard.py \
--files-from-stdin --diff-base "${commit}^" --commit "$commit"; then
fail "canonical completion guard @ $commit"
fi
-done < <(git rev-list --reverse --no-merges "$BASE_SHA".."$HEAD_SHA")
+done <<< "$COMMITS"
+
+if [ "$FAILURES" -gt 0 ]; then
+ echo "Canonical completion guard failed; remaining source checks have not run." >&2
+ exit 1
+fi
# Type-checking cannot establish rendered acceptance. Use the existing final
# content guard, including receipt-only edits and merge resolutions, without
diff --git a/scripts/tests/test_dev_prepush_frontend.py b/scripts/tests/test_dev_prepush_frontend.py
index 2fd6f132dc..757a5ff164 100644
--- a/scripts/tests/test_dev_prepush_frontend.py
+++ b/scripts/tests/test_dev_prepush_frontend.py
@@ -6,6 +6,7 @@ import hashlib
import json
import os
from pathlib import Path
+import shutil
import subprocess
import tempfile
import unittest
@@ -240,13 +241,14 @@ class DevPrepushFrontendTest(DevPrepushFixture):
self.assertEqual([call["args"] for call in calls], [["run", "type-check"]])
self.assertEqual(len(guards), 1)
- def test_canonical_failure_is_not_cleared_by_a_clean_audit(self):
+ def test_canonical_failure_stops_source_checks_after_a_clean_audit(self):
self.change("frontend-modern/package.json")
self.env["PREPUSH_GUARD_STATUS"] = "4"
result, calls, guards = self.run_gate()
self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
self.assertNotIn("All pre-push checks passed", result.stdout)
- self.assertEqual([call["args"] for call in calls], [["audit", "--json"], ["run", "type-check"]])
+ self.assertIn("Canonical completion guard failed; remaining source checks have not run", result.stderr)
+ self.assertEqual([call["args"] for call in calls], [["audit", "--json"]])
self.assertEqual(len(guards), 1)
def test_documentation_only_has_no_frontend_checks(self):
@@ -285,6 +287,129 @@ class DevPrepushFrontendTest(DevPrepushFixture):
self.assertIn(paths, PREPUSH.read_text())
+class DevPrepushSourceReadsTest(DevPrepushFixture):
+ """Failed Git reads are unavailable evidence, including partial stdout."""
+
+ def setUp(self):
+ super().setUp()
+ self.browser_calls = Path(self.directory.name) / "browser-calls"
+ self.go_calls = Path(self.directory.name) / "go-calls"
+ self.env.update(
+ PREPUSH_REAL_GIT=shutil.which("git"),
+ PREPUSH_BROWSER_CALLS=str(self.browser_calls),
+ PREPUSH_GO_CALLS=str(self.go_calls),
+ )
+ self.write(
+ "scripts/release_control/browser_verification_guard.py",
+ "import os\n"
+ "with open(os.environ['PREPUSH_BROWSER_CALLS'],'a') as output:\n"
+ " output.write('browser guard\\n')\n",
+ )
+ self.git("add", "--", "scripts/release_control/browser_verification_guard.py")
+ self.git("commit", "--quiet", "-m", "Track downstream fixture checks")
+ self.base = self.git("rev-parse", "HEAD").stdout.strip()
+ self.change("frontend-modern/src/example.ts")
+ self.head = self.change("internal/fixture/example.go", trailer="fixture only")
+ self.env["PREPUSH_FIXTURE_HEAD"] = self.head
+
+ git = self.bin / "git"
+ git.write_text(
+ "#!/usr/bin/env python3\n"
+ "import os,sys\n"
+ "args=sys.argv[1:]\n"
+ "mode=os.environ.get('PREPUSH_GIT_FAULT')\n"
+ "faults={\n"
+ " 'unstaged': args == ['diff','--quiet'],\n"
+ " 'staged': args == ['diff','--cached','--quiet'],\n"
+ " 'head': args == ['rev-parse','--verify','HEAD'],\n"
+ " 'ahead': args[:2] == ['rev-list','--count'],\n"
+ " 'range-files': args[:2] == ['diff','--name-only'],\n"
+ " 'commits': args[:2] == ['rev-list','--reverse'],\n"
+ " 'trailer': args[:1] == ['log'],\n"
+ " 'commit-files': args[:1] == ['diff-tree'],\n"
+ "}\n"
+ "if faults.get(mode,False):\n"
+ " if os.environ.get('PREPUSH_GIT_PARTIAL') == 'true':\n"
+ " print({'head':os.environ['PREPUSH_FIXTURE_HEAD'],"
+ "'ahead':'1','commits':os.environ['PREPUSH_FIXTURE_HEAD'],"
+ "'trailer':'fixture partial trailer'}.get(mode,'README.md'))\n"
+ " print('fixture Git read failure: '+mode,file=sys.stderr)\n"
+ " sys.exit(73)\n"
+ "os.execv(os.environ['PREPUSH_REAL_GIT'],['git',*args])\n",
+ encoding="utf-8",
+ )
+ git.chmod(0o755)
+ go = self.bin / "go"
+ go.write_text(
+ "#!/usr/bin/env python3\n"
+ "import json,os,sys\n"
+ "with open(os.environ['PREPUSH_GO_CALLS'],'a') as output:\n"
+ " output.write(json.dumps(sys.argv[1:])+'\\n')\n",
+ encoding="utf-8",
+ )
+ go.chmod(0o755)
+
+ def assert_no_downstream_checks(self):
+ for path in (self.browser_calls, self.go_calls):
+ self.assertFalse(path.exists() and path.read_text(), str(path))
+
+ def test_failed_source_reads_stop_before_incomplete_evidence_is_used(self):
+ operations = {
+ "unstaged": "inspect unstaged changes",
+ "staged": "inspect staged changes",
+ "head": "resolve HEAD",
+ "ahead": "count outgoing commits",
+ "range-files": "list changed files",
+ "commits": "list outgoing commits",
+ "trailer": "read Contract-Neutral trailer for",
+ "commit-files": "list changed files for",
+ }
+ for mode, operation in operations.items():
+ for partial in ("false", "true"):
+ with self.subTest(mode=mode, partial=partial):
+ for path in (self.calls, self.guard_calls, self.browser_calls, self.go_calls):
+ path.write_text("")
+ self.env.update(PREPUSH_GIT_FAULT=mode, PREPUSH_GIT_PARTIAL=partial)
+ result, calls, guards = self.run_gate()
+ self.assertEqual(result.returncode, 2, result.stdout + result.stderr)
+ self.assertIn("fixture Git read failure: " + mode, result.stderr)
+ self.assertIn("Cannot " + operation, result.stderr)
+ self.assertIn("git exit 73", result.stderr)
+ self.assertNotIn("All pre-push checks passed", result.stdout)
+ self.assertEqual(calls, [])
+ self.assertEqual(guards, [])
+ self.assert_no_downstream_checks()
+
+ def test_all_canonical_failures_are_reported_before_source_checks_stop(self):
+ self.env["PREPUSH_GUARD_STATUS"] = "4"
+ result, calls, guards = self.run_gate()
+ self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
+ self.assertEqual(len(guards), 2)
+ self.assertEqual(result.stdout.count("FAIL: canonical completion guard @"), 2)
+ self.assertIn("remaining source checks have not run", result.stderr)
+ self.assertEqual(calls, [])
+ self.assert_no_downstream_checks()
+
+ def test_successful_source_reads_keep_every_downstream_check(self):
+ # Ordinary dirty index/worktree exits are 1, not read failures. The
+ # committed source still gets every guard, Go check and type-check.
+ self.write("README.md", "staged fixture delta\n")
+ self.git("add", "--", "README.md")
+ self.write("README.md", "unstaged fixture delta\n")
+ result, calls, guards = self.run_gate()
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("only committed work is checked", result.stdout)
+ self.assertIn("All pre-push checks passed", result.stdout)
+ self.assertEqual(len(guards), 2)
+ self.assertEqual([call["args"] for call in calls], [["run", "type-check"]])
+ self.assertEqual(self.browser_calls.read_text(), "browser guard\n")
+ commands = [json.loads(line) for line in self.go_calls.read_text().splitlines()]
+ self.assertEqual(len(commands), 3)
+ self.assertEqual(commands[0], ["build", "./..."])
+ self.assertEqual(commands[1][0:2], ["test", "./internal/mutationregistry"])
+ self.assertEqual(commands[2], ["test", "-count=1", "-timeout", "15m", "./internal/fixture"])
+
+
class DevPrepushBrowserTest(DevPrepushFixture):
"""Real Git and receipt admission; fixture receipts are not browser runs."""