From 346e7f2e2248c0b619e40c0ada086229ffd8c069 Mon Sep 17 00:00:00 2001 From: Ben Stull Date: Wed, 10 Jun 2026 08:35:16 -0700 Subject: [PATCH] =?UTF-8?q?feat(slice-1):=20platform/config=20=E2=80=94=20?= =?UTF-8?q?single=20env-driven=20config=20surface=20(INV-8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- backend/app/platform/config.py | 19 +++++++++++++++++++ backend/tests/test_config.py | 13 +++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 backend/app/platform/config.py create mode 100644 backend/tests/test_config.py diff --git a/backend/app/platform/config.py b/backend/app/platform/config.py new file mode 100644 index 0000000..ccf7914 --- /dev/null +++ b/backend/app/platform/config.py @@ -0,0 +1,19 @@ +"""Configuration surface — the single place deployment/environment config is read. + +INV-8: no deployment shape is baked into framework code. Every URL, credential, or +relay coordinate arrives through here from the environment (resolved from Secret +Manager in deployed environments). The localhost defaults match compose.yaml so a +clean `scripts/dev.sh` checkout needs no env setup. +""" +from __future__ import annotations + +import os + +# Dev default points at the single Postgres container compose.yaml brings up. In +# PPE/Prod the deployment supplies ECOMM_DATABASE_URL from Secret Manager (INV-8). +_DEFAULT_DATABASE_URL = "postgresql://ecomm:ecomm@localhost:5432/ecomm" + + +def database_url() -> str: + """The psycopg DSN for the application database.""" + return os.environ.get("ECOMM_DATABASE_URL") or _DEFAULT_DATABASE_URL diff --git a/backend/tests/test_config.py b/backend/tests/test_config.py new file mode 100644 index 0000000..6168d17 --- /dev/null +++ b/backend/tests/test_config.py @@ -0,0 +1,13 @@ +import os + +from app.platform import config + + +def test_database_url_defaults_to_local_compose(monkeypatch): + monkeypatch.delenv("ECOMM_DATABASE_URL", raising=False) + assert config.database_url() == "postgresql://ecomm:ecomm@localhost:5432/ecomm" + + +def test_database_url_honors_env(monkeypatch): + monkeypatch.setenv("ECOMM_DATABASE_URL", "postgresql://x:y@db:5432/z") + assert config.database_url() == "postgresql://x:y@db:5432/z"