70 lines
3.4 KiB
Bash
Executable File
70 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Verify canonical extension source and fail-closed native development packaging.
|
|
set -uo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
SANDBOX="$(mktemp -d)"
|
|
trap 'rm -rf "$SANDBOX"' EXIT
|
|
mkdir -p "$SANDBOX/repo/scripts" "$SANDBOX/repo/extensions"
|
|
cp scripts/sync-dev-extensions.sh "$SANDBOX/repo/scripts/"
|
|
cp -a extensions/goal extensions/mosaic-core "$SANDBOX/repo/extensions/"
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
check_rc() {
|
|
local name="$1" expected="$2"
|
|
shift 2
|
|
"$@" >/dev/null 2>&1
|
|
local rc=$?
|
|
if [ "$rc" -eq "$expected" ]; then PASS=$((PASS+1)); printf 'OK %s\n' "$name"
|
|
else FAIL=$((FAIL+1)); printf 'FAIL %s (exit %s, expected %s)\n' "$name" "$rc" "$expected"
|
|
fi
|
|
}
|
|
|
|
SYNC="$SANDBOX/repo/scripts/sync-dev-extensions.sh"
|
|
check_rc "initial ordinary-file install" 0 bash "$SYNC"
|
|
check_rc "installed tree matches canonical source" 0 bash "$SYNC" --check
|
|
if [ -z "$(find "$SANDBOX/repo/.pi/extensions" -type l -print -quit)" ]; then
|
|
PASS=$((PASS+1)); echo "OK installed tree has no symlinks"
|
|
else FAIL=$((FAIL+1)); echo "FAIL installed tree contains symlinks"
|
|
fi
|
|
printf '\nlocal edit\n' >> "$SANDBOX/repo/.pi/extensions/goal/README.md"
|
|
check_rc "check detects installation drift" 1 bash "$SYNC" --check
|
|
check_rc "sync refuses to overwrite installation drift" 1 bash "$SYNC"
|
|
cp "$SANDBOX/repo/extensions/goal/README.md" "$SANDBOX/repo/.pi/extensions/goal/README.md"
|
|
printf '\nextra\n' > "$SANDBOX/repo/.pi/extensions/extra-file"
|
|
check_rc "check detects an extra destination file" 1 bash "$SYNC" --check
|
|
rm "$SANDBOX/repo/.pi/extensions/extra-file"
|
|
mkdir "$SANDBOX/repo/.pi/extensions/extra-directory"
|
|
check_rc "check detects an extra destination directory" 1 bash "$SYNC" --check
|
|
rmdir "$SANDBOX/repo/.pi/extensions/extra-directory"
|
|
ln -s goal "$SANDBOX/repo/.pi/extensions/extra-link"
|
|
check_rc "check rejects a destination symlink" 1 bash "$SYNC" --check
|
|
rm "$SANDBOX/repo/.pi/extensions/extra-link"
|
|
printf '\ncanonical edit\n' >> "$SANDBOX/repo/extensions/goal/README.md"
|
|
check_rc "sync accepts a canonical source update" 0 bash "$SYNC"
|
|
check_rc "updated installation matches canonical source" 0 bash "$SYNC" --check
|
|
printf '\ninterrupted edit\n' >> "$SANDBOX/repo/extensions/goal/README.md"
|
|
check_rc "forced interruption kills the replacing process" 137 env MOSAIC_SYNC_TEST_FAULT=after-destination bash "$SYNC"
|
|
check_rc "next invocation recovers old consistent installation" 1 bash "$SYNC" --check
|
|
if ! grep -q 'interrupted edit' "$SANDBOX/repo/.pi/extensions/goal/README.md"; then
|
|
PASS=$((PASS+1)); echo "OK interrupted replacement rolled back"
|
|
else FAIL=$((FAIL+1)); echo "FAIL interrupted replacement remained active"
|
|
fi
|
|
check_rc "sync succeeds after interruption recovery" 0 bash "$SYNC"
|
|
touch "$SANDBOX/repo/.pi/.extensions-sync.lock"
|
|
check_rc "unlocked stale lock file does not block" 0 bash "$SYNC" --check
|
|
exec 8>"$SANDBOX/repo/.pi/.extensions-sync.lock"
|
|
flock -n 8
|
|
check_rc "active lock refuses a concurrent sync" 3 bash "$SYNC" --check
|
|
flock -u 8
|
|
ln -s README.md "$SANDBOX/repo/extensions/goal/forbidden-link"
|
|
check_rc "source symlink fails closed" 2 bash "$SYNC"
|
|
rm "$SANDBOX/repo/extensions/goal/forbidden-link"
|
|
mkdir "$SANDBOX/repo/extensions/goal/nested"
|
|
cp "$SANDBOX/repo/extensions/goal/index.ts" "$SANDBOX/repo/extensions/goal/nested/index.ts"
|
|
check_rc "nested second entrypoint fails closed" 2 bash "$SYNC"
|
|
|
|
printf '\nextension package selftest: %s passed, %s failed\n' "$PASS" "$FAIL"
|
|
[ "$FAIL" -eq 0 ]
|