sara-tasks 0.9.0

Sara — folder-aware task manager
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
use anyhow::Result;
use chrono::{Local, Utc};
use crossterm::event::{self, Event, KeyCode, KeyEventKind};
use ratatui::{Terminal, backend::Backend};
use rusqlite::Connection;
use tui_textarea::TextArea;

use crate::infrastructure::config::Config;
use crate::infrastructure::db;
use crate::infrastructure::model::{Priority, Task};
use crate::infrastructure::tui;
use crate::infrastructure::tui::keymap::{self, Action, KeyDispatcher, Mode};

use super::handler::{
    build_task_tree, checklist_focus_index, comment_target, compute_overlaps, depends_on_display,
    edit_text_via_external_editor, feedback_for_focus, focusables, open_in_editor, open_url,
    reconcile_dependencies, reorder_focused_step,
};
use super::render::render;
use super::types::{Detail, EditField, EditState, Focusable};

pub(super) fn edit_loop<B: Backend>(
    terminal: &mut Terminal<B>,
    conn: &Connection,
    cfg: &Config,
    detail: Detail,
) -> Result<()> {
    let mut st = EditState {
        detail,
        selected: 0,
        editing: false,
        commenting: false,
        adding_step: false,
        editor: TextArea::default(),
        due_error: false,
        dep_error: None,
        scroll: 0,
        tree_expanded: false,
        show_urgency_breakdown: false,
        verbose: false,
        show_notes: false,
    };
    let mut dispatcher = KeyDispatcher::new();
    let mut showing_help = false;

    loop {
        terminal.draw(|f| {
            render(f, &st);
            if showing_help {
                tui::render_help_overlay(f, "Task detail", &help_bindings());
            }
        })?;

        if !event::poll(std::time::Duration::from_millis(100))? {
            continue;
        }
        let Event::Key(key) = event::read()? else {
            continue;
        };
        if key.kind == KeyEventKind::Release {
            continue;
        }

        // Any key dismisses the overlay without otherwise acting on it.
        if showing_help {
            showing_help = false;
            continue;
        }

        let items = focusables(&st.detail, st.show_notes);
        // Keep the cursor in range (links/files can disappear after a reload).
        if !items.is_empty() && st.selected >= items.len() {
            st.selected = items.len() - 1;
        }
        let current = items.get(st.selected).cloned();
        let current_field = match &current {
            Some(Focusable::Field(f)) => Some(*f),
            _ => None,
        };

        if st.adding_step {
            match dispatcher.dispatch(key, Mode::Insert) {
                Action::Confirm | Action::Save => {
                    let text = st.editor.lines().join(" ");
                    if !text.trim().is_empty() {
                        // Add to the kind of the focused checklist row (so adding
                        // while on an acceptance criterion adds another criterion);
                        // default to a step otherwise.
                        let kind = match &current {
                            Some(Focusable::Checklist(i)) => st
                                .detail
                                .checklist
                                .get(*i)
                                .map(|c| c.kind.clone())
                                .unwrap_or_else(|| db::STEP_KIND_STEP.to_string()),
                            _ => db::STEP_KIND_STEP.to_string(),
                        };
                        let new_id = db::add_step(
                            conn,
                            &st.detail.task.uuid,
                            text.trim(),
                            None,
                            &kind,
                            "human",
                            None,
                        )
                        .ok();
                        st.detail.checklist =
                            db::get_checklist(conn, &st.detail.task.uuid).unwrap_or_default();
                        if let Some(id) = new_id
                            && let Some(p) = checklist_focus_index(&st.detail, st.show_notes, id)
                        {
                            st.selected = p;
                        }
                    }
                    st.adding_step = false;
                }
                Action::Cancel => st.adding_step = false,
                Action::Raw(k) => {
                    st.editor.input(k);
                }
                _ => {}
            }
        } else if st.commenting {
            match dispatcher.dispatch(key, Mode::Insert) {
                Action::Confirm | Action::Save => {
                    let text = st.editor.lines().join(" ");
                    if !text.trim().is_empty() {
                        let (tk, tid) = comment_target(&st.detail, &current);
                        let _ = db::add_annotation_full(
                            conn,
                            &st.detail.task.uuid,
                            text.trim(),
                            db::NOTE_KIND_COMMENT,
                            "human",
                            tk.as_deref(),
                            tid.as_deref(),
                            false,
                        );
                        st.detail.annotations =
                            db::get_annotations(conn, &st.detail.task.uuid).unwrap_or_default();
                    }
                    st.commenting = false;
                }
                Action::Cancel => st.commenting = false,
                Action::Raw(k) => {
                    st.editor.input(k);
                }
                _ => {}
            }
        } else if st.editing {
            let field = current_field.unwrap_or(EditField::Description);
            match dispatcher.dispatch(key, Mode::Insert) {
                Action::Confirm | Action::Save => {
                    let value = st.editor.lines().join("");
                    if field == EditField::DependsOn {
                        match reconcile_dependencies(conn, cfg, &mut st.detail, &value) {
                            Ok(()) => {
                                st.editing = false;
                                st.dep_error = None;
                            }
                            Err(e) => st.dep_error = Some(e),
                        }
                        continue;
                    }
                    if field == EditField::Due
                        && !value.trim().is_empty()
                        && !crate::infrastructure::dates::is_valid_due(&value)
                    {
                        st.due_error = true;
                        continue;
                    }
                    apply_field(&mut st.detail.task, field, &value, cfg);
                    save(conn, cfg, &mut st.detail)?;
                    st.editing = false;
                    st.due_error = false;
                }
                Action::Cancel => {
                    st.editing = false;
                    st.due_error = false;
                    st.dep_error = None;
                }
                Action::Raw(k) => {
                    st.editor.input(k);
                    if field == EditField::Due {
                        let v = st.editor.lines().join("");
                        st.due_error =
                            !v.trim().is_empty() && !crate::infrastructure::dates::is_valid_due(&v);
                    }
                }
                _ => {}
            }
        } else {
            let action = dispatcher.dispatch(key, Mode::Normal);
            // Enter and 'e' both open/confirm the focused item — 'e' isn't
            // part of the shared vocabulary (it's a domain letter, not a
            // navigation key), so it comes back as Action::Raw.
            let confirmed = matches!(action, Action::Confirm)
                || matches!(&action, Action::Raw(k) if k.code == KeyCode::Char('e'));
            if confirmed {
                match current {
                    Some(Focusable::Field(EditField::Priority)) => {
                        cycle_priority(&mut st.detail.task, true);
                        save(conn, cfg, &mut st.detail)?;
                    }
                    Some(Focusable::Field(field)) => {
                        st.editor = if field == EditField::DependsOn {
                            let mut ta = TextArea::default();
                            ta.insert_str(depends_on_display(&st.detail));
                            ta
                        } else {
                            editor_for(&st.detail.task, field)
                        };
                        st.editing = true;
                        st.due_error = false;
                        st.dep_error = None;
                    }
                    Some(Focusable::Link(i)) => {
                        if let Some(link) = st.detail.links.get(i) {
                            open_url(&link.url);
                        }
                    }
                    Some(Focusable::File(path)) => {
                        if db::is_url(&path) {
                            // URL stored as a file (legacy attach) -> browser.
                            open_url(&path);
                        } else {
                            // Real file -> open in the user's editor. Hand the
                            // terminal back while the editor runs.
                            let target = st
                                .detail
                                .project_root
                                .as_ref()
                                .map(|r| r.join(&path))
                                .unwrap_or_else(|| std::path::PathBuf::from(&path));
                            tui::suspend()?;
                            let _ = open_in_editor(&target);
                            tui::resume()?;
                            terminal.clear()?;
                        }
                    }
                    Some(Focusable::Checklist(i)) => {
                        if let Some(item) = st.detail.checklist.get(i) {
                            let _ = db::toggle_checklist_item(conn, item.id);
                            st.detail.checklist =
                                db::get_checklist(conn, &st.detail.task.uuid).unwrap_or_default();
                        }
                    }
                    // Enter on an anchor opens the file in the editor.
                    Some(Focusable::Anchor(i)) => {
                        if let Some(anchor) = st.detail.anchors.get(i) {
                            let target = st
                                .detail
                                .project_root
                                .as_ref()
                                .map(|r| r.join(&anchor.path))
                                .unwrap_or_else(|| std::path::PathBuf::from(&anchor.path));
                            tui::suspend()?;
                            let _ = open_in_editor(&target);
                            tui::resume()?;
                            terminal.clear()?;
                        }
                    }
                    // Enter on a comment opens the comment input to reply.
                    Some(Focusable::Comment(_)) => {
                        st.editor = TextArea::default();
                        st.commenting = true;
                    }
                    // Enter on a typed note opens the comment input to comment on it.
                    Some(Focusable::Note(_)) => {
                        st.editor = TextArea::default();
                        st.commenting = true;
                    }
                    None => {}
                }
            } else {
                match action {
                    Action::Quit => break,
                    // Reorder the focused checklist step within its kind.
                    Action::ReorderUp => reorder_focused_step(conn, &mut st, &current, true),
                    Action::ReorderDown => reorder_focused_step(conn, &mut st, &current, false),
                    Action::Down => {
                        if !items.is_empty() {
                            st.selected = (st.selected + 1).min(items.len() - 1);
                        }
                    }
                    Action::Up => {
                        st.selected = st.selected.saturating_sub(1);
                    }
                    Action::Top => st.selected = 0,
                    Action::Bottom => {
                        if !items.is_empty() {
                            st.selected = items.len() - 1;
                        }
                    }
                    Action::PageDown => st.scroll = st.scroll.saturating_add(5),
                    Action::PageUp => st.scroll = st.scroll.saturating_sub(5),
                    Action::ToggleMark => {
                        if let Some(Focusable::Checklist(i)) = &current
                            && let Some(item) = st.detail.checklist.get(*i)
                        {
                            let _ = db::toggle_checklist_item(conn, item.id);
                            st.detail.checklist =
                                db::get_checklist(conn, &st.detail.task.uuid).unwrap_or_default();
                        }
                    }
                    // Ctrl+E: hand the current long text field to $EDITOR
                    // instead of the in-TUI textarea. On the Description
                    // field, edit it directly; anywhere else, compose a new
                    // comment (mirroring 'c', which is unconditional on focus).
                    Action::ExternalEdit => {
                        if current_field == Some(EditField::Description) {
                            tui::suspend()?;
                            let result = edit_text_via_external_editor(&st.detail.task.description);
                            tui::resume()?;
                            terminal.clear()?;
                            if let Ok(Some(edited)) = result {
                                apply_field(
                                    &mut st.detail.task,
                                    EditField::Description,
                                    &edited,
                                    cfg,
                                );
                                save(conn, cfg, &mut st.detail)?;
                            }
                        } else {
                            tui::suspend()?;
                            let result = edit_text_via_external_editor("");
                            tui::resume()?;
                            terminal.clear()?;
                            if let Ok(Some(text)) = result {
                                let text = text.trim();
                                if !text.is_empty() {
                                    let (tk, tid) = comment_target(&st.detail, &current);
                                    let _ = db::add_annotation_full(
                                        conn,
                                        &st.detail.task.uuid,
                                        text,
                                        db::NOTE_KIND_COMMENT,
                                        "human",
                                        tk.as_deref(),
                                        tid.as_deref(),
                                        false,
                                    );
                                    st.detail.annotations =
                                        db::get_annotations(conn, &st.detail.task.uuid)
                                            .unwrap_or_default();
                                }
                            }
                        }
                    }
                    Action::Raw(k) => match k.code {
                        KeyCode::Left if current_field == Some(EditField::Priority) => {
                            cycle_priority(&mut st.detail.task, false);
                            save(conn, cfg, &mut st.detail)?;
                        }
                        KeyCode::Right if current_field == Some(EditField::Priority) => {
                            cycle_priority(&mut st.detail.task, true);
                            save(conn, cfg, &mut st.detail)?;
                        }
                        // ── Add a new checklist step ────────────────────────
                        KeyCode::Char('a') => {
                            st.editor = TextArea::default();
                            st.adding_step = true;
                        }
                        // ── Task tree panel ─────────────────────────────────
                        // 'd' expands the always-visible task tree from its
                        // compact default (2 levels, a few siblings per node)
                        // to its full fetched depth/fan-out — instant, since
                        // the tree is already fetched that deep (see
                        // `TREE_FETCH_*` in handler.rs).
                        KeyCode::Char('d') => {
                            st.tree_expanded = !st.tree_expanded;
                        }
                        // ── Review & comment loop ───────────────────────────
                        KeyCode::Char('c') => {
                            st.editor = TextArea::default();
                            st.commenting = true;
                        }
                        KeyCode::Char('r') => {
                            // Mark the focused element for reconsideration.
                            // If it already has an open comment, toggle the flag
                            // on it. If not, create a new comment with
                            // request_revision=true so the element is flagged
                            // even without a written note.
                            let fb = feedback_for_focus(&st.detail, &current);
                            if let Some(existing) = fb.first() {
                                let _ = db::set_request_revision(
                                    conn,
                                    existing.id,
                                    !existing.request_revision,
                                );
                            } else {
                                // No existing comment — auto-create a reconsider marker.
                                let (tk, tid) = comment_target(&st.detail, &current);
                                let _ = db::add_annotation_full(
                                    conn,
                                    &st.detail.task.uuid,
                                    "⟳ reconsider this",
                                    db::NOTE_KIND_COMMENT,
                                    "human",
                                    tk.as_deref(),
                                    tid.as_deref(),
                                    true, // request_revision = true
                                );
                            }
                            st.detail.annotations =
                                db::get_annotations(conn, &st.detail.task.uuid).unwrap_or_default();
                        }
                        KeyCode::Char('x') => {
                            // Resolve the focused element's latest open feedback.
                            if let Some(fb) = feedback_for_focus(&st.detail, &current).first() {
                                let _ = db::resolve_annotation(conn, fb.id, None);
                                st.detail.annotations =
                                    db::get_annotations(conn, &st.detail.task.uuid)
                                        .unwrap_or_default();
                            }
                        }
                        // ── Display density toggles ─────────────────────────
                        KeyCode::Char('u') => {
                            st.show_urgency_breakdown = !st.show_urgency_breakdown;
                        }
                        KeyCode::Char('v') => {
                            st.verbose = !st.verbose;
                        }
                        KeyCode::Char('n') => {
                            st.show_notes = !st.show_notes;
                            // Notes just appeared/disappeared from the focusable
                            // list — keep the cursor from landing mid-air on a
                            // row that no longer exists.
                            let items = focusables(&st.detail, st.show_notes);
                            if !items.is_empty() && st.selected >= items.len() {
                                st.selected = items.len() - 1;
                            }
                        }
                        KeyCode::Char('?') => {
                            showing_help = true;
                        }
                        _ => {}
                    },
                    _ => {}
                }
            }
        }
    }

    Ok(())
}

/// Info/edit's help overlay: the shared bindings it acts on (all of them —
/// unlike board, this screen reorders steps, saves fields, and toggles
/// checklist items) plus its own domain letters.
fn help_bindings() -> Vec<(&'static str, &'static str)> {
    use keymap::help::*;
    vec![
        MOVE,
        TOP_BOTTOM,
        PAGE,
        REORDER,
        TOGGLE_MARK,
        CONFIRM,
        ("e", "edit the focused field"),
        ("a", "add a checklist step"),
        ("c", "comment on the focused element"),
        ("r", "flag the focused element for reconsideration"),
        ("x", "resolve the focused element's feedback"),
        ("d", "expand/collapse the task tree"),
        ("u", "show/hide the urgency score breakdown"),
        ("v", "expand/collapse long text and checklist detail"),
        (
            "n",
            "show/hide the AI's execution notes (findings, decisions, …)",
        ),
        SAVE,
        QUIT,
        HELP,
    ]
}

pub(super) fn editor_for(task: &Task, field: EditField) -> TextArea<'static> {
    let value = current_value(task, field);
    let mut ta = TextArea::default();
    ta.insert_str(&value);
    ta
}

pub(super) fn current_value(task: &Task, field: EditField) -> String {
    match field {
        EditField::Description => task.description.clone(),
        EditField::Project => task.project.clone(),
        EditField::Priority => task
            .priority
            .as_ref()
            .map(|p| p.label().to_string())
            .unwrap_or_default(),
        EditField::Due => task
            .due
            .map(|d| d.with_timezone(&Local).format("%Y-%m-%d").to_string())
            .unwrap_or_default(),
        EditField::Tags => task.tags.join(", "),
        EditField::Estimate => task
            .estimate_mins
            .map(|m| {
                if m >= 60 {
                    let h = m / 60;
                    let rem = m % 60;
                    if rem == 0 {
                        format!("{h}h")
                    } else {
                        format!("{h}h{rem}m")
                    }
                } else {
                    format!("{m}m")
                }
            })
            .unwrap_or_default(),
        EditField::Recur => task.recur.clone().unwrap_or_default(),
        // Dependencies live in a separate table; handled via depends_on_display.
        EditField::DependsOn => String::new(),
    }
}

pub(super) fn apply_field(task: &mut Task, field: EditField, value: &str, cfg: &Config) {
    match field {
        EditField::Description => {
            if !value.trim().is_empty() {
                task.description = value.trim().to_string();
            }
        }
        EditField::Project => {
            if !value.trim().is_empty() {
                task.project = value.trim().to_string();
            }
        }
        EditField::Due => {
            if value.trim().is_empty() {
                task.due = None;
            } else {
                task.due = crate::commands::add::parse_due(value, cfg);
            }
        }
        EditField::Tags => {
            task.tags = value
                .split(',')
                .map(|s| s.trim().to_string())
                .filter(|s| !s.is_empty())
                .collect();
        }
        EditField::Priority => {}
        EditField::Estimate => {
            task.estimate_mins = parse_duration_to_mins(value);
        }
        EditField::Recur => {
            let v = value.trim().to_lowercase();
            task.recur = if v.is_empty() { None } else { Some(v) };
        }
        // Reconciled against the dependencies table in reconcile_dependencies.
        EditField::DependsOn => {}
    }
}

pub(super) fn cycle_priority(task: &mut Task, forward: bool) {
    task.priority = match (&task.priority, forward) {
        (None, true) => Some(Priority::L),
        (Some(Priority::L), true) => Some(Priority::M),
        (Some(Priority::M), true) => Some(Priority::H),
        (Some(Priority::H), true) => None,
        (None, false) => Some(Priority::H),
        (Some(Priority::H), false) => Some(Priority::M),
        (Some(Priority::M), false) => Some(Priority::L),
        (Some(Priority::L), false) => None,
    };
}

pub(super) fn save(conn: &Connection, cfg: &Config, detail: &mut Detail) -> Result<()> {
    let task = &mut detail.task;
    task.modified = Utc::now();
    task.urgency = db::compute_urgency(task, &cfg.urgency, false, 0);
    db::update_task(conn, task)?;
    db::refresh_urgency(conn, &cfg.urgency, &task.uuid)?;
    // Pull back the authoritative urgency (refresh accounts for blocking).
    if let Some(t) = db::get_task_by_uuid_prefix(conn, &task.uuid.to_string()[..8])? {
        task.urgency = t.urgency;
    }
    detail.history = db::get_history(conn, &detail.task.uuid)?;
    // Reload branch / overlaps in case project changed.
    detail.branch = db::get_task_branch(conn, &detail.task.uuid);
    detail.overlaps = compute_overlaps(conn, &detail.task, &detail.branch);
    // Reload similar tasks and checklist after any save.
    detail.similar = db::similar_tasks(
        conn,
        &detail.task.uuid,
        &detail.task.project,
        &detail.task.tags,
    )
    .unwrap_or_default();
    detail.checklist = db::get_checklist(conn, &detail.task.uuid).unwrap_or_default();
    let blockers = db::get_blockers(conn, &detail.task.uuid).unwrap_or_default();
    let blocking_tasks = db::get_blocking(conn, &detail.task.uuid).unwrap_or_default();
    detail.urgency_breakdown = Some(db::compute_urgency_breakdown(
        &detail.task,
        &cfg.urgency,
        !blockers.is_empty(),
        blocking_tasks.len(),
    ));
    // Dependencies (or the task itself) may have just changed — refresh the tree too.
    detail.tree = build_task_tree(conn, detail.task.uuid);
    Ok(())
}

/// Parse a human duration string like "2h30m", "90m", "1h", "45" (minutes) into minutes.
pub(super) fn parse_duration_to_mins(s: &str) -> Option<i64> {
    let s = s.trim();
    if s.is_empty() {
        return None;
    }
    let s_lower = s.to_lowercase();
    let rest = s_lower.as_str();
    // Parse hours (handles "2h", "2h30m", "2h 30m")
    if let Some(h_pos) = rest.find('h')
        && let Ok(h) = rest[..h_pos].trim().parse::<i64>()
    {
        let mut total = h * 60;
        let after_h = rest[h_pos + 1..].trim().trim_end_matches('m').trim();
        if !after_h.is_empty()
            && let Ok(m) = after_h.parse::<i64>()
        {
            total += m;
        }
        return Some(total);
    }
    // "Ym" or bare number (minutes)
    let m_part = rest.trim_end_matches('m').trim();
    m_part.parse::<i64>().ok()
}

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

    #[test]
    fn help_bindings_cover_shared_vocab_and_domain_letters() {
        let bindings = help_bindings();
        let labels: Vec<&str> = bindings.iter().map(|(k, _)| *k).collect();
        // Shared vocab this screen actually acts on.
        for shared in [
            "j/k, ↓/↑",
            "gg / G",
            "K/J, Shift+↓/↑",
            "Space",
            "Enter",
            "Ctrl+S",
            "q / Esc",
            "?",
        ] {
            assert!(labels.contains(&shared), "missing shared binding {shared}");
        }
        // Domain letters not part of the shared keymap vocabulary.
        for domain in ["e", "a", "c", "r", "x"] {
            assert!(labels.contains(&domain), "missing domain binding {domain}");
        }
    }
}