Files
spatial-agent-app/scripts/tests/deploy-enabled_test.sh
T
mathiasandClaude Sonnet 5.5 54e1db68f3
CD / Detect unsubstituted template (push) Successful in 0s
CD / Lint / Test / Vet (push) Successful in 6s
CD / Build & Import (push) Skipped
CD / Deploy via GitOps (push) Skipped
fix(ci): gate build and deploy behind a committed .deploy-enabled marker
Every push to main since the first substituted commit was red at "Update
image tag in infra repo": sed: can't read k3s/apps/spatial-agent-app/
deployment.yaml. mathias/infra has no such manifest and the repo is a
hello-world MVP that should not deploy yet.

Port of doodle 32acff8/006c108/3a95cc9: guard outputs deploy_enabled from
scripts/deploy-enabled.sh (regular file, not symlink); build and deploy
require it to equal 'true', so a missing output fails closed. check and the
template guard are unchanged. No marker is committed.

Wiring test seen red on the old cd.yml (no gate), green after; removing the
clause from build.if or deploy.if makes it fail.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SZkhi49hfeSqBp5aZJNXsM
2026-10-10 10:53:27 +02:00

65 lines
2.9 KiB
Bash

#!/usr/bin/env bash
# Tests for scripts/deploy-enabled.sh
#
# cd.yml gates build and deploy on this script's answer (#3). It exists because
# main was red on every push: deploy patches k3s/apps/spatial-agent-app/deployment.yaml in
# mathias/infra, which does not exist, and build kept pushing images for a
# service that is not deployed.
#
# The failure that matters is answering "true" when deployment is not meant to
# be on, so the cases below are about what must NOT enable it: a directory, a
# symlink, an absent marker.
#
# Usage: ./scripts/tests/deploy-enabled_test.sh
set -uo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
SCRIPT="$ROOT/scripts/deploy-enabled.sh"
pass=0; fail=0
ok() { printf ' ok %s\n' "$1"; pass=$((pass+1)); }
bad() { printf ' FAIL %s\n %s\n' "$1" "${2:-}"; fail=$((fail+1)); }
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
echo "deploy-enabled tests"
if [ -f "$SCRIPT" ]; then ok "script exists"
else bad "script exists" "$SCRIPT missing"; echo; echo "$pass passed, $fail failed"; exit 1; fi
# want_answer <name> <dir> <want>: stdout must equal <want> and exit must be 0.
want_answer() {
local name="$1" dir="$2" want="$3" got rc
got="$(bash "$SCRIPT" "$dir" 2>/dev/null)"; rc=$?
if [ "$got" = "$want" ] && [ "$rc" -eq 0 ]; then ok "$name"
else bad "$name" "got '$got' (exit $rc), want '$want' (exit 0)"; fi
}
mkdir "$tmp/regular"; echo "enabled" > "$tmp/regular/.deploy-enabled"
mkdir "$tmp/absent"
mkdir "$tmp/empty"; : > "$tmp/empty/.deploy-enabled"
mkdir "$tmp/isdir"; mkdir "$tmp/isdir/.deploy-enabled"
mkdir "$tmp/symlink"; echo "enabled" > "$tmp/symlink/target"; ln -s target "$tmp/symlink/.deploy-enabled"
mkdir "$tmp/dangling"; ln -s nowhere "$tmp/dangling/.deploy-enabled"
want_answer "a regular marker file enables deployment" "$tmp/regular" true
want_answer "no marker means deployment stays off" "$tmp/absent" false
want_answer "an empty marker file still enables (content is ignored)" "$tmp/empty" true
want_answer "a marker that is a directory does not enable" "$tmp/isdir" false
want_answer "a symlink to a regular file does not enable" "$tmp/symlink" false
want_answer "a dangling symlink does not enable" "$tmp/dangling" false
# A missing directory is not "off": answering false would let a typo in the
# workflow look like a deliberate opt-out. Exit 2 and print nothing on stdout.
got="$(bash "$SCRIPT" "$tmp/nope" 2>/dev/null)"; rc=$?
if [ -z "$got" ] && [ "$rc" -eq 2 ]; then ok "a missing directory exits 2 with empty stdout"
else bad "a missing directory exits 2 with empty stdout" "got '$got' (exit $rc)"; fi
# Default directory is the current one.
got="$(cd "$tmp/regular" && bash "$SCRIPT" 2>/dev/null)"
[ "$got" = "true" ] && ok "with no argument it inspects the current directory" \
|| bad "with no argument it inspects the current directory" "got '$got'"
echo
echo "$pass passed, $fail failed"
[ "$fail" -eq 0 ]