fix(e2e): wait for the macOS daemon to take up a command, and for its file watcher

komorebic is done when a command is in the daemon's queue, not when it has run, and a scenario opens a
window right after giving a rule or a name: both are events of the same queue, and the window could be
first. The platform asks for `state` after every command that changes something, which the daemon
answers in the order it got things (the rules scenario failed a different check on each run before,
and its named-workspace checks pass three runs in three now).

The daemon watches its configuration file with FSEvents, and a file written in the first half second
after it answered is never noticed (0 s: not reloaded in 12 s; 0.5 s: reloaded after 2.6 s; later
ones after two or three seconds). A start waits a second for it, as nobody edits a file that fast.
config_reload goes from 6 of 8 checks to 8 of 8.
This commit is contained in:
LGUG2Z committed 2026-11-06 14:40:50 -08:00
1 parent 5257e11b8d
commit 8dc6390eb1
1 file changed
+23
@@ -32,6 +32,13 @@ TEMP_DIR = f"{GUEST_ROOT}/tmp"
ANSI = re.compile(r"\x1b\[[0-9;]*m")
# a daemon that exited at start is launched again, this many times in all
LAUNCHES = 3
# how long after it answers the daemon takes to see a change of its configuration file: it watches
# it with FSEvents, and a file written in the first half second after it started is not noticed (a
# later one is, after two or three seconds). Nobody edits a file that fast, so a start waits this
# long (measured: 0 s loses the change, 0.5 s does not).
WATCH_SETTLE = 1.0
# the commands of `komorebic` that change nothing, which need no barrier after them
READ_ONLY = {"state", "global-state", "query", "visible-windows", "monitor-information"}
# the programs whose windows are not for the daemon to tile: the Terminal the agent runs in, and
# the desktop widgets of the stock image (Notification Center draws them as windows)
IGNORED_APPS = ("Terminal", "Notification Center")
@@ -116,6 +123,7 @@ class MacosPlatform:
)
outcome = self._wait_launched(self._daemon_pid)
if outcome is None:
time.sleep(WATCH_SETTLE * self._scale)
return
self.start_notes.append(f"launch {launch}: {outcome}")
print(f" komorebi: launch {launch} failed: {outcome}")
@@ -185,8 +193,23 @@ class MacosPlatform:
result = self._agent.exec(f"{GUEST_BIN}/komorebic", *args)
if result["status"] != 0:
raise RuntimeError(f"komorebic {' '.join(args)}: {result['stderr'] or result}")
if args and args[0] not in READ_ONLY:
self._barrier()
return result["stdout"]
def _barrier(self) -> None:
"""Returns once the daemon has taken up what `komorebic` sent it.
`komorebic` is done when the command is in the daemon's queue, not when it has been
carried out, and a window that opens right after (the scenarios do that) is an event of
the same queue: a rule or a name given just before it could come after it. The daemon
answers `state` in the order it got things, so its answer says the commands before it
have run. Nothing is asked of Windows, where the daemon is quick enough not to need it."""
try:
self._agent.exec(f"{GUEST_BIN}/komorebic", "state")
except AgentError:
pass
def komorebic_status(self, *args: str) -> tuple[int, str]:
result = self._agent.exec(f"{GUEST_BIN}/komorebic", *args)
status = result["status"] if result["status"] is not None else -1