Files
ServerKit/backend/tests/test_ftp_extraction.py
T
Juan DenisandClaude Opus 4.8 2a060c518d refactor(ftp): extract FTP backend into serverkit-ftp builtin extension
Plan 47 Phase 2. The FTP blueprint + service move out of core into
builtin-extensions/serverkit-ftp/backend/ (entry_point ftp:ftp_bp, url_prefix
unchanged). Core no longer registers /api/v1/ftp or imports ftp_service — a
fresh panel that never touches FTP loads none of it. Already in
CONVERTED_BUILTIN_SLUGS, so upgrades re-acquire the backend automatically.

Acceptance (tests/test_ftp_extraction.py): uninstalled = no /api/v1/ftp routes +
app.services.ftp_service gone; installed = blueprint hot-loads and /ftp/status
responds; uninstall removes it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-14 22:15:07 -04:00

77 lines
2.6 KiB
Python

"""Prove the FTP extraction (plan 47 Phase 2).
A fresh panel no longer carries the FTP API in core; installing the
serverkit-ftp builtin registers `/api/v1/ftp` 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-ftp'
_PKG = f'app.plugins.{SLUG}'
def test_core_has_no_ftp_routes(app):
rules = [r.rule for r in app.url_map.iter_rules()]
assert [r for r in rules if r.startswith('/api/v1/ftp')] == []
def test_core_import_of_ftp_service_is_gone():
"""The FTP service left core — importing it from app.services must fail."""
import importlib
with pytest.raises(ModuleNotFoundError):
importlib.import_module('app.services.ftp_service')
def test_ftp_in_converted_builtin_slugs():
from app.services.extension_migration import CONVERTED_BUILTIN_SLUGS
assert SLUG in CONVERTED_BUILTIN_SLUGS
@pytest.fixture
def install_dirs(tmp_path, monkeypatch):
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}
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_ftp_extension_registers_routes(app, client, auth_headers, install_dirs):
available = {e['slug'] for e in plugin_service.list_builtin_extensions()}
assert SLUG in available, 'serverkit-ftp builtin folder should exist'
plugin = plugin_service.install_builtin_extension(SLUG)
assert plugin.status == InstalledPlugin.STATUS_ACTIVE
assert plugin.has_backend is True
assert plugin.url_prefix == '/api/v1/ftp'
resp = client.get('/api/v1/ftp/status', headers=auth_headers)
assert resp.status_code not in (404, 503), resp.status_code
def test_uninstall_removes_ftp_plugin(app, install_dirs):
plugin = plugin_service.install_builtin_extension(SLUG)
assert plugin_service.uninstall_plugin(plugin.id) is True
assert InstalledPlugin.query.filter_by(slug=SLUG).first() is None