Freshness gate: fail closed on an old utils

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-22 15:37:56 +01:00
parent b0a2113e10
commit 4bab8f156d
2 changed files with 73 additions and 1 deletions

View File

@ -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" "$@"
}

View File

@ -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