From ed386375be82c2ebbbb95796d74233f78016a8d6 Mon Sep 17 00:00:00 2001 From: Fahad Date: Mon, 16 Jun 2025 16:26:23 +0400 Subject: [PATCH] Complete Redis mocking fixes for image support integration tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Properly mock Redis client operations to support add_turn functionality - Set up initial thread contexts so add_turn can find existing threads - Mock Redis set operations to return success - Ensure all Redis-dependent tests use proper mock patterns - All 473 unit tests now pass 100% with proper isolation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- tests/test_image_support_integration.py | 48 +++++++++++++++++++++++-- tools/base.py | 1 + 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/tests/test_image_support_integration.py b/tests/test_image_support_integration.py index c5d6545..0635d49 100644 --- a/tests/test_image_support_integration.py +++ b/tests/test_image_support_integration.py @@ -85,9 +85,23 @@ class TestImageSupportIntegration: """Test adding a conversation turn with images.""" mock_client = Mock() mock_redis.return_value = mock_client - + + # Mock the Redis operations to return success + mock_client.set.return_value = True + thread_id = create_thread("test_tool", {"initial": "context"}) + # Set up initial thread context for add_turn to find + initial_context = ThreadContext( + thread_id=thread_id, + created_at="2025-01-01T00:00:00Z", + last_updated_at="2025-01-01T00:00:00Z", + tool_name="test_tool", + turns=[], # Empty initially + initial_context={"initial": "context"}, + ) + mock_client.get.return_value = initial_context.model_dump_json() + success = add_turn( thread_id=thread_id, role="user", @@ -301,10 +315,24 @@ class TestImageSupportIntegration: """Test that images are preserved across different tools in conversation.""" mock_client = Mock() mock_redis.return_value = mock_client - + + # Mock the Redis operations to return success + mock_client.set.return_value = True + # Create initial thread with chat tool thread_id = create_thread("chat", {"initial": "context"}) + # Set up initial thread context for add_turn to find + initial_context = ThreadContext( + thread_id=thread_id, + created_at="2025-01-01T00:00:00Z", + last_updated_at="2025-01-01T00:00:00Z", + tool_name="chat", + turns=[], # Empty initially + initial_context={"initial": "context"}, + ) + mock_client.get.return_value = initial_context.model_dump_json() + # Add turn with images from chat tool add_turn( thread_id=thread_id, @@ -423,9 +451,23 @@ class TestImageSupportIntegration: """Test that images work correctly with conversation thread chaining.""" mock_client = Mock() mock_redis.return_value = mock_client - + + # Mock the Redis operations to return success + mock_client.set.return_value = True + # Create parent thread with images parent_thread_id = create_thread("chat", {"parent": "context"}) + + # Set up initial parent thread context for add_turn to find + parent_context = ThreadContext( + thread_id=parent_thread_id, + created_at="2025-01-01T00:00:00Z", + last_updated_at="2025-01-01T00:00:00Z", + tool_name="chat", + turns=[], # Empty initially + initial_context={"parent": "context"}, + ) + mock_client.get.return_value = parent_context.model_dump_json() add_turn( thread_id=parent_thread_id, role="user", diff --git a/tools/base.py b/tools/base.py index d65e2a2..8ea5fef 100644 --- a/tools/base.py +++ b/tools/base.py @@ -1078,6 +1078,7 @@ When recommending searches, be specific about what information you need and why _, data = image_path.split(",", 1) # Base64 encoding increases size by ~33%, so decode to get actual size import base64 + actual_size = len(base64.b64decode(data)) actual_size = len(base64.b64decode(data))