Files
light-heart-labs--dreamserver/ods/tests/test-disk-check-install-dir.sh
T
wehub-resource-sync 9e8f1bbeed
Dashboard / frontend (push) Failing after 0s
Dashboard / api (push) Failing after 0s
Lint PowerShell / powershell-lint (ubuntu-latest) (push) Failing after 1s
Python Lint / Lint Python with Ruff (push) Failing after 1s
ShellCheck / Lint shell scripts (push) Failing after 1s
Matrix Smoke / linux-smoke (push) Failing after 1s
Matrix Smoke / distro: cachyos (push) Failing after 15s
Matrix Smoke / distro: linux-mint-21.3 (push) Failing after 15s
Matrix Smoke / distro: debian-12 (push) Failing after 5m21s
Matrix Smoke / distro: fedora-41 (push) Failing after 4m56s
Matrix Smoke / distro: ubuntu-24.04 (push) Failing after 2m13s
Matrix Smoke / distro: rocky-9 (push) Failing after 10m39s
Matrix Smoke / distro: manjaro (push) Failing after 12m11s
Matrix Smoke / distro: opensuse-tw (push) Failing after 11m53s
Matrix Smoke / distro: archlinux (push) Failing after 20m3s
Matrix Smoke / distro: ubuntu-22.04 (push) Failing after 13m49s
Validate .env Schema / tier-1-env-validation (push) Successful in 52s
Validate .env Schema / tier-2-env-validation (push) Successful in 44s
Validate .env Schema / tier-3-env-validation (push) Successful in 52s
Validate .env Schema / tier-4-env-validation (push) Successful in 51s
Validate Extensions Catalog / Check catalog is up-to-date (push) Failing after 9m47s
Secret Scan / Scan for secrets (push) Failing after 21m4s
Validate Docker Compose / Validate Docker Compose files (push) Has been cancelled
Python Type Check / Type check with mypy (push) Has been cancelled
Validate .env Schema / tier-0-env-validation (push) Has been cancelled
Test Linux / integration-smoke (push) Has been cancelled
Lint PowerShell / powershell-lint (windows-latest) (push) Has been cancelled
Matrix Smoke / macos-smoke (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:33 +08:00

108 lines
4.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Tests that the installer disk check probes the INSTALL_DIR filesystem,
# not the hardcoded $HOME filesystem. Covers issue #1688.
#
# Strategy: stub df so we can assert which path it was called with,
# then run just the disk-detection block extracted from 02-detection.sh.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
DETECTION_PHASE="$ROOT_DIR/ods/installers/phases/02-detection.sh"
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
pass() { echo -e "${GREEN}${NC} $1"; }
fail() { echo -e "${RED}${NC} $1"; exit 1; }
info() { echo -e "${BLUE}${NC} $1"; }
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
# ── Stub df ───────────────────────────────────────────────────────────────────
# Records the path it was called with to $TMP/df-probe-path, then returns
# a fixed 100GB free so DISK_AVAIL is always set.
STUB_BIN="$TMP/bin"
mkdir -p "$STUB_BIN"
cat > "$STUB_BIN/df" <<'SH'
#!/bin/sh
echo "$2" >> "$TMP_DIR/df-probe-path"
printf "Filesystem 1G-blocks Used Available Use%% Mounted on\n"
printf "/dev/fake 500 400 100 80%% /\n"
SH
chmod +x "$STUB_BIN/df"
# The isolated disk-probe function extracted from 02-detection.sh.
# We source only the logic we changed so the test is fast and hermetic.
run_disk_probe() {
local install_dir="$1"
local home_dir="$2"
# Mirror the exact logic from 02-detection.sh
_disk_probe_path="${install_dir:-$home_dir/ods}"
while [[ -n "$_disk_probe_path" ]] && [[ ! -e "$_disk_probe_path" ]]; do
_disk_probe_path="$(dirname "$_disk_probe_path")"
done
_disk_probe_path="${_disk_probe_path:-$home_dir}"
TMP_DIR="$TMP" PATH="$STUB_BIN:$PATH" \
df -BG "$_disk_probe_path" > /dev/null
echo "$_disk_probe_path"
}
# ── Test 1: No INSTALL_DIR set → probes HOME ──────────────────────────────────
info "Test 1: No INSTALL_DIR → disk check should probe HOME"
FAKE_HOME="$TMP/home/user"
mkdir -p "$FAKE_HOME"
probed="$(run_disk_probe "" "$FAKE_HOME")"
[[ "$probed" == "$FAKE_HOME"* ]] \
|| fail "Expected probe path inside FAKE_HOME ($FAKE_HOME), got: $probed"
pass "No INSTALL_DIR: probed HOME filesystem ($probed)"
# ── Test 2: INSTALL_DIR exists → probes INSTALL_DIR directly ──────────────────
info "Test 2: INSTALL_DIR exists → disk check should probe INSTALL_DIR"
FAKE_INSTALL="$TMP/mnt/data/ods"
mkdir -p "$FAKE_INSTALL"
probed="$(run_disk_probe "$FAKE_INSTALL" "$FAKE_HOME")"
[[ "$probed" == "$FAKE_INSTALL" ]] \
|| fail "Expected probe path == INSTALL_DIR ($FAKE_INSTALL), got: $probed"
pass "INSTALL_DIR exists: probed INSTALL_DIR directly ($probed)"
# ── Test 3: INSTALL_DIR does NOT exist → ancestor walk resolves correctly ──────
info "Test 3: INSTALL_DIR doesn't exist yet → walk up to existing ancestor"
# Use a fresh subdir to guarantee no intermediate path was created by earlier tests
T3="$TMP/t3"
FAKE_MOUNT_T3="$T3/mnt/data"
mkdir -p "$FAKE_MOUNT_T3" # ancestor exists; $T3/mnt/data/ods does NOT
# Two non-existent segments: ods and ods/myinstall
NONEXISTENT_INSTALL="$FAKE_MOUNT_T3/ods/myinstall" # neither segment exists
probed="$(run_disk_probe "$NONEXISTENT_INSTALL" "$FAKE_HOME")"
# Walk should stop at FAKE_MOUNT_T3 (first existing ancestor)
[[ "$probed" == "$FAKE_MOUNT_T3" ]] \
|| fail "Expected first existing ancestor ($FAKE_MOUNT_T3) to be probed, got: $probed"
pass "INSTALL_DIR not yet created: walked up to nearest existing ancestor ($probed)"
# ── Test 4: INSTALL_DIR is on a completely different mount from HOME ───────────
info "Test 4: INSTALL_DIR on a different path from HOME → HOME must NOT be probed"
ANOTHER_MOUNT="$TMP/another/mount"
mkdir -p "$ANOTHER_MOUNT"
probed="$(run_disk_probe "$ANOTHER_MOUNT" "$FAKE_HOME")"
[[ "$probed" != "$FAKE_HOME" ]] \
|| fail "Disk check probed HOME even though INSTALL_DIR exists at $ANOTHER_MOUNT"
[[ "$probed" == "$ANOTHER_MOUNT"* ]] \
|| fail "Expected probe inside ANOTHER_MOUNT ($ANOTHER_MOUNT), got: $probed"
pass "Different mount: HOME was NOT used, probed INSTALL_DIR mount ($probed)"
echo ""
echo -e "${GREEN}All disk-check-install-dir tests passed.${NC}"