dugix 1.0.0

A local-first terminal chat app for deep research and multi-agent work
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
use crossterm::event::{KeyCode, KeyEvent};
use dugix_core::app::AppCommand;
use dugix_core::tools::Decision;
use ratatui::Frame;
use ratatui::layout::Rect;
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::Paragraph;

use crate::app_view::AppView;

use super::chrome::{self, PopupFrame, hint, keys};
use crate::ui::diff::{self, escaped_rows};
use crate::ui::style;

fn request_lines(
    tool: &str,
    action: &str,
    summary: &str,
    class: Option<&str>,
    width: usize,
    theme: &crate::theme::Theme,
) -> Vec<Line<'static>> {
    let dim = Style::default().fg(theme.fg_dim);
    let normal = Style::default().fg(theme.fg);
    let (evidence, summary) = summary
        .split_once('\n')
        .filter(|(head, _)| head.starts_with("in_scope ") || head.starts_with("risk: "))
        .unwrap_or(("", summary));
    let (head, body) = summary.split_once('\n').unwrap_or((summary, ""));
    let is_diff = body.starts_with("--- ") || body.starts_with("diff --git ");
    let parsed_counts = head.rsplit_once(" (+").and_then(|(label, counts)| {
        let (added, deleted) = counts.strip_suffix(')')?.split_once(" −")?;
        Some((
            label,
            added.parse::<usize>().ok()?,
            deleted.parse::<usize>().ok()?,
        ))
    });
    let label = if tool == "fs" {
        parsed_counts
            .map_or(head, |(label, _, _)| label)
            .to_string()
    } else {
        format!("{tool}{}{action}", style::SEP)
    };
    let mut header = escaped_rows(&label, width, normal, dim);
    if is_diff || parsed_counts.is_some() {
        let (added, deleted) = parsed_counts.map_or_else(
            || diff::counts(body),
            |(_, added, deleted)| (added, deleted),
        );
        let line = header.last_mut().expect("request has a header");
        line.spans.push(Span::styled(
            format!("  +{added}"),
            Style::default().fg(theme.success),
        ));
        line.spans.push(Span::styled(
            format!(" −{deleted}"),
            Style::default().fg(theme.error),
        ));
    }
    if let Some(class) = class {
        let badge_style = match class {
            "runs a command" => Style::default().fg(theme.accent2),
            "destructive" => Style::default()
                .fg(theme.error)
                .add_modifier(Modifier::BOLD),
            "reaches outside" => Style::default()
                .fg(theme.warning)
                .add_modifier(Modifier::BOLD),
            _ => dim,
        };
        let badge = escaped_rows(class, width, badge_style, dim).remove(0);
        let line = header.last_mut().expect("request has a header");
        *line = chrome::fit_line(line.clone(), width.saturating_sub(badge.width() + 1));
        let padding = width.saturating_sub(line.width() + badge.width()).max(1);
        line.spans.push(Span::raw(" ".repeat(padding)));
        line.spans.extend(badge.spans);
    }
    header.push(Line::default());
    if !evidence.is_empty() {
        header.extend(escaped_rows(evidence, width, dim, dim));
    }
    if is_diff {
        header.extend(diff::render(
            body,
            width,
            theme,
            diff::Options {
                max_rows: None,
                context: 3,
                hint: "",
            },
        ));
    } else {
        let text = if tool == "fs" { body } else { summary };
        for line in text.split('\n').filter(|line| !line.is_empty()) {
            let line = line.strip_prefix("background: ").unwrap_or(line);
            let color = if line.starts_with("could not parse safely:")
                || line.starts_with("this tool's definition changed")
            {
                Style::default().fg(theme.warning)
            } else if line.starts_with("$ ") {
                normal.add_modifier(Modifier::BOLD)
            } else if line.starts_with("in ") {
                dim
            } else {
                normal
            };
            header.extend(escaped_rows(line, width, color, dim));
        }
    }
    header
}

fn wave_lines(summary: &str, width: usize, theme: &crate::theme::Theme) -> Vec<Line<'static>> {
    let mut sections: Vec<(&str, &str, &str, String)> = Vec::new();
    for line in summary.split('\n').skip(1) {
        if let Some((number, call)) = line
            .split_once(". ")
            .filter(|(number, _)| number.parse::<usize>().is_ok())
        {
            let (tool, action) = call.split_once(' ').unwrap_or((call, ""));
            sections.push((number, tool, action, String::new()));
        } else if let Some((_, _, _, body)) = sections.last_mut() {
            if !body.is_empty() {
                body.push('\n');
            }
            body.push_str(line.strip_prefix("  ").unwrap_or(line));
        }
    }
    let mut lines = Vec::new();
    for (number, tool, action, body) in sections {
        if !lines.is_empty() {
            lines.push(Line::default());
        }
        let mut section =
            request_lines(tool, action, &body, None, width.saturating_sub(5), theme).into_iter();
        let Some(mut head) = section.next() else {
            continue;
        };
        let section_style = style::section(theme, "", 0).spans[0].style;
        for span in &mut head.spans {
            if span.style.fg == Some(theme.fg) {
                span.style = section_style;
            }
        }
        head.spans.insert(
            0,
            Span::styled(
                format!("{} {number}  ", style::glyph::SECTION),
                section_style,
            ),
        );
        lines.push(head);
        lines.extend(section);
        while lines.last().is_some_and(|line| line.width() == 0) {
            lines.pop();
        }
    }
    lines
}

/// One plain sentence saying what the agent is asking for.
fn explain(tool: &str, action: &str, text: &str) -> String {
    let text = text
        .split_once('\n')
        .filter(|(head, _)| head.starts_with("in_scope ") || head.starts_with("risk: "))
        .map_or(text, |(_, rest)| rest);
    let (head, body) = text.split_once('\n').unwrap_or((text, ""));
    let (label, counts) = head.rsplit_once(" (+").map_or((head, ""), |(l, c)| (l, c));
    let path = label.split_once(' ').map_or(label, |(_, path)| path);
    let (added, deleted) = counts
        .strip_suffix(')')
        .and_then(|counts| counts.split_once(" −"))
        .map_or_else(
            || {
                let (added, deleted) = diff::counts(body);
                (added.to_string(), deleted.to_string())
            },
            |(added, deleted)| (added.to_string(), deleted.to_string()),
        );
    let (added, deleted) = (added.as_str(), deleted.as_str());
    let lines = |n: &str| {
        if n == "1" {
            "1 line".to_string()
        } else {
            format!("{n} lines")
        }
    };
    match (tool, action) {
        ("wave", _) => {
            format!("The agent wants to make these {action} together. Each is shown below.")
        }
        ("fs", "edit") => format!(
            "The agent wants to change {path}: {} added, {} removed.",
            lines(added),
            lines(deleted)
        ),
        ("fs", "write") if body.contains("@@ -0,0 ") || !body.contains("\n-") => {
            format!("The agent wants to create {path} with {}.", lines(added))
        }
        ("fs", "write") => format!(
            "The agent wants to replace the contents of {path}: {} added, {} removed.",
            lines(added),
            lines(deleted)
        ),
        ("fs", "delete") => format!("The agent wants to delete {path} ({}).", lines(deleted)),
        ("fs", "move") => format!("The agent wants to {head}."),
        ("shell", _) => "The agent wants to run this command:".to_string(),
        ("proc", _) => "The agent wants to start this in the background:".to_string(),
        ("task", _) => {
            "The agent wants a sub-agent to edit files in its own git worktree:".to_string()
        }
        _ => format!("The agent wants to use {tool}{}{action}:", style::SEP),
    }
}

/// Put the plain-language explanation under the header, first for a wave.
fn insert_intro(
    lines: &mut Vec<Line<'static>>,
    request: &dugix_core::tools::ApprovalRequest,
    text: &str,
    width: usize,
    theme: &crate::theme::Theme,
) {
    let wave = request.tool == "wave";
    let connector = request.class.as_deref() == Some(dugix_core::connectors::exec::CLASS);
    let at = if wave {
        0
    } else {
        lines
            .iter()
            .position(|line| line.width() == 0)
            .unwrap_or(lines.len())
    };
    // Word-wrapped, then escaped: paths come from the model.
    let dim = Style::default().fg(theme.fg_dim);
    let sentence = if connector {
        format!(
            "The model wants to use {} from your {} connector. Check what it will send:",
            request.action, request.tool
        )
    } else {
        explain(&request.tool, &request.action, text)
    };
    let mut intro: Vec<Line<'static>> = crate::ui::cards::wrap_plain(&sentence, width)
        .iter()
        .flat_map(|row| escaped_rows(row, width, Style::default().fg(theme.fg), dim))
        .collect();
    if wave {
        intro.push(Line::default());
    } else {
        intro.insert(0, Line::default());
    }
    lines.splice(at..at, intro);
}

fn shell_unread(app: &AppView) -> bool {
    app.approval_request.as_ref().is_some_and(|request| {
        request.tool == "shell"
            || (request.tool == "wave"
                && request.summary.lines().next().is_some_and(|counts| {
                    counts
                        .split(", ")
                        .any(|count| count.ends_with(" command") || count.ends_with(" commands"))
                }))
    }) && app.approval_max_scroll.get() > 0
        && !app.approval_seen_end.get()
}

/// The request's preview lines at the panel's inner `width`.
fn content_lines(app: &AppView, width: usize) -> Option<Vec<Line<'static>>> {
    let request = app.approval_request.as_ref()?;
    let text = request.detail.as_deref().unwrap_or(&request.summary);
    let mut lines = if request.tool == "wave" {
        wave_lines(text, width, &app.theme)
    } else {
        request_lines(
            &request.tool,
            &request.action,
            text,
            request.class.as_deref(),
            width,
            &app.theme,
        )
    };
    insert_intro(&mut lines, request, text, width, &app.theme);
    Some(lines)
}

fn panel_block(app: &AppView) -> ratatui::widgets::Block<'static> {
    chrome::popup_block_focused("", &app.theme, true, chrome::Tone::Normal)
}

/// How tall the approval panel docked in `column` wants to be: the whole
/// request when it fits, else about half the screen.
#[must_use]
pub fn docked_height(app: &AppView, column: Rect) -> u16 {
    let frame = panel_block(app).inner(Rect::new(0, 0, column.width, 100));
    let chrome_rows = 100 - frame.height;
    let Some(lines) = content_lines(app, usize::from(frame.width)) else {
        return 0;
    };
    // Preview + a spacer + the key row + the border.
    let wanted = u16::try_from(lines.len())
        .unwrap_or(u16::MAX)
        .saturating_add(2)
        .saturating_add(chrome_rows);
    let cap = (column.height.saturating_mul(55) / 100).max(8);
    wanted.min(cap).min(column.height.saturating_sub(2)).max(4)
}

/// Draw the approval docked at the bottom of the reading column, in the
/// composer's place.
#[cfg(test)]
pub fn render(f: &mut Frame, app: &AppView) {
    let column = crate::ui::reading_column(f.area(), &app.settings.column_width);
    let height = docked_height(app, column);
    let area = Rect {
        y: column.bottom().saturating_sub(height.saturating_add(1)),
        height,
        ..column
    };
    render_in(f, app, area);
}

/// Draw the approval panel in `area` (where the composer normally is).
/// The footer keys that work for this request right now.
fn key_hints(
    app: &AppView,
    request: &dugix_core::tools::ApprovalRequest,
    wave: bool,
    connector: bool,
) -> Vec<chrome::Hint> {
    let mut hints = Vec::new();
    if shell_unread(app) {
        hints.push(hint(keys::MOVE, "read to the end to approve"));
    } else {
        hints.push(hint("y", "approve"));
        if request.allow_session {
            hints.push(hint("a", "this session"));
        }
        if connector {
            hints.push(hint("A", "always"));
        }
    }
    if wave {
        hints.push(hint("r", "one by one"));
    }
    hints.extend([hint("n", "deny"), hint(keys::ESC, "deny")]);
    hints
}

pub fn render_in(f: &mut Frame, app: &AppView, area: Rect) {
    let Some(request) = &app.approval_request else {
        return;
    };
    app.approval_area.set(Some(area));
    let wave = request.tool == "wave";
    let dim = Style::default().fg(app.theme.fg_dim);
    let width = usize::from(panel_block(app).inner(area).width);
    let Some(lines) = content_lines(app, width) else {
        return;
    };
    let inner = panel_block(app).inner(area);
    // Keep the dock's preview height and scrolling guards unchanged.
    let height = usize::from(inner.height).saturating_sub(2);
    let max_scroll = lines.len().saturating_sub(height);
    let offset = app.approval_scroll.get().min(max_scroll);
    app.approval_scroll.set(offset);
    app.approval_max_scroll.set(max_scroll);
    app.approval_page_height
        .set(height.saturating_sub(1).max(1));
    if offset == max_scroll && height > 0 && width > 0 {
        app.approval_seen_end.set(true);
    }
    let queued = app.approval_count();
    let title = if wave {
        format!(
            "Approve {}{}{}",
            request.action,
            style::SEP,
            request.summary.lines().next().unwrap_or_default()
        )
    } else {
        "Approve".to_string()
    };
    let title = escaped_rows(
        &title,
        usize::MAX,
        Style::default().fg(app.theme.accent),
        dim,
    )
    .remove(0)
    .to_string();
    let connector = request.class.as_deref() == Some(dugix_core::connectors::exec::CLASS);
    let mut count = Vec::new();
    if queued > 1 {
        count.push(format!("1 of {queued}"));
    }
    if let Some(percent) = offset.saturating_mul(100).checked_div(max_scroll) {
        count.push(format!("{percent}%"));
    }
    let count = count.join(style::SEP);
    let hints = key_hints(app, request, wave, connector);
    chrome::render_popup(
        f,
        area,
        &PopupFrame {
            title: &title,
            count: &count,
            hints: &hints,
            tone: chrome::Tone::Normal,
            focused: true,
        },
        app,
    );
    if app
        .approval_opened_at
        .is_some_and(|opened| opened.elapsed() < app.approval_delay)
    {
        f.buffer_mut().set_style(
            Rect::new(area.x, area.bottom().saturating_sub(1), area.width, 1),
            Style::default().add_modifier(Modifier::DIM),
        );
    }
    let visible = if offset < max_scroll {
        height.saturating_sub(1)
    } else {
        height
    };
    let end = offset.saturating_add(visible).min(lines.len());
    let more = lines.len() - end;
    let mut visible: Vec<_> = lines.into_iter().skip(offset).take(visible).collect();
    if more > 0 && height > 0 {
        visible.push(Line::from(Span::styled(
            format!("… {more} more lines"),
            dim,
        )));
    }
    let body = ratatui::layout::Rect {
        height: u16::try_from(height).unwrap_or(u16::MAX),
        ..inner
    };
    f.render_widget(Paragraph::new(visible), body);
}

pub fn handle_key(app: &mut AppView, key: KeyEvent) -> anyhow::Result<()> {
    let page = app.approval_page_height.get();
    let (up, amount) = match key.code {
        KeyCode::Up | KeyCode::Char('k') if !super::is_chord(key) => (true, 1),
        KeyCode::Down | KeyCode::Char('j') if !super::is_chord(key) => (false, 1),
        KeyCode::PageUp => (true, page),
        KeyCode::PageDown | KeyCode::Char(' ') => (false, page),
        KeyCode::Home | KeyCode::Char('g') if !super::is_chord(key) => (true, usize::MAX),
        KeyCode::End | KeyCode::Char('G') if !super::is_chord(key) => (false, usize::MAX),
        _ => (false, 0),
    };
    if amount > 0 {
        let offset = app.approval_scroll.get();
        app.approval_scroll.set(if up {
            offset.saturating_sub(amount)
        } else {
            offset
                .saturating_add(amount)
                .min(app.approval_max_scroll.get())
        });
        return Ok(());
    }
    let decision = match key.code {
        KeyCode::Esc => Decision::Deny,
        KeyCode::Char('y') if !super::is_chord(key) => Decision::Allow,
        KeyCode::Char('a')
            if !super::is_chord(key)
                && app
                    .approval_request
                    .as_ref()
                    .is_some_and(|request| request.allow_session) =>
        {
            Decision::AllowForSession
        }
        KeyCode::Char('A')
            if !super::is_chord(key)
                && app.approval_request.as_ref().is_some_and(|request| {
                    request.class.as_deref() == Some(dugix_core::connectors::exec::CLASS)
                }) =>
        {
            Decision::AllowAlways
        }
        KeyCode::Char('n') if !super::is_chord(key) => Decision::Deny,
        KeyCode::Char('r')
            if !super::is_chord(key)
                && app
                    .approval_request
                    .as_ref()
                    .is_some_and(|request| request.tool == "wave") =>
        {
            Decision::ReviewEach
        }
        _ => return Ok(()),
    };
    if decision != Decision::Deny
        && ((decision != Decision::ReviewEach && shell_unread(app))
            || app
                .approval_opened_at
                .is_some_and(|opened| opened.elapsed() < app.approval_delay))
    {
        return Ok(());
    }
    app.execute(AppCommand::Approve { decision })
}

#[cfg(test)]
mod tests {
    use super::*;
    use dugix_core::app::{App, Popup};
    use dugix_core::db::Db;
    use dugix_core::space::Space;
    use dugix_core::tools::ApprovalRequest;
    use ratatui::Terminal;
    use ratatui::backend::TestBackend;
    use std::time::{Duration, Instant};

    fn wave_app(summary: String) -> (AppView, tokio::sync::oneshot::Receiver<Decision>) {
        let root = std::env::temp_dir().join(format!("dugix-wave-popup-{}", uuid::Uuid::new_v4()));
        std::fs::create_dir_all(&root).unwrap();
        let mut app = AppView::new(App::new(
            Db::open_in_memory().unwrap(),
            Some("k"),
            Space { root },
        ));
        let (sender, receiver) = tokio::sync::oneshot::channel();
        app.approvals.pending = Some(sender);
        app.approvals.pending_request = Some(ApprovalRequest {
            tool: "wave".into(),
            class: None,
            detail: None,
            action: "2 calls".into(),
            summary,
            allow_session: true,
        });
        app.sync_approval_popup();
        (app, receiver)
    }

    fn draw(app: &AppView) {
        Terminal::new(TestBackend::new(120, 24))
            .unwrap()
            .draw(|f| render(f, app))
            .unwrap();
    }

    #[test]
    fn one_time_wave_hides_and_ignores_session_approval() {
        let (mut app, mut receiver) = wave_app("1 delete".into());
        app.approval_request.as_mut().unwrap().allow_session = false;
        let mut terminal = Terminal::new(TestBackend::new(120, 24)).unwrap();
        terminal.draw(|frame| render(frame, &app)).unwrap();
        let screen: String = terminal
            .backend()
            .buffer()
            .content
            .iter()
            .map(|cell| cell.symbol())
            .collect();
        assert!(!screen.contains("a this session"));
        handle_key(&mut app, KeyCode::Char('a').into()).unwrap();
        assert!(receiver.try_recv().is_err());
        handle_key(&mut app, KeyCode::Char('y').into()).unwrap();
        assert_eq!(receiver.try_recv().unwrap(), Decision::Allow);
        let root = app.space.root.clone();
        drop(app);
        std::fs::remove_dir_all(root).unwrap();
    }

    #[test]
    fn wave_keys_map_to_combined_decisions_and_keep_the_open_delay() {
        for (key, expected) in [
            (KeyCode::Char('y'), Decision::Allow),
            (KeyCode::Char('a'), Decision::AllowForSession),
            (KeyCode::Char('r'), Decision::ReviewEach),
            (KeyCode::Char('n'), Decision::Deny),
            (KeyCode::Esc, Decision::Deny),
        ] {
            let (mut app, mut receiver) = wave_app(
                "1 edit, 1 command\n1. fs write\n  write one\n2. shell run\n  $ true".into(),
            );
            let root = app.space.root.clone();
            draw(&app);
            app.approval_delay = Duration::from_millis(400);
            app.approval_opened_at = Some(Instant::now() + Duration::from_secs(1));
            handle_key(&mut app, key.into()).unwrap();
            if expected != Decision::Deny {
                assert!(receiver.try_recv().is_err());
                assert_eq!(app.popup, Popup::Approval);
                app.approval_opened_at = Some(Instant::now() - Duration::from_secs(1));
                handle_key(&mut app, key.into()).unwrap();
            }
            assert_eq!(receiver.try_recv().unwrap(), expected);
            assert_eq!(app.popup, Popup::None);
            assert!(app.approvals.pending.is_none());
            drop(app);
            std::fs::remove_dir_all(root).unwrap();
        }
    }

    #[test]
    fn combined_shell_requires_scrolling_for_allow_but_not_review_or_denial() {
        for (key, expected) in [
            (KeyCode::Char('y'), Decision::Allow),
            (KeyCode::Char('a'), Decision::AllowForSession),
            (KeyCode::Char('r'), Decision::ReviewEach),
            (KeyCode::Esc, Decision::Deny),
        ] {
            let summary = format!(
                "1 edit, 1 command\n1. fs edit\n{}\n2. shell run\n  $ echo LAST_COMMAND",
                "  +a line of diff\n".repeat(50)
            );
            let (mut app, mut receiver) = wave_app(summary);
            let root = app.space.root.clone();
            draw(&app);
            assert!(app.approval_max_scroll.get() > 0);
            assert!(!app.approval_seen_end.get());
            handle_key(&mut app, key.into()).unwrap();
            if matches!(expected, Decision::Allow | Decision::AllowForSession) {
                assert!(receiver.try_recv().is_err());
                while app.approval_scroll.get() < app.approval_max_scroll.get() {
                    handle_key(&mut app, KeyCode::PageDown.into()).unwrap();
                    draw(&app);
                }
                assert!(app.approval_seen_end.get());
                handle_key(&mut app, key.into()).unwrap();
            }
            assert_eq!(receiver.try_recv().unwrap(), expected);
            drop(app);
            std::fs::remove_dir_all(root).unwrap();
        }
    }
}