|
1 | 1 | """Tests for context_tool.py module.""" |
2 | 2 |
|
3 | | -from unittest.mock import AsyncMock, patch |
| 3 | +import os |
| 4 | +from unittest.mock import AsyncMock, MagicMock, patch |
4 | 5 |
|
5 | 6 | import pytest |
6 | 7 | from langchain_core.documents import Document |
@@ -271,6 +272,27 @@ async def test_dynamic_query_uses_provided_query(self, base_resource_config): |
271 | 272 | call_args = mock_interrupt.call_args[0][0] |
272 | 273 | assert call_args.prompt == "runtime provided query" |
273 | 274 |
|
| 275 | + @pytest.mark.asyncio |
| 276 | + @patch.dict(os.environ, {"UIPATH_FOLDER_PATH": "/Shared/TestFolder"}) |
| 277 | + async def test_deep_rag_uses_execution_folder_path(self, base_resource_config): |
| 278 | + """Test that CreateDeepRag receives index_folder_path from the execution environment.""" |
| 279 | + resource = base_resource_config( |
| 280 | + query_variant="static", |
| 281 | + query_value="test query", |
| 282 | + citation_mode_value=AgentContextValueSetting(value="Inline"), |
| 283 | + ) |
| 284 | + tool = handle_deep_rag("test_tool", resource) |
| 285 | + |
| 286 | + with patch( |
| 287 | + "uipath_langchain.agent.tools.durable_interrupt.decorator.interrupt" |
| 288 | + ) as mock_interrupt: |
| 289 | + mock_interrupt.return_value = {"mocked": "response"} |
| 290 | + assert tool.coroutine is not None |
| 291 | + await tool.coroutine() |
| 292 | + |
| 293 | + deep_rag_arg = mock_interrupt.call_args[0][0] |
| 294 | + assert deep_rag_arg.index_folder_path == "/Shared/TestFolder" |
| 295 | + |
274 | 296 |
|
275 | 297 | class TestCreateContextTool: |
276 | 298 | """Test cases for create_context_tool function.""" |
@@ -490,6 +512,17 @@ async def test_static_query_uses_predefined_query(self): |
490 | 512 | assert "documents" in result |
491 | 513 | assert len(result["documents"]) == 1 |
492 | 514 |
|
| 515 | + @patch.dict(os.environ, {"UIPATH_FOLDER_PATH": "/Shared/TestFolder"}) |
| 516 | + def test_semantic_search_uses_execution_folder_path(self, semantic_config): |
| 517 | + """Test that ContextGroundingRetriever receives folder_path from the execution environment.""" |
| 518 | + with patch( |
| 519 | + "uipath_langchain.agent.tools.context_tool.ContextGroundingRetriever" |
| 520 | + ) as mock_retriever_class: |
| 521 | + handle_semantic_search("semantic_tool", semantic_config) |
| 522 | + |
| 523 | + call_kwargs = mock_retriever_class.call_args[1] |
| 524 | + assert call_kwargs["folder_path"] == "/Shared/TestFolder" |
| 525 | + |
493 | 526 |
|
494 | 527 | class TestHandleBatchTransform: |
495 | 528 | """Test cases for handle_batch_transform function.""" |
@@ -771,6 +804,32 @@ async def test_dynamic_query_batch_transform_uses_default_destination_path(self) |
771 | 804 | assert call_args.prompt == "runtime provided query" |
772 | 805 | assert call_args.destination_path == "output.csv" |
773 | 806 |
|
| 807 | + @pytest.mark.asyncio |
| 808 | + @patch.dict(os.environ, {"UIPATH_FOLDER_PATH": "/Shared/TestFolder"}) |
| 809 | + async def test_batch_transform_uses_execution_folder_path( |
| 810 | + self, batch_transform_config |
| 811 | + ): |
| 812 | + """Test that CreateBatchTransform receives index_folder_path from the execution environment.""" |
| 813 | + tool = handle_batch_transform("batch_transform_tool", batch_transform_config) |
| 814 | + |
| 815 | + mock_uipath = MagicMock() |
| 816 | + mock_uipath.jobs.create_attachment_async = AsyncMock(return_value="att-id") |
| 817 | + with ( |
| 818 | + patch( |
| 819 | + "uipath_langchain.agent.tools.durable_interrupt.decorator.interrupt" |
| 820 | + ) as mock_interrupt, |
| 821 | + patch( |
| 822 | + "uipath_langchain.agent.tools.context_tool.UiPath", |
| 823 | + return_value=mock_uipath, |
| 824 | + ), |
| 825 | + ): |
| 826 | + mock_interrupt.return_value = MagicMock() |
| 827 | + assert tool.coroutine is not None |
| 828 | + await tool.coroutine(destination_path="output.csv") |
| 829 | + |
| 830 | + batch_transform_arg = mock_interrupt.call_args[0][0] |
| 831 | + assert batch_transform_arg.index_folder_path == "/Shared/TestFolder" |
| 832 | + |
774 | 833 |
|
775 | 834 | class TestBuildGlobPattern: |
776 | 835 | """Test cases for build_glob_pattern function.""" |
|
0 commit comments