From 7ffaec85cfc976d9706e110f15d2b501db188882 Mon Sep 17 00:00:00 2001 From: Chris Busillo Date: Sat, 30 May 2026 18:49:39 -0400 Subject: [PATCH] test(tui): stabilize Lab snapshot normalization --- .../tests/bottom_spacer_clip_regression.rs | 32 +++++++++++++++++++ .../tui/tests/vt100_chatwidget_snapshot.rs | 6 +++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/code-rs/tui/tests/bottom_spacer_clip_regression.rs b/code-rs/tui/tests/bottom_spacer_clip_regression.rs index 96031a18dfe..1de38f4707d 100644 --- a/code-rs/tui/tests/bottom_spacer_clip_regression.rs +++ b/code-rs/tui/tests/bottom_spacer_clip_regression.rs @@ -206,10 +206,42 @@ fn normalize_output(text: String) -> String { .map(normalize_glyph) .collect::() .pipe(normalize_timers) + .pipe(normalize_lab_build_name) .pipe(normalize_spacer_rows) .pipe(scrub_intro_art) } +fn normalize_lab_build_name(text: String) -> String { + let mut out = Vec::new(); + for line in text.lines() { + let content = line.trim_start(); + if content.contains(code_version::LAB_BUILD_NAME) + && content.starts_with('|') + && content.ends_with('|') + { + let indent = line.len().saturating_sub(content.len()); + let inner_width = content.len().saturating_sub(2); + let label_width = code_version::PRODUCT_NAME.len(); + let left = inner_width.saturating_sub(label_width) / 2; + let right = inner_width.saturating_sub(label_width + left); + out.push(format!( + "{}|{}{}{}|", + " ".repeat(indent), + " ".repeat(left), + code_version::PRODUCT_NAME, + " ".repeat(right) + )); + } else { + out.push(line.replace(code_version::LAB_BUILD_NAME, code_version::PRODUCT_NAME)); + } + } + let mut normalized = out.join("\n"); + if text.ends_with('\n') { + normalized.push('\n'); + } + normalized +} + fn normalize_glyph(ch: char) -> char { match ch { '┌' | '┐' | '└' | '┘' diff --git a/code-rs/tui/tests/vt100_chatwidget_snapshot.rs b/code-rs/tui/tests/vt100_chatwidget_snapshot.rs index 765462c508a..7837db29ed3 100644 --- a/code-rs/tui/tests/vt100_chatwidget_snapshot.rs +++ b/code-rs/tui/tests/vt100_chatwidget_snapshot.rs @@ -100,7 +100,11 @@ fn normalize_lab_build_name(text: String) -> String { out.push(line.replace(code_version::LAB_BUILD_NAME, code_version::PRODUCT_NAME)); } } - out.join("\n") + let mut normalized = out.join("\n"); + if text.ends_with('\n') { + normalized.push('\n'); + } + normalized } fn init_tracing_once() {