fix: Fix all failing test files with proper mocking and imports

- test_tiered_context.py: Fix aggregate imports to src.aggregate
- test_gemini_cli_adapter_parity.py: Fix subprocess.Popen mock path and JSON format
- test_gemini_cli_edge_cases.py: Fix mock path, JSON format, and adapter initialization
- test_gemini_cli_parity_regression.py: Fix mock path, reset global adapter
- test_token_usage.py: Fix SimpleNamespace mock structure for gemini response
This commit is contained in:
2026-03-05 20:15:03 -05:00
parent e02ebf7a65
commit 2c5476dc5d
7 changed files with 102 additions and 139 deletions

View File

@@ -6,25 +6,20 @@ from src.gemini_cli_adapter import GeminiCliAdapter
class TestGeminiCliAdapterParity(unittest.TestCase):
def setUp(self) -> None:
"""Set up a fresh adapter instance and reset session state for each test."""
self.adapter = GeminiCliAdapter(binary_path="gemini")
def tearDown(self) -> None:
pass
def test_count_tokens_fallback(self) -> None:
"""Test the character-based token estimation fallback."""
contents = ["Hello", "world!"]
estimated = self.adapter.count_tokens(contents)
# "Hello\nworld!" is 12 chars. 12 // 4 = 3
self.assertEqual(estimated, 3)
@patch('subprocess.Popen')
@patch('src.gemini_cli_adapter.subprocess.Popen')
def test_send_starts_subprocess_with_model(self, mock_popen: MagicMock) -> None:
"""Test that the send method correctly adds the -m <model> flag when a model is specified."""
mock_process = MagicMock()
mock_process.stdout = [b'{"kind": "message", "payload": "hi"}']
mock_process.stderr = []
mock_process.communicate.return_value = ('{"type": "message", "content": "hi"}', '')
mock_process.returncode = 0
mock_popen.return_value = mock_process
@@ -35,24 +30,21 @@ class TestGeminiCliAdapterParity(unittest.TestCase):
self.assertIn("-m", cmd_list)
self.assertIn("gemini-2.0-flash", cmd_list)
@patch('subprocess.Popen')
@patch('src.gemini_cli_adapter.subprocess.Popen')
def test_send_parses_tool_calls_from_streaming_json(self, mock_popen: MagicMock) -> None:
"""Test that tool_use messages in the streaming JSON are correctly parsed."""
tool_call_json = {
"kind": "tool_use",
"payload": {
"id": "call_abc",
"name": "list_directory",
"input": {"path": "."}
}
"type": "tool_use",
"tool_name": "list_directory",
"parameters": {"path": "."},
"tool_id": "call_abc"
}
mock_process = MagicMock()
mock_process.stdout = [
(json.dumps(tool_call_json) + "\n").encode('utf-8'),
b'{"kind": "message", "payload": "I listed the files."}'
]
mock_process.stderr = []
stdout_output = (
json.dumps(tool_call_json) + "\n" +
'{"type": "message", "content": "I listed the files."}'
)
mock_process.communicate.return_value = (stdout_output, '')
mock_process.returncode = 0
mock_popen.return_value = mock_process