|
4 | 4 | import tempfile |
5 | 5 |
|
6 | 6 | from agent_framework import WorkflowCheckpoint |
| 7 | +from uipath.runtime import ( |
| 8 | + UiPathResumeTrigger, |
| 9 | + UiPathResumeTriggerName, |
| 10 | + UiPathResumeTriggerType, |
| 11 | +) |
7 | 12 |
|
8 | 13 | from uipath_agent_framework.runtime.resumable_storage import ( |
9 | 14 | ScopedCheckpointStorage, |
@@ -236,6 +241,112 @@ async def test_dispose_allows_reconnect(self): |
236 | 241 | assert loaded.checkpoint_id == "cp-persist" |
237 | 242 | await storage2.dispose() |
238 | 243 |
|
| 244 | + async def test_delete_triggers(self): |
| 245 | + """delete_triggers removes sibling triggers and preserves runtime isolation.""" |
| 246 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 247 | + db_path = os.path.join(tmpdir, "test.db") |
| 248 | + storage = SqliteResumableStorage(db_path) |
| 249 | + await storage.setup() |
| 250 | + |
| 251 | + api_trigger = UiPathResumeTrigger( |
| 252 | + trigger_type=UiPathResumeTriggerType.API, |
| 253 | + trigger_name=UiPathResumeTriggerName.API, |
| 254 | + item_key="first", |
| 255 | + interrupt_id="interrupt-1", |
| 256 | + ) |
| 257 | + timer_trigger = UiPathResumeTrigger( |
| 258 | + trigger_type=UiPathResumeTriggerType.TIMER, |
| 259 | + trigger_name=UiPathResumeTriggerName.TIMER, |
| 260 | + item_key="third", |
| 261 | + interrupt_id="interrupt-1", |
| 262 | + ) |
| 263 | + unrelated_trigger = UiPathResumeTrigger( |
| 264 | + trigger_type=UiPathResumeTriggerType.TASK, |
| 265 | + trigger_name=UiPathResumeTriggerName.TASK, |
| 266 | + item_key="second", |
| 267 | + interrupt_id="interrupt-2", |
| 268 | + ) |
| 269 | + other_runtime_trigger = UiPathResumeTrigger( |
| 270 | + trigger_type=UiPathResumeTriggerType.API, |
| 271 | + trigger_name=UiPathResumeTriggerName.API, |
| 272 | + item_key="other-runtime", |
| 273 | + interrupt_id="interrupt-1", |
| 274 | + ) |
| 275 | + |
| 276 | + await storage.save_triggers( |
| 277 | + "runtime-a", [api_trigger, timer_trigger, unrelated_trigger] |
| 278 | + ) |
| 279 | + await storage.save_triggers("runtime-b", [other_runtime_trigger]) |
| 280 | + |
| 281 | + await storage.delete_triggers("runtime-a", [api_trigger, timer_trigger]) |
| 282 | + |
| 283 | + runtime_a_triggers = await storage.get_triggers("runtime-a") |
| 284 | + assert runtime_a_triggers is not None |
| 285 | + assert [trigger.interrupt_id for trigger in runtime_a_triggers] == [ |
| 286 | + "interrupt-2" |
| 287 | + ] |
| 288 | + assert runtime_a_triggers[0].item_key == "second" |
| 289 | + |
| 290 | + runtime_b_triggers = await storage.get_triggers("runtime-b") |
| 291 | + assert runtime_b_triggers is not None |
| 292 | + assert len(runtime_b_triggers) == 1 |
| 293 | + assert runtime_b_triggers[0].item_key == "other-runtime" |
| 294 | + await storage.dispose() |
| 295 | + |
| 296 | + async def test_delete_trigger_deletes_single_trigger(self): |
| 297 | + """delete_trigger removes one trigger through the compatibility wrapper.""" |
| 298 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 299 | + db_path = os.path.join(tmpdir, "test.db") |
| 300 | + storage = SqliteResumableStorage(db_path) |
| 301 | + await storage.setup() |
| 302 | + |
| 303 | + trigger = UiPathResumeTrigger( |
| 304 | + trigger_type=UiPathResumeTriggerType.API, |
| 305 | + trigger_name=UiPathResumeTriggerName.API, |
| 306 | + item_key="first", |
| 307 | + interrupt_id="interrupt-1", |
| 308 | + ) |
| 309 | + unrelated_trigger = UiPathResumeTrigger( |
| 310 | + trigger_type=UiPathResumeTriggerType.TASK, |
| 311 | + trigger_name=UiPathResumeTriggerName.TASK, |
| 312 | + item_key="second", |
| 313 | + interrupt_id="interrupt-2", |
| 314 | + ) |
| 315 | + |
| 316 | + await storage.save_triggers("runtime-a", [trigger, unrelated_trigger]) |
| 317 | + |
| 318 | + await storage.delete_trigger("runtime-a", trigger) |
| 319 | + |
| 320 | + runtime_a_triggers = await storage.get_triggers("runtime-a") |
| 321 | + assert runtime_a_triggers is not None |
| 322 | + assert [trigger.interrupt_id for trigger in runtime_a_triggers] == [ |
| 323 | + "interrupt-2" |
| 324 | + ] |
| 325 | + await storage.dispose() |
| 326 | + |
| 327 | + async def test_delete_triggers_empty_list_is_noop(self): |
| 328 | + """delete_triggers with an empty list leaves stored triggers unchanged.""" |
| 329 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 330 | + db_path = os.path.join(tmpdir, "test.db") |
| 331 | + storage = SqliteResumableStorage(db_path) |
| 332 | + await storage.setup() |
| 333 | + |
| 334 | + trigger = UiPathResumeTrigger( |
| 335 | + trigger_type=UiPathResumeTriggerType.API, |
| 336 | + trigger_name=UiPathResumeTriggerName.API, |
| 337 | + item_key="first", |
| 338 | + interrupt_id="interrupt-1", |
| 339 | + ) |
| 340 | + await storage.save_triggers("runtime-a", [trigger]) |
| 341 | + |
| 342 | + await storage.delete_triggers("runtime-a", []) |
| 343 | + |
| 344 | + runtime_a_triggers = await storage.get_triggers("runtime-a") |
| 345 | + assert runtime_a_triggers is not None |
| 346 | + assert len(runtime_a_triggers) == 1 |
| 347 | + assert runtime_a_triggers[0].item_key == "first" |
| 348 | + await storage.dispose() |
| 349 | + |
239 | 350 |
|
240 | 351 | class TestScopedCheckpointStorage: |
241 | 352 | """Tests for ScopedCheckpointStorage prefix isolation.""" |
|
0 commit comments