forked from Rockachopa/Timmy-time-dashboard
Merge pull request '[loop-cycle-12] feat: Kimi delegation tool for coding tasks (#67)' (#112) from fix/kimi-delegation-67 into main
This commit is contained in:
@@ -50,3 +50,103 @@ class TestListSwarmAgents:
|
||||
assert "Seer" in agent_names
|
||||
assert "Forge" in agent_names
|
||||
assert "Timmy" in agent_names
|
||||
|
||||
|
||||
class TestDelegateToKimi:
|
||||
"""Tests for delegate_to_kimi() — Timmy's Kimi delegation tool."""
|
||||
|
||||
def test_returns_dict(self, monkeypatch):
|
||||
"""delegate_to_kimi should always return a dict."""
|
||||
import shutil
|
||||
|
||||
monkeypatch.setattr(shutil, "which", lambda x: None)
|
||||
from timmy.tools_delegation import delegate_to_kimi
|
||||
|
||||
result = delegate_to_kimi("test task")
|
||||
assert isinstance(result, dict)
|
||||
assert "success" in result
|
||||
|
||||
def test_kimi_not_found_returns_error(self, monkeypatch):
|
||||
"""Should handle missing kimi CLI gracefully."""
|
||||
import shutil
|
||||
|
||||
monkeypatch.setattr(shutil, "which", lambda x: None)
|
||||
from timmy.tools_delegation import delegate_to_kimi
|
||||
|
||||
result = delegate_to_kimi("test task")
|
||||
assert result["success"] is False
|
||||
assert "not found" in result["error"]
|
||||
|
||||
def test_invalid_workdir_returns_error(self, monkeypatch):
|
||||
"""Should reject non-existent working directories."""
|
||||
import shutil
|
||||
|
||||
monkeypatch.setattr(shutil, "which", lambda x: "/usr/bin/kimi")
|
||||
from timmy.tools_delegation import delegate_to_kimi
|
||||
|
||||
result = delegate_to_kimi("test", working_directory="/nonexistent/path")
|
||||
assert result["success"] is False
|
||||
assert "does not exist" in result["error"]
|
||||
|
||||
def test_timeout_returns_error(self, monkeypatch):
|
||||
"""Should handle subprocess timeout gracefully."""
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
monkeypatch.setattr(shutil, "which", lambda x: "/usr/bin/kimi")
|
||||
|
||||
def timeout_run(*args, **kwargs):
|
||||
raise subprocess.TimeoutExpired(cmd="kimi", timeout=300)
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", timeout_run)
|
||||
from timmy.tools_delegation import delegate_to_kimi
|
||||
|
||||
result = delegate_to_kimi("complex task")
|
||||
assert result["success"] is False
|
||||
assert "timed out" in result["error"].lower()
|
||||
|
||||
def test_successful_delegation(self, monkeypatch):
|
||||
"""Should capture Kimi's output on success."""
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
monkeypatch.setattr(shutil, "which", lambda x: "/usr/bin/kimi")
|
||||
|
||||
def mock_run(*args, **kwargs):
|
||||
return subprocess.CompletedProcess(
|
||||
args=args[0] if args else [],
|
||||
returncode=0,
|
||||
stdout="Fixed the bug in session.py\n\nChanges:\n- Added null check",
|
||||
stderr="",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", mock_run)
|
||||
from config import settings
|
||||
from timmy.tools_delegation import delegate_to_kimi
|
||||
|
||||
result = delegate_to_kimi("fix session bug", working_directory=settings.repo_root)
|
||||
assert result["success"] is True
|
||||
assert "Fixed the bug" in result["output"]
|
||||
assert result["return_code"] == 0
|
||||
|
||||
def test_default_workdir_uses_repo_root(self, monkeypatch):
|
||||
"""Empty working_directory should default to settings.repo_root."""
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
calls = []
|
||||
monkeypatch.setattr(shutil, "which", lambda x: "/usr/bin/kimi")
|
||||
|
||||
def capture_run(*args, **kwargs):
|
||||
calls.append(kwargs.get("cwd", ""))
|
||||
return subprocess.CompletedProcess(
|
||||
args=args[0] if args else [], returncode=0, stdout="done", stderr=""
|
||||
)
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", capture_run)
|
||||
from config import settings
|
||||
from timmy.tools_delegation import delegate_to_kimi
|
||||
|
||||
delegate_to_kimi("test task")
|
||||
assert len(calls) == 1
|
||||
assert calls[0] == settings.repo_root
|
||||
|
||||
Reference in New Issue
Block a user