From fa2d6307010148702d5971aa3e6e2218b9feae51 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 18:36:42 -0700 Subject: [PATCH] test(e2e): the bar scenario says when the guest cannot draw, and the bar config is tested The Windows gate showed that the bar cannot open a window in the golden guest (no OpenGL 2.0: "egui_glow requires opengl 2.0+"). The scenario now reads the bar's own output (`classify`): that exact failure turns the window, stays-alive and daemon-restart checks into visible `skipped: guest has no OpenGL 2.0` lines (counted in `result.json` and printed as `skipped: N` by the runner); the schema equality, "the bar reads its configuration" (real: the configuration is parsed before the window), `komorebic state` and `stop --bar` stay checks; any other early exit of the bar (a configuration error, a panic) is a failure with the bar's output in the message, and a bar that opens its window gets the full walk as before. Unit tests for `classify` run with the runner tests. komorebi-bar-core gets tests/config.rs: windows-only widgets and the `mouse` block are accepted on every platform, `supported()/unsupported()/enabled()` name and skip what the platform cannot run (D-coord-1), a Command mouse message is a plain string and the tagged form is rejected (the e2e finding), the network widget accepts `default_interface_options` and the old key names, layouts read from their names, `KomobarConfig::read` fills the frame and refuses a non-json file. The warning text itself is not asserted (no tracing subscriber in the core). docs/dev/bar-e2e.md records the limitation and an analysis of getting rendering into the guest (wgpu with the WARP adapter recommended; a mingw Mesa is not offered by nixpkgs); nothing was added. Verified: runner and library tests (161 passed), ruff clean on the scenario (three older findings in other files are not mine), bar-core native tests 3 unit + 7 oracle + 6 config. Windows clippy and the macOS check: see the report. The scenario itself was not run. --- crates/komorebi-bar-core/tests/config.rs | 130 ++++++++++++++++++ docs/dev/bar-e2e.md | 49 +++++++ e2e/platforms/qemu_windows/extras/bar.py | 93 +++++++++++-- e2e/platforms/qemu_windows/run.py | 2 + .../qemu_windows/tests/test_bar_scenario.py | 31 +++++ 5 files changed, 297 insertions(+), 8 deletions(-) create mode 100644 crates/komorebi-bar-core/tests/config.rs create mode 100644 e2e/platforms/qemu_windows/tests/test_bar_scenario.py diff --git a/crates/komorebi-bar-core/tests/config.rs b/crates/komorebi-bar-core/tests/config.rs new file mode 100644 index 00000000..aceacf5d --- /dev/null +++ b/crates/komorebi-bar-core/tests/config.rs @@ -0,0 +1,130 @@ +//! The configuration of the bar without a window: what is accepted, what is skipped on a +//! platform that cannot run a widget (D-coord-1: accepted and skipped with a warning), and the +//! `mouse` messages. + +use komorebi_bar_core::config::KomobarConfig; +use komorebi_bar_core::config::MouseMessage; +use komorebi_bar_core::widgets::komorebi_config::KomorebiLayout; +use komorebi_bar_core::widgets::network_config::NetworkConfig; +use komorebi_bar_core::widgets::widget::WidgetConfig; + +const WINDOWS: bool = cfg!(target_os = "windows"); + +fn parse(json: &str) -> KomobarConfig { + serde_json::from_str(json).expect("the configuration parses") +} + +const MIXED: &str = r#"{ + "left_widgets": [ + {"Komorebi": {"workspaces": {"enable": true, "hide_empty_workspaces": false}, "layout": {"enable": true}}}, + {"Keyboard": {"enable": true}} + ], + "center_widgets": [{"Media": {"enable": true}}], + "right_widgets": [ + {"Storage": {"enable": true}}, + {"Time": {"enable": true, "format": "TwentyFourHour"}}, + {"Systray": {"enable": true}}, + {"Cpu": {"enable": false}} + ], + "mouse": {"on_middle_click": "echo hi", "on_extra2_click": {"message": {"type": "Retile"}}} +}"#; + +fn all(config: &KomobarConfig) -> Vec<&WidgetConfig> { + config + .left_widgets + .iter() + .chain(config.center_widgets.iter().flatten()) + .chain(config.right_widgets.iter()) + .collect() +} + +#[test] +fn windows_only_widgets_are_accepted_on_every_platform() { + let config = parse(MIXED); + assert_eq!(all(&config).len(), 7); + assert!(config.mouse.is_some()); +} + +#[test] +fn a_widget_the_platform_cannot_run_is_named_and_not_enabled() { + let config = parse(MIXED); + let unsupported: Vec<_> = all(&config) + .into_iter() + .filter_map(|w| w.unsupported()) + .collect(); + if WINDOWS { + assert!(unsupported.is_empty()); + } else { + assert_eq!(unsupported, ["Keyboard", "Media", "Systray"]); + } + + let enabled: Vec = all(&config).iter().map(|w| w.enabled()).collect(); + // Komorebi, Keyboard, Media, Storage, Time, Systray, Cpu (disabled) + let expect = [true, WINDOWS, WINDOWS, true, true, WINDOWS, false]; + assert_eq!(enabled, expect); +} + +#[test] +fn a_command_mouse_message_is_a_plain_string() { + let config = parse(MIXED); + let mouse = config.mouse.expect("mouse"); + assert!(matches!(mouse.on_middle_click, Some(MouseMessage::Command(ref c)) if c == "echo hi")); + assert!(matches!( + mouse.on_extra2_click, + Some(MouseMessage::Komorebi(_)) + )); + assert!(mouse.has_command()); +} + +/// The scenario of the Windows e2e once wrote `{"Command": ...}`; it is not a message. +#[test] +fn a_tagged_command_is_rejected() { + let bad = r#"{"left_widgets": [], "right_widgets": [], + "mouse": {"on_middle_click": {"Command": "echo hi"}}}"#; + assert!(serde_json::from_str::(bad).is_err()); +} + +#[test] +fn the_network_widget_accepts_the_windows_only_interface_options() { + let json = r#"{"enable": true, "show_total_activity": false, "show_activity": true, + "default_interface_options": {"display_type": "Ipv4"}}"#; + let config: NetworkConfig = serde_json::from_str(json).expect("parses"); + assert!(config.default_interface_options.is_some()); + // the old spellings of the two required keys + let old = + r#"{"enable": true, "show_total_data_transmitted": true, "show_network_activity": false}"#; + assert!(serde_json::from_str::(old).is_ok()); +} + +#[test] +fn a_layout_is_read_from_its_name() { + let layout: KomorebiLayout = serde_json::from_str("\"BSP\"").expect("a default layout"); + assert!(matches!(layout, KomorebiLayout::Default(_))); + assert_eq!(layout.to_string(), "BSP"); + for (name, want) in [ + ("Monocle", "Monocle"), + ("Floating", "Floating"), + ("Paused", "Paused"), + ] { + let read: KomorebiLayout = serde_json::from_str(&format!("\"{name}\"")).unwrap(); + assert_eq!(read.to_string(), want); + } + assert!(serde_json::from_str::("\"Nonsense\"").is_err()); +} + +#[test] +fn read_fills_in_the_frame_and_keeps_what_was_set() { + let dir = std::env::temp_dir().join(format!("bar-core-config-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let path = dir.join("bar.json"); + std::fs::write(&path, MIXED).unwrap(); + let config = KomobarConfig::read(&path).expect("reads"); + assert!(config.frame.is_some(), "a missing frame gets the default"); + assert_eq!(config.left_widgets.len(), 2); + assert!(config.mouse.is_some()); + // anything but json is refused + std::fs::write(dir.join("bar.toml"), MIXED).unwrap(); + let toml = dir.join("bar.toml"); + assert!(std::panic::catch_unwind(|| KomobarConfig::read(&toml)).is_err()); + std::fs::remove_dir_all(&dir).ok(); +} diff --git a/docs/dev/bar-e2e.md b/docs/dev/bar-e2e.md index 3b41647e..4f38448c 100644 --- a/docs/dev/bar-e2e.md +++ b/docs/dev/bar-e2e.md @@ -24,3 +24,52 @@ macOS (see `docs/dev/macos-handcheck.md`). Not run when it was written (the guest was reserved): lint only (`py_compile`, `ruff`, the runner's 157 unit tests pass). + +## The golden guest has no OpenGL 2.0 + +The Windows gate (candidate 5) found that the bar cannot open a window in the golden guest: +eframe's default renderer is `egui_glow`, the guest has the basic display adapter and QXL and no +OpenGL driver, so Windows offers only the generic software OpenGL 1.1 of `opengl32.dll`, and the bar +exits at start with `Error: egui_glow: OpenGL: egui_glow requires opengl 2.0+` +(`komorebi-bar/src/windows/mod.rs`, the `run_native` error). The scenario therefore reports the +window, stays-alive and daemon-restart checks as `skipped: guest has no OpenGL 2.0` when, and only +when, the bar's own output says that (`extras/bar.py`, `classify`); any other early exit is a +failure. The schema equality, the configuration read, `komorebic state` and `stop --bar` stay real +checks. A skip is not a pass: the bar's runtime behaviour is unverified until the guest can draw. + +### Getting rendering into the guest (analysis, nothing added) + +How the context is chosen: `komorebi-bar` uses `eframe` 0.33 with its default features, so only +the glow renderer is compiled (glutin + `egui_glow`); `NativeOptions` is left at its defaults on +Windows (the macOS bar sets its own), so the bar asks for a hardware OpenGL 2.0+ config through +glutin, falls back to the Windows generic GDI implementation (1.1) and `egui_glow` refuses it. + +1. Mesa llvmpipe `opengl32.dll` next to `komorebi-bar.exe` (the classic recipe: Mesa's + `opengl32.dll` takes over from the system one for that process). Not possible from this flake: + nixpkgs marks `pkgsCross.mingwW64.mesa` as an unsupported platform (`nix build --dry-run` refuses + it), and `nixpkgs` has no Windows `opengl32sw.dll` (that file ships with Qt) or ANGLE. Building + Mesa for mingw means porting its nix expression (swrast + llvm cross for mingw, a cross LLVM + build) and carrying a binary of unknown license status in the image: days of work, hours of + build, and the result is a third-party DLL in the test that real users do not run. +2. A wgpu renderer with the Windows software adapter. Windows 11 ships WARP, the software + Direct3D 12 rasteriser, in the Basic Render Driver, which the guest has; wgpu's DX12 backend + finds it as an adapter, no download. In `eframe` this is the `wgpu` feature plus + `NativeOptions { renderer: Renderer::Wgpu, .. }` (and `wgpu_options` with a fallback adapter if + it does not pick WARP by itself). The sources of the wgpu stack (wgpu 27, naga, wgpu-hal, + gpu-allocator, ash) are already in the local cargo registry because they are in `Cargo.lock` + as optional dependencies of eframe, so it should build offline. Proposal, smallest first: + in `komorebi-bar`'s `[target.'cfg(windows)'.dependencies]` ask for `eframe` with the `wgpu` + feature, and at start: try glow as now; if `run_native` fails with the OpenGL message, run again + with `Renderer::Wgpu` (the e2e then passes the window checks, and a user without OpenGL gets a + bar instead of an error). Cost: about 60 more crates in `Cargo.lock` that are compiled for + Windows only (cold build +3 to 5 minutes in CI, +8 to 12 MB in `komorebi-bar.exe`); a retry path + that needs `NativeOptions` to be built twice; a new, untested code path for real users (low + risk: it only runs where glow already failed). Without the fallback, a `KOMOREBI_BAR_RENDERER=wgpu` + switch the scenario sets would keep users on glow and cost the same dependencies. +3. ANGLE (EGL on Direct3D 11, itself on WARP) through `glutin`'s EGL support: needs + `libEGL.dll`/`libGLESv2.dll`, which are not in nix either. Rejected. + +Recommendation: 2, with the glow-then-wgpu fallback, as its own revision with the e2e `bar` +scenario as its gate (the window checks stop being skipped). Whether the guest's WARP accepts +wgpu's DX12 device (feature level, no HLSL compiler problem for egui's shaders) can only be +learned by running it; the first run should keep `RUST_LOG=wgpu_hal=debug` output in `bar.out`. diff --git a/e2e/platforms/qemu_windows/extras/bar.py b/e2e/platforms/qemu_windows/extras/bar.py index 53fdde0a..fb97bc35 100644 --- a/e2e/platforms/qemu_windows/extras/bar.py +++ b/e2e/platforms/qemu_windows/extras/bar.py @@ -17,6 +17,7 @@ an artefact (`bar.png`, `bar-after-restart.png`). import hashlib import json import os +import re import time from pathlib import Path @@ -29,6 +30,7 @@ BAR_BINARY = f"{GUEST_BIN}\\komorebi-bar.exe" BAR_CONFIG = "C:\\e2e\\bar.json" BAR_OUTPUT = "C:\\e2e\\bar.out" # the title eframe gives the window (`run_native("komorebi-bar", ...)`) +ANSI = re.compile(r"\x1b\[[0-9;]*m") BAR_TITLE = "komorebi-bar" # how long the bar must keep running, in seconds ALIVE_SECONDS = 15 @@ -102,6 +104,51 @@ def _alive_for(platform: WindowsPlatform, seconds: float) -> bool: return bool(_bar_pids(platform)) +# what the bar prints when eframe cannot make a window for lack of OpenGL (komorebi-bar's +# `run_native` error), as the gate printed it: "egui_glow requires opengl 2.0+" +NO_OPENGL_TEXT = "requires opengl" +NO_OPENGL = "guest has no OpenGL 2.0" + + +def classify(output: str) -> str | None: + """What the bar's own output says about its start: "no_opengl" (it could not make a + window for lack of OpenGL), "failed" (it ended with any other error: a configuration it + could not read, a crash) or None (no error, it runs).""" + if "Error:" not in output and "panicked" not in output: + return None + if NO_OPENGL_TEXT in output.lower(): + return "no_opengl" + return "failed" + + +def _bar_output(platform: WindowsPlatform) -> str: + try: + text = platform.agent_get_file(BAR_OUTPUT).decode(errors="replace") + except Exception: + return "" + return ANSI.sub("", text) + + +def _started(platform: WindowsPlatform) -> bool: + """The bar runs, or it has already ended with something to say.""" + return bool(_bar_pids(platform)) or classify(_bar_output(platform)) is not None + + +def _outcome(platform: WindowsPlatform) -> str: + """Waits for the bar's window or its end: "running" (the window is there), "no_opengl", + "failed", or "timeout" (neither within a minute).""" + deadline = time.monotonic() + 60 * platform._scale + while time.monotonic() < deadline: + if _bar_window(platform) is not None: + return "running" + if not _bar_pids(platform): + why = classify(_bar_output(platform)) + if why is not None: + return why + time.sleep(1) + return classify(_bar_output(platform)) or "timeout" + + def run(platform: WindowsPlatform, checks: Checks, clients: list[Client]) -> None: """Starts the bar on the tiled windows of `tiling` and walks through its life. The daemon runs at the end and the bar does not.""" @@ -129,12 +176,47 @@ def run(platform: WindowsPlatform, checks: Checks, clients: list[Client]) -> Non "cmd", "/c", f"{BAR_BINARY} --config {BAR_CONFIG} > {BAR_OUTPUT} 2>&1" ) + checks.check("the bar process starts", platform.wait_for(lambda: _started(platform), timeout=30)) + outcome = _outcome(platform) + text = _bar_output(platform) + (platform._out / "bar.out").write_text(text) + # the configuration is parsed before the window is made, so a bar that got as far as + # opening a window (or failing to) has read all of it, the Keyboard and Systray + # widgets and the mouse block included checks.check( - "the bar process starts", platform.wait_for(lambda: bool(_bar_pids(platform)), timeout=30) + "the bar reads its configuration (every widget, the mouse block)", + outcome != "failed" and "found configuration file" in text, ) - appeared = platform.wait_for(lambda: _bar_window(platform) is not None, timeout=60) - checks.check(f"the bar's window titled {BAR_TITLE!r} appears", appeared) + + if outcome == "no_opengl": + # the golden guest has no OpenGL 2.0 (basic display and QXL, no software opengl32), so + # eframe cannot make the window: not what a change of the bar did, and not a pass + for what in ( + f"the bar's window titled {BAR_TITLE!r} appears", + f"the bar keeps running for {ALIVE_SECONDS} s", + "the bar is still running after the daemon stopped", + "the bar runs on after the daemon is back", + ): + checks.skip(what, NO_OPENGL) + checks.check( + "`komorebic state` answers after the bar has started", + platform.wait_for(lambda: platform.komorebic_status("state")[0] == 0), + ) + platform.komorebic("stop", "--bar") + checks.check( + "`komorebic stop --bar` stops the daemon", + platform.wait_for(lambda: platform.komorebic_status("state")[0] != 0, timeout=20), + ) + platform.start_komorebi() + return + if outcome != "running": + checks.bad(f"the bar did not open its window ({outcome}); it printed: {text[:600]!r}") + platform.komorebic("stop", "--bar") + platform.start_komorebi() + return + window = _bar_window(platform) + checks.check(f"the bar's window titled {BAR_TITLE!r} appears", window is not None) if window is not None: frame = window["frame"] checks.check( @@ -198,10 +280,5 @@ def run(platform: WindowsPlatform, checks: Checks, clients: list[Client]) -> Non "`komorebic stop --bar` ends the bar process", platform.wait_for(lambda: not _bar_pids(platform), timeout=20), ) - try: - text = platform.agent_get_file(BAR_OUTPUT).decode(errors="replace") - (platform._out / "bar.out").write_text(text) - except Exception as e: - print(f" no bar output: {e}") # left as the other scenarios leave it: the daemon runs platform.start_komorebi() diff --git a/e2e/platforms/qemu_windows/run.py b/e2e/platforms/qemu_windows/run.py index 965a48d0..c3315d66 100644 --- a/e2e/platforms/qemu_windows/run.py +++ b/e2e/platforms/qemu_windows/run.py @@ -544,6 +544,8 @@ def main(argv: list[str]) -> int: failed += 1 continue print(f"{name}: passed {checks.passed} failed {checks.failed}") + if checks.skipped: + print(f"{name}: skipped {len(checks.skipped)}") if checks.known: print(f"{name}: known failures {len(checks.known)}") failed += checks.failed diff --git a/e2e/platforms/qemu_windows/tests/test_bar_scenario.py b/e2e/platforms/qemu_windows/tests/test_bar_scenario.py new file mode 100644 index 00000000..e4a266cd --- /dev/null +++ b/e2e/platforms/qemu_windows/tests/test_bar_scenario.py @@ -0,0 +1,31 @@ +"""What the `bar` scenario decides from the bar's own output, without a guest.""" + +from platforms.qemu_windows.extras import bar + +GL = ( + "2026-10-31T07:25:02Z INFO komorebi_bar::windows: found configuration file: C:\\e2e\\bar.json\n" + "Error: \n 0: egui_glow: OpenGL: egui_glow requires opengl 2.0+. \n" +) +PARSE = ( + "found configuration file: C:\\e2e\\bar.json\nError: \n" + " 0: data did not match any variant of untagged enum MouseMessage at line 59 column 3\n" +) + + +def test_no_opengl_is_told_from_other_errors(): + assert bar.classify(GL) == "no_opengl" + + +def test_any_other_error_is_a_failure(): + assert bar.classify(PARSE) == "failed" + assert bar.classify("thread 'main' panicked at x") == "failed" + + +def test_a_bar_that_prints_no_error_runs(): + assert bar.classify("") is None + assert bar.classify("found configuration file: x\nwatching configuration file\n") is None + + +def test_the_test_configuration_is_plain_json_values(): + # the untagged MouseMessage::Command is a string + assert isinstance(bar.CONFIG["mouse"]["on_middle_click"], str)