-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_agent_runner.py
More file actions
76 lines (61 loc) · 2.53 KB
/
Copy pathtest_agent_runner.py
File metadata and controls
76 lines (61 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import unittest
import tempfile
import shutil
from types import SimpleNamespace
from unittest.mock import patch, MagicMock
import agent_runner
class TestAgentRunner(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.mkdtemp()
def tearDown(self):
shutil.rmtree(self.temp_dir)
@patch('agent_runner.subprocess.run')
@patch('agent_runner.shutil.which')
@patch('agent_runner.logger')
def test_run_codex_uses_stdin_prompt(self, mock_logger, mock_which, mock_run):
mock_which.return_value = '/usr/bin/codex'
mock_run.return_value = MagicMock(returncode=0, stderr="OpenAI Codex\n\ntokens used\n1,227\n")
config = SimpleNamespace(
agent_cli='codex',
codex_exec_args=['--full-auto'],
codex_model=None,
codex_prompt_mode='stdin',
data_dir=self.temp_dir,
)
prompt = "Fix the failing test"
agent_runner.run_agent(prompt, self.temp_dir, config)
args, kwargs = mock_run.call_args
self.assertIn('codex', args[0][0])
self.assertEqual(args[0][:3], ['codex', 'exec', '-C'])
self.assertEqual(args[0][3], self.temp_dir)
self.assertEqual(args[0][4], '--full-auto')
self.assertEqual(args[0][-1], '-')
self.assertEqual(kwargs['input'], prompt)
mock_logger.info.assert_any_call("Codex token usage: %s tokens", "1,227")
@patch('agent_runner.subprocess.run')
@patch('agent_runner.shutil.which')
def test_run_kilocode_command(self, mock_which, mock_run):
mock_which.return_value = '/usr/bin/kilocode'
mock_run.return_value = MagicMock(returncode=0, stderr="")
config = SimpleNamespace(
agent_cli='kilocode',
kilocode_args=['-a', '-m', 'orchestrator', '-j'],
data_dir=self.temp_dir,
)
prompt = "Implement feature"
agent_runner.run_agent(prompt, self.temp_dir, config)
args, kwargs = mock_run.call_args
self.assertEqual(args[0][:4], ['kilocode', '-a', '-m', 'orchestrator'])
self.assertEqual(kwargs['input'], prompt)
@patch('agent_runner.shutil.which')
def test_missing_cli_raises(self, mock_which):
mock_which.return_value = None
config = SimpleNamespace(
agent_cli='kilocode',
kilocode_args=['-a'],
data_dir=self.temp_dir,
)
with self.assertRaises(FileNotFoundError):
agent_runner.run_agent("prompt", self.temp_dir, config)
if __name__ == '__main__':
unittest.main()