From 2e078f9ef65afba1912f9600d7b180628097e2e7 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 07:44:21 -0700 Subject: [PATCH] feat(nix): config reload, exe rules and lock scenarios in the core --- nix/tests/vm/lib/komorebi_vm/core/platform.py | 32 +++++++- .../core/scenarios/config_reload.py | 76 ++++++++++++++++++ .../lib/komorebi_vm/core/scenarios/locking.py | 55 +++++++++++++ .../komorebi_vm/core/scenarios/rules_exe.py | 53 +++++++++++++ nix/tests/vm/lib/komorebi_vm/kde_platform.py | 59 ++++++++++++-- nix/tests/vm/lib/tests/fake_platform.py | 77 ++++++++++++++++--- nix/tests/vm/lib/tests/test_focus_moving.py | 54 +++++++++++++ nix/tests/vm/lib/tests/test_tiling.py | 14 +++- nix/tests/vm/suites/core-e2e/test.py | 9 +++ nix/tests/vm/suites/core-lock/default.nix | 5 ++ nix/tests/vm/suites/core-lock/test.py | 33 ++++++++ 11 files changed, 446 insertions(+), 21 deletions(-) create mode 100644 nix/tests/vm/lib/komorebi_vm/core/scenarios/config_reload.py create mode 100644 nix/tests/vm/lib/komorebi_vm/core/scenarios/locking.py create mode 100644 nix/tests/vm/lib/komorebi_vm/core/scenarios/rules_exe.py create mode 100644 nix/tests/vm/suites/core-lock/default.nix create mode 100644 nix/tests/vm/suites/core-lock/test.py diff --git a/nix/tests/vm/lib/komorebi_vm/core/platform.py b/nix/tests/vm/lib/komorebi_vm/core/platform.py index 5d6414bc..b25fafc8 100644 --- a/nix/tests/vm/lib/komorebi_vm/core/platform.py +++ b/nix/tests/vm/lib/komorebi_vm/core/platform.py @@ -68,8 +68,8 @@ class Platform(Protocol): """A machine with a desktop and a daemon to test.""" def has(self, feature: str) -> bool: - """Whether the platform can do what a scenario needs of it (`"pointer"`), so that a - scenario that needs it is skipped, with the reason, where it cannot.""" + """Whether the platform can do what a scenario needs of it (`"pointer"`, `"lock"`), so + that a scenario that needs it is skipped, with the reason, where it cannot.""" ... @property @@ -101,6 +101,12 @@ class Platform(Protocol): """ ... + def rewrite_config(self, config: dict[str, Any]) -> None: + """Writes `config` over the `komorebi.json` that `restart_with` gave the daemon, which + the daemon watches and reloads when it changes. It returns once the file is written; a + scenario waits for the state to follow.""" + ... + def komorebic(self, *args: str) -> str: """Runs `komorebic` with `args` and returns what it printed. Fails if it does.""" ... @@ -114,11 +120,15 @@ class Platform(Protocol): """The daemon's state.""" ... - def spawn(self, title: str, app_id: str | None = None) -> Client: + def spawn(self, title: str, app_id: str | None = None, exe: str | None = None) -> Client: """Opens a window with this title and waits until the platform has it. `app_id` is the class of the window (its app id on Wayland, its window class on Windows) for a rule that matches by it; the platform's own when there is none. + + `exe` is the name of the program that opens it, without an extension (`e2e-exe` is + `e2e-exe.exe` on Windows and `e2e-exe` on Linux), for a rule that matches by it. The + platform makes a program of that name; a rule's `id` is the same on every platform. """ ... @@ -159,6 +169,22 @@ class Platform(Protocol): """Minimizes the window, as its title bar button would. `activate` restores it.""" ... + def lock(self) -> None: + """Locks the screen, as the user's lock shortcut would, and returns when it is locked. + Only where `has("lock")`.""" + ... + + def unlock(self) -> None: + """Unlocks the screen, as the user's password would, and returns when it is unlocked. + Only where `has("lock")`.""" + ... + + def move_window(self, client: Client, x: int, y: int) -> None: + """Moves the window so that its top left corner is at (x, y) of the desktop, as the + compositor or the shell would, not as the user's pointer would. The window keeps its + size.""" + ... + def work_area(self) -> Rect: """The area of the first display that windows may take.""" ... diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/config_reload.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/config_reload.py new file mode 100644 index 00000000..d4274679 --- /dev/null +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/config_reload.py @@ -0,0 +1,76 @@ +"""The daemon reloads its `komorebi.json` when the file changes: names, layout, rules.""" + +from typing import Any + +from komorebi_vm.core.checks import Checks +from komorebi_vm.core.platform import Platform + + +def _config(names: list[str], layout: str, rule: str | None = None) -> dict[str, Any]: + workspaces: list[dict[str, Any]] = [{"name": name, "layout": layout} for name in names] + if rule is not None: + matcher = {"kind": "Title", "id": rule, "matching_strategy": "StartsWith"} + workspaces[1]["workspace_rules"] = [matcher] + return {"monitors": [{"workspaces": workspaces}]} + + +def _names(platform: Platform) -> list[str | None]: + return [w.name for w in platform.state().monitors[0].workspaces] + + +def run(platform: Platform, checks: Checks) -> None: + """Starts the daemon from a file with two workspaces, a window open, and rewrites the file + three times: with new names and a third workspace and another layout, with a workspace rule + that sends the windows of a title to the second workspace, and with the rule gone. + + The daemon is left running on that file, with the window open on the first workspace, which + is in view. The daemon must have been running, with no window but the one it is given. + """ + stay = platform.spawn("reload-stays") + platform.restart_with(_config(["one", "two"], "BSP")) + checks.check( + "the daemon starts with the workspaces of the file", + _names(platform)[:2] == ["one", "two"], + ) + checks.check( + "the window that was open is managed", + platform.wait_for(lambda: platform.state().workspace_of(stay.title) == 0, timeout=30), + ) + + platform.rewrite_config(_config(["uno", "dos", "tres"], "Columns")) + checks.check( + "a file with other names and one workspace more is loaded", + platform.wait_for(lambda: _names(platform) == ["uno", "dos", "tres"], timeout=30), + ) + checks.check( + "... with the layout the file gives the first workspace", + platform.wait_for(lambda: platform.state().workspace().layout == "Columns", timeout=30), + ) + checks.check( + "... and the window that was open stays where it was", + platform.state().workspace_of(stay.title) == 0 and not platform.hidden(stay), + ) + + platform.rewrite_config(_config(["uno", "dos", "tres"], "Columns", rule="reload-sent")) + sent = platform.spawn("reload-sent-1") + checks.check( + "a rule the file gained sends a window that opens to its workspace", + platform.wait_for(lambda: platform.state().workspace_of(sent.title) == 1, timeout=30), + ) + + platform.rewrite_config(_config(["uno", "dos", "tres"], "Columns")) + # the reload does not say when it is done: the next window shows whether the rule is + platform.wait_for(lambda: False, timeout=3) + later = platform.spawn("reload-sent-2") + checks.check( + "once the file loses the rule, a window of that title stays on the first workspace", + platform.wait_for(lambda: platform.state().workspace_of(later.title) == 0, timeout=30), + ) + + platform.komorebic("change-layout", "bsp") + for client in (sent, later): + platform.close(client) + checks.check( + "the two windows are closed", + platform.wait_for(lambda: platform.state().managed() == 1, timeout=20), + ) diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/locking.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/locking.py new file mode 100644 index 00000000..b17d82f7 --- /dev/null +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/locking.py @@ -0,0 +1,55 @@ +"""The screen is locked and unlocked: the lock screen is not tiled, nothing the daemon does while +it is locked changes the layout, and the desktop is put right when it is unlocked.""" + +from komorebi_vm.core.checks import Checks +from komorebi_vm.core.platform import Client, Platform +from komorebi_vm.core.scenarios.layouts import tiled + + +def _focus_agrees(platform: Platform, clients: list[Client]) -> bool: + """The window the daemon says has the focus is the one the operating system says does.""" + workspace = platform.state().workspace() + if not workspace.containers: + return False + stack = workspace.containers[workspace.focused_container] + top = stack[workspace.focused_windows[workspace.focused_container]].title + return any( + (w := platform.os_window(c)) is not None and w.focused and w.title == top for c in clients + ) + + +def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: + """Locks the screen with `clients` tiled windows on the first workspace, moves the first + while it is locked, unlocks, and checks the windows are in their tiles and the focus is + agreed on. + + The daemon must be running, with only `clients`, tiled. Needs `has("lock")`. + """ + checks.check( + "the windows are tiled before the lock", + platform.wait_for(lambda: tiled(platform, clients), timeout=30), + ) + before = [w.frame for c in clients if (w := platform.os_window(c)) is not None] + + platform.lock() + checks.check( + "while the screen is locked the daemon has the same windows: the lock screen is not one", + platform.state().managed() == len(clients), + ) + platform.move_window(clients[0], 400, 300) + after = [platform.os_window(c) for c in clients] + checks.check( + "the others did not move for it", + all(w is not None and w.frame == f for w, f in zip(after[1:], before[1:], strict=True)), + ) + + platform.unlock() + checks.check( + "once it is unlocked the window that was moved is in its tile again", + platform.wait_for(lambda: tiled(platform, clients), timeout=30), + ) + checks.check("... with the windows the daemon had", platform.state().managed() == len(clients)) + checks.check( + "the daemon's idea of the focus is the operating system's", + platform.wait_for(lambda: _focus_agrees(platform, clients), timeout=30), + ) diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/rules_exe.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/rules_exe.py new file mode 100644 index 00000000..666f372b --- /dev/null +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/rules_exe.py @@ -0,0 +1,53 @@ +"""Rules that match a window by the program that opened it decide where it goes, or that it is +left alone. The program is `e2e-exe-sent.exe` on Windows and `e2e-exe-sent` on Linux, and the +rule is the same. + +The names differ from those of `rules_class`: `ignore-rule` drops a rule whose id an earlier +rule has, whatever its kind.""" + +from komorebi_vm.core.checks import Checks +from komorebi_vm.core.platform import Platform + + +def run(platform: Platform, checks: Checks) -> None: + """Gives the daemon a workspace rule and an ignore rule by exe, opens a window of each + program and one of neither, and checks where each went. + + The daemon must be running, on the first workspace, which is the one in view, with no window, + and with workspaces 0 and 1. The rules are cleared afterwards. + """ + platform.komorebic("ensure-workspaces", "0", "2") + platform.komorebic("workspace-rule", "exe", "e2e-exe-sent", "0", "1") + platform.komorebic("ignore-rule", "exe", "e2e-exe-left") + + sent = platform.spawn("by-exe-sent", exe="e2e-exe-sent") + checks.check( + "a window an exe rule matches goes to the workspace the rule names", + platform.wait_for(lambda: platform.state().workspace_of(sent.title) == 1, timeout=20), + ) + checks.check( + "... where it is put away while another workspace is in view", + platform.wait_for(lambda: platform.hidden(sent)), + ) + + left = platform.spawn("by-exe-left", exe="e2e-exe-left") + checks.check( + "a window an ignore rule by exe matches is not managed", + not platform.wait_for( + lambda: platform.state().workspace_of(left.title) is not None, timeout=3 + ), + ) + + plain = platform.spawn("by-exe-plain", exe="e2e-exe-other") + checks.check( + "a window of another program stays on the first workspace", + platform.wait_for(lambda: platform.state().workspace_of(plain.title) == 0, timeout=20), + ) + + platform.komorebic("clear-all-workspace-rules") + for client in (sent, left, plain): + platform.close(client) + checks.check( + "the three windows are closed", + platform.wait_for(lambda: platform.state().managed() == 0, timeout=20), + ) diff --git a/nix/tests/vm/lib/komorebi_vm/kde_platform.py b/nix/tests/vm/lib/komorebi_vm/kde_platform.py index b4f35208..450306f4 100644 --- a/nix/tests/vm/lib/komorebi_vm/kde_platform.py +++ b/nix/tests/vm/lib/komorebi_vm/kde_platform.py @@ -18,19 +18,31 @@ from komorebi_vm.kde import Kde CELL = 24 # the desktop that komorebi puts the windows it hides on, which is the last one PARK = "komorebi-park" +# the file the daemon is started with, and where a program with a name of its own is made +CONFIG = "/tmp/e2e-restart-config.json" +BIN = "/tmp/e2e-bin" class KdePlatform: """The platform of a headless KWin session of the test machine.""" def __init__( - self, kde: Kde, size: tuple[int, int], pointer: PointerDevice | None = None + self, + kde: Kde, + size: tuple[int, int], + pointer: PointerDevice | None = None, + session: bool = False, ) -> None: + """`session` is for a real Plasma session, which has a lock screen; the headless KWin of + the other suites has none.""" self.kde = kde + self.session = session self.size = size self._pointer = pointer def has(self, feature: str) -> bool: + if feature == "lock": + return self.session return feature == "pointer" and self._pointer is not None @property @@ -59,12 +71,14 @@ class KdePlatform: if self.kde.komorebi_running(): self.kde.komorebic("stop") self.kde.wait_for(lambda: not self.kde.komorebi_running(), timeout=30) - path = "/tmp/e2e-restart-config.json" - self.kde.sh(f"printf %s {shlex.quote(json.dumps(config))} > {path}") - self.kde.start_komorebi("--config", path) + self.rewrite_config(config) + self.kde.start_komorebi("--config", CONFIG) if not self.kde.wait_for(lambda: self.kde.run("komorebic state")[0] == 0, timeout=30): raise AssertionError("the daemon did not answer komorebic") + def rewrite_config(self, config: dict[str, Any]) -> None: + self.kde.sh(f"printf %s {shlex.quote(json.dumps(config))} > {CONFIG}") + def komorebic(self, *args: str) -> str: return self.kde.komorebic(*args) @@ -74,9 +88,15 @@ class KdePlatform: def state(self) -> Snapshot: return snapshot.parse(self.kde.state()) - def spawn(self, title: str, app_id: str | None = None) -> Client: + def spawn(self, title: str, app_id: str | None = None, exe: str | None = None) -> Client: name = f"-a {shlex.quote(app_id)} " if app_id else "" - self.kde.spawn(f"foot {name}-T {shlex.quote(title)} sleep 3000") + program = "foot" + if exe: + # the daemon reads the executable from /proc, where a link shows its target: a copy + # of the terminal is what has the name + program = f"{BIN}/{exe}" + self.kde.sh(f"mkdir -p {BIN} && cp -L $(command -v foot) {program}") + self.kde.spawn(f"{program} {name}-T {shlex.quote(title)} sleep 3000") self.kde.wait_for(lambda: self.kde.wid(title) != "", timeout=30) return Client(title) @@ -126,6 +146,33 @@ class KdePlatform: def close(self, client: Client) -> None: self.kde.close(self.kde.wid(client.title)) + def _session_id(self) -> str: + """The id of the user's Wayland session, which is the one that gets locked.""" + for line in self.kde.sh("loginctl list-sessions --no-legend").splitlines(): + words = line.split() + if len(words) > 2 and words[2] == self.kde.user: + shown = self.kde.sh(f"loginctl show-session {words[0]} -p Type --value") + if shown.strip() == "wayland": + return words[0] + raise AssertionError("the user has no Wayland session") + + def _locked(self, locked: bool) -> bool: + shown = self.kde.sh(f"loginctl show-session {self._session_id()} -p LockedHint --value") + return (shown.strip() == "yes") == locked + + def lock(self) -> None: + self.kde.sh(f"loginctl lock-session {self._session_id()}") + if not self.kde.wait_for(lambda: self._locked(True), timeout=30): + raise AssertionError("the screen did not lock") + + def unlock(self) -> None: + self.kde.sh(f"loginctl unlock-session {self._session_id()}") + if not self.kde.wait_for(lambda: self._locked(False), timeout=30): + raise AssertionError("the screen did not unlock") + + def move_window(self, client: Client, x: int, y: int) -> None: + self.kde.sh(f"kdotool windowmove {self.kde.wid(client.title)} {x} {y}") + def work_area(self) -> Rect: return Rect(0, 0, *self.size) diff --git a/nix/tests/vm/lib/tests/fake_platform.py b/nix/tests/vm/lib/tests/fake_platform.py index 676c9f06..88d6095f 100644 --- a/nix/tests/vm/lib/tests/fake_platform.py +++ b/nix/tests/vm/lib/tests/fake_platform.py @@ -58,6 +58,8 @@ class FakePlatform: focus_follows_move: bool = True, pointer: bool = True, follows_pointer: bool = True, + reloads: bool = True, + retiles_on_unlock: bool = True, ) -> None: self.tiles = list(TILES) self.has_pointer = pointer @@ -82,6 +84,15 @@ class FakePlatform: self.floats: list[str] = [] self.class_rules: dict[str, int] = {} self.ignored_classes: set[str] = set() + self.exe_rules: dict[str, int] = {} + self.ignored_exes: set[str] = set() + self.exes: dict[str, str] = {} + self.names: list[str | None] = [None, None, None] + self.layout_name = "Columns" + self.reloads = reloads + self.locked = False + self.moved: dict[str, Rect] = {} + self.retiles_on_unlock = retiles_on_unlock self.tiling = True self.paused = False self.flipped = False @@ -96,7 +107,20 @@ class FakePlatform: self.focus_follows_move = focus_follows_move def has(self, feature: str) -> bool: - return feature == "pointer" and self.has_pointer + return feature == "lock" or (feature == "pointer" and self.has_pointer) + + def lock(self) -> None: + self.locked = True + + def unlock(self) -> None: + self.locked = False + if self.retiles_on_unlock: + self.moved.clear() + + def move_window(self, client: Client, x: int, y: int) -> None: + here = self.os_window(client) + assert here is not None + self.moved[client.title] = Rect(x, y, here.frame.w, here.frame.h) @property def pointer(self) -> FakePointer: @@ -146,7 +170,14 @@ class FakePlatform: """The titles in view, in the order of the tiles.""" return [stack[0] for stack in self.containers] - def spawn(self, title: str, app_id: str | None = None) -> Client: + def spawn(self, title: str, app_id: str | None = None, exe: str | None = None) -> Client: + self.exes[title] = exe or "" + if exe in self.ignored_exes: + self.unmanaged.append(title) + return Client(title) + if exe in self.exe_rules: + self.spaces[self.exe_rules[exe]].append([title]) + return Client(title) if app_id in self.ignored_classes: self.unmanaged.append(title) return Client(title) @@ -196,16 +227,26 @@ class FakePlatform: return space return None - def restart_with(self, config: dict[str, Any]) -> None: - self.start_komorebi() + def rewrite_config(self, config: dict[str, Any]) -> None: + if self.reloads: + self._load(config) + + def _load(self, config: dict[str, Any]) -> None: workspaces = config["monitors"][0]["workspaces"] - self.placement = workspaces[0].get("initial_window_placement_rules") + self.names = [w.get("name") for w in workspaces] + [None] * (3 - len(workspaces)) + self.layout_name = workspaces[0]["layout"].title() self.prefix_rules = [ (rule["id"], index) for index, workspace in enumerate(workspaces) for rule in workspace.get("workspace_rules", []) if rule["matching_strategy"] == "StartsWith" ] + + def restart_with(self, config: dict[str, Any]) -> None: + self.start_komorebi() + self._load(config) + workspaces = config["monitors"][0]["workspaces"] + self.placement = workspaces[0].get("initial_window_placement_rules") for title in [t for stack in self.spaces[0] for t in stack]: target = self._by_prefix(title) if target not in (None, 0): @@ -326,6 +367,8 @@ class FakePlatform: ) tile = self.tiles[i] shift = 1920 * self.display_of.get(client.title, 0) + if client.title in self.moved: + return OsWindow(client.title, self.moved[client.title], focused=focused) return OsWindow(client.title, Rect(tile.x + shift, tile.y, tile.w, tile.h), focused=focused) def komorebic_status(self, *args: str) -> tuple[int, str]: @@ -388,6 +431,7 @@ class FakePlatform: case ("ensure-workspaces", _, _) | ("clear-all-workspace-rules",): if args[0] == "clear-all-workspace-rules": self.class_rules.clear() + self.exe_rules.clear() self.rules.clear() self.initial_rules.clear() case ("initial-workspace-rule", "title", title, _, number): @@ -396,6 +440,10 @@ class FakePlatform: self.rules[title] = int(number) case ("workspace-rule", "class", name, _, number): self.class_rules[name] = int(number) + case ("workspace-rule", "exe", name, _, number): + self.exe_rules[name] = int(number) + case ("ignore-rule", "exe", name): + self.ignored_exes.add(name) case ("ignore-rule", "class", name): self.ignored_classes.add(name) case ("ignore-rule", "title", title): @@ -474,13 +522,20 @@ class FakePlatform: return { "id": hash(title) % 1000, "rect": {"left": tile.x, "top": tile.y, "right": tile.w, "bottom": tile.h}, - "details": {"title": title, "exe": "", "class": "", "path": ""}, + "details": { + "title": title, + "exe": self.exes.get(title, ""), + "class": "", + "path": "", + }, } def rect(r: Rect) -> dict[str, int]: return {"left": r.x, "top": r.y, "right": r.w, "bottom": r.h} - def workspace(containers: list[list[str]], focus: int, current: bool) -> dict[str, Any]: + def workspace( + index: int, containers: list[list[str]], focus: int, current: bool + ) -> dict[str, Any]: floats = self.floats if current else [] monocle = None if current and self.monocle is not None: @@ -488,7 +543,7 @@ class FakePlatform: windows = {"elements": [window(self.monocle, whole)], "focused": 0} monocle = {"id": "m", "locked": False, "windows": windows} return { - "name": None, + "name": self.names[index], "containers": { "elements": [ { @@ -513,7 +568,7 @@ class FakePlatform: "elements": [window(t, Rect(300, 300, 600, 400)) for t in floats], "focused": 0, }, - "layout": {"Default": "Columns"}, + "layout": {"Default": self.layout_name}, "tile": self.tiling, "workspace_padding": self.workspace_padding, "container_padding": self.container_padding, @@ -525,7 +580,7 @@ class FakePlatform: "size": rect(Rect(0, 0, 1920, 1080)), "workspaces": { "elements": [ - workspace(c, f, i == self.current) + workspace(i, c, f, i == self.current) for i, (c, f) in enumerate(zip(self.spaces, self.focuses, strict=True)) ], "focused": self.current, @@ -535,7 +590,7 @@ class FakePlatform: { "id": n + 1, "size": rect(Rect(n * 1920, 0, 1920, 1080)), - "workspaces": {"elements": [workspace([], 0, False)], "focused": 0}, + "workspaces": {"elements": [workspace(0, [], 0, False)], "focused": 0}, } for n in range(1, 1 if self.forgets_displays else self.display_count) ] diff --git a/nix/tests/vm/lib/tests/test_focus_moving.py b/nix/tests/vm/lib/tests/test_focus_moving.py index 4656c405..ccb48b4f 100644 --- a/nix/tests/vm/lib/tests/test_focus_moving.py +++ b/nix/tests/vm/lib/tests/test_focus_moving.py @@ -6,6 +6,7 @@ from komorebi_vm.core.platform import OsWindow from komorebi_vm.core.scenarios import ( closing, commands, + config_reload, flipping, floating, focus, @@ -14,6 +15,7 @@ from komorebi_vm.core.scenarios import ( layouts, lifecycle, lifecycle_hidden, + locking, maximizing, minimizing, monocle, @@ -26,6 +28,7 @@ from komorebi_vm.core.scenarios import ( resize_commands, rules, rules_class, + rules_exe, scrolling, stacks, startup_rules, @@ -453,6 +456,57 @@ def test_a_daemon_that_ignores_class_rules_fails_rules_class() -> None: assert checks.failed > 0 +def test_a_daemon_that_is_right_passes_rules_exe() -> None: + platform = FakePlatform() + checks = Checks() + rules_exe.run(platform, checks) + assert checks.failed == 0, checks.failures + assert checks.passed > 4 + + +def test_a_daemon_that_ignores_exe_rules_fails_rules_exe() -> None: + class Deaf(FakePlatform): + def komorebic(self, *args: str) -> str: + return "" if "exe" in args else super().komorebic(*args) + + platform = Deaf() + checks = Checks() + rules_exe.run(platform, checks) + assert checks.failed > 0 + + +def test_a_daemon_that_reloads_the_file_passes_config_reload() -> None: + platform = FakePlatform() + checks = Checks() + config_reload.run(platform, checks) + assert checks.failed == 0, checks.failures + assert checks.passed > 6 + + +def test_a_daemon_that_does_not_reload_the_file_fails_config_reload() -> None: + platform = FakePlatform(reloads=False) + checks = Checks() + config_reload.run(platform, checks) + assert checks.failed > 0 + + +def test_a_daemon_that_tiles_again_on_unlock_passes_locking() -> None: + platform = FakePlatform() + checks = Checks() + clients = opened(platform, checks) + locking.run(platform, checks, clients) + assert checks.failed == 0, checks.failures + assert checks.passed > 4 + + +def test_a_daemon_that_does_not_tile_again_on_unlock_fails_locking() -> None: + platform = FakePlatform(retiles_on_unlock=False) + checks = Checks() + clients = opened(platform, checks) + locking.run(platform, checks, clients) + assert checks.failed > 0 + + def test_a_command_the_port_lacks_is_skipped_by_name() -> None: platform = FakePlatform() checks = Checks() diff --git a/nix/tests/vm/lib/tests/test_tiling.py b/nix/tests/vm/lib/tests/test_tiling.py index 10a5fd83..007ccef2 100644 --- a/nix/tests/vm/lib/tests/test_tiling.py +++ b/nix/tests/vm/lib/tests/test_tiling.py @@ -21,7 +21,7 @@ class FakePlatform: def wait_for(self, predicate, timeout: float = 10) -> bool: # noqa: ANN001 return predicate() - def spawn(self, title: str, app_id: str | None = None) -> Client: + def spawn(self, title: str, app_id: str | None = None, exe: str | None = None) -> Client: self.opened.append(title) return Client(title) @@ -72,6 +72,18 @@ class FakePlatform: def minimize(self, client: Client) -> None: pass + def rewrite_config(self, config: dict) -> None: + pass + + def lock(self) -> None: + pass + + def unlock(self) -> None: + pass + + def move_window(self, client: Client, x: int, y: int) -> None: + pass + def activate(self, client: Client) -> None: pass diff --git a/nix/tests/vm/suites/core-e2e/test.py b/nix/tests/vm/suites/core-e2e/test.py index c94e565f..e6ead4a5 100644 --- a/nix/tests/vm/suites/core-e2e/test.py +++ b/nix/tests/vm/suites/core-e2e/test.py @@ -17,6 +17,7 @@ from komorebi_vm.core.platform import Client from komorebi_vm.core.scenarios import ( closing, commands, + config_reload, flipping, floating, focus, @@ -34,6 +35,7 @@ from komorebi_vm.core.scenarios import ( resize_commands, rules, rules_class, + rules_exe, scrolling, stacks, startup_rules, @@ -488,6 +490,8 @@ rules.run(platform, checks) checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20)) print("== 12. rules by class") rules_class.run(platform, checks) +print("== 12. rules by exe") +rules_exe.run(platform, checks) print("== 12a. where a window that opens goes, from the placement rules of the config") placement.run(platform, checks) @@ -496,6 +500,11 @@ checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, t print("== 12a2. the workspace rules of the config, with a window open before the daemon") startup_rules.run(platform, checks) checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20)) + +print("== 12a3. the file is reloaded when it changes") +config_reload.run(platform, checks) +platform.close(Client("reload-stays")) +checks.check("no window is left", kde.wait_for(lambda: kde.managed_all() == 0, timeout=20)) # a window for the stop to leave behind platform.spawn("afterwards") checks.check("it is managed", kde.wait_for(lambda: kde.managed_all() == 1, timeout=20)) diff --git a/nix/tests/vm/suites/core-lock/default.nix b/nix/tests/vm/suites/core-lock/default.nix new file mode 100644 index 00000000..91ff32cb --- /dev/null +++ b/nix/tests/vm/suites/core-lock/default.nix @@ -0,0 +1,5 @@ +{ + tier = "slow"; + kind = "session"; + timeoutMinutes = 15; +} diff --git a/nix/tests/vm/suites/core-lock/test.py b/nix/tests/vm/suites/core-lock/test.py new file mode 100644 index 00000000..aab23cfe --- /dev/null +++ b/nix/tests/vm/suites/core-lock/test.py @@ -0,0 +1,33 @@ +# The neutral lock scenario, on a real Plasma session with komorebi running as the module's user +# unit: the screen is locked and unlocked through logind, and what the scenario looks at is the +# desktop, not the daemon's log. The same scenario runs against a Windows guest (`LockWorkStation`). +# `lock-sleep` keeps what is only KDE's: the daemon's log of the lock screen, and the signals. +from komorebi_vm import Checks, Kde +from komorebi_vm.core.scenarios import locking +from komorebi_vm.kde_platform import KdePlatform + +TITLES = ["lock-a", "lock-b", "lock-c"] + +start_all() +machine.wait_for_unit("multi-user.target") + +checks = Checks() +kde = Kde.session(machine, scale=SCALE) +platform = KdePlatform(kde, (1920, 1080), session=True) + +checks.check( + "the module's unit runs the daemon, which answers komorebic", + kde.wait_for(lambda: kde.run("komorebic state")[0] == 0, timeout=60), +) +# the daemon tiles again when it learns of the panel's room, so the windows open after that +kde.wait_for_panel_room() +clients = [platform.spawn(title) for title in TITLES] +checks.check( + "the daemon manages the three windows", + platform.wait_for(lambda: platform.state().managed() == len(clients), timeout=30), +) + +print("== the screen is locked and unlocked") +locking.run(platform, checks, clients) + +checks.finish()