ebman 0.34.1

k9s-style TUI for AWS Elastic Beanstalk
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
//! The keymap: chords, modifiers, filter mode, multi-select.
//!
//! Split out of the 9,515-line `app/tests.rs`. Bodies moved
//! unchanged apart from one rewrite: `super::` meant `crate::app` in
//! the flat file and would mean `crate::app::tests` here, so every
//! explicit `super::` path was re-anchored (rustfmt reflowed some
//! lines as a result, since the new path is longer).

use super::super::*;
#[allow(unused_imports)]
use super::support::*;

#[test]
fn sort_key_cycle_matches_ui_column_order() {
    let order = [
        SortKey::Name,
        SortKey::App,
        SortKey::Status,
        SortKey::Health,
        SortKey::Version,
        SortKey::Age,
    ];
    let mut cur = order[0];
    for expected in order.iter().skip(1).chain(std::iter::once(&order[0])) {
        cur = cur.next();
        assert_eq!(cur, *expected);
    }
}

#[test]
fn sort_key_parse_roundtrip() {
    for k in [
        SortKey::Name,
        SortKey::App,
        SortKey::Status,
        SortKey::Health,
        SortKey::Version,
        SortKey::Age,
    ] {
        assert_eq!(SortKey::parse(k.label()), Some(k));
    }
    assert_eq!(SortKey::parse("bogus"), None);
}

#[test]
fn parse_ignore_keys_splits_and_lowercases() {
    assert_eq!(crate::app::parse_ignore_keys(None), Vec::<String>::new());
    assert_eq!(
        crate::app::parse_ignore_keys(Some("")),
        Vec::<String>::new()
    );
    assert_eq!(
        crate::app::parse_ignore_keys(Some(" Version_Label , MinSize ,")),
        vec!["version_label".to_string(), "minsize".to_string()]
    );
}

#[test]
fn filter_config_diffs_supports_namespace_qualified_match() {
    // Operators can use `namespace:name` form to scope an ignore-
    // key to a specific namespace (so a generic "MinSize" ignore
    // doesn't drop both the ASG and the LB MinSize).
    let diffs = vec![
        crate::app::ConfigDiff {
            namespace: "aws:autoscaling:asg".into(),
            name: "MinSize".into(),
            left: Some("2".into()),
            right: Some("3".into()),
        },
        crate::app::ConfigDiff {
            namespace: "aws:elasticbeanstalk:command".into(),
            name: "MinSize".into(),
            left: Some("4".into()),
            right: Some("5".into()),
        },
    ];
    let keys = crate::app::parse_ignore_keys(Some("aws:autoscaling:asg:MinSize"));
    let filtered = crate::app::filter_config_diffs(diffs, &keys);
    assert_eq!(filtered.len(), 1);
    assert_eq!(filtered[0].namespace, "aws:elasticbeanstalk:command");
}

#[test]
fn filter_config_diffs_empty_ignore_keys_is_passthrough() {
    let diffs = vec![crate::app::ConfigDiff {
        namespace: "ns".into(),
        name: "MinSize".into(),
        left: Some("2".into()),
        right: Some("3".into()),
    }];
    let original_len = diffs.len();
    assert_eq!(
        crate::app::filter_config_diffs(diffs, &[]).len(),
        original_len
    );
}

#[test]
fn build_env_edit_body_sorts_keys_and_emits_header() {
    let vars = vec![
        ("LOG_LEVEL".into(), "info".into()),
        ("DB_HOST".into(), "db.example".into()),
        ("DB_PORT".into(), "5432".into()),
    ];
    let body = crate::app::build_env_edit_body("prod", &vars);
    // Header comment present.
    assert!(body.starts_with("# ebman env-var editor — prod\n"));
    assert!(body.contains("Secrets Manager"));
    // Keys sorted alphabetically.
    let db_host_pos = body.find("DB_HOST=").expect("DB_HOST line");
    let db_port_pos = body.find("DB_PORT=").expect("DB_PORT line");
    let log_pos = body.find("LOG_LEVEL=").expect("LOG_LEVEL line");
    assert!(db_host_pos < db_port_pos && db_port_pos < log_pos);
}

#[test]
fn parse_env_edit_body_drops_invalid_keys() {
    let body = "= no-key\n KEY WITH SPACES=foo\nGOOD=val\n";
    let parsed = crate::app::parse_env_edit_body(body);
    assert_eq!(parsed.len(), 1);
    assert!(parsed.contains_key("GOOD"));
}

#[tokio::test]
async fn first_run_hint_dismisses_on_first_key() {
    let mut app = test_app();
    app.first_run_hint = true;
    press(&mut app, KeyCode::Char('j'), KeyModifiers::NONE);
    assert!(
        !app.first_run_hint,
        "first key event should clear first_run_hint"
    );
}

#[test]
fn render_options_overlay_groups_by_namespace_and_marks_set_vs_default() {
    let rows = vec![
        opt("aws:autoscaling:asg", "MinSize", Some("2"), Some("1")),
        opt("aws:autoscaling:asg", "MaxSize", None, Some("4")),
        opt(
            "aws:elasticbeanstalk:command",
            "DeploymentPolicy",
            Some("Rolling"),
            Some("AllAtOnce"),
        ),
    ];
    let body = crate::app::render_options_overlay(&rows, None, "uflexi-prod");
    // Section headers per namespace.
    assert!(body.contains("── aws:autoscaling:asg ──"));
    assert!(body.contains("── aws:elasticbeanstalk:command ──"));
    // Operator-set rows marked with ▸; default rows with •.
    assert!(body.contains("▸ MinSize"));
    assert!(body.contains("• MaxSize"));
    assert!(body.contains("▸ DeploymentPolicy"));
    // Default value is surfaced.
    assert!(body.contains("default: 1"));
    assert!(body.contains("default: 4"));
    // Top header counts set vs default.
    assert!(body.contains("2/3 options are operator-set"));
}

#[test]
fn render_options_overlay_filters_to_namespace_when_given() {
    let rows = vec![
        opt("aws:autoscaling:asg", "MinSize", Some("2"), None),
        opt(
            "aws:elasticbeanstalk:command",
            "DeploymentPolicy",
            Some("Rolling"),
            None,
        ),
    ];
    let body =
        crate::app::render_options_overlay(&rows, Some("aws:autoscaling:asg"), "uflexi-prod");
    assert!(body.contains("MinSize"));
    assert!(!body.contains("DeploymentPolicy"));
}

#[test]
fn delta_toast_key_extracts_bucket_for_delta_shapes() {
    assert_eq!(
        crate::app::delta_toast_key("▲2 Red").as_deref(),
        Some("Red")
    );
    assert_eq!(
        crate::app::delta_toast_key("▼1 Yellow").as_deref(),
        Some("Yellow")
    );
    // Leading whitespace is allowed.
    assert_eq!(
        crate::app::delta_toast_key("  ▲10 Green").as_deref(),
        Some("Green")
    );
}

#[test]
fn parse_s3_url_extracts_bucket_and_key() {
    let (b, k) = crate::app::parse_s3_url("s3://my-bucket/path/to/bundle.zip").unwrap();
    assert_eq!(b, "my-bucket");
    assert_eq!(k, "path/to/bundle.zip");
}

#[test]
fn delta_toast_key_returns_none_for_non_delta_text() {
    assert_eq!(crate::app::delta_toast_key("refreshing…"), None);
    assert_eq!(crate::app::delta_toast_key(""), None);
    assert_eq!(crate::app::delta_toast_key(""), None);
    // Arrow with no count.
    assert_eq!(crate::app::delta_toast_key("▲ Red"), None);
    // Arrow + count but no bucket word.
    assert_eq!(crate::app::delta_toast_key("▲5 "), None);
}

#[tokio::test]
async fn diff_ignore_keys_flag_parses_and_unknown_flag_errors() {
    let mut app = test_app();
    app.environments = vec![
        mk_env("staging", "uflexi", "Web", "Green"),
        mk_env("prod", "uflexi", "Web", "Green"),
    ];
    app.rebuild_view();
    // `--ignore-keys` is consumed; positional envs still resolve and
    // the overlay opens (flag order around the env names is free).
    app.execute_command("diff staging prod --ignore-keys version,updated");
    assert!(
        matches!(app.current_overlay, Some(Overlay::Diff(_))),
        "expected Overlay::Diff with --ignore-keys present"
    );
    assert!(
        app.error_message.is_none(),
        "unexpected: {:?}",
        app.error_message
    );
    // An unrecognised flag is a clear error, not a silent no-op.
    app.current_overlay = None;
    app.execute_command("diff staging prod --bogus");
    assert!(app.current_overlay.is_none(), "shouldn't open on bad flag");
    assert!(
        app.error_message
            .as_deref()
            .unwrap_or("")
            .contains("unknown arg '--bogus'"),
        "expected unknown-arg error, got {:?}",
        app.error_message
    );
    // A third positional is rejected, not silently dropped.
    app.error_message = None;
    app.current_overlay = None;
    app.execute_command("diff staging prod extra");
    assert!(
        app.current_overlay.is_none(),
        "shouldn't open with 3 positionals"
    );
    assert!(
        app.error_message
            .as_deref()
            .unwrap_or("")
            .contains("at most two"),
        "expected too-many-args error, got {:?}",
        app.error_message
    );
}

#[tokio::test]
async fn slash_enters_filter_mode_and_text_lands() {
    let mut app = test_app();
    // Seed an env so filter has something to operate on.
    app.environments = vec![
        mk_env("prod-web", "uflexi", "Web", "Green"),
        mk_env("staging-web", "uflexi", "Web", "Green"),
    ];
    app.rebuild_view();
    press(&mut app, KeyCode::Char('/'), KeyModifiers::NONE);
    assert_eq!(app.mode, Mode::Filter);
    for c in "prod".chars() {
        press(&mut app, KeyCode::Char(c), KeyModifiers::NONE);
    }
    assert_eq!(app.view.filter().text(), "prod");
    // Esc clears the filter and returns to Normal.
    press(&mut app, KeyCode::Esc, KeyModifiers::NONE);
    assert_eq!(app.mode, Mode::Normal);
    assert!(app.view.filter().is_empty());
}

#[tokio::test]
async fn enter_on_red_env_opens_why_via_bang_keybind() {
    let mut app = test_app();
    // Seed a Red env + select it.
    app.environments = vec![mk_env("prod-web", "uflexi", "Web", "Red")];
    app.rebuild_view();
    app.table_state.select(Some(0));
    // `!` shortcut in Envs scope opens the :why overlay.
    press(&mut app, KeyCode::Char('!'), KeyModifiers::NONE);
    assert!(
        matches!(app.current_overlay, Some(Overlay::WhyRed { .. })),
        "expected WhyRed overlay, got {:?}",
        app.current_overlay
    );
}

#[tokio::test]
async fn ctrl_x_toggles_redact() {
    let mut app = test_app();
    assert!(!app.view.redact);
    press(&mut app, KeyCode::Char('x'), KeyModifiers::CONTROL);
    assert!(app.view.redact);
    press(&mut app, KeyCode::Char('x'), KeyModifiers::CONTROL);
    assert!(!app.view.redact);
}

#[tokio::test]
async fn space_toggles_multi_select_and_esc_clears_it() {
    let mut app = test_app();
    app.environments = vec![
        mk_env("api-prod", "uflexi", "Web", "Green"),
        mk_env("api-staging", "uflexi", "Web", "Green"),
    ];
    app.rebuild_view();
    // Cursor on row 0 by default. Space adds it to multi-select.
    press(&mut app, KeyCode::Char(' '), KeyModifiers::NONE);
    assert_eq!(app.multi_selected.len(), 1);
    assert!(app.multi_selected.contains("api-prod"));
    // Second space toggles the same row off.
    press(&mut app, KeyCode::Char(' '), KeyModifiers::NONE);
    assert!(app.multi_selected.is_empty());
    // Select both rows again, then Esc → clears in one keystroke.
    press(&mut app, KeyCode::Char(' '), KeyModifiers::NONE);
    press(&mut app, KeyCode::Char('j'), KeyModifiers::NONE);
    press(&mut app, KeyCode::Char(' '), KeyModifiers::NONE);
    assert_eq!(app.multi_selected.len(), 2);
    press(&mut app, KeyCode::Esc, KeyModifiers::NONE);
    assert!(app.multi_selected.is_empty());
}

#[tokio::test]
async fn filter_mode_text_input_and_backspace_round_trips() {
    let mut app = test_app();
    app.environments = vec![
        mk_env("api-prod", "uflexi", "Web", "Green"),
        mk_env("api-staging", "uflexi", "Web", "Green"),
    ];
    app.rebuild_view();
    // `/` enters Filter mode.
    press(&mut app, KeyCode::Char('/'), KeyModifiers::NONE);
    assert_eq!(app.mode, Mode::Filter);
    // Type "prod" — filter text accumulates, view rebuilds on each char.
    for c in "prod".chars() {
        press(&mut app, KeyCode::Char(c), KeyModifiers::NONE);
    }
    assert_eq!(app.view.filter().text(), "prod");
    // Backspace removes the last char.
    press(&mut app, KeyCode::Backspace, KeyModifiers::NONE);
    assert_eq!(app.view.filter().text(), "pro");
    // Enter commits the filter and returns to Normal — the filter
    // string SURVIVES (it's how `:filter` works as a stateful
    // search).
    press(&mut app, KeyCode::Enter, KeyModifiers::NONE);
    assert_eq!(app.mode, Mode::Normal);
    assert_eq!(app.view.filter().text(), "pro");
}

#[tokio::test]
async fn filter_input_is_cursor_aware_via_shared_textinput() {
    // The main filter now stores a TextInput — Left + insert edits
    // mid-string and the view still rebuilds on each accepted edit.
    let mut app = test_app();
    app.environments = vec![mk_env("api-prod", "uflexi", "Web", "Green")];
    app.rebuild_view();
    press(&mut app, KeyCode::Char('/'), KeyModifiers::NONE);
    for c in "prod".chars() {
        press(&mut app, KeyCode::Char(c), KeyModifiers::NONE);
    }
    assert_eq!(app.view.filter().text(), "prod");
    press(&mut app, KeyCode::Left, KeyModifiers::NONE);
    press(&mut app, KeyCode::Char('X'), KeyModifiers::NONE);
    assert_eq!(app.view.filter().text(), "proXd");
}

#[tokio::test]
async fn esc_in_filter_mode_clears_the_filter() {
    let mut app = test_app();
    app.environments = vec![mk_env("api-prod", "uflexi", "Web", "Green")];
    app.rebuild_view();
    press(&mut app, KeyCode::Char('/'), KeyModifiers::NONE);
    for c in "x".chars() {
        press(&mut app, KeyCode::Char(c), KeyModifiers::NONE);
    }
    assert_eq!(app.view.filter().text(), "x");
    // Esc abandons the filter — both the text AND the mode revert.
    press(&mut app, KeyCode::Esc, KeyModifiers::NONE);
    assert_eq!(app.mode, Mode::Normal);
    assert!(app.view.filter().is_empty());
}

#[tokio::test]
async fn slash_with_active_filter_rebuilds_to_full_fleet() {
    // Regression: opening filter mode while a filter is already
    // active must clear the filter AND rebuild the cached view, so
    // the full fleet shows immediately — not the stale filtered
    // subset left over until the next keystroke. (Surfaced by the
    // demo gif's closing reveal; house rule: filter mutations call
    // rebuild_view().)
    let mut app = test_app();
    app.environments = vec![
        mk_env("prod-web", "uflexi", "Web", "Green"),
        mk_env("staging-web", "uflexi", "Web", "Green"),
    ];
    app.rebuild_view();
    // Apply a filter that matches exactly one env.
    press(&mut app, KeyCode::Char('/'), KeyModifiers::NONE);
    for c in "prod".chars() {
        press(&mut app, KeyCode::Char(c), KeyModifiers::NONE);
    }
    press(&mut app, KeyCode::Enter, KeyModifiers::NONE);
    assert_eq!(app.mode, Mode::Normal);
    assert_eq!(app.view.filtered().len(), 1, "filter should hide one env");
    // `/` re-opens filter mode: filter empties and the view must
    // rebuild to show all envs right away.
    press(&mut app, KeyCode::Char('/'), KeyModifiers::NONE);
    assert_eq!(app.mode, Mode::Filter);
    assert!(app.view.filter().is_empty());
    assert_eq!(
        app.view.filtered().len(),
        2,
        "full fleet should be visible the moment filter mode opens"
    );
}

#[tokio::test]
async fn star_toggles_pinned_set_for_selected_env() {
    let mut app = test_app();
    app.environments = vec![
        mk_env("api-prod", "uflexi", "Web", "Green"),
        mk_env("api-staging", "uflexi", "Web", "Green"),
    ];
    app.rebuild_view();
    // Star pins the cursor's env.
    press(&mut app, KeyCode::Char('*'), KeyModifiers::NONE);
    assert!(app.pinned.contains("api-prod"));
    // Second star unpins it.
    press(&mut app, KeyCode::Char('*'), KeyModifiers::NONE);
    assert!(!app.pinned.contains("api-prod"));
}

#[tokio::test]
async fn quickjump_input_is_cursor_aware_via_shared_textinput() {
    // QuickJump now stores a tui_common::TextInput, so it gains
    // mid-string editing (Left + insert, Backspace at the cursor)
    // rather than the old append-only buffer.
    let mut app = test_app();
    app.environments = vec![mk_env("prod", "uflexi", "Web", "Green")];
    app.rebuild_view();
    press(&mut app, KeyCode::Char('\''), KeyModifiers::NONE);
    assert_eq!(app.mode, Mode::QuickJump);
    for c in "abc".chars() {
        press(&mut app, KeyCode::Char(c), KeyModifiers::NONE);
    }
    assert_eq!(app.quickjump_input.text(), "abc");
    // Move the cursor left one and insert — mid-string, not appended.
    press(&mut app, KeyCode::Left, KeyModifiers::NONE);
    press(&mut app, KeyCode::Char('X'), KeyModifiers::NONE);
    assert_eq!(app.quickjump_input.text(), "abXc");
    press(&mut app, KeyCode::Backspace, KeyModifiers::NONE);
    assert_eq!(app.quickjump_input.text(), "abc");
}

#[tokio::test]
async fn picker_filter_is_cursor_aware_via_shared_textinput() {
    // The picker (region/profile/…) filter now stores a TextInput.
    // `j`/`k` stay list-nav, but other chars edit, and the cursor
    // moves mid-string. Open the region picker with `r`.
    let mut app = test_app();
    press(&mut app, KeyCode::Char('r'), KeyModifiers::NONE);
    assert_eq!(app.mode, Mode::Picker);
    for c in "eu".chars() {
        press(&mut app, KeyCode::Char(c), KeyModifiers::NONE);
    }
    let txt = |a: &App| a.picker.as_ref().unwrap().filter.text().to_string();
    assert_eq!(txt(&app), "eu");
    press(&mut app, KeyCode::Left, KeyModifiers::NONE);
    press(&mut app, KeyCode::Char('X'), KeyModifiers::NONE);
    assert_eq!(txt(&app), "eXu");
    press(&mut app, KeyCode::Backspace, KeyModifiers::NONE);
    assert_eq!(txt(&app), "eu");
}

#[tokio::test]
async fn apps_scope_space_toggles_apps_selected() {
    let mut app = test_app();
    // Seed two apps + select Apps scope.
    app.applications = vec![
        crate::aws::Application {
            name: "billing".into(),
            description: String::new(),
            date_created: None,
            date_updated: None,
            version_count: 0,
            templates: vec![],
            latest_version_label: None,
            latest_version_created: None,
        },
        crate::aws::Application {
            name: "checkout".into(),
            description: String::new(),
            date_created: None,
            date_updated: None,
            version_count: 0,
            templates: vec![],
            latest_version_label: None,
            latest_version_created: None,
        },
    ];
    app.set_scope(Scope::Apps);
    app.app_table_state.select(Some(0));
    // First space adds; second space removes.
    press(&mut app, KeyCode::Char(' '), KeyModifiers::NONE);
    assert!(app.apps_selected.contains("billing"));
    press(&mut app, KeyCode::Char(' '), KeyModifiers::NONE);
    assert!(!app.apps_selected.contains("billing"));
}

#[tokio::test]
async fn apps_scope_star_pins_and_unpins_app() {
    let mut app = test_app();
    app.applications = vec![crate::aws::Application {
        name: "billing".into(),
        description: String::new(),
        date_created: None,
        date_updated: None,
        version_count: 0,
        templates: vec![],
        latest_version_label: None,
        latest_version_created: None,
    }];
    app.set_scope(Scope::Apps);
    app.app_table_state.select(Some(0));
    assert!(!app.pinned_apps.contains("billing"));
    press(&mut app, KeyCode::Char('*'), KeyModifiers::SHIFT);
    assert!(app.pinned_apps.contains("billing"));
    press(&mut app, KeyCode::Char('*'), KeyModifiers::SHIFT);
    assert!(!app.pinned_apps.contains("billing"));
}

#[tokio::test]
async fn esc_clears_apps_selected_when_no_envs_selected() {
    let mut app = test_app();
    app.apps_selected.insert("billing".into());
    app.apps_selected.insert("checkout".into());
    press(&mut app, KeyCode::Esc, KeyModifiers::NONE);
    assert!(app.apps_selected.is_empty());
}

#[tokio::test]
async fn unconsumed_key_in_filter_mode_leaves_the_view_fresh() {
    // `TextInput::handle_key` returns false for keys it doesn't consume
    // (Down, PageUp, most Ctrl chords). Taking the filter mutably to ask
    // marked the cache stale whether or not the key was consumed, and the
    // no-op arm didn't rebuild — so the next frame read a stale cache.
    let mut app = test_app();
    app.environments = vec![
        fake_env_with("api-prod", "Ready", "Green", None),
        fake_env_with("web-prod", "Ready", "Green", None),
    ];
    app.rebuild_view();
    press(&mut app, KeyCode::Char('/'), KeyModifiers::NONE);
    assert_eq!(app.mode, Mode::Filter);

    press(&mut app, KeyCode::Down, KeyModifiers::NONE);
    assert!(
        !app.view.is_stale(),
        "a key the filter buffer ignores must not leave the cache stale"
    );
    // The frame after must not trip the freshness assertion.
    let _ = render(&mut app, 120, 30);
}

#[tokio::test]
async fn the_control_socket_screen_op_reports_the_last_frame() {
    // `last_rendered_buffer` has exactly one reader — this — and the run
    // loop now only populates it when a control socket is attached.
    // Nothing covered either side of that, so a wrong condition would
    // have made `ebman ctl screen` return the placeholder forever in
    // silence.
    let mut app = test_app();
    app.environments = vec![mk_env("api-prod", "uflexi", "Web", "Green")];
    app.view.invalidate();
    app.rebuild_view();

    // No frame captured yet — say so rather than lying with a blank screen.
    assert!(
        app.screen_text().contains("no frame rendered yet"),
        "{}",
        app.screen_text()
    );

    // With a frame captured, the op returns its text.
    app.last_rendered_buffer = Some(render_buf(&mut app, 120, 20));
    let text = app.screen_text();
    assert!(
        text.contains("api-prod"),
        "the screenshot carries the rendered fleet:\n{text}"
    );
}