Files
gochat/deploy/quickstart/scripts/acceptance_scripts_test.sh
T
Rogeeandrogee abb1bed424 H-337: add local Captain acceptance fixture (#63)
* H-337: add local Captain acceptance fixture

* fix(H-337): close acceptance fixture review gaps

* fix(H-337): reject non-string skill metadata

---------

Co-authored-by: Rogee <rogee@ipao.vip>
2026-08-20 20:05:40 +08:00

100 lines
3.5 KiB
Bash
Executable File

#!/bin/sh
set -eu
root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d "${TMPDIR:-/tmp}/gochat-acceptance-scripts.XXXXXX")
trap 'rm -rf "$tmp"' EXIT HUP INT TERM
fail() {
echo "acceptance scripts test failed: $1" >&2
exit 1
}
make_source() {
mkdir -p "$1"
cat > "$1/SKILL.md" <<'EOF'
---
name: fixture
description: Local fixture
---
Use the local fixture.
EOF
printf '%s\n' 'Local assistant instructions.' > "$1/SOUL.md"
}
expect_staging_failure() {
if GANBING_SOURCE=$1 "$root/scripts/stage_captain_assets.sh" "$tmp/output" > "$tmp/staging.log" 2>&1; then
fail "$2 was accepted"
fi
if grep -qx 'skill_status=active' "$tmp/output/manifest.txt" 2>/dev/null; then
fail "$2 generated an active manifest"
fi
rm -rf "$tmp/output"
}
mkdir "$tmp/bin"
cat > "$tmp/bin/docker" <<'EOF'
#!/bin/sh
case " $* " in
*" config --quiet "*) ;;
*" ps --status running --services "*)
printf '%s\n' captain-fixture gochat
;;
*" exec -T postgres "*)
if [ -n "${MOCK_PROVIDER_CONFIG:-}" ]; then printf '%s\n' 1; else printf '%s\n' 0; fi
;;
*" exec -T gochat curl "*|*" exec -T gochat sh "*) ;;
*) echo "unexpected docker invocation" >&2; exit 2 ;;
esac
EOF
chmod 700 "$tmp/bin/docker"
make_source "$tmp/clean"
clean_before=$(find "$tmp/clean" -type f -exec sha256sum {} +)
GANBING_SOURCE=$tmp/clean PATH=$tmp/bin:$PATH "$root/scripts/preflight_acceptance.sh" > "$tmp/preflight-clean.log" 2>&1 || fail "clean preflight failed"
[ "$clean_before" = "$(find "$tmp/clean" -type f -exec sha256sum {} +)" ] || fail "staging modified its source"
provider_config='{"base_url":"http://captain-fixture:8080/v1","api_key":"must-not-leak","extra":true}'
if GANBING_SOURCE=$tmp/clean MOCK_PROVIDER_CONFIG=$provider_config PATH=$tmp/bin:$PATH "$root/scripts/preflight_acceptance.sh" > "$tmp/preflight-override.log" 2>&1; then
fail "nonempty database provider override was accepted"
fi
grep -F "$provider_config" "$tmp/preflight-override.log" >/dev/null && fail "provider override leaked to logs"
make_source "$tmp/malformed"
cat > "$tmp/malformed/SKILL.md" <<'EOF'
---
name: fixture
---
description: This is body text, not frontmatter.
EOF
expect_staging_failure "$tmp/malformed" "missing frontmatter description"
case_number=0
for field in name description; do
for value in null Null NULL '~' '""' "''" '[]' '{}' true 123 .5 '[fixture]'; do
case_number=$((case_number + 1))
source="$tmp/frontmatter-$case_number"
make_source "$source"
sed -i "s/^$field:.*/$field: $value/" "$source/SKILL.md"
expect_staging_failure "$source" "$field value $value"
done
done
for fixture in json yaml markdown; do
source="$tmp/credential-$fixture"
make_source "$source"
case "$fixture" in
json) printf '%s\n' '{"api_key":"fixture-secret"}' > "$source/config.json" ;;
yaml) printf '%s\n' 'access_token: fixture-token' > "$source/reference.md" ;;
markdown) printf '%s\n' '**password** = `fixture-password`' > "$source/reference.md" ;;
esac
expect_staging_failure "$source" "$fixture credential assignment"
done
GANBING_SOURCE=$tmp/clean "$root/scripts/stage_captain_assets.sh" "$tmp/output" >/dev/null
[ "$clean_before" = "$(find "$tmp/clean" -type f -exec sha256sum {} +)" ] || fail "staging modified its source"
grep -qx 'skill_status=active' "$tmp/output/manifest.txt" || fail "valid string frontmatter did not generate an active manifest"
find "$tmp/output" -type f -exec stat -c '%a' {} + | grep -vx 600 >/dev/null && fail "staged file permissions are not 0600"
echo "acceptance scripts tests passed"