async def test_cross_tool_conversation_with_files_context(self, mock_get_thread, mock_redis):
        """Test that file context is preserved across tool switches"""
        mock_client = Mock()
        mock_redis.return_value = mock_client

        # Create existing context with files from analysis tool
        existing_context = ThreadContext(
            thread_id="test-thread-id",
            created_at="2023-01-01T00:00:00Z",
            last_updated_at="2023-01-01T00:01:00Z",
            tool_name="test_analysis",
            turns=[
                ConversationTurn(
                    role="assistant",
                    content="Analysis of auth.py complete",
                    timestamp="2023-01-01T00:01:00Z",
                    tool_name="test_analysis",
                    files=["/src/auth.py", "/src/utils.py"],
                )
            ],
            initial_context={"code": "authentication code", "files": ["/src/auth.py"]},
        )

        # Mock get_thread to return the existing context
        mock_get_thread.return_value = existing_context

        # Mock review tool response
        with patch.object(self.review_tool, "create_model") as mock_create_model:
            mock_model = Mock()
            mock_response = Mock()
            mock_response.candidates = [
                Mock(
                    content=Mock(parts=[Mock(text="Security review of auth.py shows vulnerabilities")]),
                    finish_reason="STOP",
                )
            ]
            mock_model.generate_content.return_value = mock_response
            mock_create_model.return_value = mock_model

            # Execute review tool with additional files
            arguments = {
                "findings": "Auth vulnerabilities found",
                "continuation_id": "test-thread-id",
                "files": ["/src/security.py"],  # Additional file for review
            }
            response = await self.review_tool.execute(arguments)
            response_data = json.loads(response[0].text)

            assert response_data["status"] == "continuation_available"

        # Verify files from both tools are tracked in Redis calls
        setex_calls = mock_client.setex.call_args_list
        assert len(setex_calls) >= 1  # At least the add_turn call from review tool

        # Get the final thread state
        final_thread_data = setex_calls[-1][0][2]
        final_context = json.loads(final_thread_data)

        # Check that the new turn includes the review tool's files
        review_turn = final_context["turns"][1]  # Second turn (review tool)
        assert review_turn["tool_name"] == "test_review"
        assert review_turn["files"] == ["/src/security.py"]

        # Original turn's files should still be there
        analysis_turn = final_context["turns"][0]  # First turn (analysis tool)
        assert analysis_turn["files"] == ["/src/auth.py", "/src/utils.py"]
Test that file context is preserved across tool switches
tests/test_cross_tool_continuation.py