From eaf43a2ca409812ca5da66c534242206c980e447 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 23:19:01 -0700 Subject: [PATCH] build(bar-core): add the komorebi-bar-core crate with the schema oracle test Skeleton of the shared bar crate (D25/D26): an empty library and the oracle that every later move of bar code is held to. tests/schema_oracle.rs pins the checked-in schema.bar.json of the Windows bar (9,090 lines, FNV-1a 0x557301341968bff9) and of the macOS bar (3,774 lines, 0xc99e02949424e5d7), so any change to either file, intended or not, fails the test until the pin is updated in a reviewed revision. Once config.rs moves into the crate the test generates the schema and compares it with the file instead. The pins are of the files as they are after the previous revision (the regenerated Windows file) and are the values the out-of-tree harness (S/bar2/regen.sh over the real sources) reproduces: macOS byte-identical, Windows byte-identical to the regenerated file. Verified: native cargo test -p komorebi-bar-core: 2 passed, 0 failed; Windows cargo clippy --workspace --locked --all-targets -D warnings clean; macOS fake-CC cargo check --locked --workspace --all-targets finished, 0 errors. --- Cargo.lock | 4 + Cargo.toml | 1 + crates/komorebi-bar-core/Cargo.toml | 5 ++ crates/komorebi-bar-core/src/lib.rs | 6 ++ .../komorebi-bar-core/tests/schema_oracle.rs | 78 +++++++++++++++++++ 5 files changed, 94 insertions(+) create mode 100644 crates/komorebi-bar-core/Cargo.toml create mode 100644 crates/komorebi-bar-core/src/lib.rs create mode 100644 crates/komorebi-bar-core/tests/schema_oracle.rs diff --git a/Cargo.lock b/Cargo.lock index 1b779bf9..a1964393 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3431,6 +3431,10 @@ dependencies = [ "windows-icons 0.1.0 (git+https://github.com/LGUG2Z/windows-icons?rev=d67cc9920aa9b4883393e411fb4fa2ddd4c498b5)", ] +[[package]] +name = "komorebi-bar-core" +version = "0.1.42" + [[package]] name = "komorebi-client" version = "0.1.42" diff --git a/Cargo.toml b/Cargo.toml index c4cd9097..290284f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ members = [ "komorebi-themes", "crates/komorebi-protocol", "crates/komorebi-transport", + "crates/komorebi-bar-core", "komorebi-shortcuts", "e2e/guest/agent", "e2e/guest/testwin", diff --git a/crates/komorebi-bar-core/Cargo.toml b/crates/komorebi-bar-core/Cargo.toml new file mode 100644 index 00000000..f5edd858 --- /dev/null +++ b/crates/komorebi-bar-core/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "komorebi-bar-core" +version = "0.1.42" +description = "The status bar shared by the Windows and macOS komorebi bars: configuration, widgets and the platform seam" +edition = "2024" diff --git a/crates/komorebi-bar-core/src/lib.rs b/crates/komorebi-bar-core/src/lib.rs new file mode 100644 index 00000000..fa91b405 --- /dev/null +++ b/crates/komorebi-bar-core/src/lib.rs @@ -0,0 +1,6 @@ +//! The code the Windows and the macOS `komorebi-bar` share. +//! +//! The crate is being filled in by pure moves, one file at a time, each held to the schema +//! oracle in `tests/schema_oracle.rs`: the checked-in `schema.bar.json` of both bars must not +//! change unless a reviewed revision says so. +#![warn(clippy::all)] diff --git a/crates/komorebi-bar-core/tests/schema_oracle.rs b/crates/komorebi-bar-core/tests/schema_oracle.rs new file mode 100644 index 00000000..48380b84 --- /dev/null +++ b/crates/komorebi-bar-core/tests/schema_oracle.rs @@ -0,0 +1,78 @@ +//! The schema oracle of the shared bar. +//! +//! `schema.bar.json` (Windows, at the root) and `komorebi-for-mac/schema.bar.json` are what +//! `komorebi-bar --schema` prints. They are pinned here by size and a FNV-1a hash of their bytes, +//! so that a move or a convergence of bar code cannot change them unnoticed. A reviewed change +//! to either file updates the matching pin in the same revision. +//! +//! The bar binaries cannot run on Linux (Windows and AppKit APIs), so this test cannot +//! regenerate the schema until the configuration types live in this crate; from then on it +//! compares the generated text with the file instead of a hash. + +use std::path::PathBuf; + +struct Pin { + file: &'static str, + lines: usize, + bytes: usize, + fnv1a: u64, +} + +const PINS: [Pin; 2] = [ + Pin { + file: "schema.bar.json", + lines: 9_090, + bytes: 248_529, + fnv1a: 0x5573_0134_1968_bff9, + }, + Pin { + file: "komorebi-for-mac/schema.bar.json", + lines: 3_774, + bytes: 116_925, + fnv1a: 0xc99e_0294_9424_e5d7, + }, +]; + +fn fnv1a(bytes: &[u8]) -> u64 { + bytes.iter().fold(0xcbf2_9ce4_8422_2325, |hash, byte| { + (hash ^ u64::from(*byte)).wrapping_mul(0x0100_0000_01b3) + }) +} + +fn read(file: &str) -> Vec { + let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../..") + .join(file); + std::fs::read(&path).unwrap_or_else(|error| panic!("{}: {error}", path.display())) +} + +#[test] +fn the_checked_in_bar_schemas_are_the_pinned_ones() { + for pin in PINS { + let bytes = read(pin.file); + let lines = bytes.iter().filter(|byte| **byte == b'\n').count(); + assert_eq!(lines, pin.lines, "{}: line count", pin.file); + assert_eq!(bytes.len(), pin.bytes, "{}: size", pin.file); + assert_eq!( + fnv1a(&bytes), + pin.fnv1a, + "{}: FNV-1a (is {:#018x})", + pin.file, + fnv1a(&bytes) + ); + } +} + +#[test] +fn the_checked_in_bar_schemas_are_json_schemas_of_komobar_config() { + for pin in PINS { + let text = String::from_utf8(read(pin.file)).expect("utf-8"); + assert!(text.starts_with("{\n \"$schema\""), "{}", pin.file); + assert!( + text.contains("\"title\": \"KomobarConfig\""), + "{}", + pin.file + ); + assert!(text.ends_with("}\n"), "{}", pin.file); + } +}