rustvello-test-suite 0.1.3

Shared test definitions for rustvello backend implementations
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
//! Shared orchestrator test definitions.
//!
//! Each function tests a specific behavior of the [`Orchestrator`] trait.

use rustvello_core::orchestrator::Orchestrator;
use rustvello_proto::call::{CallDTO, SerializedArguments};
use rustvello_proto::config::TaskConfig;
use rustvello_proto::identifiers::TaskId;
use rustvello_proto::status::InvocationStatus;

use crate::helpers::test_task_id;

fn make_call(task_id: &TaskId) -> CallDTO {
    CallDTO::new(task_id.clone(), SerializedArguments::default())
}

/// Register an invocation and verify initial status is Registered.
pub async fn test_register_invocation(orch: &dyn Orchestrator) {
    let task_id = test_task_id("test_task");
    let call = make_call(&task_id);
    let inv_id = orch.register_invocation(&call).await.unwrap();

    let record = orch.get_invocation_status(&inv_id).await.unwrap();
    assert_eq!(record.status, InvocationStatus::Registered);
}

/// Transition: Registered → Pending → Running → Success.
pub async fn test_status_transitions(orch: &dyn Orchestrator) {
    let task_id = test_task_id("test_task");
    let call = make_call(&task_id);
    let inv_id = orch.register_invocation(&call).await.unwrap();

    let runner_id = rustvello_proto::identifiers::RunnerId::new();
    let rec = orch
        .set_invocation_status(&inv_id, InvocationStatus::Pending, Some(&runner_id))
        .await
        .unwrap();
    assert_eq!(rec.status, InvocationStatus::Pending);

    let rec = orch
        .set_invocation_status(&inv_id, InvocationStatus::Running, Some(&runner_id))
        .await
        .unwrap();
    assert_eq!(rec.status, InvocationStatus::Running);

    let rec = orch
        .set_invocation_status(&inv_id, InvocationStatus::Success, Some(&runner_id))
        .await
        .unwrap();
    assert_eq!(rec.status, InvocationStatus::Success);
}

/// Query invocations by task.
pub async fn test_get_invocations_by_task(orch: &dyn Orchestrator) {
    let task_a = test_task_id("task_a");
    let task_b = test_task_id("task_b");

    let call_a = make_call(&task_a);
    let call_b = make_call(&task_b);

    let inv_a = orch.register_invocation(&call_a).await.unwrap();
    let _inv_b = orch.register_invocation(&call_b).await.unwrap();

    let invs = orch.get_invocations_by_task(&task_a).await.unwrap();
    assert!(invs.contains(&inv_a));
    assert_eq!(invs.len(), 1);
}

/// Query invocations by status.
pub async fn test_get_invocations_by_status(orch: &dyn Orchestrator) {
    let task_id = test_task_id("test_task");
    let call = make_call(&task_id);
    let inv_id = orch.register_invocation(&call).await.unwrap();

    let registered = orch
        .get_invocations_by_status(InvocationStatus::Registered, None)
        .await
        .unwrap();
    assert!(registered.contains(&inv_id));

    let runner_id = rustvello_proto::identifiers::RunnerId::from_string("test-runner");
    orch.set_invocation_status(&inv_id, InvocationStatus::Pending, Some(&runner_id))
        .await
        .unwrap();

    let registered = orch
        .get_invocations_by_status(InvocationStatus::Registered, None)
        .await
        .unwrap();
    assert!(!registered.contains(&inv_id));

    let pending = orch
        .get_invocations_by_status(InvocationStatus::Pending, None)
        .await
        .unwrap();
    assert!(pending.contains(&inv_id));
}

/// Concurrency control check.
pub async fn test_concurrency_control(orch: &dyn Orchestrator) {
    let task_id = test_task_id("cc_task");
    let config = TaskConfig::default();

    let result = orch
        .check_running_concurrency(&task_id, &config, None)
        .await
        .unwrap();
    // With default config (no concurrency limit), should always authorize
    assert!(result);
}

/// Count invocations with optional task/status filters.
pub async fn test_count_invocations(orch: &dyn Orchestrator) {
    let task_a = test_task_id("count_a");
    let task_b = test_task_id("count_b");

    let call_a1 = make_call(&task_a);
    let call_a2 = make_call(&task_a);
    let call_b1 = make_call(&task_b);

    let _inv_a1 = orch.register_invocation(&call_a1).await.unwrap();
    let inv_a2 = orch.register_invocation(&call_a2).await.unwrap();
    let _inv_b1 = orch.register_invocation(&call_b1).await.unwrap();

    // Count all
    let total = orch.count_invocations(None, None).await.unwrap();
    assert_eq!(total, 3);

    // Count by task
    let count_a = orch.count_invocations(Some(&task_a), None).await.unwrap();
    assert_eq!(count_a, 2);

    // Count by status
    let count_reg = orch
        .count_invocations(None, Some(&[InvocationStatus::Registered]))
        .await
        .unwrap();
    assert_eq!(count_reg, 3);

    // Move one to Pending, then count
    let runner_id = rustvello_proto::identifiers::RunnerId::from_string("counter");
    orch.set_invocation_status(&inv_a2, InvocationStatus::Pending, Some(&runner_id))
        .await
        .unwrap();
    let count_reg_a = orch
        .count_invocations(Some(&task_a), Some(&[InvocationStatus::Registered]))
        .await
        .unwrap();
    assert_eq!(count_reg_a, 1);
}

/// Paginate invocation ids.
pub async fn test_get_invocation_ids_paginated(orch: &dyn Orchestrator) {
    let task_id = test_task_id("paged");
    for _ in 0..5 {
        let call = make_call(&task_id);
        orch.register_invocation(&call).await.unwrap();
    }

    let page1 = orch
        .get_invocation_ids_paginated(Some(&task_id), None, 2, 0)
        .await
        .unwrap();
    assert_eq!(page1.len(), 2);

    let page2 = orch
        .get_invocation_ids_paginated(Some(&task_id), None, 2, 2)
        .await
        .unwrap();
    assert_eq!(page2.len(), 2);

    // No overlap
    for id in &page1 {
        assert!(!page2.contains(id));
    }
}

/// Filter a set of ids by status.
pub async fn test_filter_by_status(orch: &dyn Orchestrator) {
    let task_id = test_task_id("filter_task");
    let c1 = make_call(&task_id);
    let c2 = make_call(&task_id);
    let c3 = make_call(&task_id);

    let inv1 = orch.register_invocation(&c1).await.unwrap();
    let inv2 = orch.register_invocation(&c2).await.unwrap();
    let inv3 = orch.register_invocation(&c3).await.unwrap();

    let runner_id = rustvello_proto::identifiers::RunnerId::from_string("filter-runner");
    orch.set_invocation_status(&inv2, InvocationStatus::Pending, Some(&runner_id))
        .await
        .unwrap();

    let all = vec![inv1.clone(), inv2.clone(), inv3.clone()];
    let registered = orch
        .filter_by_status(&all, &[InvocationStatus::Registered])
        .await
        .unwrap();
    assert_eq!(registered.len(), 2);
    assert!(registered.contains(&inv1));
    assert!(registered.contains(&inv3));
    assert!(!registered.contains(&inv2));
}

/// Active runner ids based on heartbeat timeout.
pub async fn test_get_active_runner_ids(orch: &dyn Orchestrator) {
    let runner_id = rustvello_proto::identifiers::RunnerId::from_string("active-runner");
    orch.register_heartbeat(&runner_id, false).await.unwrap();

    let active = orch.get_active_runner_ids(60).await.unwrap();
    assert!(active.iter().any(|r| r.to_string() == "active-runner"));
}

/// Purge clears invocations.
pub async fn test_purge(orch: &dyn Orchestrator) {
    let task_id = test_task_id("purge_task");
    let call = make_call(&task_id);
    let _inv = orch.register_invocation(&call).await.unwrap();

    let before = orch.count_invocations(None, None).await.unwrap();
    assert!(before >= 1);

    orch.purge().await.unwrap();

    let after = orch.count_invocations(None, None).await.unwrap();
    assert_eq!(after, 0);
}

// ===========================================================================
// Negative path tests
// ===========================================================================

/// Reject an invalid status transition (Registered → Running skips Pending).
pub async fn test_invalid_status_transition(orch: &dyn Orchestrator) {
    let task_id = test_task_id("test_task");
    let call = make_call(&task_id);
    let inv_id = orch.register_invocation(&call).await.unwrap();

    let runner_id = rustvello_proto::identifiers::RunnerId::new();
    let result = orch
        .set_invocation_status(&inv_id, InvocationStatus::Running, Some(&runner_id))
        .await;
    assert!(result.is_err(), "Registered → Running should be rejected");
}

/// Reject transition from a terminal state (Success → Pending).
pub async fn test_terminal_state_no_transition(orch: &dyn Orchestrator) {
    let task_id = test_task_id("test_task");
    let call = make_call(&task_id);
    let inv_id = orch.register_invocation(&call).await.unwrap();

    let runner_id = rustvello_proto::identifiers::RunnerId::new();
    // Drive to Success
    orch.set_invocation_status(&inv_id, InvocationStatus::Pending, Some(&runner_id))
        .await
        .unwrap();
    orch.set_invocation_status(&inv_id, InvocationStatus::Running, Some(&runner_id))
        .await
        .unwrap();
    orch.set_invocation_status(&inv_id, InvocationStatus::Success, Some(&runner_id))
        .await
        .unwrap();

    // Any transition from Success should fail
    let result = orch
        .set_invocation_status(&inv_id, InvocationStatus::Pending, Some(&runner_id))
        .await;
    assert!(result.is_err(), "Success → Pending should be rejected");
}

/// Get status of a non-existent invocation should return an error.
pub async fn test_get_missing_invocation(orch: &dyn Orchestrator) {
    let fake_id = rustvello_proto::identifiers::InvocationId::from_string(
        "nonexistent::task||missing-call-id".to_string(),
    );
    let result = orch.get_invocation_status(&fake_id).await;
    assert!(result.is_err(), "Missing invocation should return error");
}

/// CC type = Task with running_concurrency = 1: blocks second invocation.
pub async fn test_cc_task_blocks_duplicate(orch: &dyn Orchestrator) {
    let task_id = test_task_id("cc_task_block");
    let mut config = TaskConfig::default();
    config.concurrency_control = rustvello_proto::status::ConcurrencyControlType::Task;
    config.running_concurrency = Some(1);

    let call = make_call(&task_id);
    let inv1 = orch.register_invocation(&call).await.unwrap();
    let runner = rustvello_proto::identifiers::RunnerId::from_string("cc-runner");
    orch.set_invocation_status(&inv1, InvocationStatus::Pending, Some(&runner))
        .await
        .unwrap();
    orch.index_for_concurrency_control(&inv1, &task_id, Some(&SerializedArguments::new()))
        .await
        .unwrap();

    // Task-level CC: second invocation should be blocked
    let allowed = orch
        .check_running_concurrency(&task_id, &config, Some(&SerializedArguments::new()))
        .await
        .unwrap();
    assert!(!allowed, "Task CC should block second invocation");

    // Remove from index → allowed again
    orch.remove_from_concurrency_index(&inv1).await.unwrap();
    let allowed = orch
        .check_running_concurrency(&task_id, &config, Some(&SerializedArguments::new()))
        .await
        .unwrap();
    assert!(allowed, "Should be allowed after removing from index");
}

/// CC type = Argument: same args blocked, different args allowed.
pub async fn test_cc_argument_same_args_blocked(orch: &dyn Orchestrator) {
    let task_id = test_task_id("cc_arg_block");
    let mut config = TaskConfig::default();
    config.concurrency_control = rustvello_proto::status::ConcurrencyControlType::Argument;
    config.running_concurrency = Some(1);

    let mut args1 = SerializedArguments::new();
    args1.insert("x", "1");
    let mut args2 = SerializedArguments::new();
    args2.insert("x", "2");

    let call = CallDTO::new(task_id.clone(), args1.clone());
    let inv1 = orch.register_invocation(&call).await.unwrap();
    let runner = rustvello_proto::identifiers::RunnerId::from_string("cc-arg-runner");
    orch.set_invocation_status(&inv1, InvocationStatus::Pending, Some(&runner))
        .await
        .unwrap();
    orch.index_for_concurrency_control(&inv1, &task_id, Some(&args1))
        .await
        .unwrap();

    // Same args → blocked
    let allowed = orch
        .check_running_concurrency(&task_id, &config, Some(&args1))
        .await
        .unwrap();
    assert!(!allowed, "Same args should be blocked");

    // Different args → allowed
    let allowed = orch
        .check_running_concurrency(&task_id, &config, Some(&args2))
        .await
        .unwrap();
    assert!(allowed, "Different args should be allowed");
}

/// CC type = Argument with key_arguments subset: only the subset determines blocking.
pub async fn test_cc_key_arguments_subset(orch: &dyn Orchestrator) {
    let task_id = test_task_id("cc_keyarg");
    let mut config = TaskConfig::default();
    config.concurrency_control = rustvello_proto::status::ConcurrencyControlType::Argument;
    config.running_concurrency = Some(1);
    config.key_arguments = vec!["order_id".to_string()];

    // Index with key_arguments subset (only "order_id" matters)
    let mut key_args = SerializedArguments::new();
    key_args.insert("order_id", "100");

    let mut full_args1 = SerializedArguments::new();
    full_args1.insert("order_id", "100");
    full_args1.insert("quantity", "5");

    let call = CallDTO::new(task_id.clone(), full_args1.clone());
    let inv1 = orch.register_invocation(&call).await.unwrap();
    let runner = rustvello_proto::identifiers::RunnerId::from_string("key-runner");
    orch.set_invocation_status(&inv1, InvocationStatus::Pending, Some(&runner))
        .await
        .unwrap();
    // Index with only the key_argument subset
    orch.index_for_concurrency_control(&inv1, &task_id, Some(&key_args))
        .await
        .unwrap();

    // Same order_id (different quantity) → blocked (keyed on order_id only)
    let allowed = orch
        .check_running_concurrency(&task_id, &config, Some(&key_args))
        .await
        .unwrap();
    assert!(!allowed, "Same key_argument value should be blocked");

    // Different order_id → allowed
    let mut diff_key = SerializedArguments::new();
    diff_key.insert("order_id", "200");
    let allowed = orch
        .check_running_concurrency(&task_id, &config, Some(&diff_key))
        .await
        .unwrap();
    assert!(allowed, "Different key_argument value should be allowed");
}

/// Record and retrieve atomic service executions.
///
/// Backends that don't override the default no-op trait impls will return an
/// empty timeline — the test gracefully skips assertions in that case.
pub async fn test_atomic_service_timeline(orch: &dyn Orchestrator) {
    let runner_id = rustvello_proto::identifiers::RunnerId::from_string("atomic-runner");
    let now = chrono::Utc::now();
    let start = now - chrono::Duration::seconds(10);
    let end = now - chrono::Duration::seconds(5);

    orch.record_atomic_service_execution(&runner_id, start, end)
        .await
        .unwrap();

    let timeline = orch.get_atomic_service_timeline().await.unwrap();
    // Default trait impl returns empty vec; only assert when the backend
    // actually persists atomic-service executions.
    if !timeline.is_empty() {
        assert_eq!(timeline[0].runner_id, "atomic-runner");
        assert!(timeline[0].duration_secs() > 0.0);
    }
}

/// Stale pending invocations are detected after timeout.
pub async fn test_stale_pending_detection(orch: &dyn Orchestrator) {
    let task_id = test_task_id("stale_pending");
    let call = make_call(&task_id);
    let inv_id = orch.register_invocation(&call).await.unwrap();

    let runner = rustvello_proto::identifiers::RunnerId::from_string("dead-runner");
    orch.set_invocation_status(&inv_id, InvocationStatus::Pending, Some(&runner))
        .await
        .unwrap();

    // Wait briefly then check with 0-second timeout (immediate stale)
    tokio::time::sleep(std::time::Duration::from_millis(10)).await;
    let stale = orch.get_stale_pending_invocations(0).await.unwrap();
    assert!(
        stale.contains(&inv_id),
        "Should detect stale pending invocation"
    );
}

/// Stale running invocations are detected after timeout.
pub async fn test_stale_running_detection(orch: &dyn Orchestrator) {
    let task_id = test_task_id("stale_running");
    let call = make_call(&task_id);
    let inv_id = orch.register_invocation(&call).await.unwrap();

    let runner = rustvello_proto::identifiers::RunnerId::from_string("dead-runner-2");
    orch.set_invocation_status(&inv_id, InvocationStatus::Pending, Some(&runner))
        .await
        .unwrap();
    orch.set_invocation_status(&inv_id, InvocationStatus::Running, Some(&runner))
        .await
        .unwrap();

    tokio::time::sleep(std::time::Duration::from_millis(10)).await;
    let stale = orch.get_stale_running_invocations(0).await.unwrap();
    assert!(
        stale.contains(&inv_id),
        "Should detect stale running invocation"
    );
}

/// Ownership violation: a different runner cannot transition a Pending invocation.
pub async fn test_ownership_violation(orch: &dyn Orchestrator) {
    let task_id = test_task_id("test_task");
    let call = make_call(&task_id);
    let inv_id = orch.register_invocation(&call).await.unwrap();

    let runner_a = rustvello_proto::identifiers::RunnerId::new();
    let runner_b = rustvello_proto::identifiers::RunnerId::new();

    // runner_a claims the invocation
    orch.set_invocation_status(&inv_id, InvocationStatus::Pending, Some(&runner_a))
        .await
        .unwrap();

    // runner_b tries to transition it — should be rejected
    let result = orch
        .set_invocation_status(&inv_id, InvocationStatus::Running, Some(&runner_b))
        .await;
    assert!(
        result.is_err(),
        "Different runner should not own this invocation"
    );
}

/// Macro to generate all orchestrator suite tests.
#[macro_export]
macro_rules! orchestrator_suite {
    ($setup:expr) => {
        #[tokio::test]
        async fn suite_orch_register_invocation() {
            let orch = $setup;
            $crate::orchestrator::test_register_invocation(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_status_transitions() {
            let orch = $setup;
            $crate::orchestrator::test_status_transitions(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_get_invocations_by_task() {
            let orch = $setup;
            $crate::orchestrator::test_get_invocations_by_task(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_get_invocations_by_status() {
            let orch = $setup;
            $crate::orchestrator::test_get_invocations_by_status(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_concurrency_control() {
            let orch = $setup;
            $crate::orchestrator::test_concurrency_control(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_count_invocations() {
            let orch = $setup;
            $crate::orchestrator::test_count_invocations(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_get_invocation_ids_paginated() {
            let orch = $setup;
            $crate::orchestrator::test_get_invocation_ids_paginated(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_filter_by_status() {
            let orch = $setup;
            $crate::orchestrator::test_filter_by_status(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_get_active_runner_ids() {
            let orch = $setup;
            $crate::orchestrator::test_get_active_runner_ids(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_purge() {
            let orch = $setup;
            $crate::orchestrator::test_purge(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_invalid_status_transition() {
            let orch = $setup;
            $crate::orchestrator::test_invalid_status_transition(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_terminal_state_no_transition() {
            let orch = $setup;
            $crate::orchestrator::test_terminal_state_no_transition(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_get_missing_invocation() {
            let orch = $setup;
            $crate::orchestrator::test_get_missing_invocation(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_ownership_violation() {
            let orch = $setup;
            $crate::orchestrator::test_ownership_violation(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_cc_task_blocks_duplicate() {
            let orch = $setup;
            $crate::orchestrator::test_cc_task_blocks_duplicate(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_cc_argument_same_args_blocked() {
            let orch = $setup;
            $crate::orchestrator::test_cc_argument_same_args_blocked(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_cc_key_arguments_subset() {
            let orch = $setup;
            $crate::orchestrator::test_cc_key_arguments_subset(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_atomic_service_timeline() {
            let orch = $setup;
            $crate::orchestrator::test_atomic_service_timeline(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_stale_pending_detection() {
            let orch = $setup;
            $crate::orchestrator::test_stale_pending_detection(&orch).await;
        }

        #[tokio::test]
        async fn suite_orch_stale_running_detection() {
            let orch = $setup;
            $crate::orchestrator::test_stale_running_detection(&orch).await;
        }
    };
}

/// Async-setup variant of [`orchestrator_suite!`] for testcontainers backends.
///
/// `$setup` is an async expression returning `(_guard, orchestrator)`.
/// Tests are `#[ignore = "requires Docker"]`.
#[macro_export]
macro_rules! async_orchestrator_suite {
    ($setup:expr) => {
        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_register_invocation() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_register_invocation(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_status_transitions() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_status_transitions(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_get_invocations_by_task() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_get_invocations_by_task(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_get_invocations_by_status() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_get_invocations_by_status(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_concurrency_control() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_concurrency_control(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_count_invocations() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_count_invocations(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_get_invocation_ids_paginated() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_get_invocation_ids_paginated(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_filter_by_status() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_filter_by_status(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_get_active_runner_ids() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_get_active_runner_ids(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_purge() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_purge(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_invalid_status_transition() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_invalid_status_transition(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_terminal_state_no_transition() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_terminal_state_no_transition(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_get_missing_invocation() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_get_missing_invocation(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_ownership_violation() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_ownership_violation(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_cc_task_blocks_duplicate() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_cc_task_blocks_duplicate(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_cc_argument_same_args_blocked() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_cc_argument_same_args_blocked(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_cc_key_arguments_subset() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_cc_key_arguments_subset(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_atomic_service_timeline() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_atomic_service_timeline(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_stale_pending_detection() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_stale_pending_detection(&orch).await;
        }

        #[tokio::test]
        #[ignore = "requires Docker"]
        async fn suite_orch_stale_running_detection() {
            let (_c, orch) = $setup.await;
            $crate::orchestrator::test_stale_running_detection(&orch).await;
        }
    };
}