test_enhanced_handlers.py•5.18 kB
# Aidderall MCP Server - Hierarchical task management for AI assistants
# Copyright (C) 2024 Briam R. <briamr@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import asyncio
import pytest
from src.handlers import AidderallHandlers
from src.task_manager import TaskManager
class TestEnhancedHandlers:
def setup_method(self):
self.task_manager = TaskManager()
self.handlers = AidderallHandlers(self.task_manager)
@pytest.mark.asyncio
async def test_handle_peek_context_with_body(self):
# Create main task and sub task
await self.handlers.handle_create_new_task("Main Task", "Main Body")
await self.handlers.handle_extend_current_task("Sub Task", "Sub Body")
# Test without body
result = await self.handlers.handle_peek_context(include_body=False)
assert "body" not in result["parent_context"]
assert "created_at" in result["parent_context"]
assert "status" in result["parent_context"]
# Test with body
result = await self.handlers.handle_peek_context(include_body=True)
assert result["parent_context"]["body"] == "Main Body"
assert "created_at" in result["parent_context"]
assert "status" in result["parent_context"]
@pytest.mark.asyncio
async def test_handle_list_siblings_with_body(self):
# Create main task and multiple sub tasks
await self.handlers.handle_create_new_task("Main Task", "Main Body")
await self.handlers.handle_extend_current_task("Sub Task 1", "Sub Body 1")
await self.handlers.handle_extend_current_task("Sub Task 2", "Sub Body 2")
# Test without body
result = await self.handlers.handle_list_siblings(include_body=False)
assert result["count"] == 1
assert "body" not in result["siblings"][0]
assert "created_at" in result["siblings"][0]
assert "status" in result["siblings"][0]
# Test with body
result = await self.handlers.handle_list_siblings(include_body=True)
assert result["count"] == 1
assert result["siblings"][0]["body"] == "Sub Body 1"
assert "created_at" in result["siblings"][0]
@pytest.mark.asyncio
async def test_handle_get_big_picture_json_format(self):
# Create tasks
await self.handlers.handle_create_new_task("Main Task 1", "Body 1")
await self.handlers.handle_extend_current_task("Sub Task 1", "Sub Body 1")
# Test text format (default)
result = await self.handlers.handle_get_big_picture(format="text")
assert "structure" in result
assert isinstance(result["structure"], str)
assert "Main Task 1" in result["structure"]
# Test JSON format
result = await self.handlers.handle_get_big_picture(format="json")
assert "zen_state" in result
assert "tasks" in result
assert len(result["tasks"]) == 1
assert result["tasks"][0]["title"] == "Main Task 1"
assert result["tasks"][0]["is_current"] == False
assert "created_at" in result["tasks"][0]
assert len(result["tasks"][0]["sub_tasks"]) == 1
assert result["tasks"][0]["sub_tasks"][0]["is_current"] == True
@pytest.mark.asyncio
async def test_handle_get_stack_overview_with_timestamps(self):
# Create tasks
await self.handlers.handle_create_new_task("Main Task", "Body")
await self.handlers.handle_extend_current_task("Sub Task", "Sub Body")
result = await self.handlers.handle_get_stack_overview()
# Check main task has timestamps
main_task = result["global_tasks"][0]
assert "created_at" in main_task
assert "completed_at" in main_task
assert main_task["completed_at"] is None # Not completed yet
# Check sub task has timestamps
sub_task = main_task["sub_tasks"][0]
assert "created_at" in sub_task
assert "completed_at" in sub_task
assert sub_task["completed_at"] is None # Not completed yet
@pytest.mark.asyncio
async def test_completed_task_timestamps(self):
# Create and complete a task
await self.handlers.handle_create_new_task("Task to Complete", "Body")
await self.handlers.handle_complete_current_task()
# Check completed tasks have timestamps
result = await self.handlers.handle_get_completed_tasks()
assert result["count"] == 1
task = result["tasks"][0]
assert "completed_at" in task
assert task["completed_at"] is not None # Should have a timestamp