diff --git a/src/crewai/cli/reset_memories_command.py b/src/crewai/cli/reset_memories_command.py index 554232f52..6275f66ff 100644 --- a/src/crewai/cli/reset_memories_command.py +++ b/src/crewai/cli/reset_memories_command.py @@ -12,7 +12,7 @@ from crewai.utilities.task_output_storage_handler import TaskOutputStorageHandle def reset_memories_command( long, short, - entity, + entities, # Changed from entity to entities to match CLI parameter knowledge, kickoff_outputs, all, @@ -23,7 +23,7 @@ def reset_memories_command( Args: long (bool): Whether to reset the long-term memory. short (bool): Whether to reset the short-term memory. - entity (bool): Whether to reset the entity memory. + entities (bool): Whether to reset the entity memory. kickoff_outputs (bool): Whether to reset the latest kickoff task outputs. all (bool): Whether to reset all memories. knowledge (bool): Whether to reset the knowledge. @@ -45,7 +45,7 @@ def reset_memories_command( if short: ShortTermMemory().reset() click.echo("Short term memory has been reset.") - if entity: + if entities: # Changed from entity to entities EntityMemory().reset() click.echo("Entity memory has been reset.") if kickoff_outputs: diff --git a/tests/cli/test_reset_memories.py b/tests/cli/test_reset_memories.py new file mode 100644 index 000000000..a30e4b651 --- /dev/null +++ b/tests/cli/test_reset_memories.py @@ -0,0 +1,62 @@ +import os +import tempfile +from unittest.mock import patch, MagicMock + +import pytest +from click.testing import CliRunner + +from crewai.cli.cli import reset_memories +from crewai.cli.reset_memories_command import reset_memories_command + + +def test_reset_memories_command_parameters(): + """Test that the CLI parameters match the function parameters.""" + # Create a mock for reset_memories_command + with patch('crewai.cli.cli.reset_memories_command') as mock_reset: + runner = CliRunner() + + # Test with entities flag + result = runner.invoke(reset_memories, ['--entities']) + assert result.exit_code == 0 + + # Check that the function was called with the correct parameters + # The third parameter should be True for entities + mock_reset.assert_called_once_with(False, False, True, False, False, False) + + +def test_reset_memories_all_flag(): + """Test that the --all flag resets all memories.""" + with patch('crewai.cli.cli.reset_memories_command') as mock_reset: + runner = CliRunner() + + # Test with all flag + result = runner.invoke(reset_memories, ['--all']) + assert result.exit_code == 0 + + # Check that the function was called with the correct parameters + # The last parameter should be True for all + mock_reset.assert_called_once_with(False, False, False, False, False, True) + + +def test_reset_memories_knowledge_flag(): + """Test that the --knowledge flag resets knowledge storage.""" + with patch('crewai.cli.cli.reset_memories_command') as mock_reset: + runner = CliRunner() + + # Test with knowledge flag + result = runner.invoke(reset_memories, ['--knowledge']) + assert result.exit_code == 0 + + # Check that the function was called with the correct parameters + # The fourth parameter should be True for knowledge + mock_reset.assert_called_once_with(False, False, False, True, False, False) + + +def test_reset_memories_no_flags(): + """Test that an error message is shown when no flags are provided.""" + runner = CliRunner() + + # Test with no flags + result = runner.invoke(reset_memories, []) + assert result.exit_code == 0 + assert "Please specify at least one memory type" in result.output