Files
openwaf/scripts/ci-linux-rehearsal.sh
T
Pavlo Ratushnyi 8082e6a598 The alerting pillar had an endpoint and nobody reading it
`GET /admin-api/alerts` appeared in **zero** gate scripts. Both alert kinds were
proven in-process, against `FakeUpstream`, at the database level — and the half
that matters for an alert, the half where a human sees it, had nothing on the
other end. The console read six endpoints and this was not one of them.

The page now renders them: kind, source, count, last status and path, when. The
kind an operator has to act on is marked rather than only printed, and the note
above the table says what each kind means in words, because `server_error_streak`
and `candidate_ban` are different sentences: your upstream is failing (and the
edge will not ban the visitor who saw it) versus the rule would have banned and
the mode is Observe.

`scripts/console-smoke.sh` seeds four 502s from an address chosen for this run
(`/boom`, added last commit), and `scripts/console-check.cjs` asserts the row by
**source and count**, the note text, the marking, and that the table survives the
phone pass: 26 → **30 assertions**.

The wiring was the interesting part. The seeding runs in one container and the
browser in another, so the address chosen at seed time cannot be inherited — an
empty `SEED_ERROR` on the driver side would have quietly turned "the alert this
run wrote" into "some alert exists somewhere". The seed now writes its values to
`console-seed.env` (gitignored) and the rehearsal passes them to the browser
container.

`AdminConsoleTests` got the fast half: the markup contains the alerts table and
fetches the endpoint. A static check cannot assert the row is there — that is
what the browser gate is for — but it can notice the table disappearing without
waiting for Chromium. 28 → **29 integration tests**.

Numbers. Host: build 0 warnings, unit 54/54, integration 29/29. Linux rehearsal,
one invocation on this tree, EXIT=0: source gates 54/54 + 29/29 + smoke 19/19,
compose **35/35**, console **30/30** in a real Chromium. actionlint 1.7.12 over
both workflow files: 0 problems; shellcheck, `bash -n` and `node --check` clean.

Two things said plainly. The console number above is the Linux one: this laptop's
browser cache has chromium-1223/1228/1234 and the pinned Playwright wants 1243,
so the darwin console gate was not re-run for this change. And during the run the
table's own note read "Newest 25" — the endpoint is capped and residue from
earlier runs fills the page. That is OPEN-18's amplification showing up where an
operator would see it, and the note states the cap instead of pretending the
table is everything.
2026-10-01 16:40:37 +02:00

222 lines
9.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Run the CI gates on the operating system the runner uses, without a runner.
#
# Every green number this project has quoted was produced on macOS. The workflow
# runs on ubuntu-latest. That gap is where a first CI run dies: a gate that
# passes on darwin and fails on linux is not a gate, it is a local habit. This
# script closes the part of the gap that can be closed at a desk.
#
# scripts/ci-linux-rehearsal.sh # all three stages
# scripts/ci-linux-rehearsal.sh source # restore, build, unit, integration, smoke
# scripts/ci-linux-rehearsal.sh compose # compose-smoke against the host daemon
# scripts/ci-linux-rehearsal.sh console # the page, in a real Chromium on Linux
#
# Covered: the dotnet suites and smoke.sh (Ubuntu 24.04, the same SDK family the
# runner installs), compose-smoke.sh (Alpine container, linux image build, the
# host daemon doing the work) and the console gate (the official Playwright image
# with the same Playwright version the CI console job pins).
set -euo pipefail
cd "$(dirname "$0")/.."
STAGE=${1:-all}
SOURCE_IMAGE=${SOURCE_IMAGE:-mcr.microsoft.com/dotnet/sdk:10.0}
COMPOSE_IMAGE=${COMPOSE_IMAGE:-docker:cli}
BROWSER_IMAGE=${BROWSER_IMAGE:-mcr.microsoft.com/playwright:v1.63.0-noble}
# The version the CI console job pins. If these two ever disagree, the
# rehearsal is not rehearsing what CI will do.
PLAYWRIGHT_VERSION=${PLAYWRIGHT_VERSION:-1.63.0}
DOCKER_SOCKET=${DOCKER_SOCKET:-/var/run/docker.sock}
# The stack is created by the host daemon, so its published port lives in the
# host's namespace; from inside a container that is the gateway, not 127.0.0.1.
HOST_EDGE=${HOST_EDGE:-http://host.docker.internal:8080}
OPENWAF_ADMIN_TOKEN=${OPENWAF_ADMIN_TOKEN:-ci-only-throwaway}
export OPENWAF_ADMIN_TOKEN DOTNET_CLI_TELEMETRY_OPTOUT=1 DOTNET_NOLOGO=1
source_status=0
compose_status=0
console_status=0
source_ran=0
compose_ran=0
console_ran=0
# A stage the caller never asked for and a stage that could not run are
# different answers. Printing "skipped (no docker socket)" for a stage that was
# not selected is the kind of lie a summary line tells by accident.
verdict() {
ran=$1; status=$2; selected=$3; needs_socket=$4
if [ "$ran" -eq 1 ]; then
if [ "$status" -eq 0 ]; then echo PASS; else echo "FAIL ($status)"; fi
elif [ "$selected" -eq 0 ]; then
echo 'not run'
elif [ "$needs_socket" -eq 1 ]; then
echo 'skipped (no docker socket)'
else
echo 'not run'
fi
}
source_selected=0; compose_selected=0; console_selected=0
case "$STAGE" in
all) source_selected=1; compose_selected=1; console_selected=1 ;;
source) source_selected=1 ;;
compose) compose_selected=1 ;;
console) console_selected=1 ;;
esac
if [ "$STAGE" = all ] || [ "$STAGE" = source ]; then
WORK=$(mktemp -d /tmp/openwaf-linux.XXXXXX)
trap 'rm -rf "$WORK"' EXIT
echo "copying the tree (no .git, no build output) into $WORK"
# A copy, not a mount: Linux-built binaries landing in a macOS working tree
# make the next local `--no-build` try to exec an ELF file.
tar --exclude='./.git' --exclude='bin' --exclude='obj' -cf - . | tar -xf - -C "$WORK"
source_ran=1
echo "== source gates in $SOURCE_IMAGE =="
docker run --rm -v "$WORK:/src" -w /src \
-e DOTNET_CLI_TELEMETRY_OPTOUT=1 -e DOTNET_NOLOGO=1 \
"$SOURCE_IMAGE" bash -euo pipefail -c '
echo "-- what the container is --"
uname -srm
grep -m1 PRETTY_NAME /etc/os-release
cd dotnet && echo "sdk resolving global.json: $(dotnet --version)" && cd ..
echo "== gate: restore =="
dotnet restore dotnet/OpenWaf.slnx
echo "== gate: build (TreatWarningsAsErrors) =="
dotnet build dotnet/OpenWaf.slnx -c Release --no-restore
echo "== gate: unit =="
dotnet test dotnet/OpenWaf.Tests.Unit/OpenWaf.Tests.Unit.csproj -c Release --no-build
echo "== gate: integration =="
dotnet test dotnet/OpenWaf.Tests.Integration/OpenWaf.Tests.Integration.csproj -c Release --no-build
# smoke.sh uses `python3 -m http.server` as the upstream it knows nothing
# about. The runner image has python3; the dotnet sdk image does not.
echo "== python3 for the smoke upstream =="
command -v python3 || { apt-get update -qq && apt-get install -y -qq python3 >/dev/null; }
python3 --version
echo "== gate: smoke =="
./scripts/smoke.sh
' || source_status=$?
fi
if [ "$STAGE" = all ] || [ "$STAGE" = compose ]; then
if [ ! -S "$DOCKER_SOCKET" ]; then
echo "compose stage SKIPPED: no docker socket at $DOCKER_SOCKET"
else
compose_ran=1
echo "== compose gate in $COMPOSE_IMAGE, driven by the host daemon =="
# The repo is mounted at the SAME absolute path it has on the host, because
# the daemon that builds the image resolves the build context on its own
# side of the mount: a different path inside the container would send
# `compose build` looking for a context that does not exist there.
# docker:cli ships no bash and no curl, both of which the gate uses, so the
# container adds them itself.
# The stack is created by the host daemon, so its published port lives in
# the host's namespace, not this container's: the first run of this stage
# reached the docker API fine (the image's own HEALTHCHECK assertion passed)
# and got curl code 000 on every HTTP assertion, because 127.0.0.1 inside
# the container is the container. EDGE is the gate's own override for
# exactly this, pointed at the gateway.
docker run --rm \
-v "$PWD:$PWD" -w "$PWD" \
-v "$DOCKER_SOCKET:/var/run/docker.sock" \
--add-host=host.docker.internal:host-gateway \
-e OPENWAF_ADMIN_TOKEN \
-e EDGE="${EDGE:-http://host.docker.internal:8080}" \
"$COMPOSE_IMAGE" sh -euo pipefail -c '
echo "-- what the container is --"
uname -srm 2>/dev/null || grep -m1 NAME /etc/os-release
docker --version
docker compose version
# compose-smoke.sh asserts over JSON with python3 (jcount/jget) and
# reads the clock with it; the first Linux run of this stage failed 23
# of 27 assertions for nothing but a missing python3. The runner image
# has python3; a bare container does not.
command -v bash >/dev/null || apk add --no-cache bash >/dev/null
command -v curl >/dev/null || apk add --no-cache curl >/dev/null
command -v python3 >/dev/null || apk add --no-cache python3 >/dev/null
echo "== gate: compose-smoke =="
bash ./scripts/compose-smoke.sh
' || compose_status=$?
fi
fi
if [ "$STAGE" = all ] || [ "$STAGE" = console ]; then
if [ ! -S "$DOCKER_SOCKET" ]; then
echo "console stage SKIPPED: no docker socket at $DOCKER_SOCKET"
else
console_ran=1
echo "== console gate: seeded by $COMPOSE_IMAGE, driven in $BROWSER_IMAGE =="
# Start and seed the stack through the host daemon, and leave it up: the
# page is driven from the next container, which is the one with a Chromium.
docker run --rm \
-v "$PWD:$PWD" -w "$PWD" \
-v "$DOCKER_SOCKET:/var/run/docker.sock" \
--add-host=host.docker.internal:host-gateway \
-e OPENWAF_ADMIN_TOKEN -e EDGE="$HOST_EDGE" -e SEED_ONLY=1 \
"$COMPOSE_IMAGE" sh -euo pipefail -c '
command -v bash >/dev/null || apk add --no-cache bash >/dev/null
command -v curl >/dev/null || apk add --no-cache curl >/dev/null
bash ./scripts/console-smoke.sh
' || console_status=$?
if [ "$console_status" -eq 0 ]; then
# The seeding container chose SEED_ERROR for this run and wrote it out; the
# driver has to look at the same address, or the alert assertion checks
# nothing in particular.
SEED_ERROR=$(sed -n 's/^SEED_ERROR=//p' console-seed.env 2>/dev/null)
[ -n "$SEED_ERROR" ] || { echo 'console stage: no SEED_ERROR in console-seed.env' >&2; console_status=1; }
fi
if [ "$console_status" -eq 0 ]; then
docker run --rm \
-v "$PWD:$PWD:ro" -w /tmp \
--add-host=host.docker.internal:host-gateway \
-e EDGE_URL="$HOST_EDGE" -e OPENWAF_ADMIN_TOKEN \
-e SEED_SOURCE=203.0.113.55 -e SEED_BLOCK=203.0.113.77 \
-e SEED_ERROR="$SEED_ERROR" \
-e SCREENSHOT=/tmp/console-linux.png \
-e CHECK="$PWD/scripts/console-check.cjs" \
-e PW_VERSION="$PLAYWRIGHT_VERSION" \
"$BROWSER_IMAGE" bash -euo pipefail -c '
echo "-- what the container is --"
uname -srm
node --version
ls /ms-playwright | head -3
# The official image ships the browsers (PLAYWRIGHT_BROWSERS_PATH is
# /ms-playwright) but NOT the npm package — checked, there is no
# playwright-core anywhere in it. So the package is installed here at
# the version the CI console job pins, into /tmp: the repo is mounted
# read-only for this stage, and node_modules must not land in it.
npm init -y >/dev/null 2>&1
npm install --no-save "playwright@${PW_VERSION}" >/dev/null 2>&1
node -e "console.log(\"playwright-core: \" + require.resolve(\"playwright-core\"))"
echo "== gate: console =="
PLAYWRIGHT_CORE=/tmp/node_modules/playwright-core node "$CHECK"
' || console_status=$?
fi
docker run --rm -v "$PWD:$PWD" -w "$PWD" \
-v "$DOCKER_SOCKET:/var/run/docker.sock" \
"$COMPOSE_IMAGE" sh -c 'docker compose down >/dev/null 2>&1 || true'
fi
fi
source_verdict=$(verdict "$source_ran" "$source_status" "$source_selected" 0)
compose_verdict=$(verdict "$compose_ran" "$compose_status" "$compose_selected" 1)
console_verdict=$(verdict "$console_ran" "$console_status" "$console_selected" 1)
echo
echo '== rehearsal summary =='
printf ' source gates (restore/build/unit/integration/smoke): %s\n' "$source_verdict"
printf ' compose gate: %s\n' "$compose_verdict"
printf ' console gate: %s\n' "$console_verdict"
[ "$source_status" -eq 0 ] && [ "$compose_status" -eq 0 ] && [ "$console_status" -eq 0 ]