prole/tests/test_render_supabase_placement.py
chrisfu 65369811f7 Harden ingress targeting and normalize HOME paths
- enforce app-cluster-only rendering for public ingress hosts with DB-cluster guardrails\n- fix Supabase/GitLab/authority ingress host ownership and ingress-class safety checks\n- normalize persisted home-directory paths to /Users/chrisfu and update gke config defaults\n- add/adjust regression tests for ingress placement/hostname and cfg path normalization

Co-authored-by: Junie <junie@jetbrains.com>
2026-04-12 12:32:09 -07:00

79 lines
2.3 KiB
Python

from __future__ import annotations
import configparser
import importlib.util
from pathlib import Path
from types import SimpleNamespace
def _load_render_supabase_module():
repo_root = Path(__file__).resolve().parents[1]
mod_path = repo_root / "supabase" / "helm" / "render_supabase.py"
spec = importlib.util.spec_from_file_location("prole_render_supabase", mod_path)
assert spec is not None
module = importlib.util.module_from_spec(spec)
assert spec.loader is not None
spec.loader.exec_module(module)
return module
def _minimal_cfg() -> configparser.ConfigParser:
cfg = configparser.ConfigParser(interpolation=None)
cfg.read_string(
"""
[Global]
NAMESPACE = prole
STORAGE_BACKEND = local
"""
)
return cfg
def test_supabase_overlay_pins_components_to_merlin_in_k3s_mode(monkeypatch, tmp_path):
m = _load_render_supabase_module()
cfg = _minimal_cfg()
args = SimpleNamespace(output_dir=str(tmp_path), config=str(tmp_path / "prole.cfg"))
monkeypatch.setenv("DB_PASSWORD", "test-db-password")
monkeypatch.setenv("PROLE_MODE", "k3s")
monkeypatch.setenv("SUPABASE_PRIMARY_NODE", "merlin.prole.org")
overlay, _meta = m._build_overlay(cfg, args)
deployment = overlay["deployment"]
for component in (
"analytics",
"auth",
"imgproxy",
"kong",
"meta",
"minio",
"realtime",
"rest",
"storage",
"studio",
):
assert component in deployment
assert (
deployment[component]["nodeSelector"]["kubernetes.io/hostname"]
== "merlin.prole.org"
)
def test_supabase_overlay_does_not_pin_components_outside_k3s(monkeypatch, tmp_path):
m = _load_render_supabase_module()
cfg = _minimal_cfg()
args = SimpleNamespace(output_dir=str(tmp_path), config=str(tmp_path / "prole.cfg"))
monkeypatch.setenv("DB_PASSWORD", "test-db-password")
monkeypatch.setenv("PROLE_MODE", "k3d")
monkeypatch.delenv("SUPABASE_PRIMARY_NODE", raising=False)
overlay, _meta = m._build_overlay(cfg, args)
deployment = overlay["deployment"]
# The renderer only injects hostname pinning in k3s mode.
assert "nodeSelector" not in deployment.get("auth", {})
assert "nodeSelector" not in deployment.get("analytics", {})
assert "nodeSelector" not in deployment.get("db", {})