feat(e2e): sync the neutral core from kfde 0be4c6ee

The Platform protocol gains has() and a Pointer, and the core gains the
resize scenario that drags the edge two tiles share. From kfde change
wumvluop.
This commit is contained in:
LGUG2Z committed 2026-10-30 18:22:44 -07:00
1 parent b34b02814f
commit 94333870d8
5 files changed
+215 -5

No files matched your search

+36
View File
@@ -38,9 +38,45 @@ class OsWindow:
focused: bool
class Pointer(Protocol):
"""A pointer a scenario moves and presses, in the pixels of the first display.
A drag is one press, a glide to the end with the button held, and one release, because a
window manager that is asked to follow the pointer drops moves that come a round trip apart.
"""
def move(self, x: int, y: int) -> None:
"""Puts the pointer on the pixel (x, y)."""
...
def down(self) -> None:
"""Presses the left button."""
...
def up(self) -> None:
"""Lets go of the left button."""
...
def drag(
self, start: tuple[int, int], end: tuple[int, int], steps: int = 25, ms: int = 30
) -> None:
"""Presses the left button at `start`, glides to `end` with it held, and lets go there."""
...
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."""
...
@property
def pointer(self) -> Pointer:
"""The pointer. Only where `has("pointer")`."""
...
@property
def tolerance(self) -> int:
"""How far a window's frame may be short of the one asked for, in pixels.
@@ -0,0 +1,90 @@
"""Dragging the edge two tiles share resizes both, and nothing else moves."""
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.geometry import Rect
from komorebi_vm.core.platform import Client, Platform
# how far outside a window's frame its resize border is pressed: the gap between two tiles
OFFSET = 4
# how far the edge may end up from where the pointer put it, in pixels
SLACK = 6
def _side_by_side(layout: list[Rect]) -> tuple[int, int] | None:
"""The first pair of tiles of which the second is to the right of the first, with the same top,
so that the edge between them is one the pointer can take."""
for i, a in enumerate(layout):
for j, b in enumerate(layout):
if i != j and b.x >= a.x + a.w and a.y < b.y + b.h and b.y < a.y + a.h:
return i, j
return None
def run(platform: Platform, checks: Checks, clients: list[Client], dx: int = 60) -> None:
"""Drags the edge between a tile and the one to its right by `dx` pixels, and checks that the
two tiles moved the edge by what the pointer moved, that every other edge stayed, and that the
windows still tile on the work area, as the operating system has them.
`clients` are the tiled windows of the first workspace, each in a container of its own.
"""
if not platform.has("pointer"):
print(" skipped: this platform has no pointer")
return
state = platform.state()
workspace = state.workspace()
layout = workspace.latest_layout
pair = _side_by_side(layout)
checks.check("two tiles share a vertical edge", pair is not None)
if pair is None:
return
left, right = pair
titles = [c[0].title for c in workspace.containers]
window = platform.os_window(Client(titles[left]))
assert window is not None
before = list(layout)
grab = (window.frame.x + window.frame.w + OFFSET, window.frame.y + window.frame.h // 2)
platform.pointer.drag(grab, (grab[0] + dx, grab[1]))
def edge_moved() -> bool:
now = platform.state().workspace().latest_layout
return len(now) == len(before) and abs(now[left].w - (before[left].w + dx)) <= SLACK
checks.check(
f"the tile on the left of the edge is {dx} pixels wider",
platform.wait_for(edge_moved, timeout=20),
)
now = platform.state().workspace().latest_layout
print(f" tiles before {before}, after {now}")
edge = before[left].x + before[left].w
# the tiles on either side of the edge: every one that ends at it, and every one that starts
# at or after it with the edge as its own left side (a column of tiles shares it)
ends = [i for i, t in enumerate(before) if t.x + t.w == edge]
starts = [i for i, t in enumerate(before) if t.x == before[right].x]
checks.check(
f"the tiles that end at the edge are {dx} pixels wider and start where they did",
all(abs(now[i].w - (before[i].w + dx)) <= SLACK and now[i].x == before[i].x for i in ends),
)
checks.check(
f"the tiles that start after the edge start {dx} pixels later and end where they did",
all(
abs(now[i].x - (before[i].x + dx)) <= SLACK
and abs((now[i].x + now[i].w) - (before[i].x + before[i].w)) <= SLACK
for i in starts
),
)
checks.check(
"no tile moved up or down or changed its height",
all((now[i].y, now[i].h) == (before[i].y, before[i].h) for i in range(len(before))),
)
checks.check(
"every tile that does not touch the edge is where it was",
all(now[i] == before[i] for i in range(len(before)) if i not in ends and i not in starts),
)
area = platform.work_area()
frames = [w.frame for c in clients if (w := platform.os_window(c)) is not None]
checks.check("the windows are inside the work area", all(f.inside(area) for f in frames))
checks.check(
"and do not overlap",
not any(a.overlaps(b) for i, a in enumerate(frames) for b in frames[i + 1 :]),
)
+54 -3
View File
@@ -16,10 +16,42 @@ from komorebi_vm.core.snapshot import Snapshot, parse
TILES = [Rect(0, 0, 640, 1080), Rect(640, 0, 640, 1080), Rect(1280, 0, 640, 1080)]
class FakePointer:
"""A pointer that, dragged from just outside the right edge of a tile, moves that edge."""
def __init__(self, platform: "FakePlatform") -> None:
self.platform = platform
self.at = (0, 0)
def move(self, x: int, y: int) -> None:
self.at = (x, y)
def down(self) -> None:
pass
def up(self) -> None:
pass
def drag(
self, start: tuple[int, int], end: tuple[int, int], steps: int = 25, ms: int = 30
) -> None:
self.platform.resize(start, end[0] - start[0])
class FakePlatform:
tolerance = 24
def __init__(self, *, moves: bool = True, focus_follows_move: bool = True) -> None:
def __init__(
self,
*,
moves: bool = True,
focus_follows_move: bool = True,
pointer: bool = True,
follows_pointer: bool = True,
) -> None:
self.tiles = list(TILES)
self.has_pointer = pointer
self.follows_pointer = follows_pointer
self.spaces: list[list[list[str]]] = [[], []]
"""The two workspaces: for each, the stack of each container, in the order of the tiles,
and the first window of a stack is the one in view."""
@@ -28,6 +60,25 @@ class FakePlatform:
self.moves = moves
self.focus_follows_move = focus_follows_move
def has(self, feature: str) -> bool:
return feature == "pointer" and self.has_pointer
@property
def pointer(self) -> FakePointer:
return FakePointer(self)
def resize(self, start: tuple[int, int], dx: int) -> None:
"""The edge of the tile that `start` is 4 pixels outside of moves by `dx`, when the daemon
follows the pointer."""
if not self.follows_pointer:
return
for i, tile in enumerate(self.tiles[:-1]):
if abs(start[0] - (tile.x + tile.w + 4)) <= 1:
a, b = tile, self.tiles[i + 1]
self.tiles[i] = Rect(a.x, a.y, a.w + dx, a.h)
self.tiles[i + 1] = Rect(b.x + dx, b.y, b.w - dx, b.h)
return
def wait_for(self, predicate: Any, timeout: float = 10) -> bool:
return bool(predicate())
@@ -157,7 +208,7 @@ class FakePlatform:
"id": str(i),
"locked": False,
"windows": {
"elements": [window(t, TILES[i]) for t in stack],
"elements": [window(t, self.tiles[i]) for t in stack],
"focused": 0,
},
}
@@ -170,7 +221,7 @@ class FakePlatform:
"floating_windows": {"elements": [], "focused": 0},
"layout": {"Default": "Columns"},
"tile": True,
"latest_layout": [rect(r) for r in TILES[: len(containers)]],
"latest_layout": [rect(r) for r in self.tiles[: len(containers)]],
}
monitor = {
+27 -1
View File
@@ -1,7 +1,7 @@
"""The focus and moving scenarios against a daemon that is right, and against ones that are not."""
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.scenarios import focus, moving, stacks, tiling, workspaces
from komorebi_vm.core.scenarios import focus, moving, resize, stacks, tiling, workspaces
from tests.fake_platform import FakePlatform
@@ -51,3 +51,29 @@ def test_a_daemon_that_is_right_passes_workspaces() -> None:
workspaces.run(platform, checks, clients)
assert checks.failed == 0, checks.failures
assert checks.passed > 7
def test_a_daemon_that_follows_the_pointer_passes_resize() -> None:
platform = FakePlatform()
checks = Checks()
clients = opened(platform, checks)
resize.run(platform, checks, clients)
assert checks.failed == 0, checks.failures
assert checks.passed > 8
def test_a_daemon_that_ignores_the_pointer_fails_resize() -> None:
platform = FakePlatform(follows_pointer=False)
checks = Checks()
clients = opened(platform, checks)
resize.run(platform, checks, clients)
assert any("pixels wider" in f for f in checks.failures)
def test_a_platform_with_no_pointer_skips_resize() -> None:
platform = FakePlatform(pointer=False)
checks = Checks()
clients = opened(platform, checks)
passed = checks.passed
resize.run(platform, checks, clients)
assert (checks.passed, checks.failed) == (passed, 0)
+8 -1
View File
@@ -4,7 +4,7 @@ from PIL import Image
from komorebi_vm.core.checks import Checks
from komorebi_vm.core.geometry import Rect
from komorebi_vm.core.platform import Client, OsWindow
from komorebi_vm.core.platform import Client, OsWindow, Pointer
from komorebi_vm.core.scenarios import tiling
from komorebi_vm.core.snapshot import Snapshot, parse
@@ -35,6 +35,13 @@ class FakePlatform:
def hidden(self, client: Client) -> bool:
return False
def has(self, feature: str) -> bool:
return False
@property
def pointer(self) -> Pointer:
raise AssertionError("no pointer")
def work_area(self) -> Rect:
return Rect(0, 0, 1920, 1080)