refactor(#11-Kritik): Contacts-Entities aus statischem Core-Registry entfernt — ContactsPlugin.get_entity_models() ist Single Source (contact/contacts/company); conftest spiegelt Produktions-Bootstrap idempotent (autouse-Fixture); Regressionstests beweisen Plugin-Registrierung; 12 ACL-Batch-Failures per Stash-Test als Vorbestand bewiesen (Suite-Isolation, identisch auf clean HEAD)
This commit is contained in:
+26
-1
@@ -65,12 +65,19 @@ from app.plugins.registry import get_registry
|
||||
|
||||
_registry = get_registry()
|
||||
_registry.discover_builtins()
|
||||
from app.services.entity_permission_service import register_entity_model # noqa: E402
|
||||
|
||||
for _plugin_name in _registry.list_discovered():
|
||||
_plugin = _registry.get_plugin(_plugin_name)
|
||||
if _plugin is not None:
|
||||
# Importing get_entity_models() triggers model class imports
|
||||
# which registers them with Base.metadata
|
||||
_plugin.get_entity_models()
|
||||
_entity_models = _plugin.get_entity_models()
|
||||
# Mirror the production bootstrap (main.py lifespan / activation):
|
||||
# every plugin's entity models are registered in ENTITY_MODELS —
|
||||
# the core registry itself carries core entities only.
|
||||
for _entity_type, _model_class in _entity_models.items():
|
||||
register_entity_model(_entity_type, _model_class)
|
||||
# Also import the plugin's __init__ to ensure all models are loaded
|
||||
import importlib
|
||||
try:
|
||||
@@ -83,6 +90,24 @@ for _plugin_name in _registry.list_discovered():
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _ensure_plugin_entity_models():
|
||||
"""Mirror the production bootstrap before EVERY test (idempotent).
|
||||
|
||||
Lifecycle tests may deactivate plugins (deregistering their entity
|
||||
models). In production main.py lifespan re-activates them at startup;
|
||||
in tests we re-run the same registration so isolation is guaranteed
|
||||
without a static duplicate in the core registry.
|
||||
"""
|
||||
for _plugin_name in _registry.list_discovered():
|
||||
_plugin = _registry.get_plugin(_plugin_name)
|
||||
if _plugin is None:
|
||||
continue
|
||||
for _entity_type, _model_class in _plugin.get_entity_models().items():
|
||||
register_entity_model(_entity_type, _model_class)
|
||||
yield
|
||||
|
||||
# Also import core models that may be missing
|
||||
# Wiki plugin models — not loaded by get_entity_models()
|
||||
from app.core.permission_registry import init_permission_registry # noqa: F401
|
||||
|
||||
Reference in New Issue
Block a user