From 2b8bb4f054036330f3a837565358d9bb7af9522a Mon Sep 17 00:00:00 2001 From: Cemil ILIK Date: Thu, 12 Nov 2026 02:17:47 +0300 Subject: [PATCH 1/3] test: make the ERR-trap bash comparison bash-version aware (#1075) GitHub's `ubuntu-latest` moved from ubuntu-24.04 (bash 5.2) to ubuntu-26.04 (bash 5.3) between the 2026-11-04 and 2026-11-05 nightly runs. Bash 5.2 takes a bare `exit` in an ERR trap from the trap's last command, so `trap 'echo x; exit' ERR` masked a failing step; bash 5.3 keeps the status the trap was entered with, so the step now fails. The one shape in `test_verdicts_match_bash` that encoded the 5.2 behaviour failed on every runner using the new image, in the nightly and in pull-request `test` jobs. - tests: read bash's (major, minor) and expect return code 1 for that shape from 5.3 on; the guard's finding stays expected on every version. Add a table-consistency test and a test that the report names both behaviours. - tools/check_ci_failure_masking.py: reword the ERR-trap bare-`exit` finding so it no longer describes bash 5.2 only. - CHANGELOG: Fixed entry. Verified in throwaway containers: ubuntu:24.04 (bash 5.2.21) and ubuntu:26.04 (bash 5.3.9) both pass tests/test_check_ci_failure_masking.py (479 passed); full gauntlet green locally. Fixes #1075 Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 8 ++++ tests/test_check_ci_failure_masking.py | 52 +++++++++++++++++++++----- tools/check_ci_failure_masking.py | 12 ++++-- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcaeaaf9..677ce6d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ All notable changes to ForgeLM are documented here. ### Fixed +- **The nightly compatibility run and every pull-request `test` job no longer fail on bash 5.3.** GitHub's + `ubuntu-latest` label moved from `ubuntu-24.04` (bash 5.2) to `ubuntu-26.04` (bash 5.3) between the 2026-11-04 and + 2026-11-05 nightly runs, and + `tests/test_check_ci_failure_masking.py::test_verdicts_match_bash` expected a bare `exit` in an ERR trap after + another command to leave the step with status 0. Bash 5.3 keeps the status the trap was entered with, so the step + fails, as it should. The comparison now takes the bash version into account for that one shape, and the guard's + report names both behaviours instead of describing bash 5.2 only; the guard still flags the shape on every version, + because the runner image decides which bash a workflow gets. Test-only: no runtime code changes (#1075). - CI/CD examples capture ForgeLM and `jq` statuses separately: a JSON parser's exit 4 cannot be mistaken for an approval hold, and a multi-stage approval hold retains ForgeLM's exit 4. The guide's JSON-reference section links use the compiled heading IDs and preserve the page route and heading on reload diff --git a/tests/test_check_ci_failure_masking.py b/tests/test_check_ci_failure_masking.py index 89c83abb..68edcdec 100644 --- a/tests/test_check_ci_failure_masking.py +++ b/tests/test_check_ci_failure_masking.py @@ -1142,22 +1142,40 @@ def test_a_root_given_another_way_scans_the_same(self, guard, tmp_path, capsys, assert guard.main(["--root", given]) == 0, capsys.readouterr().out -def _bash5() -> Optional[str]: - """A bash of version 5 or newer on Linux or macOS, as on GitHub's Linux runners; None otherwise. +def _bash5() -> Optional[tuple[str, tuple[int, int]]]: + """A bash of version 5 or newer on Linux or macOS, as on GitHub's Linux runners: (path, (major, minor)). - Windows' bash (Git Bash) runs in another environment, so the comparison stays on POSIX systems. + None otherwise. Windows' bash (Git Bash) runs in another environment, so the comparison stays on POSIX systems. """ path = shutil.which("bash") if sys.platform != "win32" else None if path is None: return None try: - version = subprocess.run([path, "-c", "echo ${BASH_VERSINFO[0]}"], capture_output=True, text=True, timeout=30) + probe = subprocess.run( + [path, "-c", 'echo "${BASH_VERSINFO[0]} ${BASH_VERSINFO[1]}"'], capture_output=True, text=True, timeout=30 + ) except (OSError, subprocess.SubprocessError): return None - return path if version.stdout.strip().isdigit() and int(version.stdout) >= 5 else None - - -_BASH = _bash5() + parts = probe.stdout.split() + if len(parts) != 2 or not all(part.isdigit() for part in parts): + return None + version = (int(parts[0]), int(parts[1])) + return (path, version) if version[0] >= 5 else None + + +_BASH_FOUND = _bash5() +_BASH = _BASH_FOUND[0] if _BASH_FOUND else None +_BASH_VERSION = _BASH_FOUND[1] if _BASH_FOUND else (0, 0) + +# Shapes whose status under `bash -e` depends on the bash version: the first (major, minor) from which the step +# fails instead of going on. The guard's verdict does not move with the version, because a workflow that says +# `ubuntu-latest` runs whichever bash the image ships (5.2 on ubuntu-24.04, 5.3 on ubuntu-26.04), so it reports +# what an older bash would let through. +_STEP_FAILS_FROM_BASH = { + # bash 5.2 takes a bare `exit` in an ERR trap from the trap's last command (`echo`, status 0); 5.3 keeps the + # status the trap was entered with. + "trap 'echo x; exit' ERR\npytest\necho done": (5, 3), +} # Shapes where the guard's verdict must equal bash's. Each required program is a # stub that exits 1, ci/t.sh masks `pytest` and ci/env.sh turns errexit off. A @@ -1272,14 +1290,28 @@ def test_verdicts_match_bash(guard, tmp_path, script, expected): [_BASH, "--noprofile", "--norc", "-e", str(step)], cwd=tmp_path, env=env, capture_output=True, timeout=30 ) findings = guard.scan_script(script, "run", guard.GITHUB_DEFAULT, tmp_path)[0] + fixed_from = _STEP_FAILS_FROM_BASH.get(script) + masked = expected is not None and not (fixed_from is not None and _BASH_VERSION >= fixed_from) + assert result.returncode == (0 if masked else 1), (script, _BASH_VERSION, result.returncode, result.stderr) if expected is None: - assert result.returncode == 1, (script, result.returncode, result.stderr) assert findings == [], findings else: - assert result.returncode == 0, (script, result.returncode, result.stderr) assert any(expected in finding for finding in findings), findings +def test_version_dependent_shapes_are_shapes_the_guard_reports(): + """A shape listed as bash-version dependent must still be one the guard flags, or the table rots.""" + expected_by_script = dict(_AGAINST_BASH) + for script in _STEP_FAILS_FROM_BASH: + assert expected_by_script.get(script) is not None, script + + +def test_err_trap_message_names_the_bash_versions(guard, tmp_path): + """The report cannot say a bare `exit` in an ERR trap always masks the step: bash 5.3 keeps the step's status.""" + findings = guard.scan_script("trap 'echo x; exit' ERR\npytest\necho done", "run", guard.GITHUB_DEFAULT, tmp_path)[0] + assert any("bash 5.2" in finding and "5.3 keeps the step's" in finding for finding in findings), findings + + @pytest.mark.skipif( not (sys.platform.startswith("linux") and os.environ.get("CI")), reason="only CI's Linux runners must have bash 5" ) diff --git a/tools/check_ci_failure_masking.py b/tools/check_ci_failure_masking.py index 2d5ea644..5ee1adf1 100644 --- a/tools/check_ci_failure_masking.py +++ b/tools/check_ci_failure_masking.py @@ -1662,11 +1662,15 @@ def trap_problem( if id(exit_command) in reraises or (code is None and kind == "EXIT") or (number or 0) % 256: continue if code is None: - where = "on ERR it exits" if kind == "ERR" else "it exits" - return ( - f"sets {specific} that runs a bare `exit` after another command; {where} with that command's " - "status instead of the step's" + # bash 5.2 takes a bare `exit` in an ERR trap from the last command the trap ran; 5.3 keeps the + # status the trap was entered with. The guard still reports it: the runner image, and with it the + # bash version, moves under a workflow that says `ubuntu-latest`. + where = ( + "on ERR, bash 5.2 exits with that command's status instead of the step's (5.3 keeps the step's)" + if kind == "ERR" + else "it exits with that command's status instead of the step's" ) + return f"sets {specific} that runs a bare `exit` after another command; {where}" if code in ("$?", "${?}"): return ( f"sets {label} that runs `exit {code}` after another command, so it exits with that " From bf6bf0faae286a1c57dccb829fd3f8ba42f89341 Mon Sep 17 00:00:00 2001 From: Cemil ILIK Date: Thu, 12 Nov 2026 02:32:07 +0300 Subject: [PATCH 2/3] test: address review on the bash-version-aware ERR-trap comparison (#1075) - tools/check_ci_failure_masking.py: qualify the `_reraising_exits` docstring by bash version (5.2 reads a bare `exit` in an ERR trap as `exit $?`; 5.3 keeps the entry status), so it no longer reads as universal bash behaviour. - tests: qualify the two ERR-trap comments the same way; use `Tuple` from `typing` as docs/standards/coding.md requires. - CHANGELOG: describe the observable change (the guard's report and the restored nightly / PR CI) instead of the test internals, per release.md rule 5. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 15 +++++++-------- tests/test_check_ci_failure_masking.py | 10 ++++++---- tools/check_ci_failure_masking.py | 3 ++- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 677ce6d1..5b2c45c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,14 +6,13 @@ All notable changes to ForgeLM are documented here. ### Fixed -- **The nightly compatibility run and every pull-request `test` job no longer fail on bash 5.3.** GitHub's - `ubuntu-latest` label moved from `ubuntu-24.04` (bash 5.2) to `ubuntu-26.04` (bash 5.3) between the 2026-11-04 and - 2026-11-05 nightly runs, and - `tests/test_check_ci_failure_masking.py::test_verdicts_match_bash` expected a bare `exit` in an ERR trap after - another command to leave the step with status 0. Bash 5.3 keeps the status the trap was entered with, so the step - fails, as it should. The comparison now takes the bash version into account for that one shape, and the guard's - report names both behaviours instead of describing bash 5.2 only; the guard still flags the shape on every version, - because the runner image decides which bash a workflow gets. Test-only: no runtime code changes (#1075). +- **The CI failure-masking guard explains the bash 5.2 / 5.3 difference for a bare `exit` in an ERR trap.** + `tools/check_ci_failure_masking.py` used to report that such a trap exits with the status of the command + before it. That holds on bash 5.2 only: bash 5.3, the shell on `ubuntu-26.04`, which `ubuntu-latest` now + resolves to, keeps the status the trap was entered with. The report now names both behaviours and still flags + the shape on every version, because the runner image decides which bash a workflow gets. The same difference + had turned the nightly compatibility run and every pull-request `test` job red since the 2026-11-05 nightly + run; they pass again. ForgeLM's runtime behaviour is unchanged (#1075). - CI/CD examples capture ForgeLM and `jq` statuses separately: a JSON parser's exit 4 cannot be mistaken for an approval hold, and a multi-stage approval hold retains ForgeLM's exit 4. The guide's JSON-reference section links use the compiled heading IDs and preserve the page route and heading on reload diff --git a/tests/test_check_ci_failure_masking.py b/tests/test_check_ci_failure_masking.py index 68edcdec..4c8a0ea5 100644 --- a/tests/test_check_ci_failure_masking.py +++ b/tests/test_check_ci_failure_masking.py @@ -18,7 +18,7 @@ import sys import time from pathlib import Path -from typing import Optional +from typing import Optional, Tuple import pytest @@ -282,7 +282,8 @@ class TestReviewedShapes: # `|| true` is refused inside substitutions and trap actions too. ("v=$(git describe || true)\npytest", "discards its failure"), ("trap 'rm -f x || true' EXIT\npytest", "discards its failure"), - # On ERR a bare `exit` uses the status of the command before it, and `set +e` lets the step go on. + # On ERR a bare `exit` uses the status of the command before it (bash 5.2; 5.3 keeps the step's), + # and `set +e` lets the step go on. ("trap 'echo x; exit' ERR\npytest\necho done", "bare `exit` after another command"), ("f() { echo x; exit; }\ntrap f ERR\npytest\necho done", "bare `exit` after another command"), ("trap 'set +e' ERR\npytest\necho done", "turns errexit off"), @@ -1142,7 +1143,7 @@ def test_a_root_given_another_way_scans_the_same(self, guard, tmp_path, capsys, assert guard.main(["--root", given]) == 0, capsys.readouterr().out -def _bash5() -> Optional[tuple[str, tuple[int, int]]]: +def _bash5() -> Optional[Tuple[str, Tuple[int, int]]]: """A bash of version 5 or newer on Linux or macOS, as on GitHub's Linux runners: (path, (major, minor)). None otherwise. Windows' bash (Git Bash) runs in another environment, so the comparison stays on POSIX systems. @@ -1212,7 +1213,8 @@ def _bash5() -> Optional[tuple[str, tuple[int, int]]]: ("pytest &\nwait", "background"), ("set +e\npytest\necho done", "errexit is off"), ("if pytest; then echo ok; fi", "condition"), - # ERR traps: a bare `exit` there uses the last command's status, and `set +e` lets the step go on. + # ERR traps: a bare `exit` there uses the last command's status on bash 5.2 (5.3 keeps the step's; see + # `_STEP_FAILS_FROM_BASH`), and `set +e` lets the step go on. ("trap 'echo x; exit' ERR\npytest\necho done", "bare `exit` after another command"), ("trap 'set +e' ERR\npytest\necho done", "turns errexit off"), ("trap 'exit' ERR\npytest\necho done", None), diff --git a/tools/check_ci_failure_masking.py b/tools/check_ci_failure_masking.py index 5ee1adf1..e92658cc 100644 --- a/tools/check_ci_failure_masking.py +++ b/tools/check_ci_failure_masking.py @@ -666,7 +666,8 @@ def _reraising_exits( *entry_status*); after ``||`` it holds the failed command's non-zero status; and ``rc=$?`` as the first command keeps it for a later ``exit "$rc"``, unless something assigns ``rc`` again. *bare_is_status* reads a bare ``exit`` as - ``exit $?``, as bash does in an ERR trap. + ``exit $?``, as bash 5.2 does in an ERR trap; bash 5.3 keeps the status the + trap was entered with, so this is the stricter of the two readings. """ found: set = set() if not action.items: From 1f299a075f5c4355ea8a965306fa1dfb7577a6c6 Mon Sep 17 00:00:00 2001 From: Cemil ILIK Date: Thu, 12 Nov 2026 02:52:05 +0300 Subject: [PATCH 3/3] docs: qualify the trap_problem docstring by bash version (#1075) The docstring still said that, except on EXIT, bash reads a bare `exit` as `exit $?`. On ERR that is bash 5.2 only; bash 5.3 keeps the entry status, and the guard deliberately keeps the stricter reading. Raised in review on #1077. Co-Authored-By: Claude Sonnet 5.5 --- tools/check_ci_failure_masking.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/check_ci_failure_masking.py b/tools/check_ci_failure_masking.py index e92658cc..d97a0d8f 100644 --- a/tools/check_ci_failure_masking.py +++ b/tools/check_ci_failure_masking.py @@ -1632,9 +1632,11 @@ def trap_problem( *entry_status* says whether ``$?`` still holds the status the trap was entered with when *handler* starts: true for an EXIT/ERR action itself and for a function it calls first. Except on EXIT, where it keeps the entry - status, bash reads a bare ``exit`` as ``exit $?``, and turning errexit off - keeps a failing command from stopping the step. DEBUG and RETURN run between - the script's commands, so ``set -n`` there stops it. + status, bash reads a bare ``exit`` as ``exit $?`` (on ERR that is bash 5.2; + 5.3 keeps the entry status there too, and the guard keeps the stricter + reading), and turning errexit off keeps a failing command from stopping the + step. DEBUG and RETURN run between the script's commands, so ``set -n`` + there stops it. """ label = _trap_label(kind) if self.has_required(handler):