async def test_main_with_session_name_passes_name_to_run_session(
    mock_noop_condenser,
    mock_llm_condenser,
    mock_run_session,
    mock_read_task,
    mock_check_security,
    mock_get_settings_store,
    mock_setup_config,
    mock_parse_args,
):
    """Test main function with a session name passes it to run_session."""
    loop = asyncio.get_running_loop()
    test_session_name = 'my_named_session'

    # Mock arguments
    mock_args = MagicMock()
    mock_args.agent_cls = None
    mock_args.llm_config = None
    mock_args.name = test_session_name  # Set the session name
    mock_parse_args.return_value = mock_args

    # Mock config
    mock_config = MagicMock()
    mock_config.workspace_base = '/test/dir'
    mock_config.cli_multiline_input = False
    mock_setup_config.return_value = mock_config

    # Mock settings store
    mock_settings_store = AsyncMock()
    mock_settings = MagicMock()
    mock_settings.agent = 'test-agent'
    mock_settings.llm_model = 'test-model'  # Copied from test_main_without_task
    mock_settings.llm_api_key = 'test-api-key'  # Copied from test_main_without_task
    mock_settings.llm_base_url = 'test-base-url'  # Copied from test_main_without_task
    mock_settings.confirmation_mode = True  # Copied from test_main_without_task
    mock_settings.enable_default_condenser = True  # Copied from test_main_without_task
    mock_settings_store.load.return_value = mock_settings
    mock_get_settings_store.return_value = mock_settings_store

    # Mock condenser config (as in test_main_without_task)
    mock_llm_condenser_instance = MagicMock()
    mock_llm_condenser.return_value = mock_llm_condenser_instance

    # Mock security check
    mock_check_security.return_value = True

    # Mock read_task to return no task
    mock_read_task.return_value = None

    # Mock run_session to return False (no new session requested)
    mock_run_session.return_value = False

    # Run the function
    await cli.main_with_loop(loop)

    # Assertions
    mock_parse_args.assert_called_once()
    mock_setup_config.assert_called_once_with(mock_args)
    mock_get_settings_store.assert_called_once()
    mock_settings_store.load.assert_called_once()
    mock_check_security.assert_called_once_with(mock_config, '/test/dir')
    mock_read_task.assert_called_once()

    # Check that run_session was called with the correct session_name
    mock_run_session.assert_called_once_with(
        loop,
        mock_config,
        mock_settings_store,
        '/test/dir',
        None,
        session_name=test_session_name,
        skip_banner=False,
    )
Test main function with a session name passes it to run_session.
tests/unit/test_cli.py