Something went wrong. Try again.
A video game where you play as a misaligned AI, deceiving and building power. An experiment in spec-driven development. forked from cameron.stream/misaligned
Something went wrong. Try again.
7.5 kB · 273 lines
Shell
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274#!/usr/bin/env bash# Fixture tests for tools/site-deploy.sh using a local bare remote and a fake# SSH transport. Covers missing-branch initial publish, identical-tree no-op,# changed-tree publish, and ls-remote transport failure classification.set -euo pipefailcd "$(dirname "$0")/.." || exit 1
fail=0tmp=$(mktemp -d)trap 'rm -rf "$tmp"' EXIT
setup_fixture_repo() { local root=$1
mkdir -p "$root/tools" "$root/site/dist" cp tools/site-deploy.sh "$root/tools/site-deploy.sh"
cat > "$root/tools/site-build.sh" <<'EOF'#!/usr/bin/env bashset -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"DIST="$ROOT/site/dist"VARIANT="${SITE_DEPLOY_FIXTURE_VARIANT:-base}"
rm -rf "$DIST"mkdir -p "$DIST"printf '%s\n' "$VARIANT" > "$DIST/content.txt"printf '<!doctype html><title>%s</title><meta name="misaligned-source-revision" content="%s">\n' \ "$VARIANT" "$SITE_SOURCE_REVISION" > "$DIST/index.html"printf '' > "$DIST/.nojekyll"EOF chmod +x "$root/tools/site-build.sh"
cat > "$root/fake-ssh.sh" <<'EOF'#!/usr/bin/env bashset -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"REMOTE="$ROOT/remote.git"LOG="$ROOT/ssh.log"SERVICES="$ROOT/ssh-services.log"joined="$*"
printf '%s\n' "$joined" >> "$LOG"
case "$joined" in *git-upload-pack*) service="git-upload-pack" ;; *git-receive-pack*) service="git-receive-pack" ;; *) echo "fake-ssh: unsupported invocation: $joined" >&2 exit 97 ;;esac
printf '%s\n' "$service" >> "$SERVICES"
if [ "${FAKE_SSH_FAIL_ON:-}" = "$service" ]; then echo "fake-ssh: forced failure for $service" >&2 exit 66fi
case "$service" in git-upload-pack) exec git-upload-pack "$REMOTE" ;; git-receive-pack) exec git-receive-pack "$REMOTE" ;;esacEOF chmod +x "$root/fake-ssh.sh"
git init --bare -q "$root/remote.git" git -C "$root" init -q git -C "$root" config user.name "Fixture User" git -C "$root" config user.email "fixture@example.com" git -C "$root" config core.sshCommand "$root/fake-ssh.sh" git -C "$root" remote add origin "ssh://fixture/placeholder.git" cat > "$root/.gitignore" <<'EOF'remote.git/site/dist/ssh.logssh-services.logEOF printf 'fixture source\n' > "$root/source.txt" git -C "$root" add .gitignore source.txt fake-ssh.sh tools/site-build.sh tools/site-deploy.sh git -C "$root" commit -q -m "fixture source"}
run_deploy_ok() { local root=$1 local variant=$2 ( cd "$root" GIT_SSH_VARIANT=simple SITE_DEPLOY_FIXTURE_VARIANT="$variant" bash tools/site-deploy.sh ) 2>&1}
run_deploy_fail() { local root=$1 local variant=$2 local fail_on=$3 ( cd "$root" GIT_SSH_VARIANT=simple SITE_DEPLOY_FIXTURE_VARIANT="$variant" FAKE_SSH_FAIL_ON="$fail_on" \ bash tools/site-deploy.sh ) 2>&1}
remote_head() { git -C "$1/remote.git" rev-parse "refs/heads/$2"}
remote_tree() { git -C "$1/remote.git" rev-parse "refs/heads/$2^{tree}"}
parent_count() { git -C "$1/remote.git" rev-list --parents -n 1 "refs/heads/$2" | awk '{ print NF - 1 }'}
count_service() { local root=$1 local service=$2 if [ ! -f "$root/ssh-services.log" ]; then echo 0 return fi awk -v service="$service" '$0 == service { count++ } END { print count + 0 }' "$root/ssh-services.log"}
reset_ssh_logs() { : > "$1/ssh.log" : > "$1/ssh-services.log"}
echo "=== fixture: missing branch initial publish ==="root="$tmp/missing-branch"setup_fixture_repo "$root"output="$(run_deploy_ok "$root" base)" || { echo "FAIL fixture missing-branch: expected success" echo "$output" fail=1}echo "$output" | grep -q "missing remote pages branch origin/pages, initial publish" || { echo "FAIL fixture missing-branch: did not report initial publish" echo "$output" fail=1}head_before="$(remote_head "$root" pages)"tree_before="$(remote_tree "$root" pages)"[ "$(parent_count "$root" pages)" = "0" ] || { echo "FAIL fixture missing-branch: initial publish commit is not orphaned" fail=1}[ "$(count_service "$root" git-upload-pack)" = "1" ] || { echo "FAIL fixture missing-branch: ls-remote did not use fake SSH exactly once" fail=1}[ "$(count_service "$root" git-receive-pack)" = "1" ] || { echo "FAIL fixture missing-branch: push did not use fake SSH exactly once" fail=1}
echo "=== fixture: identical-tree no-op ==="reset_ssh_logs "$root"output="$(run_deploy_ok "$root" base)" || { echo "FAIL fixture identical-tree: expected success" echo "$output" fail=1}echo "$output" | grep -q "public-site content is current on origin/pages" || { echo "FAIL fixture identical-tree: missing current-content message" echo "$output" fail=1}echo "$output" | grep -q "nothing to publish" || { echo "FAIL fixture identical-tree: missing no-op message" echo "$output" fail=1}[ "$head_before" = "$(remote_head "$root" pages)" ] || { echo "FAIL fixture identical-tree: remote head changed on no-op" fail=1}[ "$(count_service "$root" git-upload-pack)" = "2" ] || { echo "FAIL fixture identical-tree: expected ls-remote + fetch through fake SSH" fail=1}[ "$(count_service "$root" git-receive-pack)" = "0" ] || { echo "FAIL fixture identical-tree: no-op should not push" fail=1}
echo "=== fixture: changed-tree publish ==="reset_ssh_logs "$root"output="$(run_deploy_ok "$root" changed)" || { echo "FAIL fixture changed-tree: expected success" echo "$output" fail=1}head_after="$(remote_head "$root" pages)"tree_after="$(remote_tree "$root" pages)"[ "$head_before" != "$head_after" ] || { echo "FAIL fixture changed-tree: remote head did not change" fail=1}[ "$tree_before" != "$tree_after" ] || { echo "FAIL fixture changed-tree: remote tree did not change" fail=1}[ "$(parent_count "$root" pages)" = "0" ] || { echo "FAIL fixture changed-tree: publish commit is not orphaned" fail=1}[ "$(count_service "$root" git-upload-pack)" = "2" ] || { echo "FAIL fixture changed-tree: expected ls-remote + fetch through fake SSH" fail=1}[ "$(count_service "$root" git-receive-pack)" = "1" ] || { echo "FAIL fixture changed-tree: changed tree did not push exactly once" fail=1}
echo "=== fixture: transport failure is not treated as missing branch ==="root="$tmp/transport-failure"setup_fixture_repo "$root"if output="$(run_deploy_fail "$root" base git-upload-pack)"; then echo "FAIL fixture transport-failure: expected non-zero exit" fail=1else echo "$output" | grep -q "fake-ssh: forced failure for git-upload-pack" || { echo "FAIL fixture transport-failure: missing forced-failure output" echo "$output" fail=1 } if echo "$output" | grep -q "missing remote pages branch"; then echo "FAIL fixture transport-failure: transport failure was misclassified as missing branch" echo "$output" fail=1 fifi
echo "=== fixture: dirty source tree is not published ==="root="$tmp/dirty-source"setup_fixture_repo "$root"printf 'uncommitted\n' >> "$root/source.txt"if output="$(run_deploy_ok "$root" base)"; then echo "FAIL fixture dirty-source: expected non-zero exit" fail=1else echo "$output" | grep -q "refusing to publish a dirty source tree" || { echo "FAIL fixture dirty-source: missing dirty-tree refusal" echo "$output" fail=1 } [ ! -e "$root/remote.git/refs/heads/pages" ] || { echo "FAIL fixture dirty-source: pages branch was created" fail=1 }fi
if [ "$fail" -ne 0 ]; then echo "site deploy fixtures: FAILED" exit 1fi
echo "site deploy fixtures: OK"