diff --git a/e2e/lib/komorebi_vm/core/scenarios/commands.py b/e2e/lib/komorebi_vm/core/scenarios/commands.py index 96e04caa..55dae21e 100644 --- a/e2e/lib/komorebi_vm/core/scenarios/commands.py +++ b/e2e/lib/komorebi_vm/core/scenarios/commands.py @@ -353,3 +353,20 @@ def prints(platform: Platform, checks: Checks) -> None: checks.skip(f"komorebic {line}", "the port has no such command") continue checks.check(f"komorebic {line}", status == 0) + + +def unknown_monitor(platform: Platform, checks: Checks, clients: list[Client]) -> None: + """Sends the focused window to a monitor that does not exist, and checks that no window is lost. + + A port may refuse the command or ignore it, but a window that was managed has to stay managed: + a daemon that stops managing it leaves it on the screen with nothing tiling it. The platform + has fewer than seven displays. + """ + managed = platform.state().managed() + for command in ("send-to-monitor", "move-to-monitor"): + platform.komorebic_status(command, "7") + platform.wait_for(lambda: unhealthy(platform, clients) is None, timeout=5) + checks.check( + f"after {command} 7, which no display has, the daemon still manages every window", + platform.state().managed() == managed and unhealthy(platform, clients) is None, + ) diff --git a/e2e/lib/tests/fake_platform.py b/e2e/lib/tests/fake_platform.py index 8a6c4e5f..4068e225 100644 --- a/e2e/lib/tests/fake_platform.py +++ b/e2e/lib/tests/fake_platform.py @@ -241,6 +241,8 @@ class FakePlatform: self.spaces[int(number)].append([window]) case ("change-layout", _): pass + case ("send-to-monitor", _): + pass case ("move-to-monitor", number): if int(number) < self.display_count: self.display_of[self.containers[self.focus][0]] = int(number) diff --git a/e2e/lib/tests/test_focus_moving.py b/e2e/lib/tests/test_focus_moving.py index fa58aa83..0d2d008f 100644 --- a/e2e/lib/tests/test_focus_moving.py +++ b/e2e/lib/tests/test_focus_moving.py @@ -212,3 +212,26 @@ def test_the_sweep_plugs_in_a_second_display_when_there_is_only_one() -> None: commands.sweep(platform, checks, clients, config="unused", commands=("focus right",)) assert platform.display_count == 2 assert checks.failed == 0, checks.failures + + +def test_a_daemon_that_loses_a_window_sent_to_no_monitor_fails() -> None: + class Loses(FakePlatform): + def komorebic_status(self, *args: str) -> tuple[int, str]: + if args[:1] == ("send-to-monitor",): + self.containers[self.focus].clear() + return 0, "" + return super().komorebic_status(*args) + + platform = Loses() + checks = Checks() + clients = opened(platform, checks) + commands.unknown_monitor(platform, checks, clients) + assert any("send-to-monitor 7" in f for f in checks.failures) + + +def test_a_daemon_that_ignores_a_monitor_that_does_not_exist_passes() -> None: + platform = FakePlatform() + checks = Checks() + clients = opened(platform, checks) + commands.unknown_monitor(platform, checks, clients) + assert checks.failed == 0, checks.failures