Files
samios/tests/test_packages.sh
Sami Ahmed 5d735b2987
SamiOS CI / lint-and-test (push) Successful in 10s
[grade=C→fixing] Desktop overlay + build script + CI improvements
- packages.x86_64.desktop: 30+ packages for desktop variant (Plasma,
  Firefox, VLC, LibreOffice, PipeWire). No duplicates with base list.
- build-desktop.sh: creates temp profile, merges package lists, enables
  SDDM via preset + display-manager.service symlink. WORK_DIR is
  mktemp-created (not caller-selected) to prevent symlink races. VERSION
  copied into temp profile so profiledef.sh resolves correctly.
  Cleans up both temp dirs via trap.
- CI workflow: Python AST validation (sys.argv), VERSION SSOT gate,
  single make check (no double-lint).
- test_packages.sh: 15 assertions for desktop overlay (existence,
  package count, no dups, Plasma/Firefox exact match, build script
  structure: mktemp WORK_DIR, VERSION copy, SDDM, cleanup trap).

Codex D-grade findings fixed: symlink race (use mktemp), VERSION path
(../../VERSION not ../VERSION).
2026-08-12 03:41:50 -07:00

149 lines
5.3 KiB
Bash
Executable File

#!/bin/bash
# Test: packages.x86_64 format and content
# Validates package list format, required packages, and font policy.
source "$(dirname "$0")/test_helper.sh"
suite "packages.x86_64 tests"
PKGLIST="$PROFILE_DIR/packages.x86_64"
assert_file_exists "packages.x86_64 exists" "$PKGLIST"
# Every non-comment, non-empty line must be a valid package name
assert "all package names match valid format (alphanumeric, dashes, +)" \
bash -c '
while IFS= read -r line; do
# skip comments and blank lines
[[ -z "$line" || "$line" == \#* ]] && continue
# validate: letters, digits, dashes, underscores, plus signs
if ! grep -qE "^[a-zA-Z0-9][a-zA-Z0-9_+.-]*$" <<< "$line"; then
echo "invalid package name: $line"
exit 1
fi
done < "'"$PKGLIST"'"
'
# Required core packages
assert_contains "includes base" "$PKGLIST" "^base$"
assert_contains "includes linux" "$PKGLIST" "^linux$"
assert_contains "includes linux-firmware" "$PKGLIST" "^linux-firmware$"
assert_contains "includes networkmanager" "$PKGLIST" "^networkmanager$"
# Font policy: no actual package (non-comment line) containing '7777'
assert "no package with '7777' in name" \
bash -c '
if grep -vE "^\s*#" "'"$PKGLIST"'" | grep -i "7777"; then
exit 1
fi
'
# No blank trailing package lines (exactly one trailing newline)
assert "no trailing blank lines in package list" \
bash -c '
content="$(cat "'"$PKGLIST"'")"
# wc -l should equal number of non-empty lines
[ "$(tail -c1 "'"$PKGLIST"'" | wc -l)" -le 1 ]
'
# No duplicate packages
assert "no duplicate package entries" \
bash -c '
dups=$(grep -vE "^\s*#|^\s*$" "'"$PKGLIST"'" | sort | uniq -d)
if [ -n "$dups" ]; then
echo "duplicates: $dups"
exit 1
fi
'
# ── Desktop overlay ──────────────────────────────────────────────────────
DESKTOP_PKGLIST="$PROFILE_DIR/packages.x86_64.desktop"
DESKTOP_BUILD="$PROFILE_DIR/build-desktop.sh"
export DESKTOP_PKGLIST DESKTOP_BUILD
assert_file_exists "desktop overlay packages file exists" "$DESKTOP_PKGLIST"
assert_file_exists "desktop build script exists" "$DESKTOP_BUILD"
assert "desktop overlay has at least 10 packages" \
bash -c '
count="$(grep -vE "^\s*#|^\s*$" "$DESKTOP_PKGLIST" | wc -l)"
if [ "$count" -lt 10 ]; then
echo "expected ≥10 desktop packages, got $count"
exit 1
fi
'
assert "desktop overlay includes Plasma desktop" \
bash -c "grep -Fqx 'plasma-meta' '$DESKTOP_PKGLIST'"
assert "desktop overlay includes Firefox" \
bash -c "grep -Fqx 'firefox' '$DESKTOP_PKGLIST'"
assert "desktop build script merges base + overlay" \
bash -c "grep -q 'packages.x86_64.desktop' '$DESKTOP_BUILD'"
assert "desktop build script uses mkarchiso" \
bash -c "grep -q 'mkarchiso' '$DESKTOP_BUILD'"
assert "desktop build script has cleanup trap" \
bash -c "grep -q 'trap cleanup' '$DESKTOP_BUILD'"
assert "desktop build script enables SDDM display manager" \
bash -c "grep -q 'sddm' '$DESKTOP_BUILD'"
assert "desktop build script creates display-manager symlink" \
bash -c "grep -q 'display-manager.service' '$DESKTOP_BUILD'"
assert "desktop build script uses mktemp for WORK_DIR (not caller-selected)" \
bash -c "grep -q 'WORK_DIR=.*mktemp' '$DESKTOP_BUILD'"
assert "desktop build script copies VERSION into temp profile" \
bash -c "grep -q 'VERSION' '$DESKTOP_BUILD' && grep -q 'TMP_PROFILE/VERSION' '$DESKTOP_BUILD'"
assert "desktop build script cleanup trap removes both temp dirs" \
bash -c "grep -q 'TMP_PROFILE.*WORK_DIR' '$DESKTOP_BUILD'"
assert "desktop build script excludes output dir during copy (not after)" \
bash -c "grep -q 'out|.|..' '$DESKTOP_BUILD'"
assert "desktop build script passes bash -n syntax check" \
bash -c "bash -n '$DESKTOP_BUILD'"
# Desktop overlay must not duplicate base packages
assert "desktop overlay has no duplicates with base package list" \
bash -c '
dups="$(grep -hE "^[a-zA-Z0-9]" "$PKGLIST" "$DESKTOP_PKGLIST" | sort | uniq -d)"
if [ -n "$dups" ]; then
echo "packages in both base and desktop overlay: $dups"
exit 1
fi
'
# Regression test: prove the duplicate check actually catches duplicates
assert "duplicate-check regression: a planted duplicate IS detected" \
bash -c '
tmp_a="$(mktemp)"
tmp_b="$(mktemp)"
trap "rm -f ${tmp_a:?} ${tmp_b:?}" EXIT
echo -e "base\nlinux\nnetworkmanager" > "$tmp_a"
echo -e "firefox\nbase\nvlc" > "$tmp_b"
dups="$(grep -hE "^[a-zA-Z0-9]" "$tmp_a" "$tmp_b" | sort | uniq -d)"
if [ "$dups" != "base" ]; then
echo "expected to detect duplicate: base, got: $dups"
exit 1
fi
'
# No obsolete packages (khotkeys removed from Arch, neofetch renamed)
assert "desktop overlay does not include known-obsolete packages" \
bash -c '
for bad in khotkeys neofetch; do
if grep -q "^$bad$" "$DESKTOP_PKGLIST"; then
echo "obsolete package found: $bad"
exit 1
fi
done
'
print_summary