197 lines
9.1 KiB
Bash
197 lines
9.1 KiB
Bash
#!/bin/sh
|
|
# Dependencies and conflicts (ROADMAP 2.3): minimum versions, conflicts
|
|
# both ways by name, every problem reported before the prompt, removal of
|
|
# a dependency refused, user deps met by system packages, the library's
|
|
# own enforcement at commit and for live contexts, and the index's
|
|
# auto|explicit field. Runs INSIDE the Dockerfile.alpine_root image:
|
|
#
|
|
# ./run_docker.sh Dockerfile.alpine_root # builds glacier-alpine_root
|
|
# docker run --rm -v "$PWD/tests/deps_alpine.sh:/t.sh:ro" glacier-alpine_root sh /t.sh
|
|
FAILS=0
|
|
check() { d=$1; shift; if "$@"; then echo "PASS: $d"; else echo "FAIL: $d"; FAILS=$((FAILS+1)); fi; }
|
|
nocolor() { sed 's/\x1b\[[0-9;]*m//g'; }
|
|
has() { echo "$OUT" | grep -qxF "$1"; }
|
|
hasnt() { ! echo "$OUT" | grep -qF "$1"; }
|
|
inst() { grep -q "^$1::" /glacier/sys/index/current; }
|
|
SP() { OUT=$(echo y | ./syspkg "$@" 2>&1 | nocolor); echo "$OUT" | sed 's/^/ /'; }
|
|
|
|
# mkpkg NAME VER REPO [DEPS] [CONFS] -> /srv/NAME-VER.gpkg (+ sidecar)
|
|
# DEPS / CONFS: space-separated name:version
|
|
mkpkg() {
|
|
w=$(mktemp -d); d=$w/$1-$2
|
|
mkdir -p $d/files/usr/share/$1
|
|
echo "$1 $2" > $d/files/usr/share/$1/data
|
|
{
|
|
printf 'PKG_NAME = "%s";\nPKG_VER = "%s";\nPKG_DESC = "t";\nPKG_MAINT = "t@e";\nPKG_COPYRIGHT = "MIT";\nPKG_REPO = "%s";\n' "$1" "$2" "$3"
|
|
for list in DEPS CONFS; do
|
|
[ $list = DEPS ] && items=$4 || items=$5
|
|
printf 'PKG_%s = (' $list; sep=""
|
|
for it in $items; do
|
|
printf '%s{ PKG_NAME = "%s"; PKG_VER = "%s"; }' "$sep" "${it%%:*}" "${it#*:}"; sep=", "
|
|
done
|
|
printf ');\n'
|
|
done
|
|
} > $d/manifest.gpm.cfg
|
|
tar czf /srv/$1-$2.gpkg -C $w $1-$2
|
|
printf 'sha256:%s\n' "$(sha256sum /srv/$1-$2.gpkg | cut -d' ' -f1)" > /srv/$1-$2.gpkg.sha256
|
|
gsign -S -s /root/glacier-test.sec -m /srv/$1-$2.gpkg.sha256 >/dev/null
|
|
chmod 644 /srv/$1-$2.gpkg /srv/$1-$2.gpkg.sha256 /srv/$1-$2.gpkg.sha256.sig
|
|
rm -rf $w
|
|
}
|
|
mkdir -p /srv; chmod 755 /srv
|
|
mkpkg lib 1.0.0 extra
|
|
mkpkg lib 1.3.0 extra
|
|
mkpkg app 1.0.0 extra "lib:1.2.0"
|
|
mkpkg multi 1.0.0 extra "ghost:2.0.0 phantom:0.1.0"
|
|
mkpkg core 1.0.0 base
|
|
mkpkg usescore 1.0.0 extra "core:1.0.0"
|
|
mkpkg x 1.0.0 extra "" "y:9.9.9"
|
|
mkpkg y 1.0.0 extra
|
|
mkpkg w 1.0.0 community
|
|
mkpkg x2 1.0.0 extra "" "w:1.0.0"
|
|
mkpkg other 1.0.0 extra
|
|
mkpkg uapp 1.0.0 extra "core:1.0.0"
|
|
mkpkg unoway 1.0.0 extra "nowhere:1.0.0"
|
|
|
|
cd /app && ./syspkg -n >/dev/null 2>&1
|
|
|
|
echo "== 1. missing dependency: refused before the prompt"
|
|
SP -l /srv/app-1.0.0.gpkg
|
|
check "message names the dependency and its minimum" has "[x] extra::app requires lib >= 1.2.0, which is not installed."
|
|
check "refused before the prompt" hasnt "Proceed?"
|
|
check "app not installed" sh -c '! grep -q "^extra::app::" /glacier/sys/index/current'
|
|
|
|
echo "== 2. dependency installed but too old"
|
|
SP -l /srv/lib-1.0.0.gpkg
|
|
SP -l /srv/app-1.0.0.gpkg
|
|
check "too-old version refused" has "[x] extra::app requires lib >= 1.2.0, which is not installed."
|
|
check "still not installed" sh -c '! grep -q "^extra::app::" /glacier/sys/index/current'
|
|
|
|
echo "== 3. every problem reported, one line each"
|
|
SP -l /srv/multi-1.0.0.gpkg
|
|
check "first missing dep" has "[x] extra::multi requires ghost >= 2.0.0, which is not installed."
|
|
check "second missing dep" has "[x] extra::multi requires phantom >= 0.1.0, which is not installed."
|
|
|
|
echo "== 4. a batch satisfies itself, in any order (with -O replacing lib 1.0.0)"
|
|
SP -lO /srv/app-1.0.0.gpkg /srv/lib-1.3.0.gpkg
|
|
check "batch completed" has "[✓] Completed with no errors."
|
|
check "app installed" inst extra::app
|
|
check "lib upgraded to 1.3.0" grep -q "^extra::lib::1.3.0" /glacier/sys/index/current
|
|
|
|
echo "== 5. removing a dependency is refused"
|
|
SP -x lib
|
|
check "removal refused with the dependent named" has "[x] Removing extra::lib breaks extra::app."
|
|
check "refused before the prompt" hasnt "Proceed?"
|
|
check "lib still installed" inst extra::lib
|
|
|
|
echo "== 6. a downgrade below a dependent's minimum is refused"
|
|
SP -lO /srv/lib-1.0.0.gpkg
|
|
check "downgrade refused" has "[x] extra::app requires lib >= 1.2.0, which is not installed."
|
|
check "lib still 1.3.0" grep -q "^extra::lib::1.3.0" /glacier/sys/index/current
|
|
|
|
echo "== 7. removing the dependent and the dependency together is fine"
|
|
SP -x app lib
|
|
check "both removed" sh -c '! grep -q "^extra::\(app\|lib\)::" /glacier/sys/index/current'
|
|
|
|
echo "== 8. a dependency is met from any repo"
|
|
SP -l /srv/core-1.0.0.gpkg /srv/usescore-1.0.0.gpkg
|
|
check "extra package depending on a base package installs" inst extra::usescore
|
|
|
|
echo "== 9. conflicts, both directions, version ignored"
|
|
SP -l /srv/y-1.0.0.gpkg
|
|
SP -l /srv/x-1.0.0.gpkg
|
|
check "new package listing an installed one" has "[x] extra::x conflicts with extra::y."
|
|
SP -l /srv/w-1.0.0.gpkg
|
|
SP -l /srv/x2-1.0.0.gpkg
|
|
check "new package listing an installed one, other repo" has "[x] extra::x2 conflicts with community::w."
|
|
SP -x w
|
|
SP -l /srv/x2-1.0.0.gpkg
|
|
SP -l /srv/w-1.0.0.gpkg
|
|
check "installed package listing the new one" has "[x] community::w conflicts with extra::x2."
|
|
SP -x x2
|
|
SP -l /srv/x2-1.0.0.gpkg /srv/w-1.0.0.gpkg
|
|
check "a conflicting pair in one batch is reported once" test "$(echo "$OUT" | grep -c 'conflicts with')" = 1
|
|
|
|
echo "== 10. an already-inconsistent store doesn't block unrelated work"
|
|
M=$(ls -d /glacier/sys/store/extra/usescore/usescore-*)/.glacier-manifest
|
|
sed -i 's/^PKG_DEPS = (\(.*\));/PKG_DEPS = (\1, { PKG_NAME = "ghost"; PKG_VER = "1.0.0"; });/' $M
|
|
grep -q ghost $M || echo " (manifest edit failed)"
|
|
SP -l /srv/other-1.0.0.gpkg
|
|
check "unrelated install still works" inst extra::other
|
|
|
|
echo "== 11. index: auto|explicit field, and the CLIs still parse it"
|
|
check "index lines carry ::explicit" grep -q "^extra::other::1.0.0::explicit$" /glacier/sys/index/current
|
|
cat > /tmp/auto.lua <<'EOF'
|
|
package.path = "/app/?.lua;" .. package.path
|
|
local ffi = require("ffi"); require("lib/glacier_cdef")
|
|
local istore = ffi.load("/app/lib/glacier/libglacier_istoreutils.so")
|
|
local txn = ffi.load("/app/lib/glacier/libglacier_transaction.so")
|
|
local live = ffi.new("gl_context_t")
|
|
txn.gl_init_live_context(live, ffi.C.GL_SCOPE_SYS, 0)
|
|
os.exit(istore.gl_set_pkg_auto(live, "extra", "other", true) == 0 and 0 or 1)
|
|
EOF
|
|
check "gl_set_pkg_auto succeeds" luajit /tmp/auto.lua
|
|
check "index line now ::auto" grep -q "^extra::other::1.0.0::auto$" /glacier/sys/index/current
|
|
SP -x other
|
|
check "-x summary shows the plain version" sh -c 'echo "$1" | grep -q "extra::other.*1\.0\.0 *$"' _ "$OUT"
|
|
check "auto package removed by name" sh -c '! grep -q "^extra::other::" /glacier/sys/index/current'
|
|
|
|
echo "== 12. the library enforces the rules itself (no CLI pre-check)"
|
|
cat > /tmp/lib.lua <<'EOF'
|
|
package.path = "/app/?.lua;" .. package.path
|
|
local ffi = require("ffi"); require("lib/glacier_cdef")
|
|
local istore = ffi.load("/app/lib/glacier/libglacier_istoreutils.so")
|
|
local txn = ffi.load("/app/lib/glacier/libglacier_transaction.so")
|
|
local what = arg[1]
|
|
local ctx = ffi.new("gl_context_t")
|
|
if what == "stage-install" or what == "stage-remove" then
|
|
assert(txn.gl_init_stage_context(ctx, ffi.C.GL_SCOPE_SYS, 0) == 0)
|
|
if what == "stage-install" then
|
|
assert(istore.gl_install_pkg(ctx, "/srv/app-1.0.0.gpkg") == 0)
|
|
else
|
|
assert(istore.gl_remove_pkg(ctx, "core", "base") == 0)
|
|
end
|
|
local st = txn.gl_commit_transaction(ctx)
|
|
txn.gl_abort_transaction(ctx)
|
|
print(tonumber(st))
|
|
else
|
|
txn.gl_init_live_context(ctx, ffi.C.GL_SCOPE_SYS, 0)
|
|
if what == "live-install" then
|
|
print(tonumber(istore.gl_install_pkg(ctx, "/srv/app-1.0.0.gpkg")))
|
|
else
|
|
print(tonumber(istore.gl_remove_pkg(ctx, "core", "base")))
|
|
end
|
|
end
|
|
EOF
|
|
OUT=$(luajit /tmp/lib.lua stage-install 2>&1 | nocolor); echo "$OUT" | sed 's/^/ /'
|
|
check "staged install with a missing dep: commit refuses (GL_TXN_ERR_DEPS)" has "9"
|
|
check "and says why" has "[x] extra::app requires lib >= 1.2.0, which is not installed."
|
|
check "app not committed" sh -c '! grep -q "^extra::app::" /glacier/sys/index/current'
|
|
OUT=$(luajit /tmp/lib.lua stage-remove 2>&1 | nocolor); echo "$OUT" | sed 's/^/ /'
|
|
check "staged removal of a dependency: commit refuses" has "9"
|
|
check "and says why" has "[x] Removing base::core breaks extra::usescore."
|
|
check "core still installed" inst base::core
|
|
OUT=$(luajit /tmp/lib.lua live-install 2>&1 | nocolor); echo "$OUT" | sed 's/^/ /'
|
|
check "live install with a missing dep: GL_INSTALL_ERR_DEPS" has "8"
|
|
check "app not in the live store" test ! -e /glacier/sys/store/extra/app
|
|
OUT=$(luajit /tmp/lib.lua live-remove 2>&1 | nocolor); echo "$OUT" | sed 's/^/ /'
|
|
check "live removal of a dependency: GL_REMOVE_ERR_DEPS" has "4"
|
|
check "core still in the live store" test -d /glacier/sys/store/base/core
|
|
|
|
echo "== 13. user scope: deps met by system packages; system ignores users"
|
|
U() { OUT=$(su glacier -c "cd /app && echo y | ./gpkg $*" 2>&1 | nocolor); echo "$OUT" | sed 's/^/ /'; }
|
|
su glacier -c "doas /app/gstore -n" >/dev/null 2>&1
|
|
U -l /srv/uapp-1.0.0.gpkg
|
|
check "user package depending on a system package installs" has "[✓] Completed with no errors."
|
|
U -l /srv/unoway-1.0.0.gpkg
|
|
check "user package with a missing dep refused" has "[x] extra::unoway requires nowhere >= 1.0.0, which is not installed."
|
|
SP -x usescore
|
|
SP -x core
|
|
check "syspkg -x ignores user-scope dependents" has "[✓] Completed with no errors."
|
|
U -x uapp
|
|
check "user can still remove their package" has "[✓] Completed with no errors."
|
|
|
|
echo
|
|
[ $FAILS -eq 0 ] && echo "ALL PASSED" || echo "$FAILS FAILED"
|
|
exit $FAILS
|