From 4bab8f156d270efbf65f4e846a678bd0ca147533 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sun, 22 Nov 2026 15:37:56 +0100 Subject: [PATCH] Freshness gate: fail closed on an old utils Co-Authored-By: Claude Opus 5.5 --- .../scripts/check_dependency_freshness.sh | 22 +++++++- .../tests/test_freshness_wrapper.py | 52 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 _installer_import/tests/test_freshness_wrapper.py diff --git a/_installer_import/scripts/check_dependency_freshness.sh b/_installer_import/scripts/check_dependency_freshness.sh index 49d6e29..641eeb7 100755 --- a/_installer_import/scripts/check_dependency_freshness.sh +++ b/_installer_import/scripts/check_dependency_freshness.sh @@ -18,7 +18,18 @@ set -euo pipefail -readonly SHARED_GATE="${UTILS_ROOT:-$HOME/src/utils}/scripts/check_dependency_freshness.sh" +readonly UTILS="${UTILS_ROOT:-$HOME/src/utils}" +readonly SHARED_GATE="$UTILS/scripts/check_dependency_freshness.sh" +readonly PACMAN_PARSER="$UTILS/dep_freshness/parsers/pacman_lock.py" + +# True when this run must judge the native-Proton lock (a full run, or the lock staged). +needs_pacman_adapter() { + local arg + for arg in "$@"; do + [[ "$arg" == "--all" || "$arg" == *proton-native.lock ]] && return 0 + done + return 1 +} main() { if [[ ! -x "$SHARED_GATE" ]]; then @@ -28,6 +39,15 @@ main() { exit 1 fi + # An older utils checkout skips a manifest it has no parser for and exits + # 0, which would wave any Proton pin through. Fail closed instead. + if needs_pacman_adapter "$@" && [[ ! -f "$PACMAN_PARSER" ]]; then + echo "Error: $UTILS has no dep_freshness/parsers/pacman_lock.py, so it" >&2 + echo " cannot check steam_installer/data/proton-native.lock." >&2 + echo " Update it: git -C $UTILS pull --ff-only" >&2 + exit 1 + fi + exec bash "$SHARED_GATE" "$@" } diff --git a/_installer_import/tests/test_freshness_wrapper.py b/_installer_import/tests/test_freshness_wrapper.py new file mode 100644 index 0000000..cdf3b6b --- /dev/null +++ b/_installer_import/tests/test_freshness_wrapper.py @@ -0,0 +1,52 @@ +"""The freshness wrapper fails closed when ~/src/utils cannot read the Proton lock.""" + +import subprocess +from pathlib import Path + +WRAPPER = Path(__file__).resolve().parent.parent / "scripts" / "check_dependency_freshness.sh" +LOCK = "steam_installer/data/proton-native.lock" + + +def _utils(tmp_path: Path, *, adapter: bool) -> Path: + root = tmp_path / "utils" + gate = root / "scripts" / "check_dependency_freshness.sh" + gate.parent.mkdir(parents=True) + gate.write_text("#!/bin/bash\necho shared-gate-ran\n") + gate.chmod(0o755) + if adapter: + parser = root / "dep_freshness" / "parsers" / "pacman_lock.py" + parser.parent.mkdir(parents=True) + parser.write_text("") + return root + + +def _run(root: Path, *args: str) -> subprocess.CompletedProcess: + return subprocess.run( + ["bash", str(WRAPPER), *args], + env={"UTILS_ROOT": str(root), "PATH": "/usr/bin:/bin"}, + capture_output=True, + text=True, + check=False, + ) + + +def test_lock_without_the_pacman_adapter_fails(tmp_path): + result = _run(_utils(tmp_path, adapter=False), LOCK) + assert result.returncode == 1 + assert "pacman_lock" in result.stderr + assert "shared-gate-ran" not in result.stdout + + +def test_full_run_without_the_pacman_adapter_fails(tmp_path): + assert _run(_utils(tmp_path, adapter=False), "--all", "--strict").returncode == 1 + + +def test_lock_with_the_adapter_reaches_the_shared_gate(tmp_path): + result = _run(_utils(tmp_path, adapter=True), LOCK) + assert result.returncode == 0 + assert "shared-gate-ran" in result.stdout + + +def test_other_manifests_skip_the_adapter_check(tmp_path): + result = _run(_utils(tmp_path, adapter=False), "requirements.txt") + assert result.returncode == 0