Пример #1
0
def test_should_return_an_error_when_selected_is_empty(mocker):
    mock_agent = create_mock_agent()
    mocker.patch.object(AgentDatasource,
                        'get_instances',
                        return_value=[mock_agent],
                        autospec=True)
    mocker.patch.object(AgentDatasource,
                        'all_plugins',
                        return_value=ALL_PLUGINS,
                        autospec=True)
    mocker.patch.object(ConfigStorage,
                        'read_config',
                        return_value=PluginConfig(selected=["nlc2cmd"]),
                        autospec=True)
    mocker.patch.object(ConfigStorage,
                        'store_config',
                        return_value=None,
                        autospec=True)
    message_handler = MessageHandler(ServerStatusDatasource(),
                                     AgentDatasource())

    select_agent = clai_select_state('')
    action = message_handler.process_message(select_agent)

    assert action.suggested_command == NOOP_COMMAND
    assert action.origin_command == select_agent.command
    assert action.execute
    assert action.description == create_error_select('').description
    assert message_handler.agent_datasource.get_current_plugin_name(
        select_agent.user_name) == ['nlc2cmd']
Пример #2
0
    def execute(self, state: State) -> Action:
        plugin_to_select = state.command.replace(f'{self.SELECT_DIRECTIVE}',
                                                 '').strip()
        plugin_to_select = extract_quoted_agent_name(plugin_to_select)

        agent_descriptor = self.agent_datasource.get_agent_descriptor(
            plugin_to_select)

        plugins_config = self.config_storage.read_config(None)

        if not agent_descriptor:
            return create_error_select(plugin_to_select)

        if agent_descriptor and not agent_descriptor.installed:
            logger.info(
                f'installing dependencies of plugin {agent_descriptor.name}')

            command = f'$CLAI_PATH/fileExist.sh {agent_descriptor.pkg_name} $CLAI_PATH' \
                    f'{" --user" if plugins_config.user_install else ""}'
            action_selected_to_return = Action(suggested_command=command,
                                               execute=True)
        else:
            self.select_plugin(plugin_to_select, state)
            action_selected_to_return = Action(suggested_command=":",
                                               execute=True)

        action_selected_to_return.origin_command = state.command
        return action_selected_to_return