testsAndMisc/linux_configuration/tests/test_deploy.bats
Krzysztof kuhy Rudnicki f75fb60687
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Add deploy command: ff the live checkout
testsAndMisc had no '- deploy:' line, so Ship reported 'pushed, not
deployed'. scripts/deploy.sh fast-forwards ~/src/testsAndMisc to
origin/main, keeps unrelated local edits, and health-checks HEAD =
origin/main plus the tracked hooks. bats: 7/7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 08:57:05 +01:00

86 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bats
# Tests for scripts/deploy.sh against a scratch origin + "live" clone, so the
# real ~/src/testsAndMisc is never touched.
#
# bats linux_configuration/tests/test_deploy.bats
bats_require_minimum_version 1.5.0
setup() {
ROOT="$(cd -- "$(dirname -- "$BATS_TEST_FILENAME")/../.." && pwd)"
SCRIPT="$ROOT/scripts/deploy.sh"
T="$BATS_TEST_TMPDIR"
export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.com
export GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.com
git init -q --bare -b main "$T/origin.git"
git clone -q "$T/origin.git" "$T/dev" 2>/dev/null
mkdir -p "$T/dev/linux_configuration/.githooks"
echo a >"$T/dev/file.txt"
touch "$T/dev/linux_configuration/.githooks/pre-commit"
git -C "$T/dev" add -A
git -C "$T/dev" commit -q -m base
git -C "$T/dev" push -q origin HEAD:main
git clone -q "$T/origin.git" "$T/live"
git -C "$T/live" config core.hooksPath linux_configuration/.githooks
export TESTSANDMISC_DIR="$T/live"
}
push_change() {
echo "$1" >"$T/dev/${2:-file.txt}"
git -C "$T/dev" commit -qam "$1"
git -C "$T/dev" push -q origin HEAD:main
}
@test "CLAUDE.md declares scripts/deploy.sh as the deploy command" {
local tick="\`" n=0 line
while IFS= read -r line; do
[[ "$line" == "- deploy: ${tick}scripts/deploy.sh${tick}"* ]] && n=$((n + 1))
done <"$ROOT/CLAUDE.md"
[ "$n" -eq 1 ]
[ -x "$SCRIPT" ]
}
@test "fast-forwards the live checkout to origin/main" {
push_change b
run "$SCRIPT"
[ "$status" -eq 0 ]
[ "$(git -C "$T/live" rev-parse HEAD)" = "$(git -C "$T/origin.git" rev-parse main)" ]
}
@test "is idempotent: a second run is a no-op that still passes" {
push_change b
"$SCRIPT"
run "$SCRIPT"
[ "$status" -eq 0 ]
}
@test "keeps unrelated uncommitted work and still deploys" {
echo wip >"$T/live/other.txt"
git -C "$T/live" add other.txt
push_change b
run "$SCRIPT"
[ "$status" -eq 0 ]
[ "$(cat "$T/live/other.txt")" = wip ]
}
@test "refuses when uncommitted work collides with the update" {
echo mine >"$T/live/file.txt"
push_change theirs
run "$SCRIPT"
[ "$status" -ne 0 ]
[ "$(cat "$T/live/file.txt")" = mine ]
}
@test "fails the health check when hooks are not wired" {
git -C "$T/live" config --unset core.hooksPath
run "$SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *hooksPath* ]]
}
@test "fails when the live checkout is not on main" {
git -C "$T/live" switch -q -c feature
run "$SCRIPT"
[ "$status" -ne 0 ]
}