feat(headless): Implement Phase 1 - Project Setup & Headless Scaffold
This commit is contained in:
48
tests/test_headless_startup.py
Normal file
48
tests/test_headless_startup.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import patch, MagicMock
|
||||
import gui_2
|
||||
|
||||
class TestHeadlessStartup(unittest.TestCase):
|
||||
|
||||
@patch('gui_2.immapp.run')
|
||||
@patch('gui_2.api_hooks.HookServer')
|
||||
@patch('gui_2.save_config')
|
||||
@patch('gui_2.ai_client.cleanup')
|
||||
@patch('uvicorn.run') # Mock uvicorn.run to prevent hanging
|
||||
def test_headless_flag_prevents_gui_run(self, mock_uvicorn_run, mock_cleanup, mock_save_config, mock_hook_server, mock_immapp_run):
|
||||
# Setup mock argv with --headless
|
||||
test_args = ["gui_2.py", "--headless"]
|
||||
|
||||
with patch.object(sys, 'argv', test_args):
|
||||
with patch('gui_2.session_logger.close_session'), \
|
||||
patch('gui_2.session_logger.open_session'):
|
||||
app = gui_2.App()
|
||||
|
||||
# Mock _fetch_models to avoid network calls
|
||||
app._fetch_models = MagicMock()
|
||||
|
||||
app.run()
|
||||
|
||||
# Expectation: immapp.run should NOT be called in headless mode
|
||||
mock_immapp_run.assert_not_called()
|
||||
# Expectation: uvicorn.run SHOULD be called
|
||||
mock_uvicorn_run.assert_called_once()
|
||||
|
||||
@patch('gui_2.immapp.run')
|
||||
def test_normal_startup_calls_gui_run(self, mock_immapp_run):
|
||||
test_args = ["gui_2.py"]
|
||||
with patch.object(sys, 'argv', test_args):
|
||||
# In normal mode, it should still call immapp.run
|
||||
with patch('gui_2.api_hooks.HookServer'), \
|
||||
patch('gui_2.save_config'), \
|
||||
patch('gui_2.ai_client.cleanup'), \
|
||||
patch('gui_2.session_logger.close_session'), \
|
||||
patch('gui_2.session_logger.open_session'):
|
||||
app = gui_2.App()
|
||||
app._fetch_models = MagicMock()
|
||||
app.run()
|
||||
mock_immapp_run.assert_called_once()
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user