One process owns this database — the image has run a single uvicorn worker for that reason since the four-engines bug — so a file beside the flows is the honest shape for it, and it is what lets `fluksio serve` need no infrastructure at all. Live values, node execution and the work queue never came here anyway; what does is a rollup a minute at a time, a row per cascade and the run history, and WAL keeps the readers going while that one writer works. DATA_DIR is now the one setting that moves everything an installation keeps; the rest derive from it and the images still spell theirs out. The schema is prepared in-process at startup, so the prestart service is gone, and the ten Postgres-only revisions collapse into one portable baseline. Three things only worked because psycopg was casting for us: a token's subject arriving as a string where the column is a UUID, `greatest`, and `date_bin`. The timestamps needed a column type of their own — SQLite stores no offset, and a naive datetime read back either raises against an aware `now` or serialises as local time. Postgres stays in the stack only for Umami, behind the analytics profile.
42 lines
2.2 KiB
Python
42 lines
2.2 KiB
Python
"""Redirect the suite at its own database.
|
|
|
|
`fluksio.core.db` builds the engine at import time and several modules bind
|
|
that object, so the URL has to be in the environment before anything imports
|
|
the settings. Overriding it here — the first module pytest imports for the
|
|
package — keeps a test run from touching the development data.
|
|
|
|
A file rather than `:memory:`: the suite starts the engine's own threads (the
|
|
run service, the metrics collector, the portal connector) against this engine,
|
|
and an in-memory database is per connection unless every one of them shares a
|
|
single connection, which those threads would then contend for.
|
|
"""
|
|
|
|
import os
|
|
import tempfile
|
|
|
|
_DB_DIR = tempfile.mkdtemp(prefix="fluksio-test-")
|
|
os.environ.setdefault("DATABASE_URL", f"sqlite:///{_DB_DIR}/app_test.db")
|
|
# Nothing outside this directory: the suite must not pick up a checkout's .env
|
|
# and write into the development data.
|
|
os.environ.setdefault("FLUKSIO_ENV_FILE", os.path.join(_DB_DIR, "env"))
|
|
os.environ.setdefault("DATA_DIR", _DB_DIR)
|
|
# Named here rather than taken from a developer's .env, so the suite is the
|
|
# same run everywhere and a checkout's own superuser is never involved.
|
|
os.environ.setdefault("FIRST_SUPERUSER", "admin@example.com")
|
|
os.environ.setdefault("FIRST_SUPERUSER_PASSWORD", "testpassword")
|
|
# What `emails_enabled` needs; the tests that send mail patch SMTP_HOST on top
|
|
# of it. Nothing is delivered — the sender is faked where it matters.
|
|
os.environ.setdefault("EMAILS_FROM_EMAIL", "noreply@example.com")
|
|
# The MCP session manager can only be entered once per instance, and the suite
|
|
# builds a TestClient — and so a lifespan — per test module. Tests that want the
|
|
# endpoint mount it themselves.
|
|
os.environ["MCP_ENABLED"] = "false"
|
|
# The private seeding endpoints are opt-in; the suite is one of the two places
|
|
# (with the dev stack) where they are meant to work.
|
|
os.environ["PRIVATE_API_ENABLED"] = "true"
|
|
# The suite is the development configuration by definition: `/private` is
|
|
# gated on it (app/api/routes/private.py) and the MCP host allow-list is
|
|
# built from DOMAIN (app/mcp/http.py), while the tests speak to api.localhost.
|
|
os.environ["ENVIRONMENT"] = "local"
|
|
os.environ["DOMAIN"] = "localhost"
|