Freshness gate: use utils origin/main snapshot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-22 15:58:01 +01:00
parent 4bab8f156d
commit 96c5a1edef
2 changed files with 94 additions and 6 deletions

View File

@ -31,6 +31,37 @@ needs_pacman_adapter() {
return 1
}
# Print a gate directory that can read the Proton lock, or nothing.
#
# kuhy's ~/src/utils can lag origin/main (local commits not yet pushed, so it
# cannot fast-forward). Then the gate runs a read-only snapshot of utils'
# origin/main from the cache instead: the checkout itself is never touched.
gate_root_for_lock() {
if [[ -f "$PACMAN_PARSER" ]]; then
echo "$UTILS"
return
fi
local sha snapshot
local -a paths=(scripts/check_dependency_freshness.sh dep_freshness)
git -C "$UTILS" cat-file -e origin/main:dep_freshness/parsers/pacman_lock.py 2>/dev/null ||
return 0
sha="$(git -C "$UTILS" rev-parse origin/main)"
snapshot="${XDG_CACHE_HOME:-$HOME/.cache}/steam-game-installer/utils-gate/$sha"
if [[ ! -f "$snapshot/dep_freshness/parsers/pacman_lock.py" ]]; then
rm -rf "$snapshot.tmp"
mkdir -p "$snapshot.tmp"
# The fleet allowlist lives beside the gate, when utils has one.
if git -C "$UTILS" cat-file -e origin/main:dependency-freshness.allowlist.yaml 2>/dev/null; then
paths+=(dependency-freshness.allowlist.yaml)
fi
git -C "$UTILS" archive origin/main "${paths[@]}" | tar -x -C "$snapshot.tmp"
rm -rf "$snapshot"
mv "$snapshot.tmp" "$snapshot"
fi
echo "dependency-freshness: $UTILS lacks the pacman adapter; using its origin/main ${sha:0:12}" >&2
echo "$snapshot"
}
main() {
if [[ ! -x "$SHARED_GATE" ]]; then
echo "Error: shared dependency-freshness gate not found at $SHARED_GATE" >&2
@ -39,16 +70,20 @@ main() {
exit 1
fi
local root="$UTILS"
# 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
if needs_pacman_adapter "$@"; then
root="$(gate_root_for_lock)"
if [[ -z "$root" ]]; 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
fi
exec bash "$SHARED_GATE" "$@"
exec bash "$root/scripts/check_dependency_freshness.sh" "$@"
}
main "$@"

View File

@ -50,3 +50,56 @@ def test_lock_with_the_adapter_reaches_the_shared_gate(tmp_path):
def test_other_manifests_skip_the_adapter_check(tmp_path):
result = _run(_utils(tmp_path, adapter=False), "requirements.txt")
assert result.returncode == 0
def _git(repo: Path, *args: str) -> str:
return subprocess.run(
["git", "-C", str(repo), *args], capture_output=True, text=True, check=True
).stdout.strip()
def _diverged_utils(tmp_path: Path, *, origin_has_adapter: bool) -> Path:
"""A utils checkout without the adapter whose origin/main may have it."""
root = _utils(tmp_path, adapter=False)
_git(root, "init", "-q")
_git(root, "-c", "user.name=t", "-c", "user.email=t@t", "add", "-A")
_git(root, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "old")
old = _git(root, "rev-parse", "HEAD")
if origin_has_adapter:
gate = root / "scripts" / "check_dependency_freshness.sh"
gate.write_text('#!/bin/bash\necho "snapshot-gate-ran $(dirname "$0")"\n')
parser = root / "dep_freshness" / "parsers" / "pacman_lock.py"
parser.parent.mkdir(parents=True)
parser.write_text("")
_git(root, "-c", "user.name=t", "-c", "user.email=t@t", "add", "-A")
_git(root, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "new")
_git(root, "update-ref", "refs/remotes/origin/main", _git(root, "rev-parse", "HEAD"))
_git(root, "reset", "-q", "--hard", old)
return root
def _run_cached(root: Path, cache: Path, *args: str) -> subprocess.CompletedProcess:
return subprocess.run(
["bash", str(WRAPPER), *args],
env={"UTILS_ROOT": str(root), "PATH": "/usr/bin:/bin", "XDG_CACHE_HOME": str(cache)},
capture_output=True,
text=True,
check=False,
)
def test_old_checkout_runs_origin_main_snapshot(tmp_path):
root = _diverged_utils(tmp_path, origin_has_adapter=True)
result = _run_cached(root, tmp_path / "cache", LOCK)
assert result.returncode == 0, result.stderr
assert "snapshot-gate-ran" in result.stdout
assert str(tmp_path / "cache") in result.stdout
# The checkout itself is left exactly as it was.
assert not (root / "dep_freshness" / "parsers" / "pacman_lock.py").exists()
def test_old_checkout_and_old_origin_fail_closed(tmp_path):
root = _diverged_utils(tmp_path, origin_has_adapter=False)
result = _run_cached(root, tmp_path / "cache", LOCK)
assert result.returncode == 1
assert "pacman_lock" in result.stderr