refactor: rename platform_domain → main_domain to avoid confusion with platform.domain
Some checks failed
CI / ruff (push) Successful in 10s
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / pytest (push) Has started running

The setting `settings.platform_domain` (the global/main domain like "wizard.lu")
was easily confused with `platform.domain` (per-platform domain like "rewardflow.lu").
Renamed to `settings.main_domain` / `MAIN_DOMAIN` env var across the entire codebase.

Also updated docs to reflect the refactored store detection logic with
`is_platform_domain` / `is_subdomain_of_platform` guards.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-14 04:45:28 +01:00
parent 4a1f71a312
commit c2c0e3c740
26 changed files with 152 additions and 113 deletions

View File

@@ -37,7 +37,7 @@ def client(db):
with patch("middleware.store_context.get_db", override_get_db):
with patch("middleware.theme_context.get_db", override_get_db):
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
client = TestClient(app)
yield client
```

View File

@@ -49,7 +49,7 @@ def client(db):
This patches:
1. get_db in both middleware modules to use the test database
2. settings.platform_domain in store_context to use 'platform.com' for testing
2. settings.main_domain in store_context to use 'platform.com' for testing
This ensures middleware can see test fixtures and detect subdomains correctly.
"""
@@ -64,7 +64,7 @@ def client(db):
# Patch get_db in middleware modules - they have their own imports
# The middleware calls: db_gen = get_db(); db = next(db_gen)
# Also patch settings.platform_domain so subdomain detection works with test hosts
# Also patch settings.main_domain so subdomain detection works with test hosts
# Also bypass StorefrontAccessMiddleware subscription check for test routes —
# these tests verify store context detection, not subscription access.
from middleware.storefront_access import SKIP_PATH_PREFIXES
@@ -76,7 +76,7 @@ def client(db):
with patch("middleware.theme_context.get_db", override_get_db):
with patch("middleware.store_context.settings") as mock_settings:
with patch("middleware.storefront_access.SKIP_PATH_PREFIXES", test_skip_prefixes):
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
client = TestClient(app)
yield client

View File

@@ -102,7 +102,7 @@ async def test_inactive_store_detection(request: Request):
@router.get("/platform-domain")
async def test_platform_domain(request: Request):
async def test_main_domain(request: Request):
"""Test platform domain without subdomain."""
store = getattr(request.state, "store", None)
return {"store_detected": store is not None}

View File

@@ -7,7 +7,7 @@ for all routing modes: subdomain, custom domain, and path-based.
Note: These tests require the middleware conftest.py which patches:
1. get_db in middleware modules to use the test database session
2. settings.platform_domain to use 'platform.com' for testing subdomain detection
2. settings.main_domain to use 'platform.com' for testing subdomain detection
"""
import pytest
@@ -137,7 +137,7 @@ class TestStoreContextFlow:
data = response.json()
assert data["store_detected"] is False
def test_platform_domain_without_subdomain_no_store(self, client):
def test_main_domain_without_subdomain_no_store(self, client):
"""Test that platform domain without subdomain doesn't detect store."""
response = client.get(
"/middleware-test/platform-domain", headers={"host": "platform.com"}

View File

@@ -43,7 +43,7 @@ class TestStoreContextManager:
request.url = Mock(path="/")
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.detect_store_context(request)
@@ -59,7 +59,7 @@ class TestStoreContextManager:
request.url = Mock(path="/")
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.detect_store_context(request)
@@ -75,7 +75,7 @@ class TestStoreContextManager:
request.url = Mock(path="/")
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.detect_store_context(request)
@@ -91,7 +91,7 @@ class TestStoreContextManager:
request.url = Mock(path="/")
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.detect_store_context(request)
@@ -155,7 +155,7 @@ class TestStoreContextManager:
request.state.platform_clean_path = None
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.detect_store_context(request)
@@ -170,7 +170,7 @@ class TestStoreContextManager:
request.state.platform_clean_path = None
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.detect_store_context(request)
@@ -185,7 +185,7 @@ class TestStoreContextManager:
request.state.platform_clean_path = None
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.detect_store_context(request)
@@ -200,7 +200,7 @@ class TestStoreContextManager:
request.state.platform_clean_path = None
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.detect_store_context(request)
@@ -441,7 +441,7 @@ class TestStoreContextManager:
request.headers = {"referer": "http://orion.platform.com/storefront/products"} # noqa: SEC034
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.extract_store_from_referer(request)
@@ -456,7 +456,7 @@ class TestStoreContextManager:
request.headers = {"referer": "http://my-custom-shop.com/storefront/products"} # noqa: SEC034
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.extract_store_from_referer(request)
@@ -490,7 +490,7 @@ class TestStoreContextManager:
request.headers = {"referer": "http://admin.platform.com/dashboard"} # noqa: SEC034
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.extract_store_from_referer(request)
@@ -503,7 +503,7 @@ class TestStoreContextManager:
request.headers = {"referer": "http://www.platform.com/storefront"} # noqa: SEC034
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.extract_store_from_referer(request)
@@ -515,7 +515,7 @@ class TestStoreContextManager:
request.headers = {"referer": "http://localhost:8000/storefront"}
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.extract_store_from_referer(request)
@@ -996,7 +996,7 @@ class TestEdgeCases:
request.url = Mock(path="/")
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
mock_settings.main_domain = "platform.com"
context = StoreContextManager.detect_store_context(request)

View File

@@ -207,7 +207,7 @@ class TestPlatformInjectionIntoStoreContext:
mock_request.url = Mock(path="/store/login")
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "omsflow.lu"
mock_settings.main_domain = "omsflow.lu"
context = StoreContextManager.detect_store_context(mock_request)