agentd 0.1.2

Agent daemon for secure capability execution with pluggable isolation backends
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
757
758
759
760
761
762
763
764
//! Testing infrastructure for NATS-dependent code
//!
//! This module provides mock implementations of NATS client functionality
//! to enable unit testing of code that depends on NATS without requiring
//! a running NATS server.

use anyhow::Result;
use async_trait::async_trait;
use parking_lot::Mutex;
use std::collections::{HashMap, VecDeque};
use std::sync::Arc;

// Re-export traits from the main nats module
pub use crate::nats::{IntentResultPublisher, NatsPublisher};

/// Mock NATS publisher for testing
///
/// Records all published messages for verification in tests.
#[derive(Default)]
pub struct MockNatsPublisher {
    /// Recorded published messages: (subject, payload)
    published_messages: Arc<Mutex<Vec<(String, Vec<u8>)>>>,

    /// Recorded request-reply messages: (subject, payload)
    request_messages: Arc<Mutex<Vec<(String, Vec<u8>)>>>,

    /// Pre-configured responses for request-reply
    responses: Arc<Mutex<HashMap<String, VecDeque<Vec<u8>>>>>,

    /// Whether to simulate failures
    fail_on_publish: Arc<Mutex<bool>>,

    /// Specific subjects to fail on
    fail_subjects: Arc<Mutex<Vec<String>>>,
}

impl MockNatsPublisher {
    /// Create a new mock publisher
    pub fn new() -> Self {
        Self::default()
    }

    /// Configure a response for a specific subject
    pub fn set_response(&self, subject: &str, response: Vec<u8>) {
        let mut responses = self.responses.lock();
        responses
            .entry(subject.to_string())
            .or_insert_with(VecDeque::new)
            .push_back(response);
    }

    /// Configure multiple responses for a subject (FIFO)
    pub fn set_responses(&self, subject: &str, responses_list: Vec<Vec<u8>>) {
        let mut responses = self.responses.lock();
        let queue = responses
            .entry(subject.to_string())
            .or_insert_with(VecDeque::new);
        for response in responses_list {
            queue.push_back(response);
        }
    }

    /// Enable publish failures
    pub fn set_fail_on_publish(&self, fail: bool) {
        *self.fail_on_publish.lock() = fail;
    }

    /// Set specific subjects that should fail
    pub fn set_fail_subjects(&self, subjects: Vec<String>) {
        *self.fail_subjects.lock() = subjects;
    }

    /// Get all published messages
    pub fn get_published(&self) -> Vec<(String, Vec<u8>)> {
        self.published_messages.lock().clone()
    }

    /// Get all request messages
    pub fn get_requests(&self) -> Vec<(String, Vec<u8>)> {
        self.request_messages.lock().clone()
    }

    /// Get published messages for a specific subject
    pub fn get_published_to(&self, subject: &str) -> Vec<Vec<u8>> {
        self.published_messages
            .lock()
            .iter()
            .filter(|(s, _)| s == subject)
            .map(|(_, p)| p.clone())
            .collect()
    }

    /// Check if a message was published to a subject
    pub fn was_published_to(&self, subject: &str) -> bool {
        self.published_messages
            .lock()
            .iter()
            .any(|(s, _)| s == subject)
    }

    /// Get the count of messages published
    pub fn published_count(&self) -> usize {
        self.published_messages.lock().len()
    }

    /// Clear all recorded messages
    pub fn clear(&self) {
        self.published_messages.lock().clear();
        self.request_messages.lock().clear();
    }

    fn should_fail(&self, subject: &str) -> bool {
        if *self.fail_on_publish.lock() {
            return true;
        }
        self.fail_subjects.lock().contains(&subject.to_string())
    }
}

#[async_trait]
impl NatsPublisher for MockNatsPublisher {
    async fn publish(&self, subject: &str, payload: &[u8]) -> Result<()> {
        if self.should_fail(subject) {
            return Err(anyhow::anyhow!(
                "Mock NATS publish failure for subject: {}",
                subject
            ));
        }

        self.published_messages
            .lock()
            .push((subject.to_string(), payload.to_vec()));
        Ok(())
    }

    async fn publish_with_reply(&self, subject: &str, _reply: &str, payload: &[u8]) -> Result<()> {
        if self.should_fail(subject) {
            return Err(anyhow::anyhow!(
                "Mock NATS publish failure for subject: {}",
                subject
            ));
        }

        self.published_messages
            .lock()
            .push((subject.to_string(), payload.to_vec()));
        Ok(())
    }

    async fn request(&self, subject: &str, payload: &[u8]) -> Result<Vec<u8>> {
        if self.should_fail(subject) {
            return Err(anyhow::anyhow!(
                "Mock NATS request failure for subject: {}",
                subject
            ));
        }

        self.request_messages
            .lock()
            .push((subject.to_string(), payload.to_vec()));

        // Get pre-configured response if available
        let response = {
            let mut responses = self.responses.lock();
            responses
                .get_mut(subject)
                .and_then(|queue| queue.pop_front())
        };

        match response {
            Some(r) => Ok(r),
            None => Err(anyhow::anyhow!(
                "No mock response configured for subject: {}",
                subject
            )),
        }
    }
}

/// Trait for NATS result publishing
///
/// This trait abstracts the result publishing functionality
/// used by the admission pipeline.
#[async_trait]
pub trait ResultPublisher: Send + Sync {
    /// Publish an intent result
    async fn publish_result(&self, intent_id: &str, result: &[u8]) -> Result<()>;
}

/// Mock result publisher for testing
#[derive(Default)]
pub struct MockResultPublisher {
    /// Recorded results: (intent_id, result)
    results: Arc<Mutex<Vec<(String, Vec<u8>)>>>,

    /// Whether to fail on publish
    fail_on_publish: Arc<Mutex<bool>>,
}

impl MockResultPublisher {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn set_fail_on_publish(&self, fail: bool) {
        *self.fail_on_publish.lock() = fail;
    }

    pub fn get_results(&self) -> Vec<(String, Vec<u8>)> {
        self.results.lock().clone()
    }

    pub fn get_result_for(&self, intent_id: &str) -> Option<Vec<u8>> {
        self.results
            .lock()
            .iter()
            .find(|(id, _)| id == intent_id)
            .map(|(_, r)| r.clone())
    }

    pub fn was_result_published(&self, intent_id: &str) -> bool {
        self.results.lock().iter().any(|(id, _)| id == intent_id)
    }

    pub fn result_count(&self) -> usize {
        self.results.lock().len()
    }

    pub fn clear(&self) {
        self.results.lock().clear();
    }
}

#[async_trait]
impl ResultPublisher for MockResultPublisher {
    async fn publish_result(&self, intent_id: &str, result: &[u8]) -> Result<()> {
        if *self.fail_on_publish.lock() {
            return Err(anyhow::anyhow!(
                "Mock result publish failure for intent: {}",
                intent_id
            ));
        }

        self.results
            .lock()
            .push((intent_id.to_string(), result.to_vec()));
        Ok(())
    }
}

/// Mock intent result publisher for testing admission pipeline
///
/// Records all published IntentResults for verification in tests.
/// This is the preferred mock for testing code that uses IntentResultPublisher.
#[derive(Default)]
pub struct MockIntentResultPublisher {
    /// Recorded results: (intent_id, serialized result)
    results: Arc<Mutex<Vec<(String, smith_protocol::IntentResult)>>>,

    /// Whether to fail on publish
    fail_on_publish: Arc<Mutex<bool>>,

    /// Specific intent IDs to fail on
    fail_intent_ids: Arc<Mutex<Vec<String>>>,
}

impl MockIntentResultPublisher {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn set_fail_on_publish(&self, fail: bool) {
        *self.fail_on_publish.lock() = fail;
    }

    pub fn set_fail_intent_ids(&self, intent_ids: Vec<String>) {
        *self.fail_intent_ids.lock() = intent_ids;
    }

    pub fn get_results(&self) -> Vec<(String, smith_protocol::IntentResult)> {
        self.results.lock().clone()
    }

    pub fn get_result_for(&self, intent_id: &str) -> Option<smith_protocol::IntentResult> {
        self.results
            .lock()
            .iter()
            .find(|(id, _)| id == intent_id)
            .map(|(_, r)| r.clone())
    }

    pub fn was_result_published(&self, intent_id: &str) -> bool {
        self.results.lock().iter().any(|(id, _)| id == intent_id)
    }

    pub fn result_count(&self) -> usize {
        self.results.lock().len()
    }

    pub fn clear(&self) {
        self.results.lock().clear();
    }

    fn should_fail(&self, intent_id: &str) -> bool {
        if *self.fail_on_publish.lock() {
            return true;
        }
        self.fail_intent_ids.lock().contains(&intent_id.to_string())
    }
}

#[async_trait]
impl IntentResultPublisher for MockIntentResultPublisher {
    async fn publish_result(
        &self,
        intent_id: &str,
        result: &smith_protocol::IntentResult,
    ) -> Result<()> {
        if self.should_fail(intent_id) {
            return Err(anyhow::anyhow!(
                "Mock intent result publish failure for intent: {}",
                intent_id
            ));
        }

        self.results
            .lock()
            .push((intent_id.to_string(), result.clone()));
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    // ==================== MockNatsPublisher Tests ====================

    #[tokio::test]
    async fn test_mock_publisher_creation() {
        let publisher = MockNatsPublisher::new();
        assert_eq!(publisher.published_count(), 0);
    }

    #[tokio::test]
    async fn test_mock_publisher_publish() {
        let publisher = MockNatsPublisher::new();

        publisher.publish("test.subject", b"hello").await.unwrap();

        assert_eq!(publisher.published_count(), 1);
        assert!(publisher.was_published_to("test.subject"));

        let messages = publisher.get_published_to("test.subject");
        assert_eq!(messages.len(), 1);
        assert_eq!(messages[0], b"hello");
    }

    #[tokio::test]
    async fn test_mock_publisher_multiple_publishes() {
        let publisher = MockNatsPublisher::new();

        publisher.publish("subject1", b"msg1").await.unwrap();
        publisher.publish("subject2", b"msg2").await.unwrap();
        publisher.publish("subject1", b"msg3").await.unwrap();

        assert_eq!(publisher.published_count(), 3);
        assert_eq!(publisher.get_published_to("subject1").len(), 2);
        assert_eq!(publisher.get_published_to("subject2").len(), 1);
    }

    #[tokio::test]
    async fn test_mock_publisher_fail_on_publish() {
        let publisher = MockNatsPublisher::new();
        publisher.set_fail_on_publish(true);

        let result = publisher.publish("test.subject", b"hello").await;

        assert!(result.is_err());
        assert_eq!(publisher.published_count(), 0);
    }

    #[tokio::test]
    async fn test_mock_publisher_fail_subjects() {
        let publisher = MockNatsPublisher::new();
        publisher.set_fail_subjects(vec!["fail.subject".to_string()]);

        // Should succeed on non-failing subject
        publisher.publish("good.subject", b"hello").await.unwrap();
        assert_eq!(publisher.published_count(), 1);

        // Should fail on failing subject
        let result = publisher.publish("fail.subject", b"hello").await;
        assert!(result.is_err());
        assert_eq!(publisher.published_count(), 1); // Still 1, not 2
    }

    #[tokio::test]
    async fn test_mock_publisher_request_with_response() {
        let publisher = MockNatsPublisher::new();
        publisher.set_response("test.request", b"response".to_vec());

        let response = publisher.request("test.request", b"request").await.unwrap();

        assert_eq!(response, b"response");
        assert_eq!(publisher.get_requests().len(), 1);
    }

    #[tokio::test]
    async fn test_mock_publisher_request_multiple_responses() {
        let publisher = MockNatsPublisher::new();
        publisher.set_responses(
            "test.request",
            vec![
                b"response1".to_vec(),
                b"response2".to_vec(),
                b"response3".to_vec(),
            ],
        );

        let r1 = publisher.request("test.request", b"req1").await.unwrap();
        let r2 = publisher.request("test.request", b"req2").await.unwrap();
        let r3 = publisher.request("test.request", b"req3").await.unwrap();

        assert_eq!(r1, b"response1");
        assert_eq!(r2, b"response2");
        assert_eq!(r3, b"response3");
    }

    #[tokio::test]
    async fn test_mock_publisher_request_no_response() {
        let publisher = MockNatsPublisher::new();

        let result = publisher.request("no.response", b"request").await;

        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_mock_publisher_clear() {
        let publisher = MockNatsPublisher::new();

        publisher.publish("subject", b"msg").await.unwrap();
        publisher.set_response("request", b"response".to_vec());
        let _ = publisher.request("request", b"req").await;

        assert_eq!(publisher.published_count(), 1);
        assert_eq!(publisher.get_requests().len(), 1);

        publisher.clear();

        assert_eq!(publisher.published_count(), 0);
        assert_eq!(publisher.get_requests().len(), 0);
    }

    #[tokio::test]
    async fn test_mock_publisher_publish_with_reply() {
        let publisher = MockNatsPublisher::new();

        publisher
            .publish_with_reply("subject", "reply.to", b"msg")
            .await
            .unwrap();

        assert_eq!(publisher.published_count(), 1);
        assert!(publisher.was_published_to("subject"));
    }

    // ==================== MockResultPublisher Tests ====================

    #[tokio::test]
    async fn test_mock_result_publisher_creation() {
        let publisher = MockResultPublisher::new();
        assert_eq!(publisher.result_count(), 0);
    }

    #[tokio::test]
    async fn test_mock_result_publisher_publish() {
        let publisher = MockResultPublisher::new();

        publisher
            .publish_result("intent-123", b"result data")
            .await
            .unwrap();

        assert_eq!(publisher.result_count(), 1);
        assert!(publisher.was_result_published("intent-123"));

        let result = publisher.get_result_for("intent-123").unwrap();
        assert_eq!(result, b"result data");
    }

    #[tokio::test]
    async fn test_mock_result_publisher_multiple_results() {
        let publisher = MockResultPublisher::new();

        publisher
            .publish_result("intent-1", b"result1")
            .await
            .unwrap();
        publisher
            .publish_result("intent-2", b"result2")
            .await
            .unwrap();

        assert_eq!(publisher.result_count(), 2);
        assert!(publisher.was_result_published("intent-1"));
        assert!(publisher.was_result_published("intent-2"));
    }

    #[tokio::test]
    async fn test_mock_result_publisher_fail() {
        let publisher = MockResultPublisher::new();
        publisher.set_fail_on_publish(true);

        let result = publisher.publish_result("intent-123", b"result").await;

        assert!(result.is_err());
        assert_eq!(publisher.result_count(), 0);
    }

    #[tokio::test]
    async fn test_mock_result_publisher_clear() {
        let publisher = MockResultPublisher::new();

        publisher
            .publish_result("intent-123", b"result")
            .await
            .unwrap();
        assert_eq!(publisher.result_count(), 1);

        publisher.clear();
        assert_eq!(publisher.result_count(), 0);
    }

    #[tokio::test]
    async fn test_mock_result_publisher_get_nonexistent() {
        let publisher = MockResultPublisher::new();

        assert!(publisher.get_result_for("nonexistent").is_none());
        assert!(!publisher.was_result_published("nonexistent"));
    }

    // ==================== Thread Safety Tests ====================

    #[tokio::test]
    async fn test_mock_publisher_concurrent_access() {
        let publisher = Arc::new(MockNatsPublisher::new());

        let mut handles = vec![];
        for i in 0..10 {
            let p = publisher.clone();
            let handle = tokio::spawn(async move {
                p.publish(&format!("subject.{}", i), format!("msg{}", i).as_bytes())
                    .await
                    .unwrap();
            });
            handles.push(handle);
        }

        for handle in handles {
            handle.await.unwrap();
        }

        assert_eq!(publisher.published_count(), 10);
    }

    #[tokio::test]
    async fn test_mock_result_publisher_concurrent_access() {
        let publisher = Arc::new(MockResultPublisher::new());

        let mut handles = vec![];
        for i in 0..10 {
            let p = publisher.clone();
            let handle = tokio::spawn(async move {
                p.publish_result(&format!("intent-{}", i), format!("result{}", i).as_bytes())
                    .await
                    .unwrap();
            });
            handles.push(handle);
        }

        for handle in handles {
            handle.await.unwrap();
        }

        assert_eq!(publisher.result_count(), 10);
    }

    // ==================== MockIntentResultPublisher Tests ====================

    fn create_test_intent_result(
        status: smith_protocol::ExecutionStatus,
    ) -> smith_protocol::IntentResult {
        smith_protocol::IntentResult {
            intent_id: "test-intent".to_string(),
            status,
            output: Some(serde_json::json!({"result": "output"})),
            error: None,
            started_at_ns: 0,
            finished_at_ns: 100_000_000,
            runner_meta: smith_protocol::RunnerMetadata::empty(),
            audit_ref: smith_protocol::AuditRef {
                id: "audit-test".to_string(),
                timestamp: 0,
                hash: "test-hash".to_string(),
            },
        }
    }

    #[tokio::test]
    async fn test_mock_intent_result_publisher_creation() {
        let publisher = MockIntentResultPublisher::new();
        assert_eq!(publisher.result_count(), 0);
    }

    #[tokio::test]
    async fn test_mock_intent_result_publisher_publish() {
        let publisher = MockIntentResultPublisher::new();
        let result = create_test_intent_result(smith_protocol::ExecutionStatus::Ok);

        publisher
            .publish_result("intent-123", &result)
            .await
            .unwrap();

        assert_eq!(publisher.result_count(), 1);
        assert!(publisher.was_result_published("intent-123"));

        let stored = publisher.get_result_for("intent-123").unwrap();
        assert_eq!(stored.status, smith_protocol::ExecutionStatus::Ok);
    }

    #[tokio::test]
    async fn test_mock_intent_result_publisher_multiple_results() {
        let publisher = MockIntentResultPublisher::new();

        let result1 = create_test_intent_result(smith_protocol::ExecutionStatus::Ok);
        let result2 = create_test_intent_result(smith_protocol::ExecutionStatus::Error);

        publisher
            .publish_result("intent-1", &result1)
            .await
            .unwrap();
        publisher
            .publish_result("intent-2", &result2)
            .await
            .unwrap();

        assert_eq!(publisher.result_count(), 2);
        assert!(publisher.was_result_published("intent-1"));
        assert!(publisher.was_result_published("intent-2"));
    }

    #[tokio::test]
    async fn test_mock_intent_result_publisher_fail_on_publish() {
        let publisher = MockIntentResultPublisher::new();
        publisher.set_fail_on_publish(true);

        let result = create_test_intent_result(smith_protocol::ExecutionStatus::Ok);
        let publish_result = publisher.publish_result("intent-123", &result).await;

        assert!(publish_result.is_err());
        assert_eq!(publisher.result_count(), 0);
    }

    #[tokio::test]
    async fn test_mock_intent_result_publisher_fail_specific_intents() {
        let publisher = MockIntentResultPublisher::new();
        publisher.set_fail_intent_ids(vec!["fail-intent".to_string()]);

        let result = create_test_intent_result(smith_protocol::ExecutionStatus::Ok);

        // Should succeed on non-failing intent
        publisher
            .publish_result("good-intent", &result)
            .await
            .unwrap();
        assert_eq!(publisher.result_count(), 1);

        // Should fail on failing intent
        let fail_result = publisher.publish_result("fail-intent", &result).await;
        assert!(fail_result.is_err());
        assert_eq!(publisher.result_count(), 1);
    }

    #[tokio::test]
    async fn test_mock_intent_result_publisher_clear() {
        let publisher = MockIntentResultPublisher::new();
        let result = create_test_intent_result(smith_protocol::ExecutionStatus::Ok);

        publisher.publish_result("intent-1", &result).await.unwrap();
        assert_eq!(publisher.result_count(), 1);

        publisher.clear();
        assert_eq!(publisher.result_count(), 0);
    }

    #[tokio::test]
    async fn test_mock_intent_result_publisher_get_nonexistent() {
        let publisher = MockIntentResultPublisher::new();

        assert!(publisher.get_result_for("nonexistent").is_none());
        assert!(!publisher.was_result_published("nonexistent"));
    }

    #[tokio::test]
    async fn test_mock_intent_result_publisher_concurrent_access() {
        let publisher = Arc::new(MockIntentResultPublisher::new());

        let mut handles = vec![];
        for i in 0..10 {
            let p = publisher.clone();
            let handle = tokio::spawn(async move {
                let result = smith_protocol::IntentResult {
                    intent_id: format!("intent-{}", i),
                    status: smith_protocol::ExecutionStatus::Ok,
                    output: Some(serde_json::json!({"output": format!("output-{}", i)})),
                    error: None,
                    started_at_ns: 0,
                    finished_at_ns: 100_000_000,
                    runner_meta: smith_protocol::RunnerMetadata::empty(),
                    audit_ref: smith_protocol::AuditRef {
                        id: format!("audit-{}", i),
                        timestamp: 0,
                        hash: "test-hash".to_string(),
                    },
                };
                p.publish_result(&format!("intent-{}", i), &result)
                    .await
                    .unwrap();
            });
            handles.push(handle);
        }

        for handle in handles {
            handle.await.unwrap();
        }

        assert_eq!(publisher.result_count(), 10);
    }

    #[tokio::test]
    async fn test_mock_intent_result_publisher_get_all_results() {
        let publisher = MockIntentResultPublisher::new();

        let result1 = create_test_intent_result(smith_protocol::ExecutionStatus::Ok);
        let result2 = create_test_intent_result(smith_protocol::ExecutionStatus::Error);

        publisher
            .publish_result("intent-1", &result1)
            .await
            .unwrap();
        publisher
            .publish_result("intent-2", &result2)
            .await
            .unwrap();

        let all_results = publisher.get_results();
        assert_eq!(all_results.len(), 2);
        assert_eq!(all_results[0].0, "intent-1");
        assert_eq!(all_results[1].0, "intent-2");
    }
}