Files
pulse/scripts/ci/ui-stack.sh
T
jaredandClaude Opus 5.5 5bca0cd87b
CI / Test (jest) (push) Failing after 57s
CI / Lint (eslint) (push) Successful in 59s
CI / Security (npm audit) (push) Successful in 10s
CI / Lint (eslint) (pull_request) Successful in 28s
CI / Test (jest) (pull_request) Successful in 17s
CI / Security (npm audit) (pull_request) Successful in 12s
CI / UI (playwright) (push) Failing after 2m25s
CI / Deploy (push) Skipped
CI / Notify (push) Skipped
CI / UI (playwright) (pull_request) Failing after 1m21s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI: Playwright UI tests against a real server, workers and MariaDB
New required-to-be job `UI (playwright)` (#45 phase 5): the official
Playwright image with a MariaDB service container. scripts/ci/ui-stack.sh
starts the real server and three workers (WORKER_AUTH_ENFORCE=1), then
tests/ui/ runs 30 tests on desktop and a phone viewport:

- every page loads with no page errors, console errors or failed requests
  (enforced by a shared fixture for every test)
- quick commands run on a worker and their output and status show in
  Executions; multi-worker mode; failing commands show as failed
- workflows are created and run from the UI and complete on all workers
- Executions updates live over the authenticated browser WebSocket
- no SSO identity: 401 page and API; wrong group: 403
- every page fits a phone screen

External requests are blocked in tests so SSO headers never leave the
machine. Deploy now also waits for the UI job. The API and execution rate
limits can be raised with PULSE_API_RATE_MAX / PULSE_EXEC_RATE_MAX for
test stacks; production defaults are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:37:23 -05:00

79 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# Starts a throwaway Pulse stack for the Playwright UI tests (#45 phase 5):
# the server on PULSE_UI_PORT plus three local workers (node-01..03) that run
# real, harmless commands. The database must already exist; the server creates
# its tables on start.
#
# Used by the CI `ui` job (MariaDB service container) and locally:
# DB_HOST=127.0.0.1 DB_PORT=3399 DB_USER=pulse DB_PASSWORD=x DB_NAME=pulse \
# scripts/ci/ui-stack.sh start
# npm run test:ui
# scripts/ci/ui-stack.sh stop
#
# Every setting is passed explicitly, so a developer's .env never leaks in
# (dotenv does not override variables that are already set).
set -euo pipefail
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
PORT=${PULSE_UI_PORT:-8400}
RUN=${PULSE_UI_RUN_DIR:-$ROOT/.ui-stack}
URL="http://127.0.0.1:$PORT"
export PORT HOST=127.0.0.1 NODE_ENV=test
export TRUSTED_PROXIES=127.0.0.1 # the tests send Authelia headers themselves
export WORKER_API_KEY=ui-test-worker-key WORKER_AUTH_ENFORCE=1
export GANDALF_API_KEY=ui-test-gandalf-key
export SECRET_KEY=ui-test-secret EXECUTION_RETENTION_DAYS=30
export PULSE_API_RATE_MAX=100000 PULSE_EXEC_RATE_MAX=100000 # one test client makes many requests
stop() {
for f in "$RUN"/*.pid; do
[ -e "$f" ] || continue
kill "$(cat "$f")" 2>/dev/null || true
rm -f "$f"
done
}
wait_for() { # wait_for <description> <seconds> <command...>
local what=$1 secs=$2; shift 2
for _ in $(seq 1 "$secs"); do
if "$@" >/dev/null 2>&1; then return 0; fi
sleep 1
done
echo "::error::timed out waiting for $what" >&2
tail -n 50 "$RUN"/*.log >&2 || true
return 1
}
# Node's fetch instead of curl: the Playwright CI image has node but maybe not curl.
healthz() { # healthz [<javascript test on the parsed body>]
node -e 'fetch(process.argv[1]).then(r => r.json()).then(h => process.exit(h.db && eval(process.argv[2] || "true") ? 0 : 1), () => process.exit(1))' \
"$URL/healthz" "${1:-true}"
}
workers_online() { healthz 'h.workers === 3'; }
start() {
: "${DB_HOST:?}" "${DB_PORT:?}" "${DB_USER:?}" "${DB_PASSWORD:?}" "${DB_NAME:?}"
export DB_HOST DB_PORT DB_USER DB_PASSWORD DB_NAME
stop
mkdir -p "$RUN"
# cwd is the run dir, so dotenv finds no .env there.
(cd "$RUN" && exec node "$ROOT/server.js" >"$RUN/server.log" 2>&1) &
echo $! >"$RUN/server.pid"
wait_for "the server and database" 60 healthz
for n in 1 2 3; do
(cd "$RUN" && WORKER_NAME=node-0$n PULSE_SERVER="$URL" PULSE_WS="ws://127.0.0.1:$PORT" \
HEARTBEAT_INTERVAL=5 exec node "$ROOT/worker/worker.js" >"$RUN/worker-$n.log" 2>&1) &
echo $! >"$RUN/worker-$n.pid"
done
wait_for "3 workers to connect" 60 workers_online
echo "Pulse UI stack is up at $URL with 3 workers"
}
case "${1:-}" in
start) start ;;
stop) stop ;;
*) echo "usage: $0 start|stop" >&2; exit 2 ;;
esac