From 060c44ff78210f5cdc9c9676356d519386339c78 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Tue, 23 Dec 2025 12:15:29 -0800 Subject: [PATCH] test(tui2): narrow disallowed_methods suppression The SGR writer tests intentionally construct truecolor (RGB) and indexed colors so the emitted escape sequences are deterministic. Replace the blanket allow on the whole test with statement-level `#[expect(clippy::disallowed_methods)]` on the specific constructors (`Color::Rgb`/`Color::Indexed`), with inline rationale. --- codex-rs/tui2/src/insert_history.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/codex-rs/tui2/src/insert_history.rs b/codex-rs/tui2/src/insert_history.rs index db22acef98..86a32c16ce 100644 --- a/codex-rs/tui2/src/insert_history.rs +++ b/codex-rs/tui2/src/insert_history.rs @@ -321,14 +321,22 @@ mod tests { } #[test] - #[allow(clippy::disallowed_methods)] fn write_spans_emits_truecolor_and_indexed_sgr() { - let spans = [Span::styled( - "X", - Style::default() - .fg(Color::Rgb(1, 2, 3)) - .bg(Color::Indexed(42)), - )]; + // This test asserts that `write_spans` emits the correct SGR sequences for colors that + // can't be represented with the theme-aware ANSI palette: + // + // - `ratatui::style::Color::Rgb` (truecolor; `38;2;r;g;b`) + // - `ratatui::style::Color::Indexed` (256-color index; `48;5;n`) + // + // Those constructors are intentionally disallowed in production code (see + // `codex-rs/clippy.toml`), but the test needs them so the output bytes are fully + // deterministic. + #[expect(clippy::disallowed_methods)] + let fg = Color::Rgb(1, 2, 3); + #[expect(clippy::disallowed_methods)] + let bg = Color::Indexed(42); + + let spans = [Span::styled("X", Style::default().fg(fg).bg(bg))]; let mut actual: Vec = Vec::new(); write_spans(&mut actual, spans.iter()).unwrap();