diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/pausing.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/pausing.py new file mode 100644 index 00000000..3ea3c424 --- /dev/null +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/pausing.py @@ -0,0 +1,39 @@ +"""A paused daemon leaves new windows alone, and an unpaused one takes them up.""" + +from komorebi_vm.core.checks import Checks +from komorebi_vm.core.platform import Client, Platform +from komorebi_vm.core.scenarios.layouts import tiled + +# how long a daemon that is paused has to leave a window alone for it to count +QUIET = 3 + + +def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: + """Pauses the daemon, opens a window, unpauses it and opens another, with `clients` tiled + on the first workspace. Closes both.""" + managed = platform.state().managed() + + platform.komorebic("toggle-pause") + paused = platform.spawn("while-paused") + checks.check( + "a window that opens while the daemon is paused is not managed", + not platform.wait_for(lambda: platform.state().managed() > managed, timeout=QUIET), + ) + + platform.komorebic("toggle-pause") + after = platform.spawn("after-the-pause") + checks.check( + "after 'toggle-pause' again the next window is managed", + platform.wait_for(lambda: platform.state().managed() > managed, timeout=20), + ) + checks.check( + "... and every window it had is still tiled where the layout says", + platform.wait_for(lambda: tiled(platform, [*clients, after]), timeout=20), + ) + + platform.close(paused) + platform.close(after) + checks.check( + "the two windows are closed and the daemon has the ones it had", + platform.wait_for(lambda: platform.state().managed() == managed, timeout=20), + ) diff --git a/nix/tests/vm/lib/tests/fake_platform.py b/nix/tests/vm/lib/tests/fake_platform.py index 4d976850..13060b91 100644 --- a/nix/tests/vm/lib/tests/fake_platform.py +++ b/nix/tests/vm/lib/tests/fake_platform.py @@ -80,6 +80,7 @@ class FakePlatform: self.display_of: dict[str, int] = {} self.forgets_displays = False self.floats: list[str] = [] + self.paused = False self.flipped = False self.last = 0 self.maximized: str | None = None @@ -143,6 +144,9 @@ class FakePlatform: return [stack[0] for stack in self.containers] def spawn(self, title: str) -> Client: + if self.paused: + self.unmanaged.append(title) + return Client(title) if title in self.ignored: self.unmanaged.append(title) elif title in self.initial_rules: @@ -421,6 +425,8 @@ class FakePlatform: case ("flip-layout", "horizontal"): self.flipped = not self.flipped self._relayout() + case ("toggle-pause",): + self.paused = not self.paused case ("toggle-float",): if self.floats: self.containers.insert(self.focus, [self.floats.pop()]) diff --git a/nix/tests/vm/lib/tests/test_focus_moving.py b/nix/tests/vm/lib/tests/test_focus_moving.py index 6d5d52a0..cc60225b 100644 --- a/nix/tests/vm/lib/tests/test_focus_moving.py +++ b/nix/tests/vm/lib/tests/test_focus_moving.py @@ -17,6 +17,7 @@ from komorebi_vm.core.scenarios import ( monocle, moving, padding, + pausing, placement, promoting, resize, @@ -339,6 +340,27 @@ def test_a_daemon_that_does_not_flip_fails_flipping() -> None: assert checks.failed > 0 +def test_a_daemon_that_is_right_passes_pausing() -> None: + platform = FakePlatform() + checks = Checks() + clients = opened(platform, checks) + pausing.run(platform, checks, clients) + assert checks.failed == 0, checks.failures + assert checks.passed > 3 + + +def test_a_daemon_that_manages_while_paused_fails_pausing() -> None: + class Stubborn(FakePlatform): + def komorebic(self, *args: str) -> str: + return "" if args == ("toggle-pause",) else super().komorebic(*args) + + platform = Stubborn() + checks = Checks() + clients = opened(platform, checks) + pausing.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/suites/core-e2e/test.py b/nix/tests/vm/suites/core-e2e/test.py index 130f8f65..64ad7aa8 100644 --- a/nix/tests/vm/suites/core-e2e/test.py +++ b/nix/tests/vm/suites/core-e2e/test.py @@ -27,6 +27,7 @@ from komorebi_vm.core.scenarios import ( monocle, moving, padding, + pausing, placement, promoting, resize_commands, @@ -464,6 +465,7 @@ maximizing.run(platform, checks, neutral) resize_commands.run(platform, checks, neutral) promoting.run(platform, checks, neutral) flipping.run(platform, checks, neutral) +pausing.run(platform, checks, neutral) padding.run(platform, checks, neutral) monocle.run(platform, checks, neutral) workspace_moves.run(platform, checks, neutral)