You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2026/10/12 11:56:20 UTC
(juneau) branch juneau-release-manager updated: Ring the terminal bell when push.py finishes, on success or failure (P0113), silenced by JRM_PUSH_NO_BELL=1 or SANDBOX_RUNTIME=1
This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch juneau-release-manager
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/juneau-release-manager by this push:
new 96dc123338 Ring the terminal bell when push.py finishes, on success or failure (P0113), silenced by JRM_PUSH_NO_BELL=1 or SANDBOX_RUNTIME=1
96dc123338 is described below
commit 96dc123338d2b9dcb7e4660b40b2d92f791f9bbb
Author: James Bognar <ja...@apache.org>
AuthorDate: Mon Oct 12 07:56:14 2026 -0400
Ring the terminal bell when push.py finishes, on success or failure (P0113), silenced by JRM_PUSH_NO_BELL=1 or SANDBOX_RUNTIME=1
---
push.py | 27 +++++++++++
scripts/tests/test_push.py | 114 ++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 139 insertions(+), 2 deletions(-)
diff --git a/push.py b/push.py
index b959a3a088..90c4c91b18 100755
--- a/push.py
+++ b/push.py
@@ -26,6 +26,9 @@ Usage:
./push.py # prompts for a commit message
./push.py --dry-run "message" # show what would happen, change nothing
+ When a run ends (success or failure) on a terminal, push.py rings the terminal bell.
+ Set JRM_PUSH_NO_BELL=1 to silence it (it is also skipped when SANDBOX_RUNTIME=1).
+
Safety:
- Never uses --force or --no-verify.
- Never runs `git config` (it only reads config; you fix a missing
@@ -41,6 +44,7 @@ Safety:
"""
import argparse
+import os
import shlex
import subprocess
import sys
@@ -270,7 +274,30 @@ def commit_and_push(repo_dir, cli_message, *, dry_run=False):
return 0
+def ring_bell():
+ """
+ Ring the terminal bell (BEL) so a finished run gets noticed; macOS Terminal also badges the
+ Dock icon when the window is unfocused. Best-effort: only on a TTY (checked at write time),
+ never in sandbox mode (SANDBOX_RUNTIME=1), and not when JRM_PUSH_NO_BELL=1. Never raises.
+ """
+ if os.environ.get("JRM_PUSH_NO_BELL") == "1" or os.environ.get("SANDBOX_RUNTIME") == "1":
+ return
+ try:
+ if sys.stdout.isatty():
+ sys.stdout.write("\a")
+ sys.stdout.flush()
+ except Exception: # NOSONAR - best-effort notification must never affect the exit status
+ pass
+
+
def main():
+ try:
+ _main()
+ finally:
+ ring_bell()
+
+
+def _main():
parser = argparse.ArgumentParser(
description="Commit and push juneau-release-manager to origin.",
formatter_class=argparse.RawDescriptionHelpFormatter,
diff --git a/scripts/tests/test_push.py b/scripts/tests/test_push.py
index 9bddf1574c..5ba6737a31 100644
--- a/scripts/tests/test_push.py
+++ b/scripts/tests/test_push.py
@@ -13,10 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""
-Tests for the root push.py's refuse-on-unreviewed-changes gate, ported from the
+Tests for the root push.py: the end-of-run terminal bell (TestEndOfRunBell) and the
+refuse-on-unreviewed-changes gate, ported from the
already-reviewed gate in apache/juneau's scripts/push.py and sandbox-support-console's
scripts/push.py. This repo's push.py is a bare add/commit/push helper with no other gates, so
-this file covers only: check_unreviewed_changes(), get_staged_paths(), and commit_and_push()'s
+the gate tests cover: check_unreviewed_changes(), get_staged_paths(), and commit_and_push()'s
refuse / no-op / proceed decision (the three refusal shapes plus the allowed staged-only case).
Real temp git repos, real git -- no mocked subprocess. A bare repo stands in for the remote and
@@ -429,3 +430,112 @@ class TestGitIdentityConfigured:
def test_unset_identity_is_false(self, push_module, repo):
_run(repo, "git", "config", "--unset", "user.email")
assert push_module.git_identity_configured(repo) is False
+
+
+class _FakeStdout:
+ """Captures writes; reports whatever isatty() the test asks for."""
+
+ def __init__(self, tty):
+ self._tty = tty
+ self.written = ""
+ self.flushed = False
+
+ def isatty(self):
+ return self._tty
+
+ def write(self, text):
+ self.written += text
+
+ def flush(self):
+ self.flushed = True
+
+
+def _run_main(push_module, monkeypatch, *, tty, identity=True, commit_result=0, commit_raises=None):
+ """Run main() with every git-touching call stubbed; return (exit_code, fake_stdout)."""
+ fake = _FakeStdout(tty)
+ monkeypatch.setattr(push_module.sys, "stdout", fake)
+ monkeypatch.setattr(push_module.sys, "argv", ["push.py", "msg"])
+ monkeypatch.setattr(push_module, "git_identity_configured", lambda _repo: identity)
+
+ def fake_commit_and_push(*_args, **_kwargs):
+ if commit_raises is not None:
+ raise commit_raises
+ return commit_result
+
+ monkeypatch.setattr(push_module, "commit_and_push", fake_commit_and_push)
+ with pytest.raises(SystemExit) as exc:
+ push_module.main()
+ return exc.value.code, fake
+
+
+class TestEndOfRunBell:
+ @pytest.fixture(autouse=True)
+ def clean_env(self, monkeypatch):
+ monkeypatch.delenv("JRM_PUSH_NO_BELL", raising=False)
+ monkeypatch.delenv("SANDBOX_RUNTIME", raising=False)
+
+ def test_rings_on_tty_after_success(self, push_module, monkeypatch):
+ code, fake = _run_main(push_module, monkeypatch, tty=True)
+ assert code == 0
+ assert fake.written.endswith("\a")
+ assert fake.flushed
+
+ def test_rings_on_tty_after_refusal(self, push_module, monkeypatch):
+ code, fake = _run_main(push_module, monkeypatch, tty=True, commit_result=1)
+ assert code == 1
+ assert fake.written.endswith("\a")
+
+ def test_rings_on_tty_when_identity_gate_exits(self, push_module, monkeypatch):
+ code, fake = _run_main(push_module, monkeypatch, tty=True, identity=False)
+ assert code == 1
+ assert fake.written.endswith("\a")
+
+ def test_rings_on_tty_when_commit_message_aborts_with_system_exit(self, push_module, monkeypatch):
+ code, fake = _run_main(push_module, monkeypatch, tty=True, commit_raises=SystemExit(1))
+ assert code == 1
+ assert fake.written.endswith("\a")
+
+ def test_silent_when_not_a_tty(self, push_module, monkeypatch):
+ _, fake = _run_main(push_module, monkeypatch, tty=False)
+ assert "\a" not in fake.written
+
+ def test_still_rings_when_opt_out_is_zero(self, push_module, monkeypatch):
+ monkeypatch.setenv("JRM_PUSH_NO_BELL", "0")
+ monkeypatch.setenv("SANDBOX_RUNTIME", "0")
+ _, fake = _run_main(push_module, monkeypatch, tty=True)
+ assert fake.written.endswith("\a")
+
+ def test_rings_and_propagates_when_push_step_raises(self, push_module, monkeypatch):
+ fake = _FakeStdout(True)
+ monkeypatch.setattr(push_module.sys, "stdout", fake)
+ monkeypatch.setattr(push_module.sys, "argv", ["push.py", "msg"])
+ monkeypatch.setattr(push_module, "git_identity_configured", lambda _repo: True)
+
+ def boom(*_args, **_kwargs):
+ raise subprocess.CalledProcessError(1, ["git", "push"])
+
+ monkeypatch.setattr(push_module, "commit_and_push", boom)
+ with pytest.raises(subprocess.CalledProcessError):
+ push_module.main()
+ assert fake.written.endswith("\a")
+
+ def test_silent_when_opted_out(self, push_module, monkeypatch):
+ monkeypatch.setenv("JRM_PUSH_NO_BELL", "1")
+ _, fake = _run_main(push_module, monkeypatch, tty=True)
+ assert "\a" not in fake.written
+
+ def test_silent_in_sandbox(self, push_module, monkeypatch):
+ monkeypatch.setenv("SANDBOX_RUNTIME", "1")
+ _, fake = _run_main(push_module, monkeypatch, tty=True)
+ assert "\a" not in fake.written
+
+ def test_never_raises_when_stdout_misbehaves(self, push_module, monkeypatch):
+ class Broken(_FakeStdout):
+ def write(self, text):
+ if text == "\a":
+ raise OSError("closed")
+ super().write(text)
+
+ fake = Broken(True)
+ monkeypatch.setattr(push_module.sys, "stdout", fake)
+ push_module.ring_bell() # must not raise