Files
gochat/deploy/quickstart/scripts/preflight_acceptance.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

56 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
set -eu
root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
stage=$(mktemp -d "${TMPDIR:-/tmp}/gochat-captain-stage.XXXXXX")
trap 'rm -rf "$stage"' EXIT HUP INT TERM
"$root/scripts/stage_captain_assets.sh" "$stage"
compose() {
docker compose -f "$root/compose.yaml" -f "$root/compose.acceptance.yaml" "$@"
}
compose config --quiet
compose ps --status running --services | grep -qx captain-fixture || {
echo "preflight failed: captain-fixture is not running" >&2
exit 1
}
compose ps --status running --services | grep -qx gochat || {
echo "preflight failed: gochat is not running" >&2
exit 1
}
compose exec -T gochat curl -fsS --retry 30 --retry-delay 1 --retry-connrefused --max-time 2 http://127.0.0.1:3000/health >/dev/null
overrides=$(compose exec -T postgres sh -eu -c '
psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Atc "
SELECT count(*) FROM installation_configs
WHERE deleted_at IS NULL AND (
(name = '\''COPILOT_PROVIDER_CONFIG'\'' AND COALESCE(value, '\'''\'') <> '\'''\'') OR
(name = '\''COPILOT_CHAT_API_KEY'\'' AND value <> '\''acceptance-fixture-not-a-secret'\'') OR
(name = '\''COPILOT_EMBEDDING_API_KEY'\'' AND value <> '\'''\'')
)"
')
[ "$overrides" = "0" ] || {
echo "preflight failed: database Copilot settings override the local fixture" >&2
exit 1
}
compose exec -T gochat sh -eu -c '
test -n "$GOCHAT_COPILOT_PROVIDER_CONFIG"
test "$GOCHAT_COPILOT_CHAT_API_KEY" = acceptance-fixture-not-a-secret
case "$GOCHAT_COPILOT_PROVIDER_CONFIG" in
*http://captain-fixture:8080/v1*) ;;
*) exit 1 ;;
esac
knowledge=$(curl -fsS http://captain-fixture:8080/knowledge)
test -n "$knowledge"
case "$knowledge" in *KBASE-LOCAL-2026*) ;; *) exit 1 ;; esac
chat=$(curl -fsS -H "Content-Type: application/json" -d "{\"model\":\"gpt-5.6-luna\",\"messages\":[{\"role\":\"user\",\"content\":\"preflight\"}]}" http://captain-fixture:8080/v1/chat/completions)
case "$chat" in *chat.completion*) ;; *) exit 1 ;; esac
embedding=$(curl -fsS -H "Content-Type: application/json" -d "{\"model\":\"fixture-embedding\",\"input\":[\"preflight\"]}" http://captain-fixture:8080/v1/embeddings)
case "$embedding" in *\"object\":\"list\"*) ;; *) exit 1 ;; esac
'
echo "acceptance preflight passed: provider=injected fixture=reachable knowledge=nonempty captain_assets=staged"