prole/tests/test_render_supabase_hostname.py
chrisfu b114099e17 Use prole.cfg hostnames for Supabase front-door
- Persist and export supabase_hostname for canonical external Supabase entrypoint (db.prole.org)

- Render Supabase Helm ingress host and public URLs (API_EXTERNAL_URL/GOTRUE_SITE_URL/SUPABASE_PUBLIC_URL) from config

- Align tracked Traefik ingress manifests to db.prole.org

- Generalize service hostname/TLS wiring in k3s automation and refresh Kong/monitoring behavior

- Make optional workload policy checks deterministic when kube context is absent; add render tests
2026-03-19 04:19:38 -07:00

90 lines
3.0 KiB
Python

from __future__ import annotations
import importlib.util
from argparse import Namespace
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
_RENDER_PATH = REPO_ROOT / "supabase" / "helm" / "render_supabase.py"
def _load_render_module():
spec = importlib.util.spec_from_file_location("prole_render_supabase", _RENDER_PATH)
assert spec is not None and spec.loader is not None
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
_render_mod = _load_render_module()
_build_overlay = _render_mod._build_overlay
_read_cfg = _render_mod._read_cfg
def _write_cfg(path: Path, content: str) -> None:
path.write_text(content.strip() + "\n", encoding="utf-8")
def test_render_supabase_uses_supabase_hostname_for_public_urls(tmp_path: Path, monkeypatch):
# Ensure env doesn't interfere with config-driven behavior.
monkeypatch.delenv("SUPABASE_HOST", raising=False)
monkeypatch.delenv("SUPABASE_HOSTNAME", raising=False)
monkeypatch.delenv("PROLE_DB_NAMESPACE", raising=False)
monkeypatch.delenv("PROLE_DB_SERVICE", raising=False)
cfg_path = tmp_path / "prole.cfg"
_write_cfg(
cfg_path,
"""
[User]
supabase_hostname = db.prole.org
[Inputs]
init_password.db_password = test-password
init_password.db_host_port = 5432
[Global]
NAMESPACE = test-ns
""",
)
cfg = _read_cfg(cfg_path)
args = Namespace(output_dir=str(tmp_path / "gen"), manifests_dir=str(tmp_path / "k8s"))
overlay, _meta = _build_overlay(cfg, args)
assert overlay["ingress"]["hosts"][0]["host"] == "db.prole.org"
assert overlay["environment"]["auth"]["API_EXTERNAL_URL"] == "https://db.prole.org"
assert overlay["environment"]["auth"]["GOTRUE_SITE_URL"] == "https://db.prole.org"
assert overlay["environment"]["studio"]["SUPABASE_PUBLIC_URL"] == "https://db.prole.org"
def test_render_supabase_allows_scheme_in_supabase_hostname(tmp_path: Path, monkeypatch):
monkeypatch.delenv("SUPABASE_HOST", raising=False)
monkeypatch.delenv("SUPABASE_HOSTNAME", raising=False)
monkeypatch.delenv("PROLE_DB_NAMESPACE", raising=False)
monkeypatch.delenv("PROLE_DB_SERVICE", raising=False)
cfg_path = tmp_path / "prole.cfg"
_write_cfg(
cfg_path,
"""
[User]
supabase_hostname = http://db.prole.org
[Inputs]
init_password.db_password = test-password
init_password.db_host_port = 5432
[Global]
NAMESPACE = test-ns
""",
)
cfg = _read_cfg(cfg_path)
args = Namespace(output_dir=str(tmp_path / "gen"), manifests_dir=str(tmp_path / "k8s"))
overlay, _meta = _build_overlay(cfg, args)
assert overlay["ingress"]["hosts"][0]["host"] == "db.prole.org"
assert overlay["environment"]["auth"]["API_EXTERNAL_URL"] == "http://db.prole.org"
assert overlay["environment"]["studio"]["SUPABASE_PUBLIC_URL"] == "http://db.prole.org"