feat: add more tests for generator, patterns, recorder, and search
Some checks failed
CI / test (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-01-31 10:30:01 +00:00
parent 79db1935ff
commit 189098c432

133
tests/test_recorder.py Normal file
View File

@@ -0,0 +1,133 @@
"""Tests for CLI Command Memory recorder."""
from cli_memory.recorder import CommandRecorder
from cli_memory.models import CommandType
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"