aether-wisp 0.1.9

A terminal UI for AI coding agents via the Agent Client Protocol (ACP)
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
use std::path::PathBuf;
use tui::testing::{assert_buffer_eq, cols, key, render_component, render_lines};
use tui::{Event, GUTTER_WIDTH, KeyCode, SEPARATOR_WIDTH, ViewContext};
use wisp::components::app::{GitDiffLoadState, GitDiffMode};
use wisp::git_diff::{FileDiff, FileStatus, GitDiffDocument, Hunk, PatchLine, PatchLineKind};

fn make_test_doc() -> GitDiffDocument {
    GitDiffDocument {
        repo_root: PathBuf::from("/tmp/test"),
        files: vec![
            FileDiff {
                old_path: Some("a.rs".to_string()),
                path: "a.rs".to_string(),
                status: FileStatus::Modified,
                hunks: vec![Hunk {
                    header: "@@ -1,3 +1,3 @@".to_string(),
                    old_start: 1,
                    old_count: 3,
                    new_start: 1,
                    new_count: 3,
                    lines: vec![
                        PatchLine {
                            kind: PatchLineKind::HunkHeader,
                            text: "@@ -1,3 +1,3 @@".to_string(),
                            old_line_no: None,
                            new_line_no: None,
                        },
                        PatchLine {
                            kind: PatchLineKind::Context,
                            text: "fn main() {".to_string(),
                            old_line_no: Some(1),
                            new_line_no: Some(1),
                        },
                        PatchLine {
                            kind: PatchLineKind::Removed,
                            text: "    old();".to_string(),
                            old_line_no: Some(2),
                            new_line_no: None,
                        },
                        PatchLine {
                            kind: PatchLineKind::Added,
                            text: "    new();".to_string(),
                            old_line_no: None,
                            new_line_no: Some(2),
                        },
                        PatchLine {
                            kind: PatchLineKind::Context,
                            text: "}".to_string(),
                            old_line_no: Some(3),
                            new_line_no: Some(3),
                        },
                    ],
                }],
                binary: false,
            },
            FileDiff {
                old_path: None,
                path: "b.rs".to_string(),
                status: FileStatus::Added,
                hunks: vec![Hunk {
                    header: "@@ -0,0 +1,1 @@".to_string(),
                    old_start: 0,
                    old_count: 0,
                    new_start: 1,
                    new_count: 1,
                    lines: vec![
                        PatchLine {
                            kind: PatchLineKind::HunkHeader,
                            text: "@@ -0,0 +1,1 @@".to_string(),
                            old_line_no: None,
                            new_line_no: None,
                        },
                        PatchLine {
                            kind: PatchLineKind::Added,
                            text: "new_content".to_string(),
                            old_line_no: None,
                            new_line_no: Some(1),
                        },
                    ],
                }],
                binary: false,
            },
        ],
    }
}

fn make_mode(doc: GitDiffDocument) -> GitDiffMode {
    let mut mode = GitDiffMode::new(PathBuf::from("."));
    mode.load_document(doc);
    mode
}

fn make_wrapping_split_doc() -> GitDiffDocument {
    GitDiffDocument {
        repo_root: PathBuf::from("/tmp/test"),
        files: vec![FileDiff {
            old_path: Some("x.rs".to_string()),
            path: "x.rs".to_string(),
            status: FileStatus::Modified,
            hunks: vec![Hunk {
                header: "@@ -1,2 +1,2 @@".to_string(),
                old_start: 1,
                old_count: 2,
                new_start: 1,
                new_count: 2,
                lines: vec![
                    PatchLine {
                        kind: PatchLineKind::HunkHeader,
                        text: "@@ -1,2 +1,2 @@".to_string(),
                        old_line_no: None,
                        new_line_no: None,
                    },
                    PatchLine {
                        kind: PatchLineKind::Removed,
                        text: "LEFT_MARK".to_string(),
                        old_line_no: Some(1),
                        new_line_no: None,
                    },
                    PatchLine {
                        kind: PatchLineKind::Added,
                        text: format!("RIGHT_HEAD {} RIGHT_TAIL", "A".repeat(140)),
                        old_line_no: None,
                        new_line_no: Some(1),
                    },
                    PatchLine {
                        kind: PatchLineKind::Context,
                        text: "}".to_string(),
                        old_line_no: Some(2),
                        new_line_no: Some(2),
                    },
                ],
            }],
            binary: false,
        }],
    }
}

#[test]
fn wrapped_right_pane_rows_keep_a_neutral_boundary() {
    let mut mode = make_mode(make_wrapping_split_doc());
    let term = render_component(|ctx| mode.render_frame(ctx), 140, 12);
    let lines = term.get_lines();

    let first_row = lines
        .iter()
        .position(|line| line.contains("LEFT_MARK") && line.contains("RIGHT_HEAD"))
        .expect("expected split row containing both left and right markers");

    let right_start = lines[first_row].find("RIGHT_HEAD").expect("expected RIGHT_HEAD marker in first row");

    let wrapped_idx = lines
        .iter()
        .enumerate()
        .skip(first_row + 1)
        .find_map(|(index, line)| line.contains("RIGHT_TAIL").then_some(index))
        .expect("expected wrapped continuation row containing RIGHT_TAIL marker");

    let wrapped_start = lines[wrapped_idx].find("RIGHT_TAIL").expect("expected RIGHT_TAIL marker in wrapped row");

    assert!(
        wrapped_start >= right_start,
        "wrapped continuation should not start left of original right-pane content start (was {wrapped_start}, expected >= {right_start})"
    );

    let padding_width = GUTTER_WIDTH + SEPARATOR_WIDTH;
    assert!(wrapped_start >= padding_width, "wrapped content should leave room for separator and gutter");
    let ctx = ViewContext::new((140, 12));
    let added_bg = Some(ctx.theme.diff_added_bg());
    let removed_bg = Some(ctx.theme.diff_removed_bg());
    for col in (wrapped_start - padding_width)..wrapped_start {
        let actual_bg = term.get_style_at(wrapped_idx, col).bg;
        assert_ne!(actual_bg, added_bg, "padding column {col} should not inherit added background");
        assert_ne!(actual_bg, removed_bg, "padding column {col} should not inherit removed background");
    }
}

#[test]
fn wrapped_split_diff_continuation_row_keeps_neutral_padding() {
    let mut mode = make_mode(make_wrapping_split_doc());
    let ctx = ViewContext::new((140, 12));
    let frame = mode.render_frame(&ctx);
    let wrapped_row = frame
        .lines()
        .iter()
        .find(|line| line.plain_text().contains("RIGHT_TAIL"))
        .cloned()
        .expect("expected wrapped continuation row containing RIGHT_TAIL");

    let term = render_lines(&[wrapped_row], 140, 1);
    assert_buffer_eq(&term, &[cols(&[("", 91), ("RIGHT_TAIL", 0)])]);

    let added_bg = Some(ctx.theme.diff_added_bg());
    let removed_bg = Some(ctx.theme.diff_removed_bg());
    for col in 83..91 {
        let actual_bg = term.get_style_at(0, col).bg;
        assert_ne!(actual_bg, added_bg, "padding column {col} should not inherit added background");
        assert_ne!(actual_bg, removed_bg, "padding column {col} should not inherit removed background");
    }
}

#[test]
fn git_diff_view_keeps_wrapped_code_out_of_the_line_number_gutter() {
    let filler = "A".repeat(48);
    let mut mode = make_mode(GitDiffDocument {
        repo_root: PathBuf::from("/tmp/test"),
        files: vec![FileDiff {
            old_path: Some("x.rs".to_string()),
            path: "x.rs".to_string(),
            status: FileStatus::Modified,
            hunks: vec![Hunk {
                header: "@@ -1,2 +1,2 @@".to_string(),
                old_start: 1,
                old_count: 2,
                new_start: 1,
                new_count: 2,
                lines: vec![
                    PatchLine {
                        kind: PatchLineKind::HunkHeader,
                        text: "@@ -1,2 +1,2 @@".to_string(),
                        old_line_no: None,
                        new_line_no: None,
                    },
                    PatchLine {
                        kind: PatchLineKind::Removed,
                        text: "LEFT_MARK".to_string(),
                        old_line_no: Some(1),
                        new_line_no: None,
                    },
                    PatchLine {
                        kind: PatchLineKind::Added,
                        text: format!("RIGHT_HEAD {filler} RIGHT_TAIL"),
                        old_line_no: None,
                        new_line_no: Some(1),
                    },
                ],
            }],
            binary: false,
        }],
    });
    let term = render_component(|ctx| mode.render_frame(ctx), 140, 6);

    assert_buffer_eq(
        &term,
        &[
            cols(&[(">   M x.rs             +1/-1", 28), ("", 1), ("x.rs  (modified)", 0)]),
            String::new(),
            cols(&[("", 28), ("", 1), ("@@ -1,2 +1,2 @@", 0)]),
            cols(&[("", 29), ("   1 LEFT_MARK", 54), ("", 3), ("   1 RIGHT_HEAD", 54)]),
            cols(&[("", 29), ("", 54), ("", 3), ("", 5), (filler.as_str(), 0)]),
            cols(&[("", 29), ("", 54), ("", 3), ("", 5), ("RIGHT_TAIL", 0)]),
        ],
    );
}

#[test]
fn screenshot_shaped_git_diff_wrap_row_stays_out_of_gutters() {
    let mut mode = make_mode(GitDiffDocument {
        repo_root: PathBuf::from("/tmp/test"),
        files: vec![FileDiff {
            old_path: Some("split_diff.rs".to_string()),
            path: "split_diff.rs".to_string(),
            status: FileStatus::Modified,
            hunks: vec![Hunk {
                header: "@@ -56,2 +57,2 @@".to_string(),
                old_start: 56,
                old_count: 2,
                new_start: 57,
                new_count: 2,
                lines: vec![
                    PatchLine {
                        kind: PatchLineKind::HunkHeader,
                        text: "@@ -56,2 +57,2 @@".to_string(),
                        old_line_no: None,
                        new_line_no: None,
                    },
                    PatchLine {
                        kind: PatchLineKind::Removed,
                        text: "let left = left_lines.get(i).cloned().unwrap_or_else(|| blank_panel(left_panel));"
                            .to_string(),
                        old_line_no: Some(56),
                        new_line_no: None,
                    },
                    PatchLine {
                        kind: PatchLineKind::Added,
                        text: "let left = left_lines.get(i).cloned().unwrap_or_else(|| blank_panel(left_panel, theme.code_bg()));"
                            .to_string(),
                        old_line_no: None,
                        new_line_no: Some(57),
                    },
                ],
            }],
            binary: false,
        }],
    });
    let term = render_component(|ctx| mode.render_frame(ctx), 151, 8);
    let lines = term.get_lines();
    let wrapped_idx = lines
        .iter()
        .position(|line| line.contains("blank_panel(left_panel));") && line.contains("theme.code_bg()));"))
        .expect("expected wrapped row containing both continuation segments");
    let wrapped_row = &lines[wrapped_idx];

    assert_buffer_eq(
        &render_lines(&[tui::Line::new(wrapped_row.clone())], 151, 1),
        &[cols(&[("", 34), ("| blank_panel(left_panel));", 62), ("blank_panel(left_panel, theme.code_bg()));", 0)])],
    );

    let left_start = wrapped_row.find("| blank_panel(left_panel));").expect("expected wrapped removed continuation");
    let right_start =
        wrapped_row.find("blank_panel(left_panel, theme.code_bg()));").expect("expected wrapped added continuation");

    let ctx = ViewContext::new((151, 8));
    let added_bg = Some(ctx.theme.diff_added_bg());
    let removed_bg = Some(ctx.theme.diff_removed_bg());
    let code_panel_start = left_start.saturating_sub(GUTTER_WIDTH);
    for col in code_panel_start..left_start {
        let actual_bg = term.get_style_at(wrapped_idx, col).bg;
        assert_ne!(actual_bg, added_bg, "blank left panel column {col} should not inherit added background");
        assert_ne!(actual_bg, removed_bg, "blank left panel column {col} should not inherit removed background");
    }
    assert_eq!(term.get_style_at(wrapped_idx, left_start).bg, Some(ctx.theme.diff_removed_bg()));
    assert_eq!(term.get_style_at(wrapped_idx, right_start).bg, Some(ctx.theme.diff_added_bg()));
}

fn make_long_header_doc() -> GitDiffDocument {
    let mut doc = make_test_doc();
    let long_path = "src/components/git_diff_mode/this_is_a_deliberately_long_filename_that_should_be_clipped_in_the_patch_header.rs".to_string();
    doc.files[0].old_path = Some(long_path.clone());
    doc.files[0].path = long_path;
    doc
}

fn make_long_split_hunk_header_doc() -> GitDiffDocument {
    let mut doc = make_test_doc();
    let long_header = format!("@@ -1,3 +1,3 @@ {}", "WRAPME_".repeat(30));
    doc.files[0].hunks[0].header.clone_from(&long_header);
    doc.files[0].hunks[0].lines[0].text = long_header;
    doc
}

#[test]
fn render_empty_state() {
    let sb = 26;
    let mut mode = GitDiffMode::new(PathBuf::from("."));
    let term = render_component(|ctx| mode.render_frame(ctx), 80, 3);
    assert_buffer_eq(
        &term,
        &[cols(&[("", sb), ("", 1), ("No changes in working tree relative to HEAD", 0)]), String::new(), String::new()],
    );
}

#[test]
fn render_error_state() {
    let sb = 26;
    let mut mode = GitDiffMode::new(PathBuf::from("."));
    mode.load_state = GitDiffLoadState::Error { message: "not a repo".to_string() };
    let term = render_component(|ctx| mode.render_frame(ctx), 80, 3);
    assert_buffer_eq(
        &term,
        &[cols(&[("", sb), ("", 1), ("Git diff unavailable: not a repo", 0)]), String::new(), String::new()],
    );
}

#[test]
fn render_shows_file_list_and_patch() {
    let sb = 28;
    let doc = make_test_doc();
    let mut mode = make_mode(doc);
    let term = render_component(|ctx| mode.render_frame(ctx), 100, 8);
    assert_buffer_eq(
        &term,
        &[
            cols(&[(">   M a.rs             +1/-1", sb), ("", 1), ("a.rs  (modified)", 0)]),
            cols(&[("    A b.rs             +1/-0", sb), ("", 1)]),
            cols(&[("", sb), ("", 1), ("@@ -1,3 +1,3 @@", 0)]),
            cols(&[("", sb), ("", 1), ("1 1   fn main() {", 0)]),
            cols(&[("", sb), ("", 1), ("2   -     old();", 0)]),
            cols(&[("", sb), ("", 1), ("  2 +     new();", 0)]),
            cols(&[("", sb), ("", 1), ("3 3   }", 0)]),
            String::new(),
        ],
    );
}

#[test]
fn added_lines_use_added_background_style() {
    let mut mode = make_mode(make_test_doc());
    let term = render_component(|ctx| mode.render_frame(ctx), 100, 8);
    let lines = term.get_lines();

    let added_row = lines.iter().position(|line| line.contains("new();")).expect("expected added diff line");
    let added_col = lines[added_row].find("new();").expect("expected added code text in row");

    let ctx = ViewContext::new((100, 8));
    assert_eq!(term.get_style_at(added_row, added_col).bg, Some(ctx.theme.diff_added_bg()));
}

#[test]
fn narrow_width_renders_unified_diff_rows() {
    let mut mode = make_mode(make_test_doc());
    let term = render_component(|ctx| mode.render_frame(ctx), 108, 10);
    let lines = term.get_lines();

    assert!(lines.iter().any(|line| line.contains("old();")), "expected removed line in unified view");
    assert!(lines.iter().any(|line| line.contains("new();")), "expected added line in unified view");
    assert!(
        !lines.iter().any(|line| line.contains("old();") && line.contains("new();")),
        "unified view should keep old/new content on separate rows"
    );
}

#[test]
fn wide_width_renders_split_diff_rows() {
    let mut mode = make_mode(make_test_doc());
    let term = render_component(|ctx| mode.render_frame(ctx), 109, 10);
    let lines = term.get_lines();

    assert!(
        lines.iter().any(|line| line.contains("old();") && line.contains("new();")),
        "split view should render old/new content on the same row"
    );
}

#[test]
fn git_diff_mode_soft_wraps_long_patch_headers_in_rhs_panel() {
    let mut mode = make_mode(make_long_header_doc());
    let term = render_component(|ctx| mode.render_frame(ctx), 100, 8);
    let lines = term.get_lines();

    assert!(
        lines.iter().any(|line| line.contains("this_is_a_deliberately_long_filename")),
        "expected a line containing the start of the long header, got {lines:?}"
    );
    assert!(
        lines.iter().any(|line| line.contains("should_be_clipped_in_the_patch_header.rs")),
        "expected a line containing the wrapped tail of the long header, got {lines:?}"
    );
    assert!(lines.iter().all(|line| line.chars().count() <= 100));
}

#[test]
fn git_split_view_preserves_hunk_header_background_on_wrapped_rows() {
    let mut mode = make_mode(make_long_split_hunk_header_doc());
    let term = render_component(|ctx| mode.render_frame(ctx), 130, 10);
    let lines = term.get_lines();

    let header_row = lines
        .iter()
        .position(|line| line.contains("@@ -1,3 +1,3 @@"))
        .expect("expected hunk header row to be rendered");
    let header_col = lines[header_row].find("@@ -1,3 +1,3 @@").expect("expected hunk header text in row");

    assert!(
        lines.get(header_row + 1).is_some_and(|line| line.contains("WRAPME_")),
        "expected wrapped hunk header continuation row, got {lines:?}"
    );

    let expected_bg = term.get_style_at(header_row, header_col).bg;
    assert!(expected_bg.is_some(), "expected hunk header to have background style");
    assert_eq!(term.get_style_at(header_row + 1, header_col).bg, expected_bg);
    assert_eq!(term.get_style_at(header_row + 1, 129).bg, expected_bg);
}

fn make_comment_test_doc() -> GitDiffDocument {
    GitDiffDocument {
        repo_root: PathBuf::from("/tmp/test"),
        files: vec![FileDiff {
            old_path: Some("test.rs".to_string()),
            path: "test.rs".to_string(),
            status: FileStatus::Added,
            hunks: vec![Hunk {
                header: "@@ -0,0 +1,3 @@".to_string(),
                old_start: 0,
                old_count: 0,
                new_start: 1,
                new_count: 3,
                lines: vec![
                    PatchLine {
                        kind: PatchLineKind::HunkHeader,
                        text: "@@ -0,0 +1,3 @@".to_string(),
                        old_line_no: None,
                        new_line_no: None,
                    },
                    PatchLine {
                        kind: PatchLineKind::Added,
                        text: "line_one".to_string(),
                        old_line_no: None,
                        new_line_no: Some(1),
                    },
                    PatchLine {
                        kind: PatchLineKind::Added,
                        text: "line_two".to_string(),
                        old_line_no: None,
                        new_line_no: Some(2),
                    },
                    PatchLine {
                        kind: PatchLineKind::Added,
                        text: "line_three".to_string(),
                        old_line_no: None,
                        new_line_no: Some(3),
                    },
                ],
            }],
            binary: false,
        }],
    }
}

async fn send_keys(mode: &mut GitDiffMode, codes: &[KeyCode]) {
    let ctx = ViewContext::new((100, 20));
    for &code in codes {
        mode.render_frame(&ctx);
        mode.on_key_event(&Event::Key(key(code))).await;
    }
}

#[tokio::test]
async fn draft_comment_appears_after_correct_line_when_submitted_comment_exists() {
    let mut mode = make_mode(make_comment_test_doc());

    // Focus right panel (l on file list triggers FileOpened)
    send_keys(&mut mode, &[KeyCode::Char('l')]).await;
    // Move cursor down to line_one, open comment, type "first", submit
    send_keys(
        &mut mode,
        &[
            KeyCode::Char('j'),
            KeyCode::Char('c'),
            KeyCode::Char('f'),
            KeyCode::Char('i'),
            KeyCode::Char('r'),
            KeyCode::Char('s'),
            KeyCode::Char('t'),
            KeyCode::Enter,
        ],
    )
    .await;
    // Move cursor to line_three (two j presses), open draft, type "draft"
    send_keys(
        &mut mode,
        &[
            KeyCode::Char('j'),
            KeyCode::Char('j'),
            KeyCode::Char('c'),
            KeyCode::Char('d'),
            KeyCode::Char('r'),
            KeyCode::Char('a'),
            KeyCode::Char('f'),
            KeyCode::Char('t'),
        ],
    )
    .await;

    let term = render_component(|ctx| mode.render_frame(ctx), 100, 20);
    let lines = term.get_lines();

    let line_one_row = lines.iter().position(|l| l.contains("line_one")).expect("line_one should render");
    let comment_row = lines.iter().position(|l| l.contains("first")).expect("submitted comment should render");
    let line_two_row = lines.iter().position(|l| l.contains("line_two")).expect("line_two should render");
    let line_three_row = lines.iter().position(|l| l.contains("line_three")).expect("line_three should render");
    let draft_row = lines.iter().position(|l| l.contains("draft")).expect("draft text should render");

    assert!(
        comment_row > line_one_row,
        "submitted comment (row {comment_row}) should appear after line_one (row {line_one_row})"
    );
    assert!(
        line_two_row > comment_row,
        "line_two (row {line_two_row}) should appear after submitted comment (row {comment_row})"
    );
    assert!(
        line_three_row > line_two_row,
        "line_three (row {line_three_row}) should appear after line_two (row {line_two_row})"
    );
    assert!(
        draft_row > line_three_row,
        "draft (row {draft_row}) should appear after line_three (row {line_three_row}), \
         not shifted up by the submitted comment splice"
    );
}

#[tokio::test]
async fn submitted_comment_visible_on_last_line() {
    let mut mode = make_mode(make_comment_test_doc());

    send_keys(&mut mode, &[KeyCode::Char('l')]).await;
    send_keys(
        &mut mode,
        &[
            KeyCode::Char('j'),
            KeyCode::Char('j'),
            KeyCode::Char('j'),
            KeyCode::Char('c'),
            KeyCode::Char('h'),
            KeyCode::Char('i'),
            KeyCode::Enter,
        ],
    )
    .await;

    // height=6 → body_height=4, exactly fits 4 diff lines.
    // The 3-row comment box below line_three is entirely off-screen without a scroll fix.
    let term = render_component(|ctx| mode.render_frame(ctx), 100, 6);
    let lines = term.get_lines();

    assert!(lines.iter().any(|l| l.contains("line_three")), "cursor line should be visible, got: {lines:?}");
    assert!(
        lines.iter().any(|l| l.contains("hi")),
        "submitted comment text should be visible in viewport, got: {lines:?}"
    );
    assert!(lines.iter().any(|l| l.contains("")), "comment bottom border should be visible, got: {lines:?}");
}

#[tokio::test]
async fn draft_comment_bottom_border_visible_on_last_line() {
    let mut mode = make_mode(make_comment_test_doc());

    send_keys(&mut mode, &[KeyCode::Char('l')]).await;
    send_keys(
        &mut mode,
        &[
            KeyCode::Char('j'),
            KeyCode::Char('j'),
            KeyCode::Char('j'),
            KeyCode::Char('c'),
            KeyCode::Char('h'),
            KeyCode::Char('i'),
        ],
    )
    .await;

    // height=8 → body_height=6. 4 diff lines + 3 draft rows = 7 body rows.
    // Without fix the draft content row is visible but the bottom border is clipped.
    let term = render_component(|ctx| mode.render_frame(ctx), 100, 8);
    let lines = term.get_lines();

    assert!(lines.iter().any(|l| l.contains("hi")), "draft text should be visible, got: {lines:?}");
    assert!(lines.iter().any(|l| l.contains("")), "draft bottom border should be visible, got: {lines:?}");
}