rho-coding-agent 2.3.0

A fast Rust agent harness with a small footprint and opinionated defaults
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
use super::*;
use crate::tui::theme_terminal::{parse_palette_response, windows_console_palette};
use pretty_assertions::assert_eq;
use std::collections::HashMap;

fn palette(background: Rgb, bright_black: Option<Rgb>) -> TerminalPalette {
    let mut ansi = HashMap::from([(AnsiColor::White, Rgb::new(255, 255, 255))]);
    if let Some(bright_black) = bright_black {
        ansi.insert(AnsiColor::BrightBlack, bright_black);
    }
    TerminalPalette { background, ansi }
}

fn dim_of(background: Rgb, bright_black: Option<Rgb>) -> Color {
    Palette::from_terminal(Some(&palette(background, bright_black))).dim
}

// Covers: dim resolves from bright black with fallbacks; never from ANSI white
// Owner: tui theme palette mapping
#[test]
fn dim_foreground_policy_table() {
    let dark_bg = Rgb::new(10, 10, 10);
    let light_bg = Rgb::new(245, 245, 245);

    let cases = [
        // usable bright black on dark bg
        (
            dark_bg,
            Some(Rgb::new(170, 170, 170)),
            Color::Rgb(170, 170, 170),
        ),
        // near-white bright black rejected on dark bg
        (dark_bg, Some(Rgb::new(245, 245, 245)), Color::DarkGray),
        // near-black bright black rejected on dark bg
        (dark_bg, Some(Rgb::new(8, 8, 8)), Color::DarkGray),
        // missing bright black falls back on dark bg
        (dark_bg, None, Color::DarkGray),
        // usable bright black on light bg
        (light_bg, Some(Rgb::new(80, 80, 80)), Color::Rgb(80, 80, 80)),
        // too-light bright black rejected on light bg
        (light_bg, Some(Rgb::new(200, 200, 200)), Color::Black),
        // missing bright black falls back on light bg
        (light_bg, None, Color::Black),
    ];

    for (background, bright_black, expected) in cases {
        assert_eq!(
            dim_of(background, bright_black),
            expected,
            "bg={background:?} bright_black={bright_black:?}"
        );
    }
}

// Covers: OSC parse keeps white required and bright black optional
// Owner: tui theme palette mapping
#[test]
fn parses_osc_palette_with_optional_bright_black() {
    let chromatic_and_white = "\x1b]11;rgb:0000/0000/0000\x1b\\\
\x1b]4;1;rgb:ffff/0000/0000\x1b\\\
\x1b]4;2;rgb:0000/ffff/0000\x1b\\\
\x1b]4;3;rgb:ffff/ffff/0000\x1b\\\
\x1b]4;4;rgb:0000/0000/ffff\x1b\\\
\x1b]4;5;rgb:ffff/0000/ffff\x1b\\\
\x1b]4;6;rgb:0000/ffff/ffff\x1b\\\
\x1b]4;7;rgb:ffff/ffff/ffff\x1b\\";

    let without_bright_black =
        parse_palette_response(chromatic_and_white).expect("palette without index 8");
    assert!(!without_bright_black
        .ansi
        .contains_key(&AnsiColor::BrightBlack));
    assert_eq!(
        Palette::from_terminal(Some(&without_bright_black)).dim,
        Color::DarkGray
    );

    let with_bright_black = format!("{chromatic_and_white}\x1b]4;8;rgb:aaaa/aaaa/aaaa\x1b\\");
    let palette = parse_palette_response(&with_bright_black).expect("palette with index 8");
    assert_eq!(palette.background, Rgb::new(0, 0, 0));
    assert_eq!(palette.ansi[&AnsiColor::Red], Rgb::new(255, 0, 0));
    assert_eq!(palette.ansi[&AnsiColor::White], Rgb::new(255, 255, 255));
    assert_eq!(
        palette.ansi[&AnsiColor::BrightBlack],
        Rgb::new(170, 170, 170)
    );
    assert_eq!(
        Palette::from_terminal(Some(&palette)).dim,
        Color::Rgb(170, 170, 170)
    );
}

#[test]
fn resolves_windows_console_palette_in_attribute_bit_order() {
    let color_table = [
        0x000000, 0x110000, 0x001100, 0x111100, 0x000011, 0x110011, 0x001111, 0xeeeeee, 0x222222,
        0x330000, 0x003300, 0x333300, 0x000033, 0x330033, 0x003333, 0x333333,
    ];

    let palette = windows_console_palette(&color_table, 0x20);

    assert_eq!(palette.background, Rgb::new(0, 17, 0));
    assert_eq!(palette.ansi[&AnsiColor::Red], Rgb::new(17, 0, 0));
    assert_eq!(palette.ansi[&AnsiColor::Blue], Rgb::new(0, 0, 17));
    assert_eq!(palette.ansi[&AnsiColor::White], Rgb::new(238, 238, 238));
    assert_eq!(palette.ansi[&AnsiColor::BrightBlack], Rgb::new(34, 34, 34));
}

#[test]
fn chooses_dark_block_foreground_for_light_resolved_backgrounds() {
    let _guard = theme_test_lock();
    Theme::apply_committed("terminal");
    assert_eq!(
        block_foreground(Some(Rgb::new(240, 240, 240))),
        Color::Black
    );
    assert_eq!(block_foreground(Some(Rgb::new(20, 20, 20))), Color::White);
    assert_eq!(block_foreground(None), Color::White);
}

#[test]
fn blends_toward_terminal_ansi_color() {
    let base = Rgb::new(10, 10, 10);
    let green = Rgb::new(10, 110, 10);

    assert_eq!(base.blend_toward(green, 0.16), Rgb::new(10, 26, 10));
}

#[test]
fn resolved_ansi_background_keeps_rgb_for_foreground_contrast() {
    let _guard = theme_test_lock();
    Theme::apply_committed("terminal");
    let palette = TerminalPalette {
        background: Rgb::new(255, 255, 255),
        ansi: HashMap::from([(AnsiColor::White, Rgb::new(240, 240, 240))]),
    };

    let background = palette
        .blended_background(AnsiColor::White, USER_BACKGROUND_ALPHA)
        .expect("resolved background");

    assert_eq!(background.color, Color::Rgb(254, 254, 254));
    assert_eq!(block_foreground(background.rgb), Color::Black);
}

// Covers: reasoning uses Theme::dim only, not a second DIM modifier
// Owner: tui theme palette mapping
#[test]
fn reasoning_output_uses_one_dimming_mechanism() {
    let _guard = theme_test_lock();
    Theme::apply_committed("terminal");
    let styled = Style::default().add_modifier(Modifier::DIM | Modifier::ITALIC);
    let mut lines = vec![Line::styled("reasoning", styled).style(styled)];

    Theme::reasoning_output(&mut lines);

    for style in [lines[0].style, lines[0].spans[0].style] {
        let effective_modifiers = style.add_modifier - style.sub_modifier;
        assert!(!effective_modifiers.contains(Modifier::DIM));
        // No terminal palette in unit tests, so dim falls back to DarkGray.
        assert_eq!(style.fg, Some(Color::DarkGray));
    }
}

// Covers: fixed light schemes keep RGB dim/ink (no ANSI Black hole under Clear)
// Owner: tui theme palette mapping
#[test]
fn fixed_light_scheme_uses_rgb_dim_and_surface() {
    let _guard = theme_test_lock();
    Theme::apply_committed("terminal");
    Theme::apply_committed("monochrome-light");
    let palette = Palette::current();
    assert!(matches!(palette.surface, Some(Color::Rgb(_, _, _))));
    assert!(matches!(palette.text, Some(Color::Rgb(_, _, _))));
    assert!(
        matches!(palette.dim, Color::Rgb(_, _, _)),
        "dim must be scheme RGB, got {:?}",
        palette.dim
    );
    let surface = Theme::surface();
    assert!(matches!(surface.bg, Some(Color::Rgb(_, _, _))));
    assert!(matches!(surface.fg, Some(Color::Rgb(_, _, _))));

    // Soft panels wash toward black on light surfaces, not white-on-white.
    let panel = palette.user_background.rgb.expect("panel rgb");
    let scheme = theme_scheme::resolve_fixed_scheme("monochrome-light").unwrap();
    assert!(
        panel.luminance() < scheme.background.luminance(),
        "panel wash should darken light surfaces"
    );

    Theme::apply_committed("terminal");
}

// Covers: rail dim stays readable on wash and is ink-only so pressed rows keep their background
// Owner: tui theme palette mapping
#[test]
fn activity_rail_dim_stays_readable_on_terminal_wash() {
    let _guard = theme_test_lock();
    Theme::apply_committed("terminal");
    let rail = Theme::activity_rail();
    let dim = Theme::activity_rail_dim();
    assert_eq!(rail.bg, Some(Color::DarkGray));
    assert_eq!(dim.bg, None, "dim is ink-only so row wash can win");
    assert_ne!(dim.fg, rail.bg, "dim rail text must not match the wash");
    assert_eq!(
        dim.fg,
        Some(Palette::current().panel_dim),
        "rail dim uses the palette's wash-safe muted ink"
    );
    assert_eq!(
        dim.fg,
        Some(Color::Gray),
        "named DarkGray wash keeps a muted slot, not body white"
    );
    let pressed = Theme::activity_rail_row(crate::tui::activity::RailRowState::Pressed);
    assert_eq!(
        pressed.patch(dim).bg,
        pressed.bg,
        "pressed accent wash must survive dim activity/trailing spans"
    );

    Theme::apply_committed("one-half-dark");
    let rail = Theme::activity_rail();
    let dim = Theme::activity_rail_dim();
    let palette = Palette::current();
    assert_eq!(dim.bg, None);
    assert_ne!(dim.fg, rail.bg);
    assert_eq!(dim.fg, Some(palette.panel_dim));
    assert_eq!(
        palette.panel_dim, palette.dim,
        "built-in schemes keep muted rail ink when it still contrasts"
    );

    Theme::apply_committed("terminal");
}

// Covers: panel dim keeps usable muted ink and blends instead of jumping to body
// Owner: tui theme palette mapping
#[test]
fn panel_dim_keeps_muted_ink_instead_of_body_fallback() {
    let dark_bg = Rgb::new(10, 10, 10);
    let light_bg = Rgb::new(245, 245, 245);
    let white = Rgb::new(255, 255, 255);
    let black = Rgb::new(0, 0, 0);

    let usable = Palette::from_terminal(Some(&palette(dark_bg, Some(Rgb::new(170, 170, 170)))));
    assert_eq!(usable.dim, Color::Rgb(170, 170, 170));
    assert_eq!(usable.panel_dim, Color::Rgb(170, 170, 170));
    assert_ne!(usable.panel_dim, usable.neutral_tool_background.color);

    let unnamed = Palette::from_terminal(None);
    assert_eq!(unnamed.dim, Color::DarkGray);
    assert_eq!(unnamed.neutral_tool_background.color, Color::DarkGray);
    assert_eq!(unnamed.panel_dim, Color::Gray);

    let tight = dim_on_background(Rgb::new(20, 20, 20), [Rgb::new(30, 30, 30)], white);
    assert_eq!(tight, Color::Rgb(149, 149, 149));

    let light_tight = dim_on_background(Rgb::new(240, 240, 240), [Rgb::new(220, 220, 220)], black);
    assert_eq!(light_tight, Color::Rgb(108, 108, 108));

    let light_ok = dim_on_background(Rgb::new(240, 240, 240), [Rgb::new(80, 80, 80)], black);
    assert_eq!(light_ok, Color::Rgb(80, 80, 80));

    let no_sample = Palette::from_terminal(Some(&palette(dark_bg, None)));
    assert_eq!(no_sample.dim, Color::DarkGray);
    assert!(matches!(no_sample.panel_dim, Color::Rgb(_, _, _)));
    assert_ne!(no_sample.panel_dim, no_sample.neutral_tool_background.color);

    let light = Palette::from_terminal(Some(&palette(light_bg, Some(Rgb::new(80, 80, 80)))));
    assert_eq!(light.dim, Color::Rgb(80, 80, 80));
    assert_eq!(light.panel_dim, Color::Rgb(80, 80, 80));
}

// Covers: hover lift direction tracks surface luminance; non-RGB ink lifts to bold
// Owner: tui theme palette mapping
#[test]
fn hover_lift_blends_rgb_ink_toward_surface_opposite() {
    let _guard = theme_test_lock();
    Theme::apply_committed("terminal");
    Theme::apply_committed("one-half-dark");
    // Dark surface: mid gray lifts toward white, staying in band.
    let lifted = Theme::hover_lifted(Color::Rgb(140, 140, 140)).expect("rgb ink lifts");
    let Color::Rgb(red, green, blue) = lifted else {
        panic!("lifted ink must stay RGB, got {lifted:?}");
    };
    assert!(
        red > 140 && green > 140 && blue > 140,
        "dark-surface lift must brighten, got ({red},{green},{blue})"
    );

    Theme::apply_committed("monochrome-light");
    // Light surface: dark ink lifts toward black.
    let lifted = Theme::hover_lifted(Color::Rgb(100, 100, 100)).expect("rgb ink lifts");
    let Color::Rgb(red, green, blue) = lifted else {
        panic!("lifted ink must stay RGB, got {lifted:?}");
    };
    assert!(
        red < 100 && green < 100 && blue < 100,
        "light-surface lift must darken, got ({red},{green},{blue})"
    );

    // Named and default ink cannot blend; callers fall back to bold.
    for ink in [Color::Reset, Color::DarkGray, Color::White] {
        assert_eq!(
            Theme::hover_lifted(ink),
            None,
            "{ink:?} must fall back to bold"
        );
    }

    Theme::apply_committed("terminal");
}

// Covers: add/remove chrome uses role fg signs, soft wash, tinted plain content
// Owner: tui theme palette mapping
#[test]
fn scheme_diff_chrome_washes_row_with_fg_signs() {
    let _guard = theme_test_lock();
    Theme::apply_committed("terminal");
    Theme::apply_committed("one-half-dark");
    let palette = Palette::current();
    let add_wash = palette.diff_add_wash.expect("add wash").color;
    let del_wash = palette.diff_del_wash.expect("del wash").color;
    assert_ne!(add_wash, del_wash);

    let add = Theme::tool_diff_chrome(rho_tools::tool_card::DiffRowKind::Added);
    let del = Theme::tool_diff_chrome(rho_tools::tool_card::DiffRowKind::Removed);
    // Signs: role foreground on the same soft wash as the row (not a solid gutter).
    assert_eq!(add.sign.fg, Some(palette.success));
    assert_eq!(del.sign.fg, Some(palette.error));
    assert_eq!(add.sign.bg, Some(add_wash));
    assert_eq!(del.sign.bg, Some(del_wash));
    // washed() carries the row wash onto column bases; plain content is body text on the wash.
    assert_eq!(add.washed(Theme::tool_diff_gutter()).bg, Some(add_wash));
    assert_eq!(add.plain().fg, Theme::text().fg);
    assert_eq!(add.plain().bg, Some(add_wash));
    assert_eq!(del.plain().fg, Theme::text().fg);
    assert_eq!(del.plain().bg, Some(del_wash));
    assert_eq!(del.washed(Theme::text()).bg, Some(del_wash));
    // Context has no wash or role sign; plain content stays body text.
    let ctx = Theme::tool_diff_chrome(rho_tools::tool_card::DiffRowKind::Context);
    assert_eq!(ctx.sign, Theme::text());
    assert_eq!(ctx.plain(), Theme::text());
    assert_eq!(ctx.washed(Theme::text()).bg, None);

    Theme::apply_committed("terminal");
}

// Covers: sampled / named-scheme diff washes stay at least GitHub's 15% overlay
// and never collapse to the surface or the solid role color.
// Owner: tui theme palette mapping
#[test]
fn sampled_diff_wash_beats_github_overlay_on_light_and_dark() {
    let _guard = theme_test_lock();
    Theme::apply_committed("terminal");
    const GITHUB_ALPHA: f32 = 0x26 as f32 / 255.0;
    let schemes = [
        "one-half-dark",
        "one-half-light",
        "monochrome-dark",
        "monochrome-light",
        "nord",
        "dracula",
        "gruvbox-dark",
        "catppuccin-mocha",
    ];
    for id in schemes {
        Theme::apply_committed(id);
        let scheme = theme_scheme::resolve_fixed_scheme(id).expect(id);
        let palette = Palette::current();
        let add = palette.diff_add_wash.expect(id).rgb.expect("add rgb");
        let del = palette.diff_del_wash.expect(id).rgb.expect("del rgb");
        let bg = scheme.background;
        let green = scheme_ansi(&scheme, AnsiColor::Green);
        let red = scheme_ansi(&scheme, AnsiColor::Red);
        let add_floor = bg.blend_toward(green, GITHUB_ALPHA);
        let del_floor = bg.blend_toward(red, GITHUB_ALPHA);
        assert_ne!(add, bg, "{id} add wash must leave the surface");
        assert_ne!(del, bg, "{id} del wash must leave the surface");
        assert_ne!(add, green, "{id} add wash must not be solid green");
        assert_ne!(del, red, "{id} del wash must not be solid red");
        assert!(
            rgb_dist2(add, bg) >= rgb_dist2(add_floor, bg),
            "{id} add wash weaker than GitHub 15% overlay"
        );
        assert!(
            rgb_dist2(del, bg) >= rgb_dist2(del_floor, bg),
            "{id} del wash weaker than GitHub 15% overlay"
        );
    }

    let sampled = TerminalPalette {
        background: Rgb::new(13, 17, 23),
        ansi: HashMap::from([
            (AnsiColor::Green, Rgb::new(63, 185, 80)),
            (AnsiColor::Red, Rgb::new(255, 123, 114)),
        ]),
    };
    let palette = Palette::from_terminal(Some(&sampled));
    assert!(palette.diff_add_wash.is_some());
    assert!(palette.diff_del_wash.is_some());
    let add = palette.diff_add_wash.unwrap().rgb.unwrap();
    assert_ne!(add, sampled.background);

    // Near-surface ANSI green/red must still leave the background after rounding.
    let collapsed = TerminalPalette {
        background: Rgb::new(0, 0, 0),
        ansi: HashMap::from([
            (AnsiColor::Green, Rgb::new(0, 1, 0)),
            (AnsiColor::Red, Rgb::new(1, 0, 0)),
        ]),
    };
    let collapsed_palette = Palette::from_terminal(Some(&collapsed));
    let collapsed_add = collapsed_palette
        .diff_add_wash
        .expect("near-surface green still washes")
        .rgb
        .expect("add rgb");
    let collapsed_del = collapsed_palette
        .diff_del_wash
        .expect("near-surface red still washes")
        .rgb
        .expect("del rgb");
    assert_ne!(collapsed_add, collapsed.background);
    assert_ne!(collapsed_del, collapsed.background);

    let matrix = crate::tui::theme_terminal::matrix_fixture_palette();
    let matrix_palette = Palette::from_terminal(Some(&matrix));
    assert!(
        matrix_palette.diff_add_wash.is_some(),
        "matrix fixture must paint add wash"
    );
    assert_eq!(
        matrix_palette.diff_add_wash.unwrap().rgb.unwrap(),
        Rgb::new(0x16, 0x2f, 0x21)
    );
    assert_eq!(
        matrix_palette.diff_del_wash.unwrap().rgb.unwrap(),
        Rgb::new(0x38, 0x24, 0x27)
    );

    Theme::apply_committed("terminal");
}

fn rgb_dist2(left: Rgb, right: Rgb) -> i32 {
    let dr = i32::from(left.red) - i32::from(right.red);
    let dg = i32::from(left.green) - i32::from(right.green);
    let db = i32::from(left.blue) - i32::from(right.blue);
    dr * dr + dg * dg + db * db
}

// Covers: brand/version roles use sampled terminal RGB, not bare Color::Cyan/Green
// Owner: tui theme palette mapping
#[test]
fn terminal_palette_drives_brand_and_success_rgb() {
    let ansi = HashMap::from([
        (AnsiColor::Cyan, Rgb::new(10, 20, 30)),
        (AnsiColor::Green, Rgb::new(40, 50, 60)),
        (AnsiColor::Yellow, Rgb::new(70, 80, 90)),
        (AnsiColor::Red, Rgb::new(100, 110, 120)),
        (AnsiColor::Magenta, Rgb::new(130, 140, 150)),
        (AnsiColor::White, Rgb::new(200, 200, 200)),
    ]);
    let terminal = TerminalPalette {
        background: Rgb::new(0, 0, 0),
        ansi,
    };
    let palette = Palette::from_terminal(Some(&terminal));
    assert_eq!(palette.accent, Color::Rgb(10, 20, 30));
    assert_eq!(palette.success, Color::Rgb(40, 50, 60));
    assert_eq!(palette.warning, Color::Rgb(70, 80, 90));
    assert_eq!(palette.error, Color::Rgb(100, 110, 120));
    assert_eq!(palette.skill, Color::Rgb(130, 140, 150));

    // Sampled green/red also drive optional diff row washes.
    assert!(palette.diff_add_wash.is_some());
    assert!(palette.diff_del_wash.is_some());

    // Without a sample, keep named ANSI so the host can still paint them.
    // Skip harsh named-ANSI backgrounds for diff chrome.
    let fallback = Palette::from_terminal(None);
    assert_eq!(fallback.accent, Color::Cyan);
    assert_eq!(fallback.success, Color::Green);
    assert!(fallback.diff_add_wash.is_none());
    assert!(fallback.diff_del_wash.is_none());
}

// Covers: bright warning yellow is darkened on light surfaces for Auto/status text
// Owner: tui theme palette mapping
#[test]
fn role_ink_darkens_bright_yellow_on_light_surface() {
    let light = Rgb::new(250, 250, 250);
    let bright_yellow = Color::Rgb(0xf1, 0xfa, 0x8c);
    let adjusted = role_ink(bright_yellow, Some(light));
    let Color::Rgb(red, green, blue) = adjusted else {
        panic!("expected rgb ink, got {adjusted:?}");
    };
    let ink = Rgb::new(red, green, blue);
    assert!(
        ink.luminance() + ROLE_INK_MARGIN <= light.luminance(),
        "warning ink should sit clearly below light surface: {ink:?}"
    );
    // Still warm, not pure gray/black.
    assert!(
        red > blue && green > blue,
        "should keep a warm yellow/amber cast"
    );

    let dark = Rgb::new(20, 20, 20);
    assert_eq!(
        role_ink(bright_yellow, Some(dark)),
        bright_yellow,
        "bright yellow stays on dark surfaces"
    );
}

// Covers: preview does not commit; cancel restores committed
// Owner: tui theme state
#[test]
fn preview_then_cancel_restores_committed() {
    let _guard = theme_test_lock();
    Theme::apply_committed("terminal");
    Theme::apply_committed("one-half-dark");
    assert_eq!(Theme::committed_id(), "one-half-dark");
    assert_eq!(Theme::active_id(), "one-half-dark");

    Theme::preview("monochrome-light");
    assert_eq!(Theme::committed_id(), "one-half-dark");
    assert_eq!(Theme::active_id(), "monochrome-light");

    Theme::cancel_preview();
    assert_eq!(Theme::committed_id(), "one-half-dark");
    assert_eq!(Theme::active_id(), "one-half-dark");

    Theme::apply_committed("terminal");
}

// Covers: apply_committed updates both active and committed
// Owner: tui theme state
#[test]
fn apply_committed_updates_active_and_committed() {
    let _guard = theme_test_lock();
    Theme::apply_committed("terminal");
    Theme::apply_committed("terminal");
    let gen = Theme::generation();
    Theme::apply_committed("one-half-light");
    assert_eq!(Theme::committed_id(), "one-half-light");
    assert_eq!(Theme::active_id(), "one-half-light");
    assert!(Theme::generation() > gen);
    Theme::apply_committed("terminal");
}