@@ -239,6 +239,71 @@ def fake_secret(message: str) -> str:
239239 assert not config_file .exists ()
240240
241241
242+ def test_run_command_processes_inbound_inside_framework_runtime (tmp_path : Path ) -> None :
243+ config_file = tmp_path / "config.yml"
244+ framework = BubFramework (config_file = config_file )
245+ observed : dict [str , Any ] = {}
246+
247+ class RecordingTapeStore :
248+ def __init__ (self ) -> None :
249+ self .enter_count = 0
250+ self .exit_count = 0
251+
252+ tape_store = RecordingTapeStore ()
253+
254+ class RunPlugin :
255+ @hookimpl
256+ def register_cli_commands (self , app : typer .Typer ) -> None :
257+ app .command ("run" )(cli .run )
258+
259+ @hookimpl
260+ def provide_tape_store (self ):
261+ tape_store .enter_count += 1
262+ try :
263+ yield tape_store
264+ finally :
265+ tape_store .exit_count += 1
266+
267+ @hookimpl
268+ def build_prompt (self , message , session_id , state ) -> str :
269+ observed ["session_id" ] = session_id
270+ observed ["message_content" ] = message .content
271+ observed ["sender_id" ] = message .context ["sender_id" ]
272+ return "prompt"
273+
274+ @hookimpl
275+ async def run_model (self , prompt , session_id , state ) -> str :
276+ observed ["tape_store" ] = framework .get_tape_store ()
277+ return "model output"
278+
279+ @hookimpl
280+ def render_outbound (self , message , session_id , state , model_output ):
281+ return [{"channel" : "stdout" , "chat_id" : "local" , "content" : model_output }]
282+
283+ @hookimpl
284+ async def dispatch_outbound (self , message ) -> bool :
285+ return True
286+
287+ framework ._plugin_manager .register (RunPlugin (), name = "run-plugin" )
288+ app = framework .create_cli_app ()
289+
290+ result = CliRunner ().invoke (
291+ app ,
292+ ["run" , "hello" , "--channel" , "cli" , "--chat-id" , "room" , "--sender-id" , "frost" ],
293+ )
294+
295+ assert result .exit_code == 0
296+ assert "[stdout:local]\n model output" in result .stdout
297+ assert observed == {
298+ "session_id" : "cli:room" ,
299+ "message_content" : "hello" ,
300+ "sender_id" : "frost" ,
301+ "tape_store" : tape_store ,
302+ }
303+ assert tape_store .enter_count == 1
304+ assert tape_store .exit_count == 1
305+
306+
242307def test_onboard_collects_builtin_runtime_config_with_custom_provider (tmp_path : Path , monkeypatch ) -> None :
243308 config_file = tmp_path / "config.yml"
244309
0 commit comments