fix(arch-a2): deactivation cleanup - container services, search provider, hook deregistration, notification sync, task state, activation order
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
This commit is contained in:
@@ -197,3 +197,85 @@ class TestManifestPermissionValidator:
|
||||
display_name='X',
|
||||
permissions=['core:contacts:read'],
|
||||
)
|
||||
|
||||
|
||||
# --- A2 deactivation cleanup: lifecycle symmetry ---
|
||||
|
||||
|
||||
class TestServiceContainerRemove:
|
||||
def test_remove_registered_service(self):
|
||||
from app.core.service_container import ServiceContainer
|
||||
|
||||
container = ServiceContainer()
|
||||
container.register('svc', object())
|
||||
assert container.has('svc') is True
|
||||
container.remove('svc')
|
||||
assert container.has('svc') is False
|
||||
|
||||
def test_remove_absent_service_is_noop(self):
|
||||
from app.core.service_container import ServiceContainer
|
||||
|
||||
container = ServiceContainer()
|
||||
container.remove('never_registered') # must not raise
|
||||
assert container.has('never_registered') is False
|
||||
|
||||
|
||||
class TestKommunikationLifecycle:
|
||||
@pytest.mark.asyncio
|
||||
async def test_deactivate_removes_container_services(self):
|
||||
from app.core.event_bus import EventBus
|
||||
from app.core.service_container import ServiceContainer
|
||||
from app.plugins.builtins.kommunikation.plugin import KommunikationPlugin
|
||||
|
||||
plugin = KommunikationPlugin()
|
||||
container = ServiceContainer()
|
||||
event_bus = EventBus()
|
||||
|
||||
await plugin.on_activate(db=None, service_container=container, event_bus=event_bus)
|
||||
assert container.has('comm_websocket') is True
|
||||
assert container.has('comm_miniapps') is True
|
||||
|
||||
await plugin.on_deactivate(db=None, service_container=container, event_bus=event_bus)
|
||||
assert container.has('comm_websocket') is False
|
||||
assert container.has('comm_miniapps') is False
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reactivate_no_duplicates(self):
|
||||
from app.core.event_bus import EventBus
|
||||
from app.core.service_container import ServiceContainer
|
||||
from app.plugins.builtins.kommunikation.plugin import KommunikationPlugin
|
||||
|
||||
plugin = KommunikationPlugin()
|
||||
container = ServiceContainer()
|
||||
event_bus = EventBus()
|
||||
|
||||
await plugin.on_activate(db=None, service_container=container, event_bus=event_bus)
|
||||
await plugin.on_deactivate(db=None, service_container=container, event_bus=event_bus)
|
||||
await plugin.on_activate(db=None, service_container=container, event_bus=event_bus)
|
||||
|
||||
ws = container.get('comm_websocket')
|
||||
miniapps = container.get('comm_miniapps')
|
||||
assert ws is not None and miniapps is not None
|
||||
assert len(miniapps._apps) == len(set(miniapps._apps.keys()))
|
||||
|
||||
|
||||
class TestWikiProviderLifecycle:
|
||||
@pytest.mark.asyncio
|
||||
async def test_deactivate_unregisters_search_provider(self):
|
||||
from app.core.event_bus import EventBus
|
||||
from app.core.service_container import ServiceContainer
|
||||
from app.plugins.builtins.contracts import get_contract
|
||||
from app.plugins.builtins.wiki.plugin import WikiPlugin
|
||||
|
||||
plugin = WikiPlugin()
|
||||
container = ServiceContainer()
|
||||
event_bus = EventBus()
|
||||
|
||||
search_contract = get_contract('unified_search')
|
||||
registry = search_contract.get_search_registry()
|
||||
|
||||
await plugin.on_activate(db=None, service_container=container, event_bus=event_bus)
|
||||
assert registry.get('wiki_article') is not None
|
||||
|
||||
await plugin.on_deactivate(db=None, service_container=container, event_bus=event_bus)
|
||||
assert registry.get('wiki_article') is None
|
||||
|
||||
Reference in New Issue
Block a user