Files
komorebi/nix/tests/vm/default.nix
T
LGUG2Z b463191d00 feat(kwin): move and focus windows through a held call
With the commands of the Backend trait carried out, the daemon tiles a real
KWin. A command looks up the UUID KWin knows the window by, is queued as JSON
for the bridge, and returns; the held Poll call is answered with the queue, one
millisecond after the first command, so that a retile reaches KWin as one batch.
The bridge sets the frame, activates, raises, minimizes, restores or closes the
window, and reports what it could not do. set_rect records the frame it asked
for in the table, so the window manager sees it at once, and the geometry event
that follows says what the client made of it.

A KWin script cannot move the pointer, so the pointer follows the focus through
KWin's own "Move Mouse to Focus" action, invoked over kglobalaccel once KWin
reports the window active.

The commands are typed in bridge.js, and the declarations of KWin's API let the
bridge set a window's frame, its minimized state and the active window, raise
and close it, and nothing else. The session the tests of both sides share grows
a second batch: the backend's tests check that set_rect, focus, raise, minimize,
unminimize and close send it, and the bridge's tests answer the bridge with it
and check what KWin is asked to do, down to the command for a window that has
closed, which comes back as failed. The bridge's tests also cover findWindow's
fallback to KWin's list, a frame set as a plain object, and a command KWin
throws on.

Three VM suites check it against a real KWin. vm-core-e2e (from the spike's
m2-e2e, the sections that need no komorebic) compares what the daemon asked for,
read from its debug log, with what KWin has, read with kdotool: three windows
inside the screen, not overlapping, sharing it, the same focused window on both
sides, and the same again after a minimize, a restore and a close.
vm-client-geometry (slow) has eight real clients answer the frames komorebi asks
for: Qt programs and xterm take them exactly, foot sizes itself to whole cells,
GTK 4 programs and Firefox keep to their minimum sizes. vm-latency (slow) times
retiles from a recording of the session bus: on HVF, from the daemon's answer to
the last frame KWin reports, p50 17.3 ms, p95 27.7 ms. vm-kwin-events no longer
checks that nothing moves. The VM library gives session commands the test user's
home and data directories rather than root's, which a GTK client was refused.

The bridge's second request for a position after a resize, which matters for
windows off the screen, comes with the scrolling layout.
2026-10-27 14:48:56 -07:00

111 lines
3.2 KiB
Nix

# The NixOS VM tests. Every directory under `suites/` is one test, `checks.<system>.vm-<name>`
# (Linux) and `legacyPackages.<system>.vm.<name>` (everywhere), so a new suite needs no edit to
# the flake. See docs/dev/vm-tests.md.
#
# `hostPkgs` is the pkgs of the machine that runs QEMU; the guests are always Linux. `komorebiFor`
# returns the komorebi package of a system, and the guests get the one of their own. `scale` says
# how much slower than KVM that machine is (1 for KVM, 1.5 for HVF on a Mac, 8 for TCG), and every
# wait in the suites is multiplied by it.
{
hostPkgs,
komorebiFor,
scale ? 1,
}:
let
inherit (hostPkgs) lib;
# a Linux guest of the host's architecture, which is what the test driver boots
guestSystem = "${hostPkgs.stdenv.hostPlatform.parsed.cpu.name}-linux";
# the library the suites import, built for the python of the test driver
komorebiVm =
ps:
ps.buildPythonPackage {
pname = "komorebi-vm";
version = "0.1.0";
pyproject = true;
src = lib.fileset.toSource {
root = ./lib;
fileset = ./lib;
};
build-system = [ ps.setuptools ];
dependencies = [ ps.pillow ];
doCheck = false;
};
# unit tests of the library against a fake machine, and the linters over it
libCheck =
let
python = hostPkgs.python3.withPackages (ps: [
ps.pytest
(komorebiVm ps)
]);
in
hostPkgs.runCommand "vm-lib"
{
nativeBuildInputs = [
python
hostPkgs.ruff
hostPkgs.ty
];
src = lib.fileset.toSource {
root = ./lib;
fileset = ./lib;
};
}
''
cp -r $src lib && chmod -R u+w lib && cd lib
ruff check .
ruff format --check .
ty check --python ${python} .
pytest -q -p no:cacheprovider
touch $out
'';
suiteNames = lib.attrNames (
lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./suites)
);
suiteDefs = lib.genAttrs suiteNames (name: import (./suites + "/${name}"));
mkSuite =
name:
let
dir = ./suites + "/${name}";
suite = suiteDefs.${name};
in
hostPkgs.testers.runNixOSTest {
name = "komorebi-${name}";
extraPythonPackages = ps: [ (komorebiVm ps) ];
globalTimeout = builtins.ceil (suite.timeoutMinutes * 60 * scale);
passthru.tier = suite.tier;
# the nodes take the daemon as an argument, `komorebi`
node.specialArgs.komorebi = komorebiFor guestSystem;
nodes.machine = {
# a suite's `node`, if it has one, adds to the node of its kind
imports = [ (./nodes + "/${suite.kind}.nix") ] ++ lib.optional (suite ? node) suite.node;
};
testScript = ''
SCALE = ${toString scale}
''
+ builtins.readFile (dir + "/${suite.script or "test.py"}");
};
suites = lib.genAttrs suiteNames mkSuite;
in
{
inherit suites;
lib = libCheck;
# the suites of each tier, for the CI matrix: { fast = [ "kwin" ... ]; slow = [ ... ]; }
tiers = lib.groupBy (name: suiteDefs.${name}.tier) suiteNames;
# the guests of every suite, so that a Mac can build them on a Linux builder first
guests = lib.mapAttrs (
_: test: lib.mapAttrs (_: node: node.system.build.toplevel) test.nodes
) suites;
}