Files
xiaoxia-saas/tests/unit/test_architecture_boundaries.py
T
API文档维护Agent e2c68888e9
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
refactor: 统一 OSS 配置命名(MINIO_* → OSS_*)
- .env.production: MINIO_* 环境变量全部改为 OSS_* 命名
  - MINIO_ENDPOINT → OSS_ENDPOINT
  - MINIO_ACCESS_KEY → OSS_ACCESS_KEY_ID
  - MINIO_SECRET_KEY → OSS_ACCESS_KEY_SECRET
  - MINIO_BUCKET → OSS_BUCKET_NAME
  - MINIO_SECURE → OSS_SECURE
  - MINIO_PUBLIC_URL → OSS_PUBLIC_URL
- .env.staging: 修正 section header 为 OSS 对象存储配置
- storage.py: 移除 MinIOService 和 get_minio_service() 向后兼容别名
- test_architecture_boundaries.py: 移除 storage.py 的 allowed 例外
- 更新文档中的 MINIO_* 示例为 OSS_*:
  - docs/CI-CD.md
  - docs/基础设施安装指南.md
  - docs/本地验证检查清单.md
  - docs/静态验证报告-2026-06-19.md
2026-06-28 08:33:48 +08:00

93 lines
3.3 KiB
Python

from pathlib import Path
ALLOWED_API_ADAPTER_IMPORTS = {
Path("apps/api/app/dependencies.py"),
Path("apps/api/app/db.py"),
Path("apps/api/app/api/routes/edit_plans.py"),
}
def test_api_routes_do_not_import_sqlalchemy_adapters_directly():
offenders: list[str] = []
for path in Path("apps/api/app/api/routes").glob("*.py"):
if path in ALLOWED_API_ADAPTER_IMPORTS:
continue
text = path.read_text(encoding="utf-8")
if "packages.adapters.sqlalchemy_impl" in text or "SQLAlchemy" in text:
offenders.append(str(path))
assert offenders == []
def test_domain_auth_does_not_export_infrastructure_singletons():
text = Path("packages/domain/auth/__init__.py").read_text(encoding="utf-8")
assert "session_store," not in text
assert "email_service," not in text
assert '"session_store"' not in text
assert '"email_service"' not in text
def test_runtime_code_does_not_import_deprecated_postgres_adapters():
assert not Path("packages/adapters/postgres").exists() or not list(Path("packages/adapters/postgres").glob("*.py"))
roots = [Path("apps"), Path("packages"), Path("tests")]
offenders: list[str] = []
for root in roots:
for path in root.rglob("*.py"):
if path.resolve() == Path(__file__).resolve():
continue
if path.parts[:3] == ("packages", "adapters", "postgres"):
continue
text = path.read_text(encoding="utf-8")
if "packages.adapters.postgres" in text or "Postgres" in text:
offenders.append(str(path))
assert offenders == []
def test_canonical_auth_route_has_no_auth_simple_runtime_path():
assert not Path("apps/api/app/api/routes/auth_simple.py").exists()
offenders: list[str] = []
for root in [Path("apps"), Path("packages"), Path("tests")]:
for path in root.rglob("*.py"):
if path.resolve() == Path(__file__).resolve():
continue
text = path.read_text(encoding="utf-8")
if "auth_simple" in text or "routes.auth_simple" in text:
offenders.append(str(path))
assert offenders == []
def test_runtime_code_uses_oss_storage_naming_not_minio():
allowed: set[Path] = set()
offenders: list[str] = []
for root in [Path("apps"), Path("packages"), Path("tests")]:
for path in root.rglob("*.py"):
if path in allowed or path.resolve() == Path(__file__).resolve():
continue
text = path.read_text(encoding="utf-8")
if "MinIO" in text or "minio" in text or "get_minio_service" in text:
offenders.append(str(path))
assert offenders == []
def test_legacy_sql_schema_files_are_not_runtime_entrypoints():
init_tables = Path("init-tables.sql").read_text(encoding="utf-8")
assert "RAISE EXCEPTION" in init_tables
assert "deprecated" in init_tables.lower()
offenders: list[str] = []
for root in [Path("apps"), Path("packages"), Path("infra")]:
for pattern in ("*.py", "*.sh", "*.yml", "*.yaml", "*.md"):
for path in root.rglob(pattern):
text = path.read_text(encoding="utf-8", errors="ignore")
if "init-tables.sql" in text or "migrations/001_initial_schema.sql" in text:
offenders.append(str(path))
assert offenders == []