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.
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:54 -07:00
1 parent c5949d20ef
commit eaf43a2ca4
5 files changed
+94

No files matched your search

Generated
+4
View File
@@ -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"
+1
View File
@@ -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",
+5
View File
@@ -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"
+6
View File
@@ -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)]
@@ -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<u8> {
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);
}
}