Vision-based auto-approval system for Claude Code CLI using MiniCPM-V vision model. Features: - Automatic detection and response to approval prompts - Screenshot capture and vision analysis via Ollama - Support for multiple screenshot tools (scrot, gnome-screenshot, etc.) - Configurable timing and behavior - Debug mode for troubleshooting - Comprehensive documentation Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Jean-Philippe Brule <jp@svrnty.io>
80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
"""
|
|
Basic tests for Claude Vision Auto
|
|
"""
|
|
|
|
import pytest
|
|
from unittest.mock import Mock, patch, MagicMock
|
|
from claude_vision_auto import config
|
|
from claude_vision_auto.vision_analyzer import VisionAnalyzer
|
|
from claude_vision_auto.screenshot import find_screenshot_tool
|
|
|
|
|
|
def test_config_defaults():
|
|
"""Test default configuration values"""
|
|
assert config.VISION_MODEL == "minicpm-v:latest"
|
|
assert config.IDLE_THRESHOLD == 3.0
|
|
assert config.RESPONSE_DELAY == 1.0
|
|
assert config.OUTPUT_BUFFER_SIZE == 4096
|
|
|
|
|
|
def test_find_screenshot_tool():
|
|
"""Test screenshot tool detection"""
|
|
tool = find_screenshot_tool()
|
|
# Should find at least one tool or return None
|
|
assert tool is None or isinstance(tool, str)
|
|
|
|
|
|
@patch('requests.get')
|
|
def test_vision_analyzer_connection(mock_get):
|
|
"""Test Ollama connection check"""
|
|
mock_response = Mock()
|
|
mock_response.json.return_value = {
|
|
'models': [
|
|
{'name': 'minicpm-v:latest'},
|
|
{'name': 'llama3.2-vision:latest'}
|
|
]
|
|
}
|
|
mock_response.raise_for_status = Mock()
|
|
mock_get.return_value = mock_response
|
|
|
|
analyzer = VisionAnalyzer()
|
|
assert analyzer.test_connection() is True
|
|
|
|
|
|
@patch('requests.post')
|
|
def test_vision_analyzer_analyze(mock_post):
|
|
"""Test vision analysis"""
|
|
mock_response = Mock()
|
|
mock_response.json.return_value = {
|
|
'response': '1'
|
|
}
|
|
mock_response.raise_for_status = Mock()
|
|
mock_post.return_value = mock_response
|
|
|
|
analyzer = VisionAnalyzer()
|
|
|
|
# Create a temporary test image
|
|
import tempfile
|
|
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp:
|
|
# Write a minimal PNG header
|
|
tmp.write(b'\x89PNG\r\n\x1a\n')
|
|
tmp_path = tmp.name
|
|
|
|
result = analyzer.analyze_screenshot(tmp_path)
|
|
assert result == '1'
|
|
|
|
# Cleanup
|
|
import os
|
|
os.unlink(tmp_path)
|
|
|
|
|
|
def test_approval_keywords():
|
|
"""Test approval keyword configuration"""
|
|
assert 'Yes' in config.APPROVAL_KEYWORDS
|
|
assert 'No' in config.APPROVAL_KEYWORDS
|
|
assert '(y/n)' in config.APPROVAL_KEYWORDS
|
|
|
|
|
|
if __name__ == '__main__':
|
|
pytest.main([__file__, '-v'])
|