mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-03 05:35:09 +09:00
Moves the mail-server stack out of core into builtin-extensions/serverkit-email/: - api/email.py + email_service/dovecot/dkim/spamassassin/roundcube → extension backend (relative intra-extension imports; core imports absolute); blueprint keeps /api/v1/email (D9). Core __init__ no longer registers email. - Stays core (deviations from the audit, documented): postfix_service (the outbound relay actively uses it) + all email models (no external importers, so no DNSProviderConfig relocation / data migration needed). - Frontend: serverkit-email manifest contributes nav/route/title/palette; core App.jsx/sidebar/palette entries removed; Email page re-exported (D2 pattern). - #34 auto-install gated on real mail usage (EmailDomain/EmailAccount rows); the core Email module toggle is retired in favor of the extension. - Tests: test_email_extraction.py proves core has no /api/v1/email, install registers+responds (exercises relative-import rewiring), uninstall clean. Full backend suite: 1200 passed. Frontend lint 0 errors + build. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
74 lines
2.9 KiB
Python
74 lines
2.9 KiB
Python
"""Prove the Email extraction (Phase 4, #35).
|
|
|
|
A core panel no longer carries the mail-server API; installing the serverkit-email
|
|
builtin registers `/api/v1/email` and its routes respond (which also exercises the
|
|
extension's relative-import rewiring). Uninstall removes it again.
|
|
"""
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
import app as app_pkg
|
|
from app.models.plugin import InstalledPlugin
|
|
from app.services import plugin_service
|
|
|
|
SLUG = 'serverkit-email'
|
|
_PKG = f'app.plugins.{SLUG}'
|
|
|
|
|
|
def test_core_has_no_email_routes(app):
|
|
"""The mail-server API is gone from core after extraction."""
|
|
rules = [r.rule for r in app.url_map.iter_rules()]
|
|
assert not any(r.startswith('/api/v1/email') for r in rules)
|
|
|
|
|
|
@pytest.fixture
|
|
def install_dirs(tmp_path, monkeypatch):
|
|
"""Point the install targets at temp dirs AND make app.plugins resolve the
|
|
temp backend dir so the hot-loaded blueprint imports from there (not the repo).
|
|
"""
|
|
backend = tmp_path / 'plugins_backend'
|
|
frontend = tmp_path / 'plugins_frontend'
|
|
backend.mkdir()
|
|
frontend.mkdir()
|
|
monkeypatch.setattr(plugin_service, 'BACKEND_PLUGINS_DIR', str(backend))
|
|
monkeypatch.setattr(plugin_service, 'FRONTEND_PLUGINS_DIR', str(frontend))
|
|
|
|
added = str(backend)
|
|
import importlib
|
|
app_pkg_plugins = importlib.import_module('app.plugins')
|
|
if added not in app_pkg_plugins.__path__:
|
|
app_pkg_plugins.__path__.append(added)
|
|
|
|
yield {'backend': backend, 'frontend': frontend}
|
|
|
|
# Clean the import side effects so other tests see a pristine module graph.
|
|
if added in app_pkg_plugins.__path__:
|
|
app_pkg_plugins.__path__.remove(added)
|
|
for name in list(sys.modules):
|
|
if name == _PKG or name.startswith(_PKG + '.'):
|
|
del sys.modules[name]
|
|
|
|
|
|
def test_install_email_extension_registers_routes(app, client, auth_headers, install_dirs):
|
|
# The real builtin folder is discovered from the repo's builtin-extensions/.
|
|
available = {e['slug'] for e in plugin_service.list_builtin_extensions()}
|
|
assert SLUG in available, 'serverkit-email builtin folder should exist'
|
|
|
|
plugin = plugin_service.install_builtin_extension('serverkit-email')
|
|
assert plugin.status == InstalledPlugin.STATUS_ACTIVE
|
|
assert plugin.has_backend is True
|
|
assert plugin.url_prefix == '/api/v1/email'
|
|
|
|
# The blueprint hot-loaded: /api/v1/email/status now exists (not 404) and the
|
|
# status guard passes for an active plugin (not 503). Its handler may 200 or
|
|
# 500 depending on host mail state — we only assert the route is wired.
|
|
resp = client.get('/api/v1/email/status', headers=auth_headers)
|
|
assert resp.status_code not in (404, 503), resp.status_code
|
|
|
|
|
|
def test_uninstall_removes_email_plugin(app, install_dirs):
|
|
plugin = plugin_service.install_builtin_extension('serverkit-email')
|
|
assert plugin_service.uninstall_plugin(plugin.id) is True
|
|
assert InstalledPlugin.query.filter_by(slug=SLUG).first() is None
|