diff --git a/nix/tests/vm/lib/komorebi_vm/core/platform.py b/nix/tests/vm/lib/komorebi_vm/core/platform.py index 366e66c4..14ddf242 100644 --- a/nix/tests/vm/lib/komorebi_vm/core/platform.py +++ b/nix/tests/vm/lib/komorebi_vm/core/platform.py @@ -81,7 +81,14 @@ class Platform(Protocol): def tolerance(self) -> int: """How far a window's frame may be short of the one asked for, in pixels. - A terminal sizes itself to whole cells; a test window has no granularity. + A client that sizes itself to a grid (a terminal's cells) ends up short of the tile; one + that does not (a test window) has only the rounding of the system's own frame. The frame + is never past what was asked, so a check that something is inside an area allows no slack + for it, and a check that two sizes are the same allows this much. + + It is a bound on what a client rounds to, not a measure of a change: a scenario that + asks whether the daemon changed a size compares the daemon's layout (`latest_layout`, + which no client rounds) and then that the frame follows it within this. """ ... diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/resize_commands.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/resize_commands.py index ed1318d0..af4d117f 100644 --- a/nix/tests/vm/lib/komorebi_vm/core/scenarios/resize_commands.py +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/resize_commands.py @@ -2,7 +2,8 @@ from komorebi_vm.core.checks import Checks from komorebi_vm.core.platform import Client, Platform -from komorebi_vm.core.scenarios.support import focus_agrees +from komorebi_vm.core.scenarios.layouts import tiled +from komorebi_vm.core.scenarios.support import focus_agrees, layout_rect # how much wider the window must get for the command to have done something MIN_STEP = 10 @@ -26,18 +27,35 @@ def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: a.overlaps(b) for i, a in enumerate(frames) for b in frames[i + 1 :] ) - before = width() + def asked() -> int: + """The width the daemon's layout gives the window, which no client rounds.""" + rect = layout_rect(platform, target) + return rect.w if rect is not None else 0 + + before, asked_before = width(), asked() platform.komorebic("resize-axis", "horizontal", "increase") checks.check( - f"after 'resize-axis horizontal increase' {target.title} is wider", + f"after 'resize-axis horizontal increase' the layout gives {target.title} more width", + platform.wait_for(lambda: asked() >= asked_before + MIN_STEP, timeout=20), + ) + checks.check( + "... and the window is wider", platform.wait_for(lambda: width() >= before + MIN_STEP, timeout=20), ) - print(f" width {before} -> {width()}") + print(f" width {before} -> {width()}, asked {asked_before} -> {asked()}") + checks.check( + "... where the layout says, whatever the client rounds its size to", + platform.wait_for(lambda: tiled(platform, clients), timeout=20), + ) checks.check("... and every window is inside the work area, none over another", clear()) platform.komorebic("resize-axis", "horizontal", "decrease") checks.check( - "after 'decrease' it has the width it had", + "after 'decrease' the layout gives it the width it had", + platform.wait_for(lambda: asked() == asked_before, timeout=20), + ) + checks.check( + "... and the window has the width it had, to what the client rounds to", platform.wait_for(lambda: abs(width() - before) <= platform.tolerance, timeout=20), ) checks.check("... and every window is inside the work area, none over another", clear()) diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/support.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/support.py index fe0c0e19..b61444a3 100644 --- a/nix/tests/vm/lib/komorebi_vm/core/scenarios/support.py +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/support.py @@ -1,5 +1,6 @@ """What more than one scenario needs of a platform.""" +from komorebi_vm.core.geometry import Rect from komorebi_vm.core.platform import Client, Platform @@ -32,3 +33,17 @@ def positions(platform: Platform, clients: list[Client]) -> dict[str, tuple[int, def focus_agrees(platform: Platform, clients: list[Client], title: str) -> bool: """The operating system and the daemon's state both have `title` focused.""" return os_focused(platform, clients) == title and platform.state().focused_title() == title + + +def layout_rect(platform: Platform, client: Client) -> Rect | None: + """The rectangle the daemon's layout gives the container of `client`, or `None` if the + first workspace has no such container. + + It is what the daemon asked for: the frame the operating system gives the window may be short + of it by `platform.tolerance`, and is what the scenario then compares it with. + """ + workspace = platform.state().workspace() + for i, stack in enumerate(workspace.containers): + if any(w.title == client.title for w in stack) and i < len(workspace.latest_layout): + return workspace.latest_layout[i] + return None diff --git a/nix/tests/vm/lib/tests/test_focus_moving.py b/nix/tests/vm/lib/tests/test_focus_moving.py index 1ace2536..cd0c6a3b 100644 --- a/nix/tests/vm/lib/tests/test_focus_moving.py +++ b/nix/tests/vm/lib/tests/test_focus_moving.py @@ -308,6 +308,26 @@ def test_a_daemon_that_does_not_resize_fails_resize_commands() -> None: assert checks.failed > 0 +def test_a_decrease_that_gives_back_less_than_the_increase_fails_resize_commands() -> None: + """Within what a terminal rounds to (24 px), so the window alone cannot tell.""" + + class Short(FakePlatform): + def komorebic(self, *args: str) -> str: + if args == ("resize-axis", "horizontal", "decrease"): + i = self.focus + a, b = self.tiles[i], self.tiles[i + 1] + self.tiles[i] = Rect(a.x, a.y, a.w - 30, a.h) + self.tiles[i + 1] = Rect(b.x - 30, b.y, b.w + 30, b.h) + return "" + return super().komorebic(*args) + + platform = Short() + checks = Checks() + clients = opened(platform, checks) + resize_commands.run(platform, checks, clients) + assert any("the layout gives it the width it had" in f for f in checks.failures) + + def test_a_daemon_that_is_right_passes_promoting() -> None: platform = FakePlatform() checks = Checks()