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.

Add contract-neutral bypass to staged shape guard

rcourtman675c47d97130
diff --git a/scripts/release_control/canonical_completion_guard.py b/scripts/release_control/canonical_completion_guard.py
index eccbc55f02..6370b53508 100644
--- a/scripts/release_control/canonical_completion_guard.py
+++ b/scripts/release_control/canonical_completion_guard.py
@@ -10,6 +10,7 @@ from __future__ import annotations
import argparse
import json
+import os
from pathlib import Path
import subprocess
import sys
@@ -20,6 +21,21 @@ from repo_file_io import load_repo_json
from subsystem_contracts import load_contract_index, referenced_contracts_for_path
+CONTRACT_NEUTRAL_OVERRIDE_ENV = "PULSE_ALLOW_CONTRACT_NEUTRAL_COMMIT"
+
+
+def contract_neutral_override_reason() -> str | None:
+ """Return the operator-supplied reason for bypassing canonical-shape checks.
+
+ The `PULSE_ALLOW_CONTRACT_NEUTRAL_COMMIT` env var opts a single commit out of
+ the canonical-shape block when the author knows the runtime change is
+ behavioral (no public-contract delta). A non-empty value is required so the
+ reason is auditable in stderr; empty strings are treated as unset.
+ """
+ reason = os.environ.get(CONTRACT_NEUTRAL_OVERRIDE_ENV, "").strip()
+ return reason or None
+
+
REPO_ROOT = Path(__file__).resolve().parents[2]
SUBSYSTEM_REGISTRY = DEFAULT_CONTROL_PLANE["registry_path"]
@@ -518,12 +534,34 @@ def check_staged_contracts(staged_files: Sequence[str]) -> int:
if not missing_contracts and not insufficient_contract_updates and not missing_verification:
return 0
+ formatted = format_missing_requirements(
+ missing_contracts,
+ insufficient_contract_updates,
+ missing_verification,
+ )
+
+ override_reason = contract_neutral_override_reason()
+ if override_reason:
+ print(
+ "Canonical completion guard: canonical-shape block bypassed by "
+ f"{CONTRACT_NEUTRAL_OVERRIDE_ENV}={override_reason!r}",
+ file=sys.stderr,
+ )
+ print("Suppressed requirements (logged for audit):", file=sys.stderr)
+ print(formatted, file=sys.stderr)
+ return 0
+
+ print(formatted, file=sys.stderr)
+ print(
+ "",
+ file=sys.stderr,
+ )
print(
- format_missing_requirements(
- missing_contracts,
- insufficient_contract_updates,
- missing_verification,
- ),
+ "If this change is contract-neutral (behavioral fix, no public-contract "
+ "delta), you may bypass only this block by setting "
+ f"{CONTRACT_NEUTRAL_OVERRIDE_ENV}=<reason>. The reason is logged to "
+ "stderr. Sensitivity, gitleaks, governance-stage, control-plane, "
+ "status, registry, and contract audits still run.",
file=sys.stderr,
)
return 1
diff --git a/scripts/release_control/canonical_completion_guard_test.py b/scripts/release_control/canonical_completion_guard_test.py
index 445af5a4e1..8e296627f2 100644
--- a/scripts/release_control/canonical_completion_guard_test.py
+++ b/scripts/release_control/canonical_completion_guard_test.py
@@ -1,10 +1,16 @@
+import io
+import os
import unittest
+from contextlib import redirect_stderr
from pathlib import Path
+from unittest.mock import patch
from canonical_completion_guard import (
+ CONTRACT_NEUTRAL_OVERRIDE_ENV,
REPO_ROOT,
SUBSYSTEM_REGISTRY,
build_verification_requirements,
+ check_staged_contracts,
contract_patch_has_substantive_change,
infer_impacted_subsystems,
is_ignored_runtime_file,
@@ -4208,5 +4214,88 @@ index 1111111..2222222 100644
)
+class ContractNeutralOverrideTest(unittest.TestCase):
+ def test_check_staged_contracts_returns_zero_when_override_set(self):
+ stderr = io.StringIO()
+ with (
+ patch.dict(
+ os.environ,
+ {CONTRACT_NEUTRAL_OVERRIDE_ENV: "contract-neutral fix"},
+ clear=False,
+ ),
+ patch(
+ "canonical_completion_guard.infer_impacted_subsystems",
+ return_value={
+ "cloud-paid": {
+ "contract_path": "docs/subsystems/cloud-paid.md",
+ "verification_requirements": [],
+ }
+ },
+ ),
+ patch(
+ "canonical_completion_guard.required_contract_updates",
+ return_value={"docs/subsystems/cloud-paid.md": {}},
+ ),
+ patch(
+ "canonical_completion_guard.staged_contract_has_substantive_change",
+ return_value=False,
+ ),
+ patch(
+ "canonical_completion_guard.staged_verification_files_for_requirement",
+ return_value=[],
+ ),
+ patch(
+ "canonical_completion_guard.format_missing_requirements",
+ return_value="BLOCKED: missing contract",
+ ),
+ redirect_stderr(stderr),
+ ):
+ self.assertEqual(check_staged_contracts(["pkg/cloud/runtime.go"]), 0)
+
+ stderr_value = stderr.getvalue()
+ self.assertIn("canonical-shape block bypassed by", stderr_value)
+ self.assertIn("contract-neutral fix", stderr_value)
+ self.assertIn("Suppressed requirements", stderr_value)
+ self.assertIn("BLOCKED: missing contract", stderr_value)
+
+ def test_check_staged_contracts_blocks_and_suggests_bypass_when_unset(self):
+ stderr = io.StringIO()
+ with (
+ patch.dict(os.environ, {CONTRACT_NEUTRAL_OVERRIDE_ENV: ""}, clear=False),
+ patch(
+ "canonical_completion_guard.infer_impacted_subsystems",
+ return_value={
+ "cloud-paid": {
+ "contract_path": "docs/subsystems/cloud-paid.md",
+ "verification_requirements": [],
+ }
+ },
+ ),
+ patch(
+ "canonical_completion_guard.required_contract_updates",
+ return_value={"docs/subsystems/cloud-paid.md": {}},
+ ),
+ patch(
+ "canonical_completion_guard.staged_contract_has_substantive_change",
+ return_value=False,
+ ),
+ patch(
+ "canonical_completion_guard.staged_verification_files_for_requirement",
+ return_value=[],
+ ),
+ patch(
+ "canonical_completion_guard.format_missing_requirements",
+ return_value="BLOCKED: missing contract",
+ ),
+ redirect_stderr(stderr),
+ ):
+ self.assertEqual(check_staged_contracts(["pkg/cloud/runtime.go"]), 1)
+
+ stderr_value = stderr.getvalue()
+ self.assertIn("BLOCKED: missing contract", stderr_value)
+ self.assertIn(CONTRACT_NEUTRAL_OVERRIDE_ENV, stderr_value)
+ self.assertIn("contract-neutral", stderr_value)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/scripts/release_control/staged_commit_shape_guard.py b/scripts/release_control/staged_commit_shape_guard.py
index 320b4611e1..bb5211cc63 100644
--- a/scripts/release_control/staged_commit_shape_guard.py
+++ b/scripts/release_control/staged_commit_shape_guard.py
@@ -9,6 +9,8 @@ import sys
from typing import Sequence
from canonical_completion_guard import (
+ CONTRACT_NEUTRAL_OVERRIDE_ENV,
+ contract_neutral_override_reason,
format_missing_requirements,
git_staged_files as canonical_git_staged_files,
infer_impacted_subsystems,
@@ -304,7 +306,18 @@ def format_combined_errors(errors: Sequence[str]) -> str:
def main() -> int:
staged_files = git_staged_files()
- errors = canonical_commit_shape_errors(staged_files)
+ override_reason = contract_neutral_override_reason()
+ canonical_errors = canonical_commit_shape_errors(staged_files)
+ if canonical_errors and override_reason:
+ print(
+ "Staged commit shape guard: canonical-shape block bypassed by "
+ f"{CONTRACT_NEUTRAL_OVERRIDE_ENV}={override_reason!r}",
+ file=sys.stderr,
+ )
+ print("Suppressed canonical-shape errors (logged for audit):", file=sys.stderr)
+ print(format_combined_errors(canonical_errors), file=sys.stderr)
+ canonical_errors = []
+ errors = list(canonical_errors)
errors.extend(lane_progress_shape_errors(staged_files))
errors.extend(staged_promotion_proof_errors(staged_files))
if not errors:
@@ -312,6 +325,16 @@ def main() -> int:
return 0
print(format_combined_errors(errors), file=sys.stderr)
+ if not override_reason:
+ print(
+ "\nIf this is a contract-neutral change (behavioral bug fix with no "
+ "public-contract delta) you may bypass only the canonical-shape "
+ f"block by setting {CONTRACT_NEUTRAL_OVERRIDE_ENV}=<reason>. The "
+ "reason is logged to stderr for audit. Lane-progress, promotion-proof, "
+ "sensitivity, gitleaks, governance-stage, control-plane, status, "
+ "registry, and contract audits still run.",
+ file=sys.stderr,
+ )
return 1
diff --git a/scripts/release_control/staged_commit_shape_guard_test.py b/scripts/release_control/staged_commit_shape_guard_test.py
index 37b537ab8e..3bf53b070b 100644
--- a/scripts/release_control/staged_commit_shape_guard_test.py
+++ b/scripts/release_control/staged_commit_shape_guard_test.py
@@ -1,9 +1,11 @@
import io
+import os
import unittest
from contextlib import redirect_stderr, redirect_stdout
from unittest.mock import patch
from staged_commit_shape_guard import (
+ CONTRACT_NEUTRAL_OVERRIDE_ENV,
advanced_lane_ids,
format_combined_errors,
lane_progress_shape_errors,
@@ -195,6 +197,7 @@ class StagedCommitShapeGuardTest(unittest.TestCase):
stdout = io.StringIO()
stderr = io.StringIO()
with (
+ patch.dict(os.environ, {CONTRACT_NEUTRAL_OVERRIDE_ENV: ""}, clear=False),
patch("staged_commit_shape_guard.git_staged_files", return_value=["runtime/file.go"]),
patch(
"staged_commit_shape_guard.canonical_commit_shape_errors",
@@ -214,10 +217,12 @@ class StagedCommitShapeGuardTest(unittest.TestCase):
self.assertEqual(main(), 1)
self.assertEqual(stdout.getvalue(), "")
- self.assertEqual(
- stderr.getvalue(),
- "BLOCKED: canonical issue\n\nBLOCKED: lane progress issue\n\nBLOCKED: promotion proof issue\n",
- )
+ stderr_value = stderr.getvalue()
+ self.assertIn("BLOCKED: canonical issue", stderr_value)
+ self.assertIn("BLOCKED: lane progress issue", stderr_value)
+ self.assertIn("BLOCKED: promotion proof issue", stderr_value)
+ self.assertIn(CONTRACT_NEUTRAL_OVERRIDE_ENV, stderr_value)
+ self.assertIn("contract-neutral", stderr_value)
def test_main_reports_success_when_no_errors(self) -> None:
stdout = io.StringIO()
@@ -235,6 +240,71 @@ class StagedCommitShapeGuardTest(unittest.TestCase):
self.assertEqual(stdout.getvalue(), "Staged commit shape guard passed.\n")
self.assertEqual(stderr.getvalue(), "")
+ def test_main_bypasses_canonical_errors_when_env_reason_set(self) -> None:
+ stdout = io.StringIO()
+ stderr = io.StringIO()
+ with (
+ patch.dict(
+ os.environ,
+ {CONTRACT_NEUTRAL_OVERRIDE_ENV: "behavioral bug fix #1429"},
+ clear=False,
+ ),
+ patch("staged_commit_shape_guard.git_staged_files", return_value=["runtime/file.go"]),
+ patch(
+ "staged_commit_shape_guard.canonical_commit_shape_errors",
+ return_value=["BLOCKED: canonical issue"],
+ ),
+ patch("staged_commit_shape_guard.lane_progress_shape_errors", return_value=[]),
+ patch("staged_commit_shape_guard.staged_promotion_proof_errors", return_value=[]),
+ redirect_stdout(stdout),
+ redirect_stderr(stderr),
+ ):
+ self.assertEqual(main(), 0)
+
+ self.assertEqual(stdout.getvalue(), "Staged commit shape guard passed.\n")
+ stderr_value = stderr.getvalue()
+ self.assertIn("canonical-shape block bypassed by", stderr_value)
+ self.assertIn("behavioral bug fix #1429", stderr_value)
+ self.assertIn("Suppressed canonical-shape errors", stderr_value)
+ self.assertIn("BLOCKED: canonical issue", stderr_value)
+
+ def test_main_bypass_does_not_suppress_lane_or_promotion_errors(self) -> None:
+ stdout = io.StringIO()
+ stderr = io.StringIO()
+ with (
+ patch.dict(
+ os.environ,
+ {CONTRACT_NEUTRAL_OVERRIDE_ENV: "behavioral bug fix #1429"},
+ clear=False,
+ ),
+ patch("staged_commit_shape_guard.git_staged_files", return_value=["runtime/file.go"]),
+ patch(
+ "staged_commit_shape_guard.canonical_commit_shape_errors",
+ return_value=["BLOCKED: canonical issue"],
+ ),
+ patch(
+ "staged_commit_shape_guard.lane_progress_shape_errors",
+ return_value=["BLOCKED: lane progress issue"],
+ ),
+ patch(
+ "staged_commit_shape_guard.staged_promotion_proof_errors",
+ return_value=["BLOCKED: promotion proof issue"],
+ ),
+ redirect_stdout(stdout),
+ redirect_stderr(stderr),
+ ):
+ self.assertEqual(main(), 1)
+
+ stderr_value = stderr.getvalue()
+ self.assertIn("canonical-shape block bypassed by", stderr_value)
+ self.assertIn("BLOCKED: lane progress issue", stderr_value)
+ self.assertIn("BLOCKED: promotion proof issue", stderr_value)
+ # When the bypass is active the discoverability hint should not repeat.
+ self.assertNotIn(
+ "If this is a contract-neutral change",
+ stderr_value,
+ )
+
if __name__ == "__main__":
unittest.main()