Files
komorebi/nix/tests/vm/suites/check/test.py
T
LGUG2Z 44f7236698 feat(cli): check the desktop
komorebi fails quietly when the desktop is not what it was made for: over ssh
there is no session bus, a daemon whose script is not in KWin tiles nothing
while it runs, and komorebi needs KWin 6. `komorebic check` now looks at the
desktop after the configuration, and `--configuration-only` leaves that out for
a machine that is not the one komorebi will run on.

It looks at the session (KDE, Wayland), the session bus, KWin on it and KWin's
version, the daemon and its script (the daemon is running when its socket takes
a connection, the script is in KWin when KWin says it has loaded it), and what
starts komorebi at login. A bus that cannot be connected to or does not answer,
and no KWin on it, are errors, and the looking stops there because nothing after
them can be answered. Every call has two seconds to answer, so a bus that never
does cannot hold the check.

The test of the missing session bus used to remove the address and the runtime
directory from the environment and so depended on it: a machine with a user bus
at /run/user/UID/bus answered it. It now gives an address with no socket behind
it. A bus that accepts and never answers, the autostart finding and
--configuration-only have tests too, and the VM suite vm-check runs the command
against a real KWin with the daemon running, with its script gone, with no
daemon and with no KWin on the bus.

It also looks at the two effects KWin draws and animates with, and at the Plasma
shell. Only komorebi's builds of them do everything komorebi asks (a color for
each kind of window, every animation style), so the check tells a build by what
it contains: the interface of the border effect in its plugin file or its object
on the bus, a Curve setting in the animation effect's script. It looks for them
where KWin looks, from KWin's own environment, and a stock effect is a warning
only when the configuration asks for what it cannot do (borders, an animation
style other than the stock curve), and so is a copy in the user's own data
directory that hides komorebi's. The Plasma shell is looked for when the file
has wallpapers. vm-check runs all of it against KWin.
2026-10-28 07:20:57 -07:00

171 lines
6.2 KiB
Python

# `komorebic check` against a real (headless) KWin: what it finds of the desktop, and what it says
# when something is missing: no Plasma shell for the wallpapers, a stock effect shadowing komorebi's
# own, komorebi without its script in KWin, komorebi not running, no KWin on the bus. What only a
# real KWin can tell: that its version is read from what KWin says of itself, that the effects are
# komorebi's builds because of what they contain, that a daemon is told from its script by KWin's
# own answer, and that a bus with no KWin on it is an error with an exit status that says so. The
# configuration and the exit status are covered by `komorebi/src/check.rs` and
# `komorebic/tests/check.rs`, against no desktop.
import base64
import json
import re
import shlex
import struct
import zlib
from komorebi_vm import Checks, Kde
start_all()
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("user@1000.service")
checks = Checks()
kde = Kde.headless(machine, "main", size=(1920, 1080), scale=SCALE)
CONFIG = "/tmp/check-config.json"
EMPTY_BUS = "/tmp/check-empty.bus"
FLAT = "/tmp/check-flat.png"
def flat_png() -> bytes:
"""A picture of one color all over: a wallpaper no theme can be made from."""
raw = b"".join(b"\x00" + bytes([200, 40, 40]) * 8 for _ in range(8))
def chunk(kind: bytes, data: bytes) -> bytes:
body = kind + data
return struct.pack(">I", len(data)) + body + struct.pack(">I", zlib.crc32(body) & 0xFFFFFFFF)
header = struct.pack(">IIBBBBB", 8, 8, 8, 2, 0, 0, 0)
return (
b"\x89PNG\r\n\x1a\n"
+ chunk(b"IHDR", header)
+ chunk(b"IDAT", zlib.compress(raw))
+ chunk(b"IEND", b"")
)
kde.sh(f"echo {base64.b64encode(flat_png()).decode()} | base64 -d > {FLAT}")
# borders and animation, which want their effects; a wallpaper, which wants the Plasma shell and
# cannot make a theme; one workspace that is a layout and one that is only a name, which komorebi
# does not tile
kde.sh(
"printf %s "
+ shlex.quote(
json.dumps(
{
"border": True,
"animation": {"enabled": True, "style": "Linear"},
"monitors": [
{
"wallpaper": {"path": FLAT},
"workspaces": [{"name": "a", "layout": "BSP"}, {"name": "b"}],
}
],
}
)
)
+ f" > {CONFIG}"
)
def check(bus: str | None = None, data_home: str | None = None) -> tuple[int, str]:
"""Runs `komorebic check` on the session's bus, or on the bus at `bus`, with `data_home` as the
user's data directory when KWin's environment does not name one."""
prefix = f"DBUS_SESSION_BUS_ADDRESS=unix:path={bus} " if bus else ""
prefix += f"XDG_DATA_HOME={data_home} " if data_home else ""
status, out = kde.run(f"{prefix}komorebic check --komorebi-config {CONFIG}")
print(out)
return status, out
print("== 1. a desktop that is as it should be, with komorebi running")
kde.start_komorebi("--config", CONFIG)
checks.check(
"the daemon answers komorebic",
kde.wait_for(lambda: kde.run("komorebic state")[0] == 0, timeout=30),
)
checks.check("its script is in KWin", kde.wait_for(kde.script_loaded, timeout=30))
status, out = check()
checks.check("it passes: no errors", status == 0 and "\n0 error(s)" in out)
checks.check(
"it knows this is a KDE Plasma session on Wayland",
"this is a KDE Plasma session" in out and "it is a Wayland session" in out,
)
checks.check("it knows KWin 6", re.search(r"ok +KWin 6\.", out) is not None)
checks.check(
"it sees komorebi, and its script in KWin",
"komorebi is running, and its script is in KWin" in out,
)
checks.check(
"it says what starts komorebi at login",
re.search(r"ok +komorebi is started at login by ", out) is not None,
)
checks.check(
"the border effect is komorebi's build",
"the border effect is komorebi's build" in out,
)
checks.check(
"the animation effect is komorebi's build",
"the animation effect is komorebi's build" in out,
)
checks.check(
"the configuration is read, and the workspace that is only a name is found",
'workspace 1 of monitor 0 ("b") has no `layout`' in out,
)
checks.check(
"wallpapers need the Plasma shell, which a headless KWin does not have",
"the Plasma shell is not on the bus" in out,
)
checks.check(
"a picture of one color cannot make a theme",
f"no theme can be made from {FLAT}" in out,
)
print("== 2. the stock animation effect in the user's own directory hides komorebi's")
DATA = "/tmp/check-data"
STOCK = f"{DATA}/kwin/effects/kwin4_effect_geometry_change/contents/code"
kde.sh(f"mkdir -p {STOCK} && echo 'curve: QEasingCurve.OutExpo' > {STOCK}/main.js")
status, out = check(data_home=DATA)
checks.check(
"the effect is the stock one, and the style is ignored",
'the animation effect is the stock one: `animation.style` "Linear" is ignored' in out,
)
checks.check("and it says which copy hides which", "shadows" in out)
kde.sh(f"rm -rf {DATA}")
print("== 3. komorebi is running and its script is not in KWin")
kde.sh(
"busctl --user call org.kde.KWin /Scripting org.kde.kwin.Scripting unloadScript s komorebi-bridge"
)
checks.check("KWin has let the script go", kde.wait_for(lambda: not kde.script_loaded()))
status, out = check()
checks.check(
"it is an error, and the exit status says so",
status == 1
and re.search(r"error +komorebi is running but its script is not in KWin", out) is not None,
)
print("== 4. komorebi is not running")
kde.stop_komorebi()
checks.check("the daemon is gone", kde.wait_for(lambda: not kde.komorebi_running(), timeout=30))
status, out = check()
checks.check(
"a note, not an error",
status == 0 and re.search(r"note +komorebi is not running", out) is not None,
)
print("== 5. there is no KWin on the bus")
pid = kde.sh(f"dbus-daemon --session --address=unix:path={EMPTY_BUS} --fork --print-pid").strip()
status, out = check(EMPTY_BUS)
kde.run(f"kill {pid}")
checks.check(
"KWin missing is an error, and the desktop is looked at no further",
status == 1
and "KWin is not on the session bus" in out
and "komorebi is running" not in out
and "komorebi is not running" not in out,
)
kde.stop()
checks.finish()