File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,3 +37,5 @@ METRICS_PATH=data/runtime-metrics.json
3737# === Dashboard (optional) ===
3838# API key for dashboard endpoints. If empty, dashboard API routes are disabled.
3939DASHBOARD_API_KEY =
40+ # Start the dashboard-managed bot during application startup (production opt-in).
41+ DIGITAL_MATE_AUTO_START_BOT = false
Original file line number Diff line number Diff line change @@ -179,6 +179,11 @@ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
179179 db = await init_db (str (abs_db_path ))
180180 _brand_service = BrandService (db )
181181 _stats_service = StatsService (db )
182+ auto_start_bot = os .environ .get (
183+ "DIGITAL_MATE_AUTO_START_BOT" , ""
184+ ).strip ().lower () in {"1" , "true" , "yes" , "on" }
185+ if auto_start_bot :
186+ await bot_manager .start ()
182187 try :
183188 yield
184189 finally :
Original file line number Diff line number Diff line change @@ -41,6 +41,26 @@ async def test_start_inherits_service_output(self):
4141 assert "stdout" not in await_args .kwargs
4242 assert "stderr" not in await_args .kwargs
4343
44+ def test_lifespan_autostarts_bot_when_enabled (self , tmp_path , monkeypatch ):
45+ monkeypatch .setenv ("DASHBOARD_API_KEY" , DASHBOARD_TEST_KEY )
46+ monkeypatch .setenv ("DIGITAL_MATE_AUTO_START_BOT" , "true" )
47+
48+ with (
49+ patch ("digital_mate.web.app.PROJECT_ROOT" , tmp_path ),
50+ patch (
51+ "digital_mate.web.app.bot_manager.start" , new = AsyncMock ()
52+ ) as start_bot ,
53+ patch (
54+ "digital_mate.web.app.bot_manager.stop" , new = AsyncMock ()
55+ ) as stop_bot ,
56+ ):
57+ from digital_mate .web .app import create_app
58+
59+ with TestClient (create_app ()):
60+ start_bot .assert_awaited_once_with ()
61+
62+ stop_bot .assert_awaited_once_with ()
63+
4464
4565# ---------------------------------------------------------------------------
4666# Settings Service Tests
You can’t perform that action at this time.
0 commit comments