unique_orchestrator 1.11.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of unique_orchestrator might be problematic. Click here for more details.

@@ -0,0 +1,259 @@
1
+ from unittest.mock import MagicMock
2
+
3
+ import pytest
4
+
5
+
6
+ class TestGetFilteredUserMetadata:
7
+ """Test suite for UniqueAI._get_filtered_user_metadata method"""
8
+
9
+ @pytest.fixture
10
+ def mock_unique_ai(self):
11
+ """Create a minimal UniqueAI instance with mocked dependencies"""
12
+ # Lazy import to avoid heavy dependencies at module import time
13
+ from unique_orchestrator.unique_ai import UniqueAI
14
+
15
+ mock_logger = MagicMock()
16
+
17
+ # Create minimal event structure
18
+ dummy_event = MagicMock()
19
+ dummy_event.payload.assistant_message.id = "assist_1"
20
+ dummy_event.payload.user_message.text = "query"
21
+
22
+ # Create minimal config structure
23
+ mock_config = MagicMock()
24
+ mock_config.agent.prompt_config.user_metadata = []
25
+
26
+ # Create minimal required dependencies
27
+ mock_chat_service = MagicMock()
28
+ mock_content_service = MagicMock()
29
+ mock_debug_info_manager = MagicMock()
30
+ mock_reference_manager = MagicMock()
31
+ mock_thinking_manager = MagicMock()
32
+ mock_tool_manager = MagicMock()
33
+ mock_history_manager = MagicMock()
34
+ mock_evaluation_manager = MagicMock()
35
+ mock_postprocessor_manager = MagicMock()
36
+ mock_streaming_handler = MagicMock()
37
+ mock_message_step_logger = MagicMock()
38
+
39
+ # Instantiate UniqueAI
40
+ ua = UniqueAI(
41
+ logger=mock_logger,
42
+ event=dummy_event,
43
+ config=mock_config,
44
+ chat_service=mock_chat_service,
45
+ content_service=mock_content_service,
46
+ debug_info_manager=mock_debug_info_manager,
47
+ streaming_handler=mock_streaming_handler,
48
+ reference_manager=mock_reference_manager,
49
+ thinking_manager=mock_thinking_manager,
50
+ tool_manager=mock_tool_manager,
51
+ history_manager=mock_history_manager,
52
+ evaluation_manager=mock_evaluation_manager,
53
+ postprocessor_manager=mock_postprocessor_manager,
54
+ message_step_logger=mock_message_step_logger,
55
+ mcp_servers=[],
56
+ )
57
+
58
+ return ua
59
+
60
+ def test_returns_empty_dict_when_config_is_empty_list(self, mock_unique_ai):
61
+ """Test that empty dict is returned when config.user_metadata is an empty list"""
62
+ mock_unique_ai._config.agent.prompt_config.user_metadata = []
63
+ mock_unique_ai._event.payload.user_metadata = {
64
+ "department": "Engineering",
65
+ "role": "Developer",
66
+ }
67
+
68
+ result = mock_unique_ai._get_filtered_user_metadata()
69
+
70
+ assert result == {}
71
+ assert isinstance(result, dict)
72
+
73
+ def test_returns_empty_dict_when_user_metadata_is_none(self, mock_unique_ai):
74
+ """Test that empty dict is returned when user_metadata is None"""
75
+ mock_unique_ai._config.agent.prompt_config.user_metadata = [
76
+ "department",
77
+ "role",
78
+ ]
79
+ mock_unique_ai._event.payload.user_metadata = None
80
+
81
+ result = mock_unique_ai._get_filtered_user_metadata()
82
+
83
+ assert result == {}
84
+ assert isinstance(result, dict)
85
+
86
+ def test_returns_empty_dict_when_both_config_and_metadata_are_empty(
87
+ self, mock_unique_ai
88
+ ):
89
+ """Test that empty dict is returned when both config and user_metadata are empty/None"""
90
+ mock_unique_ai._config.agent.prompt_config.user_metadata = []
91
+ mock_unique_ai._event.payload.user_metadata = None
92
+
93
+ result = mock_unique_ai._get_filtered_user_metadata()
94
+
95
+ assert result == {}
96
+ assert isinstance(result, dict)
97
+
98
+ def test_filters_metadata_to_include_only_configured_keys(self, mock_unique_ai):
99
+ """Test that only keys specified in config are included in the result"""
100
+ mock_unique_ai._config.agent.prompt_config.user_metadata = [
101
+ "department",
102
+ "role",
103
+ ]
104
+ mock_unique_ai._event.payload.user_metadata = {
105
+ "department": "Engineering",
106
+ "role": "Developer",
107
+ "location": "San Francisco",
108
+ "salary": "100000",
109
+ }
110
+
111
+ result = mock_unique_ai._get_filtered_user_metadata()
112
+
113
+ assert result == {"department": "Engineering", "role": "Developer"}
114
+ assert "location" not in result
115
+ assert "salary" not in result
116
+ # Verify all values are strings
117
+ assert all(isinstance(v, str) for v in result.values())
118
+
119
+ def test_returns_only_existing_keys_from_user_metadata(self, mock_unique_ai):
120
+ """Test that keys in config but not in user_metadata are not included"""
121
+ mock_unique_ai._config.agent.prompt_config.user_metadata = [
122
+ "department",
123
+ "role",
124
+ "team",
125
+ "manager",
126
+ ]
127
+ mock_unique_ai._event.payload.user_metadata = {
128
+ "department": "Engineering",
129
+ "role": "Developer",
130
+ }
131
+
132
+ result = mock_unique_ai._get_filtered_user_metadata()
133
+
134
+ assert result == {"department": "Engineering", "role": "Developer"}
135
+ assert "team" not in result
136
+ assert "manager" not in result
137
+
138
+ def test_handles_single_key_in_config(self, mock_unique_ai):
139
+ """Test filtering with a single key in config"""
140
+ mock_unique_ai._config.agent.prompt_config.user_metadata = ["department"]
141
+ mock_unique_ai._event.payload.user_metadata = {
142
+ "department": "Engineering",
143
+ "role": "Developer",
144
+ }
145
+
146
+ result = mock_unique_ai._get_filtered_user_metadata()
147
+
148
+ assert result == {"department": "Engineering"}
149
+ assert isinstance(result["department"], str)
150
+
151
+ def test_handles_string_values(self, mock_unique_ai):
152
+ """Test that string values in user_metadata are preserved"""
153
+ mock_unique_ai._config.agent.prompt_config.user_metadata = [
154
+ "name",
155
+ "email",
156
+ "department",
157
+ "title",
158
+ ]
159
+ mock_unique_ai._event.payload.user_metadata = {
160
+ "name": "John Doe",
161
+ "email": "john.doe@example.com",
162
+ "department": "Engineering",
163
+ "title": "Senior Developer",
164
+ "ignored": "This should not appear",
165
+ }
166
+
167
+ result = mock_unique_ai._get_filtered_user_metadata()
168
+
169
+ assert result == {
170
+ "name": "John Doe",
171
+ "email": "john.doe@example.com",
172
+ "department": "Engineering",
173
+ "title": "Senior Developer",
174
+ }
175
+ assert "ignored" not in result
176
+ # Verify all values are strings
177
+ assert all(isinstance(v, str) for v in result.values())
178
+
179
+ def test_handles_empty_dict_user_metadata(self, mock_unique_ai):
180
+ """Test behavior when user_metadata is an empty dict"""
181
+ mock_unique_ai._config.agent.prompt_config.user_metadata = ["department"]
182
+ mock_unique_ai._event.payload.user_metadata = {}
183
+
184
+ result = mock_unique_ai._get_filtered_user_metadata()
185
+
186
+ assert result == {}
187
+
188
+ def test_handles_empty_string_values(self, mock_unique_ai):
189
+ """Test that empty string values in user_metadata are preserved if key is in config"""
190
+ mock_unique_ai._config.agent.prompt_config.user_metadata = [
191
+ "department",
192
+ "role",
193
+ ]
194
+ mock_unique_ai._event.payload.user_metadata = {
195
+ "department": "Engineering",
196
+ "role": "",
197
+ }
198
+
199
+ result = mock_unique_ai._get_filtered_user_metadata()
200
+
201
+ assert result == {"department": "Engineering", "role": ""}
202
+ assert isinstance(result["role"], str)
203
+
204
+ def test_preserves_original_metadata_unchanged(self, mock_unique_ai):
205
+ """Test that the original user_metadata dict is not modified"""
206
+ original_metadata = {
207
+ "department": "Engineering",
208
+ "role": "Developer",
209
+ "location": "San Francisco",
210
+ }
211
+ mock_unique_ai._config.agent.prompt_config.user_metadata = ["department"]
212
+ mock_unique_ai._event.payload.user_metadata = original_metadata.copy()
213
+
214
+ result = mock_unique_ai._get_filtered_user_metadata()
215
+
216
+ # Original should still have all keys
217
+ assert mock_unique_ai._event.payload.user_metadata == original_metadata
218
+ # Result should only have filtered key
219
+ assert result == {"department": "Engineering"}
220
+
221
+ def test_handles_special_characters_in_values(self, mock_unique_ai):
222
+ """Test that special characters in string values are preserved"""
223
+ mock_unique_ai._config.agent.prompt_config.user_metadata = [
224
+ "description",
225
+ "notes",
226
+ ]
227
+ mock_unique_ai._event.payload.user_metadata = {
228
+ "description": "User with special chars: @#$%^&*()",
229
+ "notes": "Multi-line\ntext\twith\ttabs",
230
+ "other": "excluded",
231
+ }
232
+
233
+ result = mock_unique_ai._get_filtered_user_metadata()
234
+
235
+ assert result == {
236
+ "description": "User with special chars: @#$%^&*()",
237
+ "notes": "Multi-line\ntext\twith\ttabs",
238
+ }
239
+ assert all(isinstance(v, str) for v in result.values())
240
+
241
+ def test_return_type_is_dict_str_str(self, mock_unique_ai):
242
+ """Test that return type is dict[str, str]"""
243
+ mock_unique_ai._config.agent.prompt_config.user_metadata = [
244
+ "department",
245
+ "role",
246
+ ]
247
+ mock_unique_ai._event.payload.user_metadata = {
248
+ "department": "Engineering",
249
+ "role": "Developer",
250
+ }
251
+
252
+ result = mock_unique_ai._get_filtered_user_metadata()
253
+
254
+ # Check it's a dict
255
+ assert isinstance(result, dict)
256
+ # Check all keys are strings
257
+ assert all(isinstance(k, str) for k in result.keys())
258
+ # Check all values are strings
259
+ assert all(isinstance(v, str) for v in result.values())