"""The domain layer must stay framework-free. This is enforced by actually importing the domain modules in a clean interpreter and asserting that neither FastAPI nor SQLAlchemy got pulled in. A comment in a README would not catch a regression; this does. """ from __future__ import annotations import subprocess import sys from pathlib import Path API_ROOT = Path(__file__).resolve().parents[1] _PROBE = """ import sys import app.domain.identity.models import app.domain.workforce.models import app.domain.billing.models import app.domain.sandbox.models import app.domain.knowledge.models import app.domain.audit.models import app.domain.ai_control.models import app.domain.projects.models import app.domain.platform.rules forbidden = [name for name in ("fastapi", "sqlalchemy", "redis", "httpx") if name in sys.modules] assert not forbidden, f"domain layer leaked: {forbidden}" print("clean") """ def test_domain_layer_has_no_framework_dependencies(): result = subprocess.run( [sys.executable, "-c", _PROBE], capture_output=True, text=True, cwd=str(API_ROOT), ) assert result.returncode == 0, result.stderr assert "clean" in result.stdout def test_domain_rules_are_usable_without_a_database(): from app.domain.platform.rules import build_host, is_port_allocatable assert build_host("my-app", "msa.artacloud.ir") == "my-app.msa.artacloud.ir" assert is_port_allocatable(8100) assert not is_port_allocatable(3000)