@@ -989,7 +989,7 @@ def test_cancelled_current_run_adopts_history(self):
989989 Message (role = "user" , content = "q2" ),
990990 Message (role = "assistant" , content = "partial answer" ),
991991 ]
992- with mock .patch ("python_agent_harness.tui.run_agent_loop" , return_value = None ):
992+ with mock .patch ("python_agent_harness.tui.core. run_agent_loop" , return_value = None ):
993993 tui ._run_agent ("q2" , tui .run_seq )
994994 self .assertEqual (
995995 [m .text () for m in tui .conversation_history ],
@@ -2107,12 +2107,12 @@ def test_run_services_pending_question_first(self):
21072107
21082108 def test_run_shows_llm_log_path (self ):
21092109 """With LLM logging enabled the log path is printed at startup."""
2110- import python_agent_harness .tui as tui_mod
2110+ import python_agent_harness .tui . core as tui_core
21112111
21122112 tui , buf = make_tui ()
21132113 tui .session .client .log_path = "/tmp/llm.log"
21142114 with (
2115- mock .patch .object (tui_mod .config , "LLM_LOG_ENABLED" , True ),
2115+ mock .patch .object (tui_core .config , "LLM_LOG_ENABLED" , True ),
21162116 mock .patch .object (tui , "_read_multiline" , return_value = None ),
21172117 ):
21182118 tui .run ()
@@ -2212,7 +2212,7 @@ def boom(*a, **k):
22122212 raise RuntimeError ("stop" )
22132213
22142214 with (
2215- mock .patch ("python_agent_harness.tui.run_agent_loop" , side_effect = boom ),
2215+ mock .patch ("python_agent_harness.tui.core. run_agent_loop" , side_effect = boom ),
22162216 mock .patch .object (tui , "_run_live" , return_value = False ) as live ,
22172217 ):
22182218 tui ._start_agent ("hello" )
@@ -2233,7 +2233,7 @@ def test_start_agent_dumb_terminal(self):
22332233 file = io .StringIO (),
22342234 )
22352235 with (
2236- mock .patch ("python_agent_harness.tui.run_agent_loop" , side_effect = RuntimeError ("stop" )),
2236+ mock .patch ("python_agent_harness.tui.core. run_agent_loop" , side_effect = RuntimeError ("stop" )),
22372237 mock .patch .object (tui , "_run_dumb" , return_value = False ) as dumb ,
22382238 ):
22392239 tui ._start_agent ("hello" )
@@ -2249,7 +2249,7 @@ def test_start_agent_keyboard_interrupt(self):
22492249 q = UiQuestion ("Approve?" )
22502250 tui .question = q
22512251 with (
2252- mock .patch ("python_agent_harness.tui.run_agent_loop" , side_effect = RuntimeError ("stop" )),
2252+ mock .patch ("python_agent_harness.tui.core. run_agent_loop" , side_effect = RuntimeError ("stop" )),
22532253 mock .patch .object (tui , "_run_live" , side_effect = KeyboardInterrupt ),
22542254 ):
22552255 tui ._start_agent ("hello" , restore = lambda : released .append (1 ))
@@ -2318,7 +2318,7 @@ def test_run_agent_error_logged(self):
23182318 status bar."""
23192319 tui , _ = make_tui ()
23202320 with mock .patch (
2321- "python_agent_harness.tui.run_agent_loop" , side_effect = RuntimeError ("boom" )
2321+ "python_agent_harness.tui.core. run_agent_loop" , side_effect = RuntimeError ("boom" )
23222322 ):
23232323 tui ._run_agent ("hi" , tui .run_seq )
23242324 self .assertIn ("agent error: boom" , tui .status )
@@ -2328,7 +2328,7 @@ def test_run_agent_calls_restore(self):
23282328 tui , _ = make_tui ()
23292329 restored = []
23302330 with mock .patch (
2331- "python_agent_harness.tui.run_agent_loop" , side_effect = RuntimeError ("boom" )
2331+ "python_agent_harness.tui.core. run_agent_loop" , side_effect = RuntimeError ("boom" )
23322332 ):
23332333 tui ._run_agent ("hi" , tui .run_seq , restore = lambda : restored .append (1 ))
23342334 self .assertEqual (restored , [1 ])
@@ -2391,7 +2391,7 @@ def test_command_args_init_invalid_returns_none(self):
23912391 def test_run_slash_command_unknown (self ):
23922392 """A slash command with no registered SessionCommand is reported."""
23932393 tui , buf = make_tui ()
2394- with mock .patch ("python_agent_harness.tui.find_command" , return_value = None ):
2394+ with mock .patch ("python_agent_harness.tui.commands. find_command" , return_value = None ):
23952395 tui ._run_slash_command ("bogus" , "" )
23962396 self .assertIn ("unknown command: /bogus" , buf .getvalue ())
23972397
@@ -2434,7 +2434,7 @@ def test_conversation_text_empty(self):
24342434
24352435 def test_run_sessions_empty (self ):
24362436 tui , buf = make_tui ()
2437- with mock .patch ("python_agent_harness.tui.SessionStore.list_sessions" , return_value = []):
2437+ with mock .patch ("python_agent_harness.tui.commands. SessionStore.list_sessions" , return_value = []):
24382438 tui ._run_sessions ()
24392439 self .assertIn ("no saved sessions" , buf .getvalue ())
24402440
@@ -2450,7 +2450,7 @@ def test_run_sessions_lists_metadata(self):
24502450 ";; End:\n "
24512451 )
24522452 with mock .patch (
2453- "python_agent_harness.tui.SessionStore.list_sessions" ,
2453+ "python_agent_harness.tui.commands. SessionStore.list_sessions" ,
24542454 return_value = [path ],
24552455 ):
24562456 tui ._run_sessions ()
@@ -2462,7 +2462,7 @@ def test_run_sessions_lists_metadata(self):
24622462 def test_run_sessions_skips_unreadable_files (self ):
24632463 tui , buf = make_tui ()
24642464 with mock .patch (
2465- "python_agent_harness.tui.SessionStore.list_sessions" ,
2465+ "python_agent_harness.tui.commands. SessionStore.list_sessions" ,
24662466 return_value = ["/nonexistent/session.md" ],
24672467 ):
24682468 tui ._run_sessions () # must not raise
@@ -2475,7 +2475,7 @@ def test_restore_no_session_found(self):
24752475 """/restore with nothing to restore prints the yellow hint."""
24762476 tui , buf = make_tui ()
24772477 with mock .patch (
2478- "python_agent_harness.tui.SessionStore.latest_session" ,
2478+ "python_agent_harness.tui.commands. SessionStore.latest_session" ,
24792479 return_value = None ,
24802480 ):
24812481 tui ._run_restore ("" )
@@ -2489,7 +2489,7 @@ def test_restore_latest_session(self):
24892489 with open (path , "w" , encoding = "utf-8" ) as f :
24902490 f .write ("**user**: hello\n \n **assistant**: hi" )
24912491 with mock .patch (
2492- "python_agent_harness.tui.SessionStore.latest_session" ,
2492+ "python_agent_harness.tui.commands. SessionStore.latest_session" ,
24932493 return_value = path ,
24942494 ):
24952495 tui ._run_restore ("--latest" )
@@ -2506,7 +2506,7 @@ def test_restore_latest_keyword(self):
25062506 with open (path , "w" , encoding = "utf-8" ) as f :
25072507 f .write ("**user**: hello\n \n **assistant**: hi" )
25082508 with mock .patch (
2509- "python_agent_harness.tui.SessionStore.latest_session" ,
2509+ "python_agent_harness.tui.commands. SessionStore.latest_session" ,
25102510 return_value = path ,
25112511 ) as latest :
25122512 tui ._run_restore ("latest" )
@@ -2520,7 +2520,7 @@ def test_restore_resolved_path_not_a_file(self):
25202520 """A resolved path that is not a file reports an error."""
25212521 tui , buf = make_tui ()
25222522 with mock .patch (
2523- "python_agent_harness.tui.SessionStore.latest_session" ,
2523+ "python_agent_harness.tui.commands. SessionStore.latest_session" ,
25242524 return_value = "/nonexistent/session.md" ,
25252525 ):
25262526 tui ._run_restore ("--latest" )
@@ -2545,7 +2545,7 @@ def test_restore_by_title_match(self):
25452545 with open (path , "w" , encoding = "utf-8" ) as f :
25462546 f .write ("**user**: hello\n \n **assistant**: hi" )
25472547 with mock .patch (
2548- "python_agent_harness.tui.SessionStore.list_sessions" ,
2548+ "python_agent_harness.tui.commands. SessionStore.list_sessions" ,
25492549 return_value = [path ],
25502550 ):
25512551 tui ._run_restore ("MY SESSION" )
@@ -2562,7 +2562,7 @@ def test_find_session_by_title(self):
25622562 open (f , "w" , encoding = "utf-8" ).close ()
25632563 files = [dash , spaced ]
25642564 with mock .patch (
2565- "python_agent_harness.tui.SessionStore.list_sessions" ,
2565+ "python_agent_harness.tui.commands. SessionStore.list_sessions" ,
25662566 return_value = files ,
25672567 ):
25682568 # exact basename match (with and without .md)
@@ -2623,7 +2623,7 @@ def test_model_numbered_selection_matches_list(self):
26232623 tui .session .llm_settings = {"model" : "gpt-5-mini" , "base_url" : "https://default" }
26242624 tui .session .model = "glm-5.2" # current IS a profile (index 3)
26252625 with mock .patch (
2626- "python_agent_harness.tui.config.load_models_config" , return_value = profiles
2626+ "python_agent_harness.tui.commands. config.load_models_config" , return_value = profiles
26272627 ):
26282628 # 1 == default: switches back to the original model
26292629 with mock .patch .object (tui , "_model_switch_by_name" ) as switch :
@@ -2659,7 +2659,7 @@ def test_model_interactive_selection_can_switch_back_to_default(self):
26592659 tui .session .model = "deepseek-chat"
26602660 with (
26612661 mock .patch ("builtins.input" , return_value = "1" ),
2662- mock .patch ("python_agent_harness.tui.config.load_models_config" , return_value = profiles ),
2662+ mock .patch ("python_agent_harness.tui.commands. config.load_models_config" , return_value = profiles ),
26632663 mock .patch .object (tui , "_model_switch_by_name" ) as switch ,
26642664 ):
26652665 tui ._run_model_command ("" )
@@ -2671,7 +2671,7 @@ def test_model_switch_by_name(self):
26712671 profiles = {"deepseek" : {"model" : "deepseek-chat" }}
26722672 tui .session .model_profiles = dict (profiles )
26732673 with (
2674- mock .patch ("python_agent_harness.tui.config.load_models_config" , return_value = profiles ),
2674+ mock .patch ("python_agent_harness.tui.commands. config.load_models_config" , return_value = profiles ),
26752675 mock .patch .object (tui .session , "switch_model" , return_value = (True , "switched" )) as sw ,
26762676 ):
26772677 tui ._run_model_command ("deepseek" )
@@ -2685,7 +2685,7 @@ def test_model_reloads_profiles_from_config_each_call(self):
26852685 tui , buf = make_tui ()
26862686 # no profiles configured: default is still listed
26872687 with (
2688- mock .patch ("python_agent_harness.tui.config.load_models_config" , return_value = {}),
2688+ mock .patch ("python_agent_harness.tui.commands. config.load_models_config" , return_value = {}),
26892689 mock .patch ("builtins.input" , return_value = "" ),
26902690 ):
26912691 tui ._run_model_command ("" )
@@ -2696,7 +2696,7 @@ def test_model_reloads_profiles_from_config_each_call(self):
26962696 new_profiles = {"new" : {"model" : "new-model" , "base_url" : "https://new/v1" }}
26972697 with (
26982698 mock .patch (
2699- "python_agent_harness.tui.config.load_models_config" , return_value = new_profiles
2699+ "python_agent_harness.tui.commands. config.load_models_config" , return_value = new_profiles
27002700 ),
27012701 mock .patch ("builtins.input" , return_value = "" ),
27022702 ):
@@ -2705,7 +2705,7 @@ def test_model_reloads_profiles_from_config_each_call(self):
27052705 buf .truncate (0 )
27062706 # and switchable by name immediately
27072707 with mock .patch (
2708- "python_agent_harness.tui.config.load_models_config" , return_value = new_profiles
2708+ "python_agent_harness.tui.commands. config.load_models_config" , return_value = new_profiles
27092709 ):
27102710 tui ._run_model_command ("new" )
27112711 self .assertEqual (tui .session .model , "new-model" )
0 commit comments