From d89aca3dbb11ffa853abfa834311a8497cdcf4be Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 08:31:42 +0000 Subject: [PATCH] Add remaining test files --- .tests/test_recorder.py | 136 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 .tests/test_recorder.py diff --git a/.tests/test_recorder.py b/.tests/test_recorder.py new file mode 100644 index 0000000..17284ab --- /dev/null +++ b/.tests/test_recorder.py @@ -0,0 +1,136 @@ +"""Tests for CLI Command Memory recorder.""" + +import tempfile +import os +from cli_memory.recorder import CommandRecorder +from cli_memory.models import Command, CommandType +from cli_memory.config import Config + + +def test_recorder_initialization(): + """Test recorder initializes correctly.""" + recorder = CommandRecorder() + assert recorder._current_project is None + + +def test_record_command(): + """Test recording a single command.""" + recorder = CommandRecorder() + cmd = recorder.record_command( + command="ls -la", + exit_code=0, + duration_ms=25, + ) + assert cmd.command == "ls -la" + assert cmd.exit_code == 0 + assert cmd.duration_ms == 25 + + +def test_record_multiple_commands(): + """Test recording multiple commands.""" + recorder = CommandRecorder() + recorder.record_command(command="pwd", exit_code=0) + recorder.record_command(command="ls", exit_code=0) + recorder.record_command(command="cd /tmp", exit_code=0) + + assert recorder is not None + + +def test_command_classification_git(): + """Test git command classification.""" + recorder = CommandRecorder() + cmd = recorder.record_command(command="git status") + assert cmd.command_type == CommandType.GIT + + cmd = recorder.record_command(command="git checkout main") + assert cmd.command_type == CommandType.GIT + + +def test_command_classification_docker(): + """Test docker command classification.""" + recorder = CommandRecorder() + cmd = recorder.record_command(command="docker ps") + assert cmd.command_type == CommandType.DOCKER + + cmd = recorder.record_command(command="docker-compose up -d") + assert cmd.command_type == CommandType.DOCKER + + +def test_command_classification_build(): + """Test build command classification.""" + recorder = CommandRecorder() + cmd = recorder.record_command(command="make build") + assert cmd.command_type == CommandType.BUILD + + cmd = recorder.record_command(command="npm run build") + assert cmd.command_type == CommandType.BUILD + + +def test_command_classification_test(): + """Test test command classification.""" + recorder = CommandRecorder() + cmd = recorder.record_command(command="pytest") + assert cmd.command_type == CommandType.TEST + + cmd = recorder.record_command(command="npm test") + assert cmd.command_type == CommandType.TEST + + +def test_command_classification_deploy(): + """Test deploy command classification.""" + recorder = CommandRecorder() + cmd = recorder.record_command(command="kubectl apply -f deploy.yaml") + assert cmd.command_type == CommandType.DEPLOY + + +def test_command_classification_file_op(): + """Test file operation classification.""" + recorder = CommandRecorder() + cmd = recorder.record_command(command="cp file1 file2") + assert cmd.command_type == CommandType.FILE_OP + + cmd = recorder.record_command(command="rm -rf temp") + assert cmd.command_type == CommandType.FILE_OP + + +def test_command_classification_system(): + """Test system command classification.""" + recorder = CommandRecorder() + cmd = recorder.record_command(command="sudo apt-get update") + assert cmd.command_type == CommandType.SYSTEM + + +def test_command_classification_other(): + """Test unknown command classification.""" + recorder = CommandRecorder() + cmd = recorder.record_command(command="my_custom_command arg1 arg2") + assert cmd.command_type == CommandType.OTHER + + +def test_record_with_tags(): + """Test recording with tags.""" + recorder = CommandRecorder() + cmd = recorder.record_command( + command="echo test", + tags=["test-tag", "debug"], + ) + assert "test-tag" in cmd.tags + assert "debug" in cmd.tags + + +def test_record_with_metadata(): + """Test recording with metadata.""" + recorder = CommandRecorder() + cmd = recorder.record_command( + command="echo test", + metadata={"key": "value", "count": 5}, + ) + assert cmd.metadata["key"] == "value" + assert cmd.metadata["count"] == 5 + + +def test_sanitize_command(): + """Test command sanitization.""" + recorder = CommandRecorder() + sanitized = recorder.sanitize_command(" ls -la ") + assert sanitized == "ls -la"