test(staging): add smoke suite script and gameplay smoke command (closes #22)
All checks were successful
CI / test-and-quality (push) Successful in 1m25s
CI / test-and-quality (pull_request) Successful in 1m26s

This commit is contained in:
2026-02-27 22:45:12 +01:00
parent 0d13ab9f80
commit 05b3d982b4
4 changed files with 179 additions and 0 deletions

59
infra/staging/smoke_suite.sh Executable file
View File

@@ -0,0 +1,59 @@
#!/usr/bin/env bash
set -euo pipefail
BASE_URL="${BASE_URL:-http://127.0.0.1:8000}"
APP_DIR="${APP_DIR:-/opt/wpp-staging/app}"
ISSUE_ON_FAIL="${ISSUE_ON_FAIL:-1}"
fail() {
local message="$1"
echo "[smoke] FAIL: ${message}" >&2
if [[ "${ISSUE_ON_FAIL}" == "1" ]] && [[ -n "${GITEA_BASE:-}" ]] && [[ -n "${GITEA_REPO:-}" ]] && [[ -n "${GITEA_USER:-}" ]] && [[ -n "${GITEA_TOKEN:-}" ]]; then
python3 - <<PY || true
import json
import os
import urllib.request
import base64
from datetime import datetime, timezone
base = os.environ["GITEA_BASE"].rstrip("/")
repo = os.environ["GITEA_REPO"]
user = os.environ["GITEA_USER"]
token = os.environ["GITEA_TOKEN"]
message = os.environ.get("SMOKE_FAIL_MESSAGE", "unknown")
when = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
payload = {
"title": f"[smoke-fail] staging smoke failed ({when})",
"body": (
"Automatisk oprettet af smoke-suite.\n\n"
f"Fejl: `{message}`\n"
"Kontekst: issue #22 (staging smoke-suite)"
),
"labels": ["smoke-fail", "need-to-have", "staging"],
}
url = f"{base}/api/v1/repos/{repo}/issues"
req = urllib.request.Request(url, data=json.dumps(payload).encode(), method="POST")
auth = base64.b64encode(f"{user}:{token}".encode()).decode()
req.add_header("Authorization", f"Basic {auth}")
req.add_header("Content-Type", "application/json")
with urllib.request.urlopen(req) as r:
print(f"[smoke] Created fail issue: HTTP {r.status}")
PY
fi
exit 1
}
echo "[smoke] healthz check: ${BASE_URL}/healthz"
curl -fsS "${BASE_URL}/healthz" >/dev/null || { SMOKE_FAIL_MESSAGE="healthz check failed" fail "healthz check failed"; }
echo "[smoke] gameplay flow via management command"
(
cd "${APP_DIR}"
.venv/bin/python manage.py smoke_staging
) || { SMOKE_FAIL_MESSAGE="manage.py smoke_staging failed" fail "manage.py smoke_staging failed"; }
echo "[smoke] OK"