Initial commit: VoIdeaAI - voice-first AI idea assistant
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
"""Tests for BaseAgent versioning methods."""
|
||||
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app.agents.base import BaseAgent
|
||||
|
||||
|
||||
class SimpleTestAgent(BaseAgent):
|
||||
"""Minimal agent for testing base methods."""
|
||||
|
||||
name = "test_agent"
|
||||
version = "1.0.0"
|
||||
description = "Test agent"
|
||||
|
||||
async def run(self, context=None):
|
||||
return await super().run(context) # pragma: no cover
|
||||
|
||||
async def health_check(self):
|
||||
return True
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def agent():
|
||||
return SimpleTestAgent()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cleanup_changelog():
|
||||
yield
|
||||
path = Path("CHANGELOG") / "agents" / "test_agent.md"
|
||||
if path.exists():
|
||||
path.unlink()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_agent_initialization(agent):
|
||||
"""Test agent initializes with default version."""
|
||||
assert agent.name == "test_agent"
|
||||
assert agent.version == "1.0.0"
|
||||
|
||||
|
||||
def test_compute_checksum(agent):
|
||||
"""Test compute_checksum returns valid SHA256."""
|
||||
checksum = agent.compute_checksum()
|
||||
assert len(checksum) == 64
|
||||
assert all(c in "0123456789abcdef" for c in checksum)
|
||||
|
||||
|
||||
def test_compute_checksum_is_deterministic(agent):
|
||||
"""Test checksum is deterministic for same file."""
|
||||
assert agent.compute_checksum() == agent.compute_checksum()
|
||||
|
||||
|
||||
def test_bump_version_patch(agent):
|
||||
"""Test bump_version patch increments patch."""
|
||||
new_version = agent.bump_version("patch")
|
||||
assert new_version == "1.0.1"
|
||||
assert agent.version == "1.0.1"
|
||||
|
||||
|
||||
def test_bump_version_minor(agent):
|
||||
"""Test bump_version minor increments minor, resets patch."""
|
||||
agent.version = "1.0.5"
|
||||
new_version = agent.bump_version("minor")
|
||||
assert new_version == "1.1.0"
|
||||
assert agent.version == "1.1.0"
|
||||
|
||||
|
||||
def test_bump_version_major(agent):
|
||||
"""Test bump_version major increments major, resets minor and patch."""
|
||||
agent.version = "1.2.3"
|
||||
new_version = agent.bump_version("major")
|
||||
assert new_version == "2.0.0"
|
||||
assert agent.version == "2.0.0"
|
||||
|
||||
|
||||
def test_bump_version_default_is_patch(agent):
|
||||
"""Test bump_version defaults to patch."""
|
||||
agent.version = "2.0.0"
|
||||
new_version = agent.bump_version()
|
||||
assert new_version == "2.0.1"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_changelog_entry_creates_file(agent, cleanup_changelog):
|
||||
"""Test _write_changelog_entry creates a new changelog file."""
|
||||
agent._write_changelog_entry("1.0.0", ["Initial version"])
|
||||
path = Path("CHANGELOG") / "agents" / "test_agent.md"
|
||||
assert path.exists()
|
||||
content = path.read_text(encoding="utf-8")
|
||||
assert "# test_agent Changelog" in content
|
||||
assert "## 1.0.0" in content
|
||||
assert "- Initial version" in content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_changelog_entry_appends(agent, cleanup_changelog):
|
||||
"""Test _write_changelog_entry appends to existing file."""
|
||||
agent._write_changelog_entry("1.0.0", ["Initial version"])
|
||||
agent._write_changelog_entry("1.0.1", ["Bugfix"])
|
||||
path = Path("CHANGELOG") / "agents" / "test_agent.md"
|
||||
content = path.read_text(encoding="utf-8")
|
||||
assert "## 1.0.0" in content
|
||||
assert "## 1.0.1" in content
|
||||
assert "- Bugfix" in content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_check_version_no_changelog(agent, cleanup_changelog):
|
||||
"""Test _check_version creates initial changelog on first run."""
|
||||
result = await agent._check_version(["Initial version"])
|
||||
assert result is not None
|
||||
path = Path("CHANGELOG") / "agents" / "test_agent.md"
|
||||
assert path.exists()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_check_version_unchanged(agent, cleanup_changelog):
|
||||
"""Test _check_version returns None when nothing changed."""
|
||||
agent._write_changelog_entry("1.0.0", ["Initial version"])
|
||||
result = await agent._check_version()
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_changelog_dir_default(agent):
|
||||
"""Test changelog_dir attribute."""
|
||||
assert str(agent.changelog_dir) == "CHANGELOG\\agents"
|
||||
Reference in New Issue
Block a user