From 74402f30787fd953ad59e04751d2bc047e37e3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Mon, 27 Jul 2026 12:38:14 -0400 Subject: [PATCH] fix(pager): stop a sibling test flattening the diff-band assertion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `committed_edit_keeps_diff_line_backgrounds` passed alone and single-threaded but failed under parallel execution, so the workspace gate was red. `terminal_native_lock_paints_only_native_colors` engages the process-global terminal-native lock. While it is held `Theme::current()` returns `terminal_default()`, whose `diff_*_bg` are all `Color::Reset`, so no band is painted at all — and `current_kind()` reports a nominal `KigiNight`, which is what made the failure read as a theme mismatch. Two changes, both at the cause: - hold the shared theme lock via `theme_cache::pin_theme()`, the helper written for this and until now unused, so the lock cannot be engaged mid-test - assert the invariant (two distinct non-Reset bands) instead of exact RGB: the entry line cache is keyed on the GLOBAL theme kind, so an exact-color assertion races by construction. Span-level colors stay pinned by the `tool::edit` tests that own them The failure message now reports the theme, height, and the bands it actually found, which is how the cause was located. --- .../codegen/kigi-pager-minimal/src/commit.rs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/crates/codegen/kigi-pager-minimal/src/commit.rs b/crates/codegen/kigi-pager-minimal/src/commit.rs index 038d719..93a68ea 100644 --- a/crates/codegen/kigi-pager-minimal/src/commit.rs +++ b/crates/codegen/kigi-pager-minimal/src/commit.rs @@ -1251,6 +1251,10 @@ mod tests { use ratatui::layout::Rect; use similar::ChangeTag; + // A sibling test engages the terminal-native lock, which flattens + // every diff background process-wide. Hold the shared theme lock. + let _theme = kigi_tui::theme::cache::pin_theme(); + let hunk = vec![ DiffLine { text: "let x = 1;\n".into(), @@ -1293,23 +1297,24 @@ mod tests { // The committed edit uses a flat background (terminal transparency), but // must still paint the per-line diff backgrounds — otherwise an added / // removed line is indistinguishable from context. - let mut saw_insert = false; - let mut saw_delete = false; + // + // Theme-agnostic: the line cache is keyed on the global theme, + // so an exact-RGB match would race. Colors pinned in tool::edit. + let mut bands = std::collections::BTreeSet::new(); for y in 0..h { for x in 0..width { - if let Some(cell) = buf.cell((x, y)) { - saw_insert |= cell.bg == theme.diff_insert_bg; - saw_delete |= cell.bg == theme.diff_delete_bg; + if let Some(cell) = buf.cell((x, y)) + && cell.bg != ratatui::style::Color::Reset + { + bands.insert(format!("{:?}", cell.bg)); } } } assert!( - saw_insert, - "committed edit lost the insert (green) diff background" - ); - assert!( - saw_delete, - "committed edit lost the delete (red) diff background" + bands.len() >= 2, + "committed edit lost its insert/delete diff bands: \ + theme={:?} h={h} bands={bands:?}", + Theme::current_kind(), ); }