feat: add test suite for core modules
Some checks failed
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
2026-01-31 10:29:09 +00:00
parent 1530177c32
commit ac4654aabf

161
tests/test_models.py Normal file
View File

@@ -0,0 +1,161 @@
"""Tests for CLI Command Memory models."""
from cli_memory.models import Project, Command, Workflow, Suggestion, Pattern, CommandType
def test_project_creation():
"""Test Project model creation."""
project = Project(
name="test-project",
path="/tmp/test",
git_remote="https://github.com/user/test.git",
tech_stack=["python", "docker"],
)
assert project.name == "test-project"
assert project.path == "/tmp/test"
assert project.git_remote == "https://github.com/user/test.git"
assert "python" in project.tech_stack
def test_project_to_dict():
"""Test Project serialization."""
project = Project(
id=1,
name="test",
path="/path",
git_remote="git@github.com:test.git",
tech_stack=["go"],
)
data = project.to_dict()
assert data["id"] == 1
assert data["name"] == "test"
assert data["tech_stack"] == ["go"]
def test_project_from_dict():
"""Test Project deserialization."""
data = {
"id": 5,
"name": "from_dict",
"path": "/some/path",
"git_remote": None,
"tech_stack": ["rust"],
"created_at": "2024-01-01T00:00:00",
"updated_at": "2024-01-01T00:00:00",
}
project = Project.from_dict(data)
assert project.id == 5
assert project.name == "from_dict"
assert "rust" in project.tech_stack
def test_command_creation():
"""Test Command model creation."""
cmd = Command(
command="git status",
command_type=CommandType.GIT,
exit_code=0,
duration_ms=50,
working_directory="/home/user/project",
)
assert cmd.command == "git status"
assert cmd.command_type == CommandType.GIT
assert cmd.exit_code == 0
def test_command_classification():
"""Test command type classification."""
from cli_memory.recorder import CommandRecorder
recorder = CommandRecorder()
cmd = recorder.record_command(command="docker ps")
assert cmd.command_type == CommandType.DOCKER
cmd = recorder.record_command(command="npm run build")
assert cmd.command_type == CommandType.BUILD
cmd = recorder.record_command(command="pytest tests/")
assert cmd.command_type == CommandType.TEST
cmd = recorder.record_command(command="kubectl deploy")
assert cmd.command_type == CommandType.DEPLOY
def test_command_to_dict():
"""Test Command serialization."""
cmd = Command(
id=1,
command="ls -la",
command_type=CommandType.SYSTEM,
exit_code=0,
tags=["important", "review"],
)
data = cmd.to_dict()
assert data["command"] == "ls -la"
assert data["command_type"] == "system"
assert "important" in data["tags"]
def test_workflow_creation():
"""Test Workflow model creation."""
cmd1 = Command(command="git checkout -b feature")
cmd2 = Command(command="git commit -m 'feat: add feature'")
workflow = Workflow(
name="Feature Branch Workflow",
description="Create and commit to feature branch",
commands=[cmd1, cmd2],
)
assert len(workflow.commands) == 2
assert workflow.name == "Feature Branch Workflow"
assert workflow.is_automated is False
def test_workflow_to_dict():
"""Test Workflow serialization."""
cmd = Command(command="echo hello")
workflow = Workflow(
id=1,
name="Test Workflow",
description="A test workflow",
commands=[cmd],
)
data = workflow.to_dict()
assert data["name"] == "Test Workflow"
assert len(data["commands"]) == 1
def test_suggestion_creation():
"""Test Suggestion model creation."""
suggestion = Suggestion(
command="git push",
context="git commit",
confidence=0.85,
frequency=10,
)
assert suggestion.command == "git push"
assert suggestion.confidence == 0.85
def test_pattern_creation():
"""Test Pattern model creation."""
pattern = Pattern(
name="Git workflow pattern",
command_sequence=["git status", "git add .", "git commit -m", "git push"],
occurrences=5,
confidence=0.75,
)
assert len(pattern.command_sequence) == 4
assert pattern.occurrences == 5
def test_command_type_enum():
"""Test CommandType enum values."""
assert CommandType.GIT.value == "git"
assert CommandType.DOCKER.value == "docker"
assert CommandType.BUILD.value == "build"
assert CommandType.TEST.value == "test"
assert CommandType.DEPLOY.value == "deploy"
assert CommandType.FILE_OP.value == "file_op"
assert CommandType.SYSTEM.value == "system"
assert CommandType.OTHER.value == "other"