|
1 | 1 | """Tests for batch_transform_tool.py module.""" |
2 | 2 |
|
| 3 | +import os |
3 | 4 | import uuid |
4 | 5 | from unittest.mock import AsyncMock, Mock, patch |
5 | 6 |
|
@@ -547,6 +548,57 @@ async def test_create_batch_transform_tool_custom_destination_path( |
547 | 548 | job_key="test-job-key", |
548 | 549 | ) |
549 | 550 |
|
| 551 | + @patch( |
| 552 | + "uipath_langchain.agent.wrappers.job_attachment_wrapper.get_job_attachment_wrapper" |
| 553 | + ) |
| 554 | + @patch("uipath_langchain.agent.tools.internal_tools.batch_transform_tool.UiPath") |
| 555 | + @patch("uipath_langchain._utils.durable_interrupt.decorator.interrupt") |
| 556 | + @patch( |
| 557 | + "uipath_langchain.agent.tools.internal_tools.batch_transform_tool.mockable", |
| 558 | + lambda **kwargs: lambda f: f, |
| 559 | + ) |
| 560 | + @patch.dict(os.environ, {"UIPATH_FOLDER_PATH": "/Shared/TestFolder"}) |
| 561 | + async def test_create_ephemeral_index_passes_folder_path( |
| 562 | + self, |
| 563 | + mock_interrupt, |
| 564 | + mock_uipath_class, |
| 565 | + mock_get_wrapper, |
| 566 | + resource_config_static, |
| 567 | + mock_llm, |
| 568 | + ): |
| 569 | + """Test that create_ephemeral_index_async receives folder_path from the execution environment.""" |
| 570 | + mock_uipath = AsyncMock() |
| 571 | + mock_uipath_class.return_value = mock_uipath |
| 572 | + mock_uipath_config = Mock() |
| 573 | + mock_uipath_config.job_key = "test-job-key" |
| 574 | + |
| 575 | + mock_index = ContextGroundingIndex( |
| 576 | + id=str(uuid.uuid4()), |
| 577 | + name="ephemeral-batch-folder", |
| 578 | + last_ingestion_status="Successful", |
| 579 | + ) |
| 580 | + mock_uipath.context_grounding.create_ephemeral_index_async = AsyncMock( |
| 581 | + return_value=mock_index |
| 582 | + ) |
| 583 | + mock_interrupt.side_effect = [{"file_path": "output.csv"}] |
| 584 | + mock_uipath.jobs.create_attachment_async = AsyncMock(return_value=uuid.uuid4()) |
| 585 | + |
| 586 | + mock_wrapper = Mock() |
| 587 | + mock_get_wrapper.return_value = mock_wrapper |
| 588 | + |
| 589 | + tool = create_batch_transform_tool(resource_config_static, mock_llm) |
| 590 | + mock_attachment = MockAttachment( |
| 591 | + ID=str(uuid.uuid4()), FullName="data.csv", MimeType="text/csv" |
| 592 | + ) |
| 593 | + |
| 594 | + assert tool.coroutine is not None |
| 595 | + await tool.coroutine(attachment=mock_attachment) |
| 596 | + |
| 597 | + call_kwargs = ( |
| 598 | + mock_uipath.context_grounding.create_ephemeral_index_async.call_args.kwargs |
| 599 | + ) |
| 600 | + assert call_kwargs["folder_path"] == "/Shared/TestFolder" |
| 601 | + |
550 | 602 | @patch( |
551 | 603 | "uipath_langchain.agent.wrappers.job_attachment_wrapper.get_job_attachment_wrapper" |
552 | 604 | ) |
|
0 commit comments