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/<name>.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 <noreply@anthropic.com>
This commit is contained in:
1 parent
c072e68fda
commit
13e676a101
12 files changed
+153
-11
No files matched your search
@@ -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,
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
264f46e9e8e6513b
|
||||
@@ -0,0 +1 @@
|
||||
3a01e3d1c17e7a42
|
||||
@@ -0,0 +1 @@
|
||||
d3c3cc6f9e97b02b
|
||||
@@ -0,0 +1 @@
|
||||
19867322b240d3af
|
||||
@@ -0,0 +1 @@
|
||||
36b4501433dfff25
|
||||
@@ -0,0 +1 @@
|
||||
216c4495455951ef
|
||||
@@ -0,0 +1 @@
|
||||
e81f5a809e024c55
|
||||
@@ -0,0 +1 @@
|
||||
aeace623f1babf2b
|
||||
@@ -0,0 +1 @@
|
||||
057c55da25ed99a6
|
||||
@@ -0,0 +1 @@
|
||||
43e2533dd7ebc46b
|
||||
@@ -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::<Vec<_>>().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<String> {
|
||||
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/<name>.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/<name>.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<u8>>, Vec<String>)> = 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<String> = (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] {
|
||||
|
||||
Reference in new issue
Block a user