pulpod 0.0.41

Pulpo daemon — manages agent sessions via tmux/Docker
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
use pulpo_common::event::{PulpoEvent, SessionEvent};
use serde::Serialize;
use tracing::{error, info};

use crate::config::DiscordWebhookConfig;

/// Builds and sends Discord webhook notifications for session events.
pub struct DiscordNotifier {
    config: DiscordWebhookConfig,
    client: reqwest::Client,
}

/// Discord embed structure.
#[derive(Debug, Serialize)]
struct DiscordEmbed {
    title: String,
    description: String,
    color: u32,
    fields: Vec<DiscordField>,
}

/// A field within a Discord embed.
#[derive(Debug, Serialize)]
struct DiscordField {
    name: String,
    value: String,
    inline: bool,
}

/// Discord webhook payload.
#[derive(Debug, Serialize)]
struct DiscordPayload {
    embeds: Vec<DiscordEmbed>,
}

/// Returns the Discord embed color for a given session status.
///
/// - active   → green  (`0x2ecc71`)
/// - ready    → blue   (`0x3498db`)
/// - stopped  → red    (`0xe74c3c`)
/// - lost     → orange (`0xe67e22`)
/// - other    → gray   (`0x95a5a6`)
pub const fn status_color(status: &str) -> u32 {
    // const fn can't use match on &str, so use byte comparison
    match status.as_bytes() {
        b"active" => 0x2e_cc71,
        b"ready" => 0x34_98db,
        b"stopped" => 0xe7_4c3c,
        b"lost" => 0xe6_7e22,
        _ => 0x95_a5a6,
    }
}

/// Builds the Discord webhook JSON payload for a session event.
pub fn build_discord_payload(event: &SessionEvent) -> serde_json::Value {
    let color = status_color(&event.status);
    let mut fields = vec![
        DiscordField {
            name: "Status".into(),
            value: event.status.clone(),
            inline: true,
        },
        DiscordField {
            name: "Node".into(),
            value: event.node_name.clone(),
            inline: true,
        },
    ];

    if let Some(prev) = &event.previous_status {
        fields.push(DiscordField {
            name: "Previous".into(),
            value: prev.clone(),
            inline: true,
        });
    }

    if let Some(url) = &event.pr_url {
        fields.push(DiscordField {
            name: "PR".into(),
            value: format!("[View PR]({url})"),
            inline: true,
        });
    }

    if let Some(branch) = &event.git_branch {
        let value = event
            .git_commit
            .as_ref()
            .map_or_else(|| branch.clone(), |commit| format!("{branch}@{commit}"));
        fields.push(DiscordField {
            name: "Branch".into(),
            value,
            inline: true,
        });
    }

    let ins = event.git_insertions.unwrap_or(0);
    let del = event.git_deletions.unwrap_or(0);
    if ins > 0 || del > 0 {
        let files = event.git_files_changed.unwrap_or(0);
        fields.push(DiscordField {
            name: "Changes".into(),
            value: format!("+{ins}/-{del} ({files} files)"),
            inline: true,
        });
    }

    if let Some(err) = &event.error_status {
        fields.push(DiscordField {
            name: "Error".into(),
            value: err.clone(),
            inline: false,
        });
    }

    if let Some(snippet) = &event.output_snippet {
        fields.push(DiscordField {
            name: "Output".into(),
            value: format!("```\n{snippet}\n```"),
            inline: false,
        });
    }

    let payload = DiscordPayload {
        embeds: vec![DiscordEmbed {
            title: format!("Session: {}", event.session_name),
            description: format!("Session `{}` is now **{}**", event.session_id, event.status),
            color,
            fields,
        }],
    };

    serde_json::to_value(&payload).unwrap_or_default()
}

/// Returns whether the notifier should send a notification for the given status.
pub fn should_notify(config: &DiscordWebhookConfig, status: &str) -> bool {
    config.events.is_empty() || config.events.iter().any(|e| e == status)
}

impl DiscordNotifier {
    /// Create a new `DiscordNotifier` from config.
    pub fn new(config: DiscordWebhookConfig) -> Self {
        Self {
            config,
            client: reqwest::Client::new(),
        }
    }

    /// Send a JSON payload as a Discord webhook notification.
    pub async fn send_payload(&self, payload: &serde_json::Value) -> Result<(), reqwest::Error> {
        self.client
            .post(&self.config.webhook_url)
            .json(payload)
            .send()
            .await?
            .error_for_status()?;
        Ok(())
    }

    /// Send a session event as a Discord webhook notification.
    pub async fn send(&self, event: &SessionEvent) -> Result<(), reqwest::Error> {
        let payload = build_discord_payload(event);
        info!(
            session = %event.session_name,
            status = %event.status,
            "Sending Discord notification"
        );
        self.send_payload(&payload).await
    }
}

/// Run the notification loop — subscribes to the event bus and sends Discord notifications.
pub async fn run_notification_loop(
    notifier: DiscordNotifier,
    mut rx: tokio::sync::broadcast::Receiver<PulpoEvent>,
    mut shutdown: tokio::sync::watch::Receiver<bool>,
) {
    loop {
        tokio::select! {
            result = rx.recv() => {
                match result {
                    Ok(event) => match event {
                        PulpoEvent::Session(ref se) => {
                            if should_notify(&notifier.config, &se.status)
                                && let Err(e) = notifier.send(se).await
                            {
                                error!(error = %e, "Discord notification failed");
                            }
                        }

                    },
                    Err(tokio::sync::broadcast::error::RecvError::Lagged(n)) => {
                        tracing::warn!(missed = n, "Discord notifier lagged, skipping events");
                    }
                    Err(tokio::sync::broadcast::error::RecvError::Closed) => {
                        info!("Event bus closed, stopping Discord notifier");
                        break;
                    }
                }
            }
            _ = shutdown.changed() => {
                info!("Discord notifier shutting down");
                break;
            }
        }
    }
}

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

    fn test_event(status: &str) -> SessionEvent {
        SessionEvent {
            session_id: "abc-123".into(),
            session_name: "my-session".into(),
            status: status.into(),
            previous_status: None,
            node_name: "node-1".into(),
            output_snippet: None,
            timestamp: "2026-01-01T00:00:00Z".into(),
            git_branch: None,
            git_commit: None,
            git_insertions: None,
            git_deletions: None,
            git_files_changed: None,
            pr_url: None,
            error_status: None,
        }
    }

    // --- status_color tests ---

    #[test]
    fn test_status_color_running() {
        assert_eq!(status_color("active"), 0x2e_cc71);
    }

    #[test]
    fn test_status_color_completed() {
        assert_eq!(status_color("ready"), 0x34_98db);
    }

    #[test]
    fn test_status_color_stopped() {
        assert_eq!(status_color("stopped"), 0xe7_4c3c);
    }

    #[test]
    fn test_status_color_stale() {
        assert_eq!(status_color("lost"), 0xe6_7e22);
    }

    #[test]
    fn test_status_color_unknown() {
        assert_eq!(status_color("creating"), 0x95_a5a6);
        assert_eq!(status_color(""), 0x95_a5a6);
    }

    // --- should_notify tests ---

    #[test]
    fn test_should_notify_empty_filter_allows_all() {
        let config = DiscordWebhookConfig {
            webhook_url: "https://example.com".into(),
            events: vec![],
        };
        assert!(should_notify(&config, "active"));
        assert!(should_notify(&config, "stopped"));
        assert!(should_notify(&config, "ready"));
    }

    #[test]
    fn test_should_notify_with_filter() {
        let config = DiscordWebhookConfig {
            webhook_url: "https://example.com".into(),
            events: vec!["ready".into(), "stopped".into()],
        };
        assert!(!should_notify(&config, "active"));
        assert!(should_notify(&config, "stopped"));
        assert!(should_notify(&config, "ready"));
        assert!(!should_notify(&config, "lost"));
    }

    // --- build_discord_payload tests ---

    #[test]
    fn test_build_payload_basic() {
        let event = test_event("active");
        let payload = build_discord_payload(&event);

        let embeds = payload["embeds"].as_array().unwrap();
        assert_eq!(embeds.len(), 1);

        let embed = &embeds[0];
        assert_eq!(embed["title"], "Session: my-session");
        assert!(embed["description"].as_str().unwrap().contains("abc-123"));
        assert_eq!(embed["color"], 0x2e_cc71);

        let fields = embed["fields"].as_array().unwrap();
        assert_eq!(fields.len(), 2); // Status + Node
        assert_eq!(fields[0]["name"], "Status");
        assert_eq!(fields[0]["value"], "active");
        assert_eq!(fields[1]["name"], "Node");
        assert_eq!(fields[1]["value"], "node-1");
    }

    #[test]
    fn test_build_payload_with_previous_status() {
        let event = SessionEvent {
            previous_status: Some("creating".into()),
            ..test_event("active")
        };
        let payload = build_discord_payload(&event);

        let fields = payload["embeds"][0]["fields"].as_array().unwrap();
        assert_eq!(fields.len(), 3);
        assert_eq!(fields[2]["name"], "Previous");
        assert_eq!(fields[2]["value"], "creating");
    }

    #[test]
    fn test_build_payload_with_output_snippet() {
        let event = SessionEvent {
            output_snippet: Some("hello world".into()),
            ..test_event("ready")
        };
        let payload = build_discord_payload(&event);

        let fields = payload["embeds"][0]["fields"].as_array().unwrap();
        assert_eq!(fields.len(), 3);
        assert_eq!(fields[2]["name"], "Output");
        assert!(fields[2]["value"].as_str().unwrap().contains("hello world"));
        assert!(!fields[2]["inline"].as_bool().unwrap());
    }

    #[test]
    fn test_build_payload_with_all_optionals() {
        let event = SessionEvent {
            previous_status: Some("lost".into()),
            output_snippet: Some("output".into()),
            ..test_event("active")
        };
        let payload = build_discord_payload(&event);

        let fields = payload["embeds"][0]["fields"].as_array().unwrap();
        assert_eq!(fields.len(), 4); // Status + Node + Previous + Output
    }

    #[test]
    fn test_build_payload_with_pr_url() {
        let mut event = test_event("ready");
        event.pr_url = Some("https://github.com/org/repo/pull/42".into());
        let payload = build_discord_payload(&event);
        let fields = payload["embeds"][0]["fields"].as_array().unwrap();
        let pr_field = fields.iter().find(|f| f["name"] == "PR").unwrap();
        assert!(pr_field["value"].as_str().unwrap().contains("[View PR]"));
        assert!(
            pr_field["value"]
                .as_str()
                .unwrap()
                .contains("https://github.com/org/repo/pull/42")
        );
        assert!(pr_field["inline"].as_bool().unwrap());
    }

    #[test]
    fn test_build_payload_with_branch_and_commit() {
        let mut event = test_event("ready");
        event.git_branch = Some("main".into());
        event.git_commit = Some("abc1234".into());
        let payload = build_discord_payload(&event);
        let fields = payload["embeds"][0]["fields"].as_array().unwrap();
        let branch_field = fields.iter().find(|f| f["name"] == "Branch").unwrap();
        assert_eq!(branch_field["value"], "main@abc1234");
    }

    #[test]
    fn test_build_payload_with_branch_no_commit() {
        let mut event = test_event("ready");
        event.git_branch = Some("fix-auth".into());
        let payload = build_discord_payload(&event);
        let fields = payload["embeds"][0]["fields"].as_array().unwrap();
        let branch_field = fields.iter().find(|f| f["name"] == "Branch").unwrap();
        assert_eq!(branch_field["value"], "fix-auth");
    }

    #[test]
    fn test_build_payload_with_changes() {
        let mut event = test_event("ready");
        event.git_insertions = Some(42);
        event.git_deletions = Some(7);
        event.git_files_changed = Some(3);
        let payload = build_discord_payload(&event);
        let fields = payload["embeds"][0]["fields"].as_array().unwrap();
        let changes_field = fields.iter().find(|f| f["name"] == "Changes").unwrap();
        assert_eq!(changes_field["value"], "+42/-7 (3 files)");
    }

    #[test]
    fn test_build_payload_with_zero_changes_omitted() {
        let mut event = test_event("ready");
        event.git_insertions = Some(0);
        event.git_deletions = Some(0);
        let payload = build_discord_payload(&event);
        let fields = payload["embeds"][0]["fields"].as_array().unwrap();
        assert!(fields.iter().all(|f| f["name"] != "Changes"));
    }

    #[test]
    fn test_build_payload_with_error_status() {
        let mut event = test_event("stopped");
        event.error_status = Some("Compile error in main.rs".into());
        let payload = build_discord_payload(&event);
        let fields = payload["embeds"][0]["fields"].as_array().unwrap();
        let err_field = fields.iter().find(|f| f["name"] == "Error").unwrap();
        assert_eq!(err_field["value"], "Compile error in main.rs");
        assert!(!err_field["inline"].as_bool().unwrap());
    }

    #[test]
    fn test_build_payload_with_all_enrichment_fields() {
        let mut event = test_event("ready");
        event.pr_url = Some("https://github.com/org/repo/pull/1".into());
        event.git_branch = Some("feat-x".into());
        event.git_commit = Some("deadbeef".into());
        event.git_insertions = Some(100);
        event.git_deletions = Some(50);
        event.git_files_changed = Some(10);
        event.error_status = Some("Lint warning".into());
        let payload = build_discord_payload(&event);
        let fields = payload["embeds"][0]["fields"].as_array().unwrap();
        // Status + Node + PR + Branch + Changes + Error = 6
        assert_eq!(fields.len(), 6);
    }

    #[test]
    fn test_build_payload_stopped_color() {
        let event = test_event("stopped");
        let payload = build_discord_payload(&event);
        assert_eq!(payload["embeds"][0]["color"], 0xe7_4c3c);
    }

    // --- DiscordNotifier tests ---

    #[test]
    fn test_notifier_new() {
        let config = DiscordWebhookConfig {
            webhook_url: "https://discord.com/api/webhooks/123/abc".into(),
            events: vec![],
        };
        let notifier = DiscordNotifier::new(config);
        assert_eq!(
            notifier.config.webhook_url,
            "https://discord.com/api/webhooks/123/abc"
        );
    }

    // --- send() tests ---

    use tokio::io::{AsyncReadExt, AsyncWriteExt};

    #[tokio::test]
    async fn test_send_success() {
        // Start a local server that returns 200
        let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
        let addr = listener.local_addr().unwrap();
        tokio::spawn(async move {
            let (mut socket, _) = listener.accept().await.unwrap();
            let mut buf = vec![0u8; 4096];
            let _ = socket.read(&mut buf).await;
            socket
                .write_all(b"HTTP/1.1 204 No Content\r\nContent-Length: 0\r\n\r\n")
                .await
                .unwrap();
        });

        let config = DiscordWebhookConfig {
            webhook_url: format!("http://{addr}/webhook"),
            events: vec![],
        };
        let notifier = DiscordNotifier::new(config);
        let result = notifier.send(&test_event("active")).await;
        assert!(result.is_ok());
    }

    #[tokio::test]
    async fn test_send_error_for_status() {
        // Start a local server that returns 400
        let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
        let addr = listener.local_addr().unwrap();
        tokio::spawn(async move {
            let (mut socket, _) = listener.accept().await.unwrap();
            let mut buf = vec![0u8; 4096];
            let _ = socket.read(&mut buf).await;
            socket
                .write_all(b"HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n")
                .await
                .unwrap();
        });

        let config = DiscordWebhookConfig {
            webhook_url: format!("http://{addr}/webhook"),
            events: vec![],
        };
        let notifier = DiscordNotifier::new(config);
        let result = notifier.send(&test_event("active")).await;
        assert!(result.is_err());
    }

    // --- run_notification_loop tests ---

    #[tokio::test]
    async fn test_notification_loop_shutdown() {
        let config = DiscordWebhookConfig {
            webhook_url: "https://example.com/webhook".into(),
            events: vec![],
        };
        let notifier = DiscordNotifier::new(config);
        let (event_tx, _) = tokio::sync::broadcast::channel::<PulpoEvent>(16);
        let rx = event_tx.subscribe();
        let (shutdown_tx, shutdown_rx) = tokio::sync::watch::channel(false);

        // Signal shutdown immediately
        shutdown_tx.send(true).unwrap();

        // Loop should exit promptly
        tokio::time::timeout(
            std::time::Duration::from_secs(2),
            run_notification_loop(notifier, rx, shutdown_rx),
        )
        .await
        .expect("notification loop should exit on shutdown");
    }

    #[tokio::test]
    async fn test_notification_loop_channel_closed() {
        let config = DiscordWebhookConfig {
            webhook_url: "https://example.com/webhook".into(),
            events: vec![],
        };
        let notifier = DiscordNotifier::new(config);
        let (event_tx, rx) = tokio::sync::broadcast::channel::<PulpoEvent>(16);
        let (_shutdown_tx, shutdown_rx) = tokio::sync::watch::channel(false);

        // Drop sender to close the channel
        drop(event_tx);

        tokio::time::timeout(
            std::time::Duration::from_secs(2),
            run_notification_loop(notifier, rx, shutdown_rx),
        )
        .await
        .expect("notification loop should exit when channel closes");
    }

    #[tokio::test]
    async fn test_notification_loop_filtered_event() {
        let config = DiscordWebhookConfig {
            webhook_url: "https://example.com/webhook".into(),
            events: vec!["stopped".into()], // Only stopped events
        };
        let notifier = DiscordNotifier::new(config);
        let (event_tx, rx) = tokio::sync::broadcast::channel::<PulpoEvent>(16);
        let (shutdown_tx, shutdown_rx) = tokio::sync::watch::channel(false);

        // Send an "active" event — should be filtered out (won't attempt HTTP)
        event_tx
            .send(PulpoEvent::Session(test_event("active")))
            .unwrap();

        // Then shutdown
        let handle = tokio::spawn(run_notification_loop(notifier, rx, shutdown_rx));

        // Give it a moment to process the event
        tokio::time::sleep(std::time::Duration::from_millis(50)).await;
        shutdown_tx.send(true).unwrap();

        tokio::time::timeout(std::time::Duration::from_secs(2), handle)
            .await
            .expect("should finish")
            .expect("should not panic");
    }

    #[tokio::test]
    async fn test_notification_loop_send_error() {
        // Use a URL that will fail immediately (connection refused)
        let config = DiscordWebhookConfig {
            webhook_url: "http://127.0.0.1:1/webhook".into(),
            events: vec![],
        };
        let notifier = DiscordNotifier::new(config);
        let (event_tx, rx) = tokio::sync::broadcast::channel::<PulpoEvent>(16);
        let (shutdown_tx, shutdown_rx) = tokio::sync::watch::channel(false);

        // Send an event that passes the filter — will attempt HTTP and fail
        event_tx
            .send(PulpoEvent::Session(test_event("active")))
            .unwrap();

        let handle = tokio::spawn(run_notification_loop(notifier, rx, shutdown_rx));

        // Wait for the HTTP attempt to fail
        tokio::time::sleep(std::time::Duration::from_millis(200)).await;
        shutdown_tx.send(true).unwrap();

        tokio::time::timeout(std::time::Duration::from_secs(5), handle)
            .await
            .expect("should finish")
            .expect("should not panic");
    }

    #[tokio::test]
    async fn test_notification_loop_lagged() {
        // Filter everything so the loop doesn't attempt HTTP after processing lag
        let config = DiscordWebhookConfig {
            webhook_url: "https://example.com/webhook".into(),
            events: vec!["stopped".into()],
        };
        let notifier = DiscordNotifier::new(config);
        // Tiny buffer to force lag
        let (event_tx, rx) = tokio::sync::broadcast::channel::<PulpoEvent>(1);
        let (shutdown_tx, shutdown_rx) = tokio::sync::watch::channel(false);

        // Overflow the buffer before the loop starts
        for i in 0..5 {
            let _ = event_tx.send(PulpoEvent::Session(SessionEvent {
                session_id: format!("id-{i}"),
                session_name: "s".into(),
                status: "active".into(),
                previous_status: None,
                node_name: "n".into(),
                output_snippet: None,
                timestamp: "t".into(),
                git_branch: None,
                git_commit: None,
                git_insertions: None,
                git_deletions: None,
                git_files_changed: None,
                pr_url: None,
                error_status: None,
            }));
        }

        let handle = tokio::spawn(run_notification_loop(notifier, rx, shutdown_rx));

        tokio::time::sleep(std::time::Duration::from_millis(100)).await;
        shutdown_tx.send(true).unwrap();

        tokio::time::timeout(std::time::Duration::from_secs(2), handle)
            .await
            .expect("should finish")
            .expect("should not panic");
    }

    #[test]
    fn test_discord_payload_serialize() {
        let payload = DiscordPayload {
            embeds: vec![DiscordEmbed {
                title: "Test".into(),
                description: "Desc".into(),
                color: 0,
                fields: vec![DiscordField {
                    name: "F".into(),
                    value: "V".into(),
                    inline: true,
                }],
            }],
        };
        let json = serde_json::to_string(&payload).unwrap();
        assert!(json.contains("\"title\":\"Test\""));
        assert!(json.contains("\"inline\":true"));
    }

    #[test]
    fn test_discord_embed_debug() {
        let embed = DiscordEmbed {
            title: "T".into(),
            description: "D".into(),
            color: 0,
            fields: vec![],
        };
        let debug = format!("{embed:?}");
        assert!(debug.contains("DiscordEmbed"));
    }

    #[test]
    fn test_discord_field_debug() {
        let field = DiscordField {
            name: "N".into(),
            value: "V".into(),
            inline: false,
        };
        let debug = format!("{field:?}");
        assert!(debug.contains("DiscordField"));
    }

    #[test]
    fn test_discord_payload_debug() {
        let payload = DiscordPayload { embeds: vec![] };
        let debug = format!("{payload:?}");
        assert!(debug.contains("DiscordPayload"));
    }
}