feat(controller): Integrate py_get_definition for on-demand lookup

This commit is contained in:
2026-03-07 15:03:03 -05:00
parent 953e9e040c
commit c6f9dc886f
4 changed files with 62 additions and 24 deletions

View File

@@ -1,27 +1,58 @@
import pytest
from src.app_controller import parse_symbols
import unittest
from unittest.mock import patch, MagicMock
from src.app_controller import parse_symbols, get_symbol_definition
def test_parse_symbols_basic():
text = "Check @MyClass and @my_func."
symbols = parse_symbols(text)
assert symbols == ["MyClass", "my_func"]
class TestSymbolLookup(unittest.TestCase):
def test_parse_symbols_basic(self):
text = "Check @MyClass and @my_func."
symbols = parse_symbols(text)
self.assertEqual(symbols, ["MyClass", "my_func"])
def test_parse_symbols_methods():
text = "Calling @MyClass.my_method and @AnotherClass.method_name."
symbols = parse_symbols(text)
assert symbols == ["MyClass.my_method", "AnotherClass.method_name"]
def test_parse_symbols_methods(self):
text = "Calling @MyClass.my_method and @AnotherClass.method_name."
symbols = parse_symbols(text)
self.assertEqual(symbols, ["MyClass.my_method", "AnotherClass.method_name"])
def test_parse_symbols_no_symbols():
text = "This string has no symbols."
symbols = parse_symbols(text)
assert symbols == []
def test_parse_symbols_no_symbols(self):
text = "This string has no symbols."
symbols = parse_symbols(text)
self.assertEqual(symbols, [])
def test_parse_symbols_mixed():
text = "Mixed text: @Class1, @func_2, and some text @MyClass.method."
symbols = parse_symbols(text)
assert symbols == ["Class1", "func_2", "MyClass.method"]
def test_parse_symbols_mixed(self):
text = "Mixed text: @Class1, @func_2, and some text @MyClass.method."
symbols = parse_symbols(text)
self.assertEqual(symbols, ["Class1", "func_2", "MyClass.method"])
def test_parse_symbols_edge_cases():
text = "@LeadingSymbol and @SymbolAtEnd"
symbols = parse_symbols(text)
assert symbols == ["LeadingSymbol", "SymbolAtEnd"]
def test_parse_symbols_edge_cases(self):
text = "@LeadingSymbol and @SymbolAtEnd"
symbols = parse_symbols(text)
self.assertEqual(symbols, ["LeadingSymbol", "SymbolAtEnd"])
def test_get_symbol_definition_found(self):
files = ["file1.py", "file2.py"]
symbol = "my_func"
def_content = "def my_func():\n pass"
with patch("src.mcp_client.py_get_definition") as mock_get_def:
# First file not found, second file found
mock_get_def.side_effect = [
"ERROR: definition 'my_func' not found in file1.py",
def_content
]
result = get_symbol_definition(symbol, files)
self.assertEqual(result, ("file2.py", def_content))
self.assertEqual(mock_get_def.call_count, 2)
def test_get_symbol_definition_not_found(self):
files = ["file1.py"]
symbol = "my_func"
with patch("src.mcp_client.py_get_definition") as mock_get_def:
mock_get_def.return_value = "ERROR: definition 'my_func' not found in file1.py"
result = get_symbol_definition(symbol, files)
self.assertIsNone(result)
if __name__ == "__main__":
unittest.main()