Files
agentic-codebase-memory-man…/tests/integration/test_cli.py
7000pctAUTO b27e444a50
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
Add conftest.py and remaining test files
2026-03-22 16:21:32 +00:00

92 lines
2.2 KiB
Python

"""Integration tests for CLI commands."""
import os
import pytest
from click.testing import CliRunner
from memory_manager.cli.main import cli
TEST_DB_PATH = ".memory/test_cli_memory.db"
def clean_test_db():
if os.path.exists(TEST_DB_PATH):
os.remove(TEST_DB_PATH)
db_dir = os.path.dirname(TEST_DB_PATH)
if db_dir and not os.path.exists(db_dir):
os.makedirs(db_dir, exist_ok=True)
@pytest.fixture(autouse=True)
def reset_env():
clean_test_db()
os.environ["MEMORY_DB_PATH"] = TEST_DB_PATH
yield
clean_test_db()
@pytest.fixture
def runner():
return CliRunner()
def test_cli_version(runner):
result = runner.invoke(cli, ["--version"])
assert result.exit_code == 0
assert "0.1.0" in result.output
def test_add_command_no_tags(runner):
result = runner.invoke(cli, [
"add",
"--title", "Test Decision",
"--content", "We decided to use PostgreSQL",
"--category", "decision",
])
assert result.exit_code == 0
def test_add_command_invalid_category(runner):
result = runner.invoke(cli, [
"add",
"--title", "Test",
"--content", "Content",
"--category", "invalid_category",
])
assert result.exit_code != 0
def test_list_command_empty(runner):
result = runner.invoke(cli, ["list"])
assert result.exit_code == 0
assert "No entries found" in result.output
def test_get_command_empty(runner):
result = runner.invoke(cli, ["get", "1"])
assert result.exit_code == 0
assert "not found" in result.output
def test_delete_command_not_found(runner):
result = runner.invoke(cli, ["delete", "1"])
assert result.exit_code == 0
assert "not found" in result.output
def test_commit_command_empty(runner):
result = runner.invoke(cli, ["commit", "--message", "Initial commit"])
assert result.exit_code == 0
assert "Created commit" in result.output
def test_log_command(runner):
runner.invoke(cli, ["commit", "--message", "Test commit"])
result = runner.invoke(cli, ["log"])
assert result.exit_code == 0
assert "commit" in result.output
def test_diff_command_no_commits(runner):
result = runner.invoke(cli, ["diff", "abc123", "def456"])
assert result.exit_code == 0