wip test stabalization is a mess still

This commit is contained in:
2026-03-03 23:53:53 -05:00
parent c0a8777204
commit 3203891b79
17 changed files with 263 additions and 422 deletions

View File

@@ -21,13 +21,10 @@ class TestGeminiCliAdapter(unittest.TestCase):
Verify that send(message) correctly starts the subprocess with
--output-format stream-json and the provided message via stdin.
"""
# Setup mock process with a minimal valid JSONL termination
# Setup mock process
process_mock = MagicMock()
jsonl_output = [json.dumps({"type": "result", "usage": {}}) + "\n"]
process_mock.stdout.readline.side_effect = jsonl_output + ['']
process_mock.stderr.read.return_value = ""
process_mock.poll.return_value = 0
process_mock.wait.return_value = 0
jsonl_output = json.dumps({"type": "result", "usage": {}}) + "\n"
process_mock.communicate.return_value = (jsonl_output, "")
mock_popen.return_value = process_mock
message = "Hello Gemini CLI"
@@ -36,18 +33,15 @@ class TestGeminiCliAdapter(unittest.TestCase):
# Verify subprocess.Popen call
mock_popen.assert_called_once()
args, kwargs = mock_popen.call_args
cmd = args[0]
cmd_list = args[0]
# Check mandatory CLI components
self.assertIn("gemini", cmd)
self.assertIn("--output-format", cmd)
self.assertIn("stream-json", cmd)
self.assertIn("gemini", cmd_list)
self.assertIn("--output-format", cmd_list)
self.assertIn("stream-json", cmd_list)
# Message should NOT be in cmd now
self.assertNotIn(message, cmd)
# Verify message was written to stdin
process_mock.stdin.write.assert_called_with(message)
# Verify message was passed to communicate
process_mock.communicate.assert_called_with(input=message)
# Check process configuration
self.assertEqual(kwargs.get('stdout'), subprocess.PIPE)
@@ -60,16 +54,13 @@ class TestGeminiCliAdapter(unittest.TestCase):
Verify that it correctly parses multiple JSONL 'message' events
and returns the combined text.
"""
jsonl_output = [
json.dumps({"type": "message", "role": "model", "text": "The quick brown "}) + "\n",
json.dumps({"type": "message", "role": "model", "text": "fox jumps."}) + "\n",
jsonl_output = (
json.dumps({"type": "message", "role": "model", "text": "The quick brown "}) + "\n" +
json.dumps({"type": "message", "role": "model", "text": "fox jumps."}) + "\n" +
json.dumps({"type": "result", "usage": {"prompt_tokens": 5, "candidates_tokens": 5}}) + "\n"
]
)
process_mock = MagicMock()
process_mock.stdout.readline.side_effect = jsonl_output + ['']
process_mock.stderr.read.return_value = ""
process_mock.poll.return_value = 0
process_mock.wait.return_value = 0
process_mock.communicate.return_value = (jsonl_output, "")
mock_popen.return_value = process_mock
result = self.adapter.send("test message")
@@ -82,17 +73,14 @@ class TestGeminiCliAdapter(unittest.TestCase):
Verify that it correctly handles 'tool_use' events in the stream
by continuing to read until the final 'result' event.
"""
jsonl_output = [
json.dumps({"type": "message", "role": "assistant", "text": "Calling tool..."}) + "\n",
json.dumps({"type": "tool_use", "name": "read_file", "args": {"path": "test.txt"}}) + "\n",
json.dumps({"type": "message", "role": "assistant", "text": "\nFile read successfully."}) + "\n",
jsonl_output = (
json.dumps({"type": "message", "role": "assistant", "text": "Calling tool..."}) + "\n" +
json.dumps({"type": "tool_use", "name": "read_file", "args": {"path": "test.txt"}}) + "\n" +
json.dumps({"type": "message", "role": "assistant", "text": "\nFile read successfully."}) + "\n" +
json.dumps({"type": "result", "usage": {}}) + "\n"
]
)
process_mock = MagicMock()
process_mock.stdout.readline.side_effect = jsonl_output + ['']
process_mock.stderr.read.return_value = ""
process_mock.poll.return_value = 0
process_mock.wait.return_value = 0
process_mock.communicate.return_value = (jsonl_output, "")
mock_popen.return_value = process_mock
result = self.adapter.send("read test.txt")
@@ -107,15 +95,12 @@ class TestGeminiCliAdapter(unittest.TestCase):
Verify that usage data is extracted from the 'result' event.
"""
usage_data = {"total_tokens": 42}
jsonl_output = [
json.dumps({"type": "message", "text": "Finalizing"}) + "\n",
jsonl_output = (
json.dumps({"type": "message", "text": "Finalizing"}) + "\n" +
json.dumps({"type": "result", "usage": usage_data}) + "\n"
]
)
process_mock = MagicMock()
process_mock.stdout.readline.side_effect = jsonl_output + ['']
process_mock.stderr.read.return_value = ""
process_mock.poll.return_value = 0
process_mock.wait.return_value = 0
process_mock.communicate.return_value = (jsonl_output, "")
mock_popen.return_value = process_mock
self.adapter.send("usage test")