|
| 1 | +"""Tests for escalation_tool.py metadata.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from uipath.agent.models.agent import ( |
| 5 | + AgentEscalationChannel, |
| 6 | + AgentEscalationChannelProperties, |
| 7 | + AgentEscalationRecipientType, |
| 8 | + AgentEscalationResourceConfig, |
| 9 | + StandardRecipient, |
| 10 | +) |
| 11 | + |
| 12 | +from uipath_langchain.agent.tools.escalation_tool import create_escalation_tool |
| 13 | + |
| 14 | + |
| 15 | +class TestEscalationToolMetadata: |
| 16 | + """Test that escalation tool has correct metadata for observability.""" |
| 17 | + |
| 18 | + @pytest.fixture |
| 19 | + def escalation_resource(self): |
| 20 | + """Create a minimal escalation tool resource config.""" |
| 21 | + return AgentEscalationResourceConfig( |
| 22 | + name="approval", |
| 23 | + description="Request approval", |
| 24 | + channels=[ |
| 25 | + AgentEscalationChannel( |
| 26 | + name="action_center", |
| 27 | + type="actionCenter", |
| 28 | + description="Action Center channel", |
| 29 | + input_schema={"type": "object", "properties": {}}, |
| 30 | + output_schema={"type": "object", "properties": {}}, |
| 31 | + properties=AgentEscalationChannelProperties( |
| 32 | + app_name="ApprovalApp", |
| 33 | + app_version=1, |
| 34 | + resource_key="test-key", |
| 35 | + ), |
| 36 | + recipients=[ |
| 37 | + StandardRecipient( |
| 38 | + type=AgentEscalationRecipientType.USER_EMAIL, |
| 39 | + value="user@example.com", |
| 40 | + ) |
| 41 | + ], |
| 42 | + ) |
| 43 | + ], |
| 44 | + ) |
| 45 | + |
| 46 | + @pytest.fixture |
| 47 | + def escalation_resource_no_recipient(self): |
| 48 | + """Create escalation resource without recipients.""" |
| 49 | + return AgentEscalationResourceConfig( |
| 50 | + name="approval", |
| 51 | + description="Request approval", |
| 52 | + channels=[ |
| 53 | + AgentEscalationChannel( |
| 54 | + name="action_center", |
| 55 | + type="actionCenter", |
| 56 | + description="Action Center channel", |
| 57 | + input_schema={"type": "object", "properties": {}}, |
| 58 | + output_schema={"type": "object", "properties": {}}, |
| 59 | + properties=AgentEscalationChannelProperties( |
| 60 | + app_name="ApprovalApp", |
| 61 | + app_version=1, |
| 62 | + resource_key="test-key", |
| 63 | + ), |
| 64 | + recipients=[], |
| 65 | + ) |
| 66 | + ], |
| 67 | + ) |
| 68 | + |
| 69 | + def test_escalation_tool_has_metadata(self, escalation_resource): |
| 70 | + """Test that escalation tool has metadata dict.""" |
| 71 | + tool = create_escalation_tool(escalation_resource) |
| 72 | + |
| 73 | + assert tool.metadata is not None |
| 74 | + assert isinstance(tool.metadata, dict) |
| 75 | + |
| 76 | + def test_escalation_tool_metadata_has_tool_type(self, escalation_resource): |
| 77 | + """Test that metadata contains tool_type for span detection.""" |
| 78 | + tool = create_escalation_tool(escalation_resource) |
| 79 | + assert tool.metadata is not None |
| 80 | + assert tool.metadata["tool_type"] == "escalation" |
| 81 | + |
| 82 | + def test_escalation_tool_metadata_has_display_name(self, escalation_resource): |
| 83 | + """Test that metadata contains display_name from app_name.""" |
| 84 | + tool = create_escalation_tool(escalation_resource) |
| 85 | + assert tool.metadata is not None |
| 86 | + assert tool.metadata["display_name"] == "ApprovalApp" |
| 87 | + |
| 88 | + def test_escalation_tool_metadata_has_channel_type(self, escalation_resource): |
| 89 | + """Test that metadata contains channel_type for span attributes.""" |
| 90 | + tool = create_escalation_tool(escalation_resource) |
| 91 | + assert tool.metadata is not None |
| 92 | + assert tool.metadata["channel_type"] == "actionCenter" |
| 93 | + |
| 94 | + def test_escalation_tool_metadata_has_assignee(self, escalation_resource): |
| 95 | + """Test that metadata contains assignee when recipient is USER_EMAIL.""" |
| 96 | + tool = create_escalation_tool(escalation_resource) |
| 97 | + assert tool.metadata is not None |
| 98 | + assert tool.metadata["assignee"] == "user@example.com" |
| 99 | + |
| 100 | + def test_escalation_tool_metadata_assignee_none_when_no_recipients( |
| 101 | + self, escalation_resource_no_recipient |
| 102 | + ): |
| 103 | + """Test that assignee is None when no recipients configured.""" |
| 104 | + tool = create_escalation_tool(escalation_resource_no_recipient) |
| 105 | + assert tool.metadata is not None |
| 106 | + assert tool.metadata["assignee"] is None |
0 commit comments