test(identity): add isolated browser mail fixture

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 11:52:38 +03:00
1 parent 86f562f5b6
commit 24638d46d2
20 files changed
+885 -20

No files matched your search

+99 -7
View File
@@ -2,7 +2,8 @@
# Runs the Playwright suite against an isolated, throwaway Compose stand.
#
# Each run gets a unique project name, a generated env file with random
# secrets and EMAIL_PROVIDER=disabled, no host port, and fresh volumes. The
# secrets, no host port, and fresh volumes. Ordinary mode uses disabled mail;
# --mail-fixture selects the separate local Resend-compatible receiver. The
# stand, its volumes, and its locally built images are removed on every exit.
# Artifacts of the last run stay in frontend/test-results/e2e.
#
@@ -14,20 +15,49 @@
# keep those images, and record passing evidence for the
# release manifest. Specs must be the committed frontend/e2e.
# Only make -C deploy release-e2e sets it.
# Invocation:
# e2e.sh ordinary browser suite with mail disabled
# e2e.sh --mail-fixture local registration suite with a bounded internal
# receiver and no outbound network
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
source "$root/deploy/scripts/e2e_user.sh"
compose_file="$root/deploy/docker/docker-compose.yml"
e2e_file="$root/deploy/docker/docker-compose.e2e.yml"
mail_file="$root/deploy/docker/docker-compose.e2e-mail.yml"
release_file="$root/deploy/docker/docker-compose.release.yml"
release_script="$root/deploy/scripts/release_manifest.py"
release_tag="${LINCODEX_RELEASE_TAG:-}"
mail_fixture=0
if [[ "$#" -gt 1 ]]; then
printf '%s\n' 'Usage: e2e.sh [--mail-fixture]' >&2
exit 2
fi
if [[ "$#" -eq 1 ]]; then
if [[ "$1" != '--mail-fixture' ]]; then
printf '%s\n' 'Usage: e2e.sh [--mail-fixture]' >&2
exit 2
fi
mail_fixture=1
fi
email_provider=disabled
if ((mail_fixture)); then
email_provider=resend
fi
compose_files=(-f "$compose_file" -f "$e2e_file")
up_args=(--build)
if [[ -n "$release_tag" ]]; then
if ((mail_fixture)); then
printf '%s\n' 'The local mail fixture cannot be used for release E2E.' >&2
exit 2
fi
compose_files+=(-f "$release_file")
up_args=(--no-build --pull never)
fi
if ((mail_fixture)); then
compose_files+=(-f "$mail_file")
fi
frontend_dir="$root/frontend"
artifacts_dir="$frontend_dir/test-results/e2e"
spec_dir="${E2E_SPEC_DIR:-$frontend_dir/e2e}"
@@ -66,6 +96,14 @@ fi
for dockerfile in "$root/backend/Dockerfile" "$root/frontend/Dockerfile"; do
[[ -f "$dockerfile" ]] || fail "Missing required build file $dockerfile."
done
if ((mail_fixture)); then
for dockerfile in "$root/backend/Dockerfile.e2e" "$root/backend/Dockerfile.mail-fixture"; do
[[ -f "$dockerfile" ]] || fail "Missing required build file $dockerfile."
done
fi
playwright_user=$(e2e_playwright_user \
"$(docker info --format '{{json .SecurityOptions}}')" "$(id -u)" "$(id -g)")
IFS=: read -r playwright_uid playwright_gid <<<"$playwright_user"
# Compose runs with a cleared environment: shell variables such as
# EMAIL_PROVIDER, RESEND_API_KEY, or COMPOSE_FILE must not leak into the
@@ -82,7 +120,7 @@ compose() {
APP_PROJECT="$project" APP_NETWORK="$network" APP_STORAGE_NETWORK="$storage_network" \
APP_SUBNET=172.29.82.0/24 APP_FRONTEND_IP=172.29.82.10 \
PLAYWRIGHT_VERSION="$declared" E2E_CI="${CI:-}" \
E2E_UID="$(id -u)" E2E_GID="$(id -g)" \
E2E_UID="$playwright_uid" E2E_GID="$playwright_gid" \
E2E_SPEC_DIR="$spec_dir" E2E_ARTIFACTS_DIR="$artifacts_dir" LINCODEX_RELEASE_TAG="$release_tag" \
docker compose \
--env-file "$env_file" \
@@ -132,8 +170,8 @@ trap 'exit 143' TERM
mkdir -p "$artifacts_dir"
rm -f "$artifacts_dir/stand.log"
# Throwaway configuration with synthetic secrets. The backend sends no mail,
# and APP_PUBLIC_URL is the origin the browser uses inside the stand.
# Throwaway configuration with synthetic secrets. The ordinary suite disables
# mail; registration E2E sends only to the Compose-internal fixture.
env_file=$(mktemp "${TMPDIR:-/tmp}/lincodex-e2e-env.XXXXXX")
chmod 600 "$env_file"
cat >"$env_file" <<EOF
@@ -145,7 +183,7 @@ SEAWEEDFS_ACCESS_KEY=e2e-$suffix
SEAWEEDFS_SECRET_KEY=$(random_secret)
SEAWEEDFS_BUCKET=lincodex
KAFKA_CLUSTER_ID=$(head -c 16 /dev/urandom | base64 | tr '+/' '-_' | tr -d '=\n')
EMAIL_PROVIDER=disabled
EMAIL_PROVIDER=$email_provider
EMAIL_FROM=no-reply@example.com
EMAIL_TIMEOUT=10s
APP_PUBLIC_URL=http://localhost:8080
@@ -176,12 +214,66 @@ done
exit 1
}
if ((mail_fixture)); then
# Exercise the real Compose DNS path and inbox before browser tests. This
# sends only one synthetic message and verifies idempotent replay.
if ! compose run --rm --no-deps -T playwright node -e '
const fail = () => { console.error("Local mail fixture transport check failed."); process.exit(1); };
try {
const recipient = "fixture-smoke@example.invalid";
const body = JSON.stringify({
from: "no-reply@example.com",
to: [recipient],
subject: "Local fixture check",
text: "Synthetic message for the local E2E fixture.",
});
const headers = {
Authorization: "Bearer re_fixture_key",
"Content-Type": "application/json",
"Idempotency-Key": "registration-fixture-smoke",
};
const send = () => fetch("http://mail-fixture:8025/emails", {
method: "POST", headers, body,
});
const firstResponse = await send();
if (!firstResponse.ok) fail();
const first = await firstResponse.json();
if (typeof first.id !== "string" || first.id.length === 0) fail();
const replayResponse = await send();
if (!replayResponse.ok) fail();
const replay = await replayResponse.json();
if (replay.id !== first.id) fail();
const inboxURL = new URL(process.env.E2E_MAILBOX_URL);
inboxURL.searchParams.set("to", recipient);
const inboxResponse = await fetch(inboxURL, {
headers: { Authorization: `Bearer ${process.env.E2E_MAILBOX_TOKEN}` },
});
if (!inboxResponse.ok) fail();
const inbox = await inboxResponse.json();
if (!Array.isArray(inbox.messages) || inbox.messages.length !== 1) fail();
if (inbox.messages[0].id !== first.id || inbox.messages[0].to[0] !== recipient) fail();
console.log("Local mail fixture accepted, deduplicated, and returned one synthetic inbox message.");
} catch {
fail();
}
'; then
printf '%s\n' 'The local mail fixture transport check failed.' >&2
exit 1
fi
fi
playwright_command=(node node_modules/@playwright/test/cli.js test)
if ((mail_fixture)); then
# Confirmation links contain one-time tokens. Do not save traces with inbox
# responses or token-bearing navigation URLs.
playwright_command+=(--trace off)
fi
set +e
compose run --rm --no-deps -T playwright
compose run --rm --no-deps -T playwright "${playwright_command[@]}"
status=$?
set -e
if ((status != 0)); then
printf 'Playwright failed with exit code %s; traces and screenshots are in %s/results.\n' \
printf 'Playwright failed with exit code %s; browser artifacts are in %s/results.\n' \
"$status" "$artifacts_dir" >&2
elif [[ -n "$release_tag" ]]; then
# The suite passed; bind the result to the image IDs that ran.