mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-23 08:54:16 +01:00
The daemon answers on its socket, but a person has no way to write a message on it. komorebic is that way: each subcommand that asks something of the daemon is one message, sent with komorebi-client, and a question's answer is printed. komorebic is a separate program because the daemon takes no input but its socket, so a key binding, a script and a terminal all drive it the same way. It has what the daemon can answer so far: state, monitor-information, query, retile and stop. Around them, start runs the komorebi on the PATH in the background and passes it what follows a --, such as --fake-backend to try it without a compositor; log follows the daemon's log, which the daemon now writes to a file a day in LOG_DIR as well as to stdout; data-directory shows where the socket is; completions prints a shell completion script. The hidden docgen writes each subcommand's help to docs/cli, in fences that name their language and wrapped at 100 columns whatever the width of the terminal, so that the pages are the same wherever they are generated; just docgen runs it. The user guide starts here: docs/index.md for KDE Plasma, and a page on running komorebi. tests/cli.rs runs each subcommand against a socket the test serves in place of the daemon. In the VM tests the guests get komorebic next to the daemon, and vm-core-e2e reads the daemon's state with it (the windows it manages, the one it focuses, after KWin restarts too) and stops it with komorebic stop, which unloads the bridge and removes the socket. In the VM test library, Kde.state asks again, a second (times the scale) after an empty answer or a failed command, up to 10 times. The daemon drops a query when it cannot take hold of the window manager within a second, and komorebic then prints an empty line and succeeds; komorebic itself gives the daemon a second to answer and fails when that is not enough. A daemon busy with the first windows does either on a machine that is loaded or slow, and a suite that polled the state died on JSONDecodeError. An answer that is not JSON still fails at once.
111 lines
3.3 KiB
Nix
111 lines
3.3 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 package of `komorebi` and `komorebic` for 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;
|
|
}
|