Files
cloud-apache-container/scripts/tests/lsphp-pin-resolve.test.sh
shadowdaoandClaude Sonnet 5.5 40f62c2b64 fix(lsphp): per-package pins so an inconsistent LiteSpeed 8.4 set still builds [skip ci]
Stage 2 pinned lsphp84, -common and -ldap to one version; LiteSpeed's repo
offers lsphp84 8.4.27-2 but lsphp84-common only 8.4.27-3 (run 5691 job 18704:
E: Version '8.4.27-2+noble' for 'lsphp84-common' was not found). New
scripts/lsphp-pin-resolve.sh resolves -common/-ldap to the exact version when
offered (unchanged for 82/83/85), else a same-PHP-version, same-distro,
>= revision; never a different PHP release. lsphp84 itself stays exact and the
post-install check requires same upstream + >=. Fixture test added to CI.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-19 09:44:50 -08:00

58 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
## lsphp-pin-resolve.test.sh — fixture test for scripts/lsphp-pin-resolve.sh.
## Fake `apt-cache madison` outputs model (a) a consistent repo (82/83/85: the
## pin must stay EXACTLY the lsphp version), (b) the 2026-11-19 lsphp84 set
## (lsphp84 -2, -common -3 only), (c) cases that must FAIL closed.
set -euo pipefail
HERE=$(cd "$(dirname "$0")/.." && pwd)
R="$HERE/lsphp-pin-resolve.sh"
T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
fail=0
ok() { echo "ok - $1"; }
bad() { echo "FAIL - $1"; fail=1; }
mk() { # file, then lines "pkg|version"
local f="$1"; shift
: >"$f"
for l in "$@"; do printf '%s | %s | http://rpms.litespeedtech.com/debian noble/main amd64 Packages\n' "${l%%|*}" "${l#*|}" >>"$f"; done
}
cat >"$T/apt-cache" <<'EOS'
#!/bin/sh
[ "$1" = madison ] || exit 2
grep -E "^ *$2 \|" "$FIX" || true
EOS
chmod +x "$T/apt-cache"
export LSPHP_MADISON_CMD="$T/apt-cache madison"
res() { FIX="$1" "$R" resolve "$2" "$3" 2>/dev/null; }
expect() { # name want fixture pkg ver
local got; got=$(res "$3" "$4" "$5") || got=FAIL
[ "$got" = "$2" ] && ok "$1" || bad "$1 (got '$got', want '$2')"
}
mk "$T/consistent" "lsphp85-common|8.5.12-2+noble" "lsphp85-ldap|8.5.12-2+noble"
expect "consistent repo: -common stays exact" "8.5.12-2+noble" "$T/consistent" lsphp85-common 8.5.12-2+noble
expect "consistent repo: -ldap stays exact" "8.5.12-2+noble" "$T/consistent" lsphp85-ldap 8.5.12-2+noble
mk "$T/incons" "lsphp84-common|8.4.27-3+noble" "lsphp84-ldap|8.4.27-2+noble"
expect "inconsistent: -common resolves to -3" "8.4.27-3+noble" "$T/incons" lsphp84-common 8.4.27-2+noble
expect "inconsistent: -ldap stays -2" "8.4.27-2+noble" "$T/incons" lsphp84-ldap 8.4.27-2+noble
mk "$T/two" "lsphp84-common|8.4.27-3+noble" "lsphp84-common|8.4.27-2+noble"
expect "exact version preferred over newer revision" "8.4.27-2+noble" "$T/two" lsphp84-common 8.4.27-2+noble
mk "$T/otherphp" "lsphp84-common|8.4.28-1+noble"
expect "different PHP version is never substituted" FAIL "$T/otherphp" lsphp84-common 8.4.27-2+noble
mk "$T/older" "lsphp84-common|8.4.27-1+noble"
expect "older revision is never substituted" FAIL "$T/older" lsphp84-common 8.4.27-2+noble
mk "$T/otherdist" "lsphp84-common|8.4.27-3+jammy"
expect "different distro suffix is never substituted" FAIL "$T/otherdist" lsphp84-common 8.4.27-2+noble
: >"$T/empty"
expect "package absent fails" FAIL "$T/empty" lsphp84-common 8.4.27-2+noble
okc() { "$R" ok "$1" "$2" 2>/dev/null; }
okc 8.4.27-3+noble 8.4.27-2+noble && ok "post-check accepts -3 for want -2" || bad "post-check accepts -3"
okc 8.4.27-2+noble 8.4.27-2+noble && ok "post-check accepts equal" || bad "post-check equal"
okc 8.4.28-1+noble 8.4.27-2+noble && bad "post-check must reject other PHP version" || ok "post-check rejects other PHP version"
okc 8.4.27-1+noble 8.4.27-2+noble && bad "post-check must reject older" || ok "post-check rejects older"
exit $fail