Fuehre die Pflicht-Suite nach dem Dev-Deploy gegen tsumugu_test auf der bestehenden Dev-Postgres aus.
Deploy Development / deploy (push) Failing after 20s
Test Suite / pytest-backend (push) Failing after 35s
Test Suite / smoke-dev (push) Failing after 0s
Test Suite / frontend-build (push) Successful in 7s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 07:21:20 +02:00
1 parent b328385561
commit 0924e28fce
8 files changed
+125 -88

No files matched your search

+13 -1
View File
@@ -47,8 +47,20 @@ trailer<</Root 1 0 R>>
"""
_LIVE_DATABASES = frozenset({"tsumugu", "tsumugu_dev", "postgres", "template0", "template1"})
def is_test_database(name: str) -> bool:
lowered = name.strip().lower()
return bool(lowered) and lowered.endswith("_test") and lowered not in _LIVE_DATABASES
def demo_allowed(settings: Settings) -> bool:
return settings.tsumugu_env == "development" and settings.db_name == "tsumugu_pytest" and settings.seed_demo
return (
settings.tsumugu_env == "development"
and is_test_database(settings.db_name)
and settings.seed_demo
)
def demo_public(settings: Settings) -> dict:
-48
View File
@@ -1,48 +0,0 @@
#!/bin/bash
# Mandatory suite against a throwaway PostgreSQL. Never the dev or prod database.
set -euo pipefail
NAME="tsumugu-pytest-db"
cleanup() {
docker rm -f "$NAME" >/dev/null 2>&1 || true
}
cleanup
trap cleanup EXIT
docker run -d --name "$NAME" \
-e POSTGRES_USER=tsumugu \
-e POSTGRES_PASSWORD=pytest \
-e POSTGRES_DB=postgres \
postgres:16-alpine >/dev/null
ready=0
for _ in $(seq 1 40); do
if docker exec "$NAME" pg_isready -U tsumugu -d postgres >/dev/null 2>&1; then
ready=1
break
fi
sleep 1
done
if [ "$ready" -ne 1 ]; then
echo "Kurzlebiges PostgreSQL ist nicht bereit."
exit 1
fi
docker run --rm --network "container:${NAME}" \
-e TSUMUGU_ENV=development \
-e TSUMUGU_TEST_HOST=127.0.0.1 \
-e TSUMUGU_TEST_PORT=5432 \
-e TSUMUGU_TEST_USER=tsumugu \
-e TSUMUGU_TEST_PASSWORD=pytest \
-e TSUMUGU_TEST_ADMIN_DB=postgres \
-e DB_HOST=127.0.0.1 \
-e DB_PORT=5432 \
-e DB_NAME=tsumugu_pytest \
-e DB_USER=tsumugu \
-e DB_PASSWORD=pytest \
-e ALLOWED_ORIGINS=http://testserver \
-e SEED_DEMO=false \
-v "$(pwd)/backend:/work" \
-w /work \
python:3.12-slim \
bash -c "pip install -q -r requirements-dev.txt && python -m pytest"
+20 -31
View File
@@ -1,4 +1,8 @@
"""Ephemeral database for the mandatory suite. Dev and prod databases are refused."""
"""Suite on the existing Dev Postgres, database tsumugu_test.
Dev and prod databases are refused. The workflow drops and recreates
tsumugu_test beside tsumugu_dev. This is not a third server.
"""
from __future__ import annotations
@@ -8,33 +12,21 @@ import tempfile
import psycopg
import pytest
TEST_DB = "tsumugu_pytest"
FORBIDDEN = {"tsumugu", "tsumugu_dev"}
FORBIDDEN = frozenset({"tsumugu", "tsumugu_dev", "postgres", "template0", "template1"})
if os.environ.get("TSUMUGU_TEST_DB") in FORBIDDEN or os.environ.get("DB_NAME") in FORBIDDEN:
raise RuntimeError("Die Test-Suite darf nicht gegen Dev- oder Prod-Datenbanken laufen.")
_name = os.environ.get("DB_NAME", "").strip().lower()
if not _name.endswith("_test") or _name in FORBIDDEN:
raise RuntimeError(
"DB_NAME fehlt oder ist gesperrt. Die Suite nutzt auf der Dev-Postgres "
"die Datenbank tsumugu_test, nicht tsumugu oder tsumugu_dev."
)
os.environ["TSUMUGU_ENV"] = "development"
os.environ["DB_HOST"] = os.environ.get("TSUMUGU_TEST_HOST", "127.0.0.1")
os.environ["DB_PORT"] = os.environ.get("TSUMUGU_TEST_PORT", "5432")
os.environ["DB_NAME"] = TEST_DB
os.environ["DB_USER"] = os.environ.get("TSUMUGU_TEST_USER", "tsumugu")
os.environ["DB_PASSWORD"] = os.environ.get("TSUMUGU_TEST_PASSWORD", "pytest")
os.environ["ALLOWED_ORIGINS"] = "http://testserver"
os.environ["SEED_DEMO"] = "false"
os.environ["MEDIA_ROOT"] = tempfile.mkdtemp(prefix="tsumugu-pytest-")
def _admin_dsn() -> str:
admin_db = os.environ.get("TSUMUGU_TEST_ADMIN_DB", "postgres")
if admin_db in FORBIDDEN or admin_db == TEST_DB:
raise RuntimeError("Die Verwaltungsverbindung der Test-Suite darf nicht die Fachdatenbank sein.")
return (
f"host={os.environ['DB_HOST']} port={os.environ['DB_PORT']} dbname={admin_db} "
f"user={os.environ['DB_USER']} password={os.environ['DB_PASSWORD']} connect_timeout=5"
)
def _reset(settings) -> None:
with psycopg.connect(settings.dsn(), autocommit=True) as conn:
conn.execute(
@@ -51,24 +43,21 @@ def _reset(settings) -> None:
@pytest.fixture(scope="session")
def database():
if os.environ["DB_NAME"] in FORBIDDEN:
raise RuntimeError("Die Test-Suite darf nicht gegen Dev- oder Prod-Datenbanken laufen.")
try:
admin = psycopg.connect(_admin_dsn(), autocommit=True)
except psycopg.OperationalError as exc:
pytest.fail(f"Die Test-Suite braucht ein kurzlebiges PostgreSQL. {exc}")
admin.execute(f"DROP DATABASE IF EXISTS {TEST_DB} WITH (FORCE)")
admin.execute(f"CREATE DATABASE {TEST_DB}")
name = os.environ.get("DB_NAME", "").strip().lower()
if name in FORBIDDEN or not name.endswith("_test"):
pytest.fail(
"DB_NAME muss auf der Dev-Postgres eine Datenbank *_test sein, "
"nicht tsumugu oder tsumugu_dev."
)
from app.core.settings import get_settings
from app.db.migrate import migrate
get_settings.cache_clear()
settings = get_settings()
assert settings.db_name == TEST_DB
if settings.db_name.lower() in FORBIDDEN or not settings.db_name.lower().endswith("_test"):
pytest.fail("Die Test-Suite darf nicht gegen Dev- oder Prod-Datenbanken laufen.")
migrate(settings)
yield settings
admin.execute(f"DROP DATABASE IF EXISTS {TEST_DB} WITH (FORCE)")
admin.close()
@pytest.fixture(scope="session")
+4 -4
View File
@@ -13,14 +13,14 @@ from app.core.settings import Settings
from app.entrypoint import prepare
from app.fixtures import purge_fixture_data
from app.ops import create_case
from app.seed import ADA_EMAIL, BEN_EMAIL, seed_demo
from tests.conftest import FORBIDDEN, TEST_DB
from app.seed import ADA_EMAIL, BEN_EMAIL, is_test_database, seed_demo
from tests.conftest import FORBIDDEN
from tests.support import PASSWORD
def test_database_is_ephemeral(database):
assert database.db_name == TEST_DB
assert database.db_name not in FORBIDDEN
assert is_test_database(database.db_name)
assert database.db_name.lower() not in FORBIDDEN
assert database.tsumugu_env == "development"