Add test to verify Engine instantiates and injects CaptureBus into passive modules (#204)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Tests for core.engine — Module lifecycle manager."""
|
||||
|
||||
import os
|
||||
import time
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
@@ -173,3 +174,52 @@ class TestEngine:
|
||||
assert success is True
|
||||
|
||||
engine.stop("mock_active")
|
||||
|
||||
def test_capture_bus_instantiated_in_start_all(self, mock_bus, mock_state, mock_config):
|
||||
"""Engine.start_all() creates and injects CaptureBus into passive modules."""
|
||||
# Create a passive module that requires CaptureBus
|
||||
class MockPassiveWithCaptureBus(BaseModule):
|
||||
name = "mock_passive_capture"
|
||||
module_type = "passive"
|
||||
priority = 100
|
||||
dependencies = []
|
||||
requires_root = False
|
||||
requires_capture_bus = True
|
||||
|
||||
def start(self):
|
||||
# This module should receive capture_bus in config
|
||||
self._capture_bus = self.config.get("capture_bus")
|
||||
if not self._capture_bus:
|
||||
raise RuntimeError("capture_bus not provided in config")
|
||||
self._running = True
|
||||
self._pid = os.getpid()
|
||||
self._start_time = time.time()
|
||||
|
||||
def stop(self):
|
||||
self._running = False
|
||||
|
||||
def status(self):
|
||||
return {"running": self._running, "pid": self._pid}
|
||||
|
||||
def configure(self, config):
|
||||
pass
|
||||
|
||||
engine = Engine(bus=mock_bus, state=mock_state, config=mock_config)
|
||||
engine.register(MockPassiveWithCaptureBus, config=mock_config)
|
||||
|
||||
# Mock CaptureBus.start() to avoid permission errors during test
|
||||
with patch("core.capture_bus.CaptureBus.start"):
|
||||
# start_all() should create CaptureBus and inject it
|
||||
results = engine.start_all()
|
||||
|
||||
# Verify CaptureBus was created
|
||||
assert engine.capture_bus is not None
|
||||
assert results.get("mock_passive_capture") is True
|
||||
|
||||
# Verify the module config has capture_bus injected
|
||||
entry = engine._modules["mock_passive_capture"]
|
||||
assert "capture_bus" in entry.config
|
||||
assert entry.config["capture_bus"] is not None
|
||||
|
||||
# Cleanup
|
||||
engine.stop_all()
|
||||
|
||||
Reference in New Issue
Block a user