From 13e676a101c8f5ceb83c0ac1608414454ba71500 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Fri, 20 Nov 2026 21:48:18 -0700 Subject: [PATCH] fix(gui): the tab bar's pictures are compared as shapes, and no picture depends on a temporary name The stored tab-bar images were compared pixel for pixel on every machine. GitHub's software renderer rasterizes the same shapes differently from the GPU that made them (thousands of faint pixels, dozens strong along glyph edges); sidenav.rs already says so and compares shapes everywhere, pixels only locally. The tab bar now does the same: a hash of the visible shapes (tests/snapshots/.shapes, TABS_BLESS=1 writes them), the pixels with TABS_PIXELS=1. The images are unchanged and still pass locally. The hash is of a description of each shape, not of its debug form, for two things in the debug form depended on the run, not on the books: a glyph's place in egui's font atlas changes with which tests ran in the process before (the same view hashed differently alone and beside another test), and the page under a short bar holds the current time, clipped away, which no picture shows. Shapes whose clip is off the window are left out. A new test renders the same companies from two differently named temporary folders, light and dark, and requires the same hue keys (the book ids), the same shapes and the same pixels. The sidenav fixture's copy outside a data root is in a folder of a fixed name, not the temporary folder's random one, since that folder's name is its badge's hue key. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-gui/tests/sidenav.rs | 13 +- .../tests/snapshots/tabs_empty_dark.shapes | 1 + .../tests/snapshots/tabs_empty_light.shapes | 1 + .../tests/snapshots/tabs_many_dark.shapes | 1 + .../tests/snapshots/tabs_many_light.shapes | 1 + .../tests/snapshots/tabs_one_dark.shapes | 1 + .../tests/snapshots/tabs_one_light.shapes | 1 + .../tests/snapshots/tabs_plus_dark.shapes | 1 + .../tests/snapshots/tabs_plus_light.shapes | 1 + .../tests/snapshots/tabs_two_dark.shapes | 1 + .../tests/snapshots/tabs_two_light.shapes | 1 + crates/ledger-gui/tests/tabs.rs | 141 +++++++++++++++++- 12 files changed, 153 insertions(+), 11 deletions(-) create mode 100644 crates/ledger-gui/tests/snapshots/tabs_empty_dark.shapes create mode 100644 crates/ledger-gui/tests/snapshots/tabs_empty_light.shapes create mode 100644 crates/ledger-gui/tests/snapshots/tabs_many_dark.shapes create mode 100644 crates/ledger-gui/tests/snapshots/tabs_many_light.shapes create mode 100644 crates/ledger-gui/tests/snapshots/tabs_one_dark.shapes create mode 100644 crates/ledger-gui/tests/snapshots/tabs_one_light.shapes create mode 100644 crates/ledger-gui/tests/snapshots/tabs_plus_dark.shapes create mode 100644 crates/ledger-gui/tests/snapshots/tabs_plus_light.shapes create mode 100644 crates/ledger-gui/tests/snapshots/tabs_two_dark.shapes create mode 100644 crates/ledger-gui/tests/snapshots/tabs_two_light.shapes diff --git a/crates/ledger-gui/tests/sidenav.rs b/crates/ledger-gui/tests/sidenav.rs index 5a04f319..2df51108 100644 --- a/crates/ledger-gui/tests/sidenav.rs +++ b/crates/ledger-gui/tests/sidenav.rs @@ -104,6 +104,7 @@ const FOOTERS: [Footer; 9] = [ /// menu), about 560 events and 110 stored receipts. Removed when dropped. struct Fixture { _dir: tempfile::TempDir, + _plain_dir: tempfile::TempDir, root: PathBuf, plain: PathBuf, } @@ -153,15 +154,19 @@ impl Fixture { std::fs::create_dir_all(&root).unwrap(); fill(&root); // The same books outside the root: no Books menu. - let plain = tempfile::Builder::new() + // Outside a data root a company's badge hue is chosen from its + // folder's name (company.rs `hue_key`), so that folder has a fixed + // name here, never the temporary folder's random one: the same + // picture on every machine and every run. + let plain_dir = tempfile::Builder::new() .prefix("wb-gui-sidenav-plain-") .tempdir() - .unwrap() - .keep(); - let plain_book = plain.join("books-data"); + .unwrap(); + let plain_book = plain_dir.path().join("wanderland-copy").join("books-data"); copy_dir(&root, &plain_book); Fixture { _dir: dir, + _plain_dir: plain_dir, root, plain: plain_book, } diff --git a/crates/ledger-gui/tests/snapshots/tabs_empty_dark.shapes b/crates/ledger-gui/tests/snapshots/tabs_empty_dark.shapes new file mode 100644 index 00000000..10571da8 --- /dev/null +++ b/crates/ledger-gui/tests/snapshots/tabs_empty_dark.shapes @@ -0,0 +1 @@ +264f46e9e8e6513b diff --git a/crates/ledger-gui/tests/snapshots/tabs_empty_light.shapes b/crates/ledger-gui/tests/snapshots/tabs_empty_light.shapes new file mode 100644 index 00000000..154f7f87 --- /dev/null +++ b/crates/ledger-gui/tests/snapshots/tabs_empty_light.shapes @@ -0,0 +1 @@ +3a01e3d1c17e7a42 diff --git a/crates/ledger-gui/tests/snapshots/tabs_many_dark.shapes b/crates/ledger-gui/tests/snapshots/tabs_many_dark.shapes new file mode 100644 index 00000000..31cc95f9 --- /dev/null +++ b/crates/ledger-gui/tests/snapshots/tabs_many_dark.shapes @@ -0,0 +1 @@ +d3c3cc6f9e97b02b diff --git a/crates/ledger-gui/tests/snapshots/tabs_many_light.shapes b/crates/ledger-gui/tests/snapshots/tabs_many_light.shapes new file mode 100644 index 00000000..933f8119 --- /dev/null +++ b/crates/ledger-gui/tests/snapshots/tabs_many_light.shapes @@ -0,0 +1 @@ +19867322b240d3af diff --git a/crates/ledger-gui/tests/snapshots/tabs_one_dark.shapes b/crates/ledger-gui/tests/snapshots/tabs_one_dark.shapes new file mode 100644 index 00000000..552b57fb --- /dev/null +++ b/crates/ledger-gui/tests/snapshots/tabs_one_dark.shapes @@ -0,0 +1 @@ +36b4501433dfff25 diff --git a/crates/ledger-gui/tests/snapshots/tabs_one_light.shapes b/crates/ledger-gui/tests/snapshots/tabs_one_light.shapes new file mode 100644 index 00000000..d53a098b --- /dev/null +++ b/crates/ledger-gui/tests/snapshots/tabs_one_light.shapes @@ -0,0 +1 @@ +216c4495455951ef diff --git a/crates/ledger-gui/tests/snapshots/tabs_plus_dark.shapes b/crates/ledger-gui/tests/snapshots/tabs_plus_dark.shapes new file mode 100644 index 00000000..3932e033 --- /dev/null +++ b/crates/ledger-gui/tests/snapshots/tabs_plus_dark.shapes @@ -0,0 +1 @@ +e81f5a809e024c55 diff --git a/crates/ledger-gui/tests/snapshots/tabs_plus_light.shapes b/crates/ledger-gui/tests/snapshots/tabs_plus_light.shapes new file mode 100644 index 00000000..ede5663b --- /dev/null +++ b/crates/ledger-gui/tests/snapshots/tabs_plus_light.shapes @@ -0,0 +1 @@ +aeace623f1babf2b diff --git a/crates/ledger-gui/tests/snapshots/tabs_two_dark.shapes b/crates/ledger-gui/tests/snapshots/tabs_two_dark.shapes new file mode 100644 index 00000000..ce94b163 --- /dev/null +++ b/crates/ledger-gui/tests/snapshots/tabs_two_dark.shapes @@ -0,0 +1 @@ +057c55da25ed99a6 diff --git a/crates/ledger-gui/tests/snapshots/tabs_two_light.shapes b/crates/ledger-gui/tests/snapshots/tabs_two_light.shapes new file mode 100644 index 00000000..775b5556 --- /dev/null +++ b/crates/ledger-gui/tests/snapshots/tabs_two_light.shapes @@ -0,0 +1 @@ +43e2533dd7ebc46b diff --git a/crates/ledger-gui/tests/tabs.rs b/crates/ledger-gui/tests/tabs.rs index 11b346da..af260588 100644 --- a/crates/ledger-gui/tests/tabs.rs +++ b/crates/ledger-gui/tests/tabs.rs @@ -89,10 +89,12 @@ struct Co { impl World { fn new() -> World { - let dir = tempfile::Builder::new() - .prefix("wb-gui-tabs-") - .tempdir() - .unwrap(); + World::named("wb-gui-tabs-") + } + + /// A world whose temporary folder's name starts with `prefix`. + fn named(prefix: &str) -> World { + let dir = tempfile::Builder::new().prefix(prefix).tempdir().unwrap(); let home = dir.path().join("home"); std::fs::create_dir_all(&home).unwrap(); let root = dir.path().join("root"); @@ -1298,11 +1300,101 @@ fn every_tab_never_writes_into_its_books_in_front_or_not() { // ---- 8: how the bar looks ---------------------------------------------------- -/// Pixels compared where there is a renderer; tolerant of antialiasing -/// (as the sidebar's are: sidenav.rs). +/// A shape in words, without where its glyphs happen to lie in egui's font +/// atlas: that depends on which text this process laid out first (other +/// tests, in other threads), and no picture shows it. Positions, colours, +/// the text and each glyph's place are all here. +fn describe(shape: &egui::epaint::Shape) -> String { + use egui::epaint::Shape; + match shape { + Shape::Text(t) => { + let mut out = format!( + "Text pos={:?} under={:?} fallback={:?} over={:?} opacity={:?} angle={:?} text={:?}", + t.pos, + t.underline, + t.fallback_color, + t.override_text_color, + t.opacity_factor, + t.angle, + t.galley.job.text, + ); + for placed in &t.galley.rows { + out.push_str(&format!(" row@{:?} size={:?}", placed.pos, placed.row.size)); + for g in &placed.row.glyphs { + out.push_str(&format!(" {}@{:?}+{:?}", g.chr, g.pos, g.advance_width)); + } + for v in &placed.row.visuals.mesh.vertices { + out.push_str(&format!(" v{:?}{:?}", v.pos, v.color)); + } + } + out + } + Shape::Vec(v) => v.iter().map(describe).collect::>().join(" | "), + Shape::Mesh(m) => { + let mut out = String::from("Mesh"); + for v in &m.vertices { + out.push_str(&format!(" v{:?}{:?}", v.pos, v.color)); + } + out + } + other => format!("{other:?}"), + } +} + +/// The shapes the window paints where it can be seen: those whose clip +/// reaches into the window. (The page under a short bar is laid out far +/// below it and holds the time now, "Nov 21 2026 04:26 UTC", which no +/// picture shows: it is clipped away.) +fn shown_shapes(h: &Harness<'_, App>) -> Vec { + let screen = h.ctx.content_rect(); + h.output() + .shapes + .iter() + .filter(|s| s.clip_rect.intersects(screen)) + .map(|s| format!("{:?} {}", s.clip_rect, describe(&s.shape))) + .collect() +} + +/// A hash of every shape the window paints where it can be seen (FNV-1a +/// over their debug form): the same shapes paint the same pixels, on any +/// renderer. What the picture shows (colours, text and where each lies) is +/// in them; how a renderer rasterizes their edges is not. +fn shapes_of(h: &Harness<'_, App>) -> u64 { + let mut hash: u64 = 0xcbf2_9ce4_8422_2325; + for shape in shown_shapes(h) { + for b in shape.bytes() { + hash ^= b as u64; + hash = hash.wrapping_mul(0x100_0000_01b3); + } + } + hash +} + +/// The look of the window, compared as sidenav.rs compares its sidebar's: +/// the shapes painted are the check everywhere +/// (`tests/snapshots/.shapes`; `TABS_BLESS=1` writes them), for +/// another renderer rasterizes the same shapes differently (CI's software +/// one differs from a GPU in antialiasing, by thousands of faint pixels +/// and some dozens of strong ones along glyph edges). The pixels +/// (`tests/snapshots/.png`, tolerant of antialiasing) are compared +/// as well on the machine that made them and any with its renderer: +/// `TABS_PIXELS=1`. fn picture(h: &mut Harness<'_, App>, name: &str) { + let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/snapshots"); + let file = dir.join(format!("{name}.shapes")); + let shapes = format!("{:016x}", shapes_of(h)); + if std::env::var("TABS_BLESS").is_ok() { + std::fs::write(&file, format!("{shapes}\n")).unwrap(); + } else { + let want = std::fs::read_to_string(&file) + .unwrap_or_else(|e| panic!("{}: {e} (TABS_BLESS=1 writes it)", file.display())); + assert_eq!(shapes, want.trim(), "the shapes of {name} changed"); + } + if std::env::var("TABS_PIXELS").is_err() { + return; + } if h.render().is_err() { - eprintln!("no renderer: {name} not compared"); + eprintln!("no renderer: {name} pixels not compared"); return; } let options = egui_kittest::SnapshotOptions::new() @@ -1390,6 +1482,41 @@ fn the_tab_bar_with_one_two_and_many_tabs() { } } +/// What the window shows depends on the books and the theme alone: not on +/// the name of the temporary folder they sit in, the clock, or the +/// machine. The same companies made in two worlds whose folders are named +/// unlike paint the same shapes and the same pixels (where there is a +/// renderer), with the badge hue chosen from the id of the books. +#[test] +fn the_bar_is_the_same_from_differently_named_folders() { + let names = ["Wanderland Labs LLC", "Fernhill Studio"]; + let mut seen: Vec<(u64, Option>, Vec)> = Vec::new(); + for (prefix, dark) in [ + ("a-", false), + ("zzzz-a-much-longer-name-", false), + ("a-", true), + ("zzzz-a-much-longer-name-", true), + ] { + let w = World::named(prefix); + let mut h = shown(&w, &names, dark, BAR_SIZE); + let keys: Vec = (0..names.len()) + .map(|i| h.state().views()[i].hue_key()) + .collect(); + let pixels = h.render().ok().map(|img| img.into_raw()); + seen.push((shapes_of(&h), pixels, keys)); + } + for pair in [(0, 1), (2, 3)] { + let (a, b) = (&seen[pair.0], &seen[pair.1]); + assert_eq!(a.2, ["co-0", "co-1"], "a company's hue key is its book id"); + assert_eq!( + a.2, b.2, + "the hue key is the book id, not the folder's name" + ); + assert_eq!(a.0, b.0, "the shapes differ with the folder's name"); + assert!(a.1 == b.1, "the pixels differ with the folder's name"); + } +} + #[test] fn the_empty_window_and_the_plus_list() { for dark in [false, true] {