test(parity): add frontend smoke harness

This commit is contained in:
2026-06-05 14:11:05 +08:00
parent 72211e6dda
commit f5b3279a82
5 changed files with 520 additions and 12 deletions
+191
View File
@@ -0,0 +1,191 @@
#!/usr/bin/env bash
# Repeatable B12 smoke harness for running the reused Chatwoot frontend against GoChat.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
CHATWOOT_DIR="${CHATWOOT_DIR:-$ROOT/reference/chatwoot}"
LOG_DIR="${GOCHAT_SMOKE_LOG_DIR:-$ROOT/.tmp/frontend-smoke}"
REPORT_PATH="${GOCHAT_SMOKE_REPORT:-$ROOT/docs/parity/frontend_smoke_report.md}"
API_HOST="${GOCHAT_SMOKE_API_HOST:-127.0.0.1}"
API_PORT="${GOCHAT_SMOKE_API_PORT:-3000}"
FRONTEND_HOST="${GOCHAT_SMOKE_FRONTEND_HOST:-127.0.0.1}"
FRONTEND_PORT="${GOCHAT_SMOKE_FRONTEND_PORT:-3036}"
SEARCH_ENGINE="${GOCHAT_SMOKE_SEARCH_ENGINE:-meilisearch}"
MEILI_HOST="${GOCHAT_SMOKE_MEILI_HOST:-http://127.0.0.1:7700}"
MEILI_API_KEY="${GOCHAT_SMOKE_MEILI_API_KEY:-gochat_dev}"
MODE="run"
KEEP_ALIVE="true"
usage() {
cat <<USAGE
Usage: scripts/parity_frontend_smoke.sh [--check|--print|--boot-only]
Modes:
--check Validate local prerequisites and write a readiness report.
--print Print the exact boot commands without starting processes.
--boot-only Start GoChat and Vite, verify /health and frontend HTTP, then exit.
Environment:
CHATWOOT_DIR Chatwoot checkout path. Default: reference/chatwoot
GOCHAT_SMOKE_API_PORT GoChat backend port. Default: 3000
GOCHAT_SMOKE_FRONTEND_PORT Vite frontend port. Default: 3036
GOCHAT_SMOKE_LOG_DIR Log directory. Default: .tmp/frontend-smoke
GOCHAT_SMOKE_REPORT Markdown report path. Default: docs/parity/frontend_smoke_report.md
GOCHAT_SMOKE_SEARCH_ENGINE Search engine for boot smoke. Default: meilisearch
GOCHAT_SMOKE_MEILI_HOST Meilisearch URL. Default: http://127.0.0.1:7700
GOCHAT_SMOKE_MEILI_API_KEY Meilisearch API key. Default: gochat_dev
USAGE
}
for arg in "$@"; do
case "$arg" in
--check) MODE="check" ;;
--print) MODE="print" ;;
--boot-only) KEEP_ALIVE="false" ;;
-h|--help) usage; exit 0 ;;
*) echo "unknown argument: $arg" >&2; usage; exit 2 ;;
esac
done
backend_cmd=(env GOCHAT_ENV=development GOCHAT_SERVER_HOST="$API_HOST" GOCHAT_SERVER_PORT="$API_PORT" GOCHAT_SERVER_MODE=debug GOCHAT_SEARCH_ENGINE="$SEARCH_ENGINE" GOCHAT_SEARCH_HOST="$MEILI_HOST" GOCHAT_SEARCH_API_KEY="$MEILI_API_KEY" GOCHAT_CAPTAIN_ENABLED=false go run ./cmd/gochat serve)
frontend_cmd=(env CHATWOOT_API_HOST="http://$API_HOST:$API_PORT" pnpm exec vite --host "$FRONTEND_HOST" --port "$FRONTEND_PORT")
need() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "missing required command: $1" >&2
return 1
fi
}
write_report() {
local status="$1"
local notes="$2"
mkdir -p "$(dirname "$REPORT_PATH")"
cat >"$REPORT_PATH" <<REPORT
# Frontend Smoke Report
Updated: $(date -u +%Y-%m-%dT%H:%M:%SZ)
## Status
$status
## Boot Command
\`\`\`bash
scripts/parity_frontend_smoke.sh --boot-only
\`\`\`
## Backend
- URL: http://$API_HOST:$API_PORT
- Command: \`${backend_cmd[*]}\`
- Search: \`$SEARCH_ENGINE\` at \`$MEILI_HOST\`
- Log: \`$LOG_DIR/gochat.log\`
## Reused Chatwoot Frontend
- URL: http://$FRONTEND_HOST:$FRONTEND_PORT
- Source: \`$CHATWOOT_DIR\`
- Command: \`(cd $CHATWOOT_DIR && ${frontend_cmd[*]})\`
- Log: \`$LOG_DIR/chatwoot-vite.log\`
## Seed Path
\`\`\`bash
GOCHAT_SEED_ADMIN_EMAIL=admin@gochat.local \\
GOCHAT_SEED_ADMIN_PASSWORD=changeme \\
GOCHAT_SEED_ACCOUNT_NAME="B12 Smoke Account" \\
GOCHAT_SEED_INBOX_NAME="B12 Smoke Website Inbox" \\
go run ./cmd/gochat seed
\`\`\`
The seed command creates deterministic login/account/inbox/contact/conversation data plus SLA, CustomRole, AgentCapacity, and Captain fixtures for the smoke paths.
## Smoke Matrix
| Area | Current result | Owner if failing |
| --- | --- | --- |
| Boot GoChat backend | Not run in check mode | B12.1 |
| Boot reused Chatwoot Vite frontend | Not run in check mode | B12.1 |
| Auth/profile | Pending browser/API smoke | B2/B12.2 |
| Inbox list/settings | Pending browser/API smoke | B5/B12.2 |
| Conversation list/detail/message send | Pending browser/API smoke | B3/B12.2 |
| Contact/company views | Pending browser/API smoke | B4/B12.2 |
| Widget config/message | Pending browser/API smoke | B12.2 |
| Public CSAT | Pending browser/API smoke | B8/B12.2 |
| Enterprise screens | Pending browser/API smoke | B7-B11/B12.3 |
## Notes
$notes
When using the default Meilisearch-first boot command, start Meilisearch separately, for example:
\`docker run --rm -p 7700:7700 -e MEILI_MASTER_KEY=$MEILI_API_KEY getmeili/meilisearch:latest\`
REPORT
}
check_prereqs() {
need go
need curl
need node
need pnpm
test -d "$CHATWOOT_DIR" || { echo "missing Chatwoot checkout: $CHATWOOT_DIR" >&2; return 1; }
test -f "$CHATWOOT_DIR/package.json" || { echo "missing Chatwoot package.json" >&2; return 1; }
test -f "$ROOT/cmd/gochat/main.go" || { echo "missing GoChat server entrypoint cmd/gochat/main.go" >&2; return 1; }
}
wait_url() {
local url="$1"
local label="$2"
for _ in $(seq 1 60); do
if curl -fsS "$url" >/dev/null 2>&1; then
echo "$label ready: $url"
return 0
fi
sleep 1
done
echo "$label did not become ready: $url" >&2
return 1
}
print_commands() {
echo "Backend: ${backend_cmd[*]}"
echo "Frontend: (cd $CHATWOOT_DIR && ${frontend_cmd[*]})"
echo "Report: $REPORT_PATH"
}
if [[ "$MODE" == "print" ]]; then
print_commands
exit 0
fi
check_prereqs
if [[ "$MODE" == "check" ]]; then
env GOCACHE="${GOCACHE:-/tmp/gochat-gocache}" GOMODCACHE="${GOMODCACHE:-/tmp/gochat-gomodcache}" go test ./cmd/gochat -count=1
write_report "Harness readiness check passed; live frontend smoke not run in this mode." "Run \`scripts/parity_frontend_smoke.sh --boot-only\` after PostgreSQL, Redis, Meilisearch, and Chatwoot frontend dependencies are available."
echo "check passed; report written to $REPORT_PATH"
exit 0
fi
mkdir -p "$LOG_DIR"
trap 'jobs -pr | xargs -r kill 2>/dev/null || true' EXIT
echo "starting GoChat backend..."
(cd "$ROOT" && "${backend_cmd[@]}") >"$LOG_DIR/gochat.log" 2>&1 &
wait_url "http://$API_HOST:$API_PORT/health" "GoChat"
echo "starting reused Chatwoot frontend..."
(cd "$CHATWOOT_DIR" && "${frontend_cmd[@]}") >"$LOG_DIR/chatwoot-vite.log" 2>&1 &
wait_url "http://$FRONTEND_HOST:$FRONTEND_PORT" "Chatwoot Vite"
write_report "Boot smoke passed for backend and reused Chatwoot frontend." "This run verified process boot and HTTP readiness only. B12.2 must add browser/API path assertions and update the smoke matrix."
echo "smoke boot passed; report written to $REPORT_PATH"
if [[ "$KEEP_ALIVE" == "true" ]]; then
echo "press Ctrl-C to stop both processes"
wait
fi