style: fix linting and formatting issues
- Run black formatter on all Python files - Fix ruff linting issues: - Remove unused imports - Remove unused variables - Fix f-string without placeholders - All 37 tests still pass - Code quality improved for CI/CD compliance 🧹 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,10 +2,17 @@
|
||||
Tests for configuration
|
||||
"""
|
||||
|
||||
from config import (DEFAULT_MODEL, MAX_CONTEXT_TOKENS,
|
||||
TEMPERATURE_ANALYTICAL, TEMPERATURE_BALANCED,
|
||||
TEMPERATURE_CREATIVE, TOOL_TRIGGERS, __author__,
|
||||
__updated__, __version__)
|
||||
from config import (
|
||||
DEFAULT_MODEL,
|
||||
MAX_CONTEXT_TOKENS,
|
||||
TEMPERATURE_ANALYTICAL,
|
||||
TEMPERATURE_BALANCED,
|
||||
TEMPERATURE_CREATIVE,
|
||||
TOOL_TRIGGERS,
|
||||
__author__,
|
||||
__updated__,
|
||||
__version__,
|
||||
)
|
||||
|
||||
|
||||
class TestConfig:
|
||||
@@ -15,11 +22,11 @@ class TestConfig:
|
||||
"""Test version information exists and has correct format"""
|
||||
# Check version format (e.g., "2.4.1")
|
||||
assert isinstance(__version__, str)
|
||||
assert len(__version__.split('.')) == 3 # Major.Minor.Patch
|
||||
|
||||
assert len(__version__.split(".")) == 3 # Major.Minor.Patch
|
||||
|
||||
# Check author
|
||||
assert __author__ == "Fahad Gilani"
|
||||
|
||||
|
||||
# Check updated date exists (don't assert on specific format/value)
|
||||
assert isinstance(__updated__, str)
|
||||
|
||||
|
||||
@@ -20,68 +20,68 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from tools.analyze import AnalyzeTool
|
||||
from tools.think_deeper import ThinkDeeperTool
|
||||
from tools.review_code import ReviewCodeTool
|
||||
from tools.debug_issue import DebugIssueTool
|
||||
|
||||
|
||||
|
||||
async def run_manual_live_tests():
|
||||
"""Run live tests manually without pytest"""
|
||||
print("🚀 Running manual live integration tests...")
|
||||
|
||||
|
||||
# Check API key
|
||||
if not os.environ.get("GEMINI_API_KEY"):
|
||||
print("❌ GEMINI_API_KEY not found. Set it to run live tests.")
|
||||
return False
|
||||
|
||||
|
||||
try:
|
||||
# Test google-genai import
|
||||
from google import genai
|
||||
from google.genai import types
|
||||
|
||||
print("✅ google-genai library import successful")
|
||||
|
||||
|
||||
# Test tool integration
|
||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
|
||||
f.write("def hello(): return 'world'")
|
||||
temp_path = f.name
|
||||
|
||||
|
||||
try:
|
||||
# Test AnalyzeTool
|
||||
tool = AnalyzeTool()
|
||||
result = await tool.execute({
|
||||
"files": [temp_path],
|
||||
"question": "What does this code do?",
|
||||
"thinking_mode": "low"
|
||||
})
|
||||
|
||||
result = await tool.execute(
|
||||
{
|
||||
"files": [temp_path],
|
||||
"question": "What does this code do?",
|
||||
"thinking_mode": "low",
|
||||
}
|
||||
)
|
||||
|
||||
if result and result[0].text:
|
||||
print("✅ AnalyzeTool live test successful")
|
||||
else:
|
||||
print("❌ AnalyzeTool live test failed")
|
||||
return False
|
||||
|
||||
# Test ThinkDeeperTool
|
||||
|
||||
# Test ThinkDeeperTool
|
||||
think_tool = ThinkDeeperTool()
|
||||
result = await think_tool.execute({
|
||||
"current_analysis": "Testing live integration",
|
||||
"thinking_mode": "minimal" # Fast test
|
||||
})
|
||||
|
||||
result = await think_tool.execute(
|
||||
{
|
||||
"current_analysis": "Testing live integration",
|
||||
"thinking_mode": "minimal", # Fast test
|
||||
}
|
||||
)
|
||||
|
||||
if result and result[0].text and "Extended Analysis" in result[0].text:
|
||||
print("✅ ThinkDeeperTool live test successful")
|
||||
else:
|
||||
print("❌ ThinkDeeperTool live test failed")
|
||||
return False
|
||||
|
||||
|
||||
finally:
|
||||
Path(temp_path).unlink(missing_ok=True)
|
||||
|
||||
|
||||
print("\n🎉 All manual live tests passed!")
|
||||
print("✅ google-genai library working correctly")
|
||||
print("✅ All tools can make live API calls")
|
||||
print("✅ All tools can make live API calls")
|
||||
print("✅ Thinking modes functioning properly")
|
||||
return True
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Live test failed: {e}")
|
||||
return False
|
||||
@@ -90,4 +90,4 @@ async def run_manual_live_tests():
|
||||
if __name__ == "__main__":
|
||||
# Run live tests when script is executed directly
|
||||
success = asyncio.run(run_manual_live_tests())
|
||||
exit(0 if success else 1)
|
||||
exit(0 if success else 1)
|
||||
|
||||
@@ -33,9 +33,7 @@ class TestServerTools:
|
||||
|
||||
# Check descriptions are verbose
|
||||
for tool in tools:
|
||||
assert (
|
||||
len(tool.description) > 50
|
||||
) # All should have detailed descriptions
|
||||
assert len(tool.description) > 50 # All should have detailed descriptions
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_call_tool_unknown(self):
|
||||
@@ -49,8 +47,9 @@ class TestServerTools:
|
||||
"""Test chat functionality"""
|
||||
# Set test environment
|
||||
import os
|
||||
|
||||
os.environ["PYTEST_CURRENT_TEST"] = "test"
|
||||
|
||||
|
||||
# Create a mock for the model
|
||||
with patch("tools.base.BaseTool.create_model") as mock_create:
|
||||
mock_model = Mock()
|
||||
@@ -58,9 +57,9 @@ class TestServerTools:
|
||||
candidates=[Mock(content=Mock(parts=[Mock(text="Chat response")]))]
|
||||
)
|
||||
mock_create.return_value = mock_model
|
||||
|
||||
|
||||
result = await handle_call_tool("chat", {"prompt": "Hello Gemini"})
|
||||
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].text == "Chat response"
|
||||
|
||||
@@ -69,7 +68,7 @@ class TestServerTools:
|
||||
"""Test listing models"""
|
||||
result = await handle_call_tool("list_models", {})
|
||||
assert len(result) == 1
|
||||
|
||||
|
||||
# Check if we got models or an error
|
||||
text = result[0].text
|
||||
if "Error" in text:
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
Tests for thinking_mode functionality across all tools
|
||||
"""
|
||||
|
||||
import os
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
@@ -22,7 +21,7 @@ def setup_test_env():
|
||||
|
||||
class TestThinkingModes:
|
||||
"""Test thinking modes across all tools"""
|
||||
|
||||
|
||||
def test_default_thinking_modes(self):
|
||||
"""Test that tools have correct default thinking modes"""
|
||||
tools = [
|
||||
@@ -31,35 +30,40 @@ class TestThinkingModes:
|
||||
(ReviewCodeTool(), "medium"),
|
||||
(DebugIssueTool(), "medium"),
|
||||
]
|
||||
|
||||
|
||||
for tool, expected_default in tools:
|
||||
assert tool.get_default_thinking_mode() == expected_default, \
|
||||
f"{tool.__class__.__name__} should default to {expected_default}"
|
||||
|
||||
assert (
|
||||
tool.get_default_thinking_mode() == expected_default
|
||||
), f"{tool.__class__.__name__} should default to {expected_default}"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("tools.base.BaseTool.create_model")
|
||||
async def test_thinking_mode_minimal(self, mock_create_model):
|
||||
"""Test minimal thinking mode"""
|
||||
mock_model = Mock()
|
||||
mock_model.generate_content.return_value = Mock(
|
||||
candidates=[Mock(content=Mock(parts=[Mock(text="Minimal thinking response")]))]
|
||||
candidates=[
|
||||
Mock(content=Mock(parts=[Mock(text="Minimal thinking response")]))
|
||||
]
|
||||
)
|
||||
mock_create_model.return_value = mock_model
|
||||
|
||||
|
||||
tool = AnalyzeTool()
|
||||
result = await tool.execute({
|
||||
"files": ["test.py"],
|
||||
"question": "What is this?",
|
||||
"thinking_mode": "minimal"
|
||||
})
|
||||
|
||||
result = await tool.execute(
|
||||
{
|
||||
"files": ["test.py"],
|
||||
"question": "What is this?",
|
||||
"thinking_mode": "minimal",
|
||||
}
|
||||
)
|
||||
|
||||
# Verify create_model was called with correct thinking_mode
|
||||
mock_create_model.assert_called_once()
|
||||
args = mock_create_model.call_args[0]
|
||||
assert args[2] == "minimal" # thinking_mode parameter
|
||||
|
||||
|
||||
assert result[0].text.startswith("Analysis:")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("tools.base.BaseTool.create_model")
|
||||
async def test_thinking_mode_low(self, mock_create_model):
|
||||
@@ -69,43 +73,44 @@ class TestThinkingModes:
|
||||
candidates=[Mock(content=Mock(parts=[Mock(text="Low thinking response")]))]
|
||||
)
|
||||
mock_create_model.return_value = mock_model
|
||||
|
||||
|
||||
tool = ReviewCodeTool()
|
||||
result = await tool.execute({
|
||||
"files": ["test.py"],
|
||||
"thinking_mode": "low"
|
||||
})
|
||||
|
||||
result = await tool.execute({"files": ["test.py"], "thinking_mode": "low"})
|
||||
|
||||
# Verify create_model was called with correct thinking_mode
|
||||
mock_create_model.assert_called_once()
|
||||
args = mock_create_model.call_args[0]
|
||||
assert args[2] == "low"
|
||||
|
||||
|
||||
assert "Code Review" in result[0].text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("tools.base.BaseTool.create_model")
|
||||
async def test_thinking_mode_medium(self, mock_create_model):
|
||||
"""Test medium thinking mode (default for most tools)"""
|
||||
mock_model = Mock()
|
||||
mock_model.generate_content.return_value = Mock(
|
||||
candidates=[Mock(content=Mock(parts=[Mock(text="Medium thinking response")]))]
|
||||
candidates=[
|
||||
Mock(content=Mock(parts=[Mock(text="Medium thinking response")]))
|
||||
]
|
||||
)
|
||||
mock_create_model.return_value = mock_model
|
||||
|
||||
|
||||
tool = DebugIssueTool()
|
||||
result = await tool.execute({
|
||||
"error_description": "Test error",
|
||||
# Not specifying thinking_mode, should use default (medium)
|
||||
})
|
||||
|
||||
result = await tool.execute(
|
||||
{
|
||||
"error_description": "Test error",
|
||||
# Not specifying thinking_mode, should use default (medium)
|
||||
}
|
||||
)
|
||||
|
||||
# Verify create_model was called with default thinking_mode
|
||||
mock_create_model.assert_called_once()
|
||||
args = mock_create_model.call_args[0]
|
||||
assert args[2] == "medium"
|
||||
|
||||
|
||||
assert "Debug Analysis" in result[0].text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("tools.base.BaseTool.create_model")
|
||||
async def test_thinking_mode_high(self, mock_create_model):
|
||||
@@ -115,19 +120,21 @@ class TestThinkingModes:
|
||||
candidates=[Mock(content=Mock(parts=[Mock(text="High thinking response")]))]
|
||||
)
|
||||
mock_create_model.return_value = mock_model
|
||||
|
||||
|
||||
tool = AnalyzeTool()
|
||||
result = await tool.execute({
|
||||
"files": ["complex.py"],
|
||||
"question": "Analyze architecture",
|
||||
"thinking_mode": "high"
|
||||
})
|
||||
|
||||
await tool.execute(
|
||||
{
|
||||
"files": ["complex.py"],
|
||||
"question": "Analyze architecture",
|
||||
"thinking_mode": "high",
|
||||
}
|
||||
)
|
||||
|
||||
# Verify create_model was called with correct thinking_mode
|
||||
mock_create_model.assert_called_once()
|
||||
args = mock_create_model.call_args[0]
|
||||
assert args[2] == "high"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("tools.base.BaseTool.create_model")
|
||||
async def test_thinking_mode_max(self, mock_create_model):
|
||||
@@ -137,47 +144,58 @@ class TestThinkingModes:
|
||||
candidates=[Mock(content=Mock(parts=[Mock(text="Max thinking response")]))]
|
||||
)
|
||||
mock_create_model.return_value = mock_model
|
||||
|
||||
|
||||
tool = ThinkDeeperTool()
|
||||
result = await tool.execute({
|
||||
"current_analysis": "Initial analysis",
|
||||
# Not specifying thinking_mode, should use default (max)
|
||||
})
|
||||
|
||||
result = await tool.execute(
|
||||
{
|
||||
"current_analysis": "Initial analysis",
|
||||
# Not specifying thinking_mode, should use default (max)
|
||||
}
|
||||
)
|
||||
|
||||
# Verify create_model was called with default thinking_mode
|
||||
mock_create_model.assert_called_once()
|
||||
args = mock_create_model.call_args[0]
|
||||
assert args[2] == "max"
|
||||
|
||||
|
||||
assert "Extended Analysis by Gemini" in result[0].text
|
||||
|
||||
|
||||
def test_thinking_budget_mapping(self):
|
||||
"""Test that thinking modes map to correct budget values"""
|
||||
from tools.base import BaseTool
|
||||
|
||||
|
||||
# Create a simple test tool
|
||||
class TestTool(BaseTool):
|
||||
def get_name(self): return "test"
|
||||
def get_description(self): return "test"
|
||||
def get_input_schema(self): return {}
|
||||
def get_system_prompt(self): return "test"
|
||||
def get_request_model(self): return None
|
||||
async def prepare_prompt(self, request): return "test"
|
||||
|
||||
tool = TestTool()
|
||||
|
||||
def get_name(self):
|
||||
return "test"
|
||||
|
||||
def get_description(self):
|
||||
return "test"
|
||||
|
||||
def get_input_schema(self):
|
||||
return {}
|
||||
|
||||
def get_system_prompt(self):
|
||||
return "test"
|
||||
|
||||
def get_request_model(self):
|
||||
return None
|
||||
|
||||
async def prepare_prompt(self, request):
|
||||
return "test"
|
||||
|
||||
# Expected mappings
|
||||
expected_budgets = {
|
||||
"minimal": 128,
|
||||
"low": 2048,
|
||||
"medium": 8192,
|
||||
"high": 16384,
|
||||
"max": 32768
|
||||
"max": 32768,
|
||||
}
|
||||
|
||||
|
||||
# Check each mode in create_model
|
||||
for mode, expected_budget in expected_budgets.items():
|
||||
# The budget mapping is inside create_model
|
||||
# We can't easily test it without calling the method
|
||||
# But we've verified the values are correct in the code
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -120,7 +120,9 @@ class TestDebugIssueTool:
|
||||
# Mock model
|
||||
mock_model = Mock()
|
||||
mock_model.generate_content.return_value = Mock(
|
||||
candidates=[Mock(content=Mock(parts=[Mock(text="Root cause: race condition")]))]
|
||||
candidates=[
|
||||
Mock(content=Mock(parts=[Mock(text="Root cause: race condition")]))
|
||||
]
|
||||
)
|
||||
mock_create_model.return_value = mock_model
|
||||
|
||||
@@ -157,9 +159,7 @@ class TestAnalyzeTool:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("tools.base.BaseTool.create_model")
|
||||
async def test_execute_with_analysis_type(
|
||||
self, mock_model, tool, tmp_path
|
||||
):
|
||||
async def test_execute_with_analysis_type(self, mock_model, tool, tmp_path):
|
||||
"""Test execution with specific analysis type"""
|
||||
# Create test file
|
||||
test_file = tmp_path / "module.py"
|
||||
@@ -168,9 +168,7 @@ class TestAnalyzeTool:
|
||||
# Mock response
|
||||
mock_response = Mock()
|
||||
mock_response.candidates = [Mock()]
|
||||
mock_response.candidates[0].content.parts = [
|
||||
Mock(text="Architecture analysis")
|
||||
]
|
||||
mock_response.candidates[0].content.parts = [Mock(text="Architecture analysis")]
|
||||
|
||||
mock_instance = Mock()
|
||||
mock_instance.generate_content.return_value = mock_response
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
Tests for utility functions
|
||||
"""
|
||||
|
||||
from utils import (check_token_limit, estimate_tokens, read_file_content,
|
||||
read_files)
|
||||
from utils import check_token_limit, estimate_tokens, read_file_content, read_files
|
||||
|
||||
|
||||
class TestFileUtils:
|
||||
@@ -12,9 +11,7 @@ class TestFileUtils:
|
||||
def test_read_file_content_success(self, tmp_path):
|
||||
"""Test successful file reading"""
|
||||
test_file = tmp_path / "test.py"
|
||||
test_file.write_text(
|
||||
"def hello():\n return 'world'", encoding="utf-8"
|
||||
)
|
||||
test_file.write_text("def hello():\n return 'world'", encoding="utf-8")
|
||||
|
||||
content, tokens = read_file_content(str(test_file))
|
||||
assert "--- BEGIN FILE:" in content
|
||||
@@ -71,18 +68,18 @@ class TestFileUtils:
|
||||
(tmp_path / "file1.py").write_text("print('file1')", encoding="utf-8")
|
||||
(tmp_path / "file2.js").write_text("console.log('file2')", encoding="utf-8")
|
||||
(tmp_path / "readme.md").write_text("# README", encoding="utf-8")
|
||||
|
||||
|
||||
# Create subdirectory
|
||||
subdir = tmp_path / "src"
|
||||
subdir.mkdir()
|
||||
(subdir / "module.py").write_text("class Module: pass", encoding="utf-8")
|
||||
|
||||
|
||||
# Create hidden file (should be skipped)
|
||||
(tmp_path / ".hidden").write_text("secret", encoding="utf-8")
|
||||
|
||||
|
||||
# Read the directory
|
||||
content, summary = read_files([str(tmp_path)])
|
||||
|
||||
|
||||
# Check files are included
|
||||
assert "file1.py" in content
|
||||
assert "file2.js" in content
|
||||
@@ -90,17 +87,17 @@ class TestFileUtils:
|
||||
# Handle both forward and backslashes for cross-platform compatibility
|
||||
assert "module.py" in content
|
||||
assert "class Module: pass" in content
|
||||
|
||||
|
||||
# Check content
|
||||
assert "print('file1')" in content
|
||||
assert "console.log('file2')" in content
|
||||
assert "# README" in content
|
||||
assert "class Module: pass" in content
|
||||
|
||||
|
||||
# Hidden file should not be included
|
||||
assert ".hidden" not in content
|
||||
assert "secret" not in content
|
||||
|
||||
|
||||
# Check summary
|
||||
assert "Processed 1 dir(s)" in summary
|
||||
assert "Read 4 file(s)" in summary
|
||||
@@ -110,23 +107,23 @@ class TestFileUtils:
|
||||
# Create files
|
||||
file1 = tmp_path / "direct.py"
|
||||
file1.write_text("# Direct file", encoding="utf-8")
|
||||
|
||||
|
||||
# Create directory with files
|
||||
subdir = tmp_path / "subdir"
|
||||
subdir.mkdir()
|
||||
(subdir / "sub1.py").write_text("# Sub file 1", encoding="utf-8")
|
||||
(subdir / "sub2.py").write_text("# Sub file 2", encoding="utf-8")
|
||||
|
||||
|
||||
# Read mix of direct file and directory
|
||||
content, summary = read_files([str(file1), str(subdir)])
|
||||
|
||||
|
||||
assert "direct.py" in content
|
||||
assert "sub1.py" in content
|
||||
assert "sub2.py" in content
|
||||
assert "# Direct file" in content
|
||||
assert "# Sub file 1" in content
|
||||
assert "# Sub file 2" in content
|
||||
|
||||
|
||||
assert "Processed 1 dir(s)" in summary
|
||||
assert "Read 3 file(s)" in summary
|
||||
|
||||
@@ -135,19 +132,19 @@ class TestFileUtils:
|
||||
# Create files with known token counts
|
||||
# ~250 tokens each (1000 chars)
|
||||
large_content = "x" * 1000
|
||||
|
||||
|
||||
for i in range(5):
|
||||
(tmp_path / f"file{i}.txt").write_text(large_content, encoding="utf-8")
|
||||
|
||||
|
||||
# Read with small token limit (should skip some files)
|
||||
# Reserve 50k tokens, limit to 51k total = 1k available
|
||||
# Each file ~250 tokens, so should read ~3-4 files
|
||||
content, summary = read_files([str(tmp_path)], max_tokens=51_000)
|
||||
|
||||
|
||||
assert "Skipped" in summary
|
||||
assert "token limit" in summary
|
||||
assert "--- SKIPPED FILES (TOKEN LIMIT) ---" in content
|
||||
|
||||
|
||||
# Count how many files were read
|
||||
read_count = content.count("--- BEGIN FILE:")
|
||||
assert 2 <= read_count <= 4 # Should read some but not all
|
||||
@@ -157,9 +154,9 @@ class TestFileUtils:
|
||||
# Create a file larger than max_size (1MB)
|
||||
large_file = tmp_path / "large.txt"
|
||||
large_file.write_text("x" * 2_000_000, encoding="utf-8") # 2MB
|
||||
|
||||
|
||||
content, summary = read_files([str(large_file)])
|
||||
|
||||
|
||||
assert "--- FILE TOO LARGE:" in content
|
||||
assert "2,000,000 bytes" in content
|
||||
assert "Read 1 file(s)" in summary # File is counted but shows error message
|
||||
@@ -171,13 +168,13 @@ class TestFileUtils:
|
||||
(tmp_path / "style.css").write_text("css", encoding="utf-8")
|
||||
(tmp_path / "binary.exe").write_text("exe", encoding="utf-8")
|
||||
(tmp_path / "image.jpg").write_text("jpg", encoding="utf-8")
|
||||
|
||||
|
||||
content, summary = read_files([str(tmp_path)])
|
||||
|
||||
|
||||
# Code files should be included
|
||||
assert "code.py" in content
|
||||
assert "style.css" in content
|
||||
|
||||
|
||||
# Binary files should not be included (not in CODE_EXTENSIONS)
|
||||
assert "binary.exe" not in content
|
||||
assert "image.jpg" not in content
|
||||
|
||||
Reference in New Issue
Block a user