#!/usr/bin/env bats # tests/deploy.bats — black-box tests for scripts/deploy.sh (Refs #42) # # Contract (see script header): the repo checkout IS the deployment; sync adopts # identicals, links new files, quarantines-and-replaces divergents, and stows the # zz-$(hostname) package last. One thing it must NEVER do is deploy generated theme # output: noctalia rewrites `noctalia.*` / `themes/noctalia*` in place, so a tracked # copy is a stale snapshot, and a sync would revert a live palette to whatever colour # scheme was current on the day it was committed. # # Nothing is observed except exit status, stdout, the file/symlink shape under $HOME, # and the quarantine directory. setup() { TEST_TMP="$(mktemp -d)" REPO="$TEST_TMP/repo" DEPLOY="$BATS_TEST_DIRNAME/../scripts/deploy.sh" mkdir -p "$REPO/scripts" "$REPO/dotfiles" # A git repo, because the deployment checkout IS one and deploy.sh arms hooksPath. git init -q -b main "$REPO" cp "$DEPLOY" "$REPO/scripts/deploy.sh" chmod +x "$REPO/scripts/deploy.sh" export HOME="$TEST_TMP/home" mkdir -p "$HOME" export DEPLOY_REPO="$REPO" DEPLOY_HOST=box } teardown() { rm -rf "$TEST_TMP"; } # repo_file repo_file() { mkdir -p "$(dirname "$REPO/dotfiles/$1")"; printf '%s\n' "$2" > "$REPO/dotfiles/$1"; } # live_file live_file() { mkdir -p "$(dirname "$1")"; printf '%s\n' "$2" > "$1"; } @test "generated theme output is never adopted into a symlink" { repo_file "ghostty/.config/ghostty/themes/noctalia" 'background = "#f43841"' live_file "$HOME/.config/ghostty/themes/noctalia" 'background = "#f43841"' run "$REPO/scripts/deploy.sh" [ "$status" -eq 0 ] [[ "$output" == *"SKIP"*".config/ghostty/themes/noctalia"* ]] [ -f "$HOME/.config/ghostty/themes/noctalia" ] [ ! -L "$HOME/.config/ghostty/themes/noctalia" ] } @test "a diverged live palette is never quarantined and reverted to a stale copy" { # The dangerous shape: the tracked file matches today's palette, the theme changes # tomorrow, and sync would quarantine the live file and restore the stale one. repo_file "niri/.config/niri/noctalia.kdl" 'active-color "#e01b24"' live_file "$HOME/.config/niri/noctalia.kdl" 'active-color "#ff8c00"' run "$REPO/scripts/deploy.sh" [ "$status" -eq 0 ] grep -q 'active-color "#ff8c00"' "$HOME/.config/niri/noctalia.kdl" [ ! -L "$HOME/.config/niri/noctalia.kdl" ] [ ! -d "$REPO/.quarantine" ] } @test "an ordinary identical config is still adopted" { # Control against an exclusion so broad the tool stops deploying anything. repo_file "ghostty/.config/ghostty/config.ghostty" 'theme = "gruber"' live_file "$HOME/.config/ghostty/config.ghostty" 'theme = "gruber"' run "$REPO/scripts/deploy.sh" [ "$status" -eq 0 ] [ -L "$HOME/.config/ghostty/config.ghostty" ] [ "$(realpath "$HOME/.config/ghostty/config.ghostty")" = "$(realpath "$REPO/dotfiles/ghostty/.config/ghostty/config.ghostty")" ] } @test "--check reports and writes nothing" { repo_file "ghostty/.config/ghostty/config.ghostty" 'theme = "gruber"' live_file "$HOME/.config/ghostty/config.ghostty" 'theme = "tokyo-night"' run "$REPO/scripts/deploy.sh" --check [ "$status" -eq 0 ] [[ "$output" == *"DRIFT"* || "$output" == *"QUAR"* ]] [ ! -L "$HOME/.config/ghostty/config.ghostty" ] grep -q 'theme = "tokyo-night"' "$HOME/.config/ghostty/config.ghostty" [ ! -d "$REPO/.quarantine" ] }