Files
komorebi/nix/tests/vm/lib/komorebi_vm/machine.py
T
LGUG2Z 0e8e25957c build(nix): the demo guest as a VM suite
The demo guest is what the command `run-kde` starts, so it should not stop
working between the times somebody runs it by hand. The suite `run-kde` puts the
guest module, nix/dev/run-kde.nix, on the session node, as the rdp suite does
with krdp.nix, and checks what only a booted session can say: the demo opens two
Konsole windows, Kate and Dolphin and komorebi tiles them clear of the panel,
the cheat sheet is a window that is not a tile, what it shows of `komorebic
check` has no error, and KWin says what it draws with.

The node makes the directory the host shares as the guest finds it once it has
mounted it: owned by a user the guest does not have, with a password and a
public key in it. The suite checks that the guest takes them as root before the
login, that ssh lets in that key and no other, that KRDP starts by itself and
listens, and that a client with the password is let in and shows the display.

The client of those RDP checks moves from the rdp suite into the library as
RdpClient, with unit tests against the fake machine, so that both suites run the
same checks; the machine protocol gains copy_from_machine for it.
2026-10-28 14:20:08 -07:00

45 lines
1.5 KiB
Python

"""The part of the NixOS test driver's `Machine` that the library uses.
The driver's own class is not importable outside a test run, so the library
depends on this protocol instead, and its unit tests pass a fake. The methods
take only what the library passes; the driver's accept more (a timeout, whether
to check the exit status), which does not stop its class from satisfying the
protocol.
"""
from pathlib import Path
from typing import Protocol
class Machine(Protocol):
"""A virtual machine the test can run commands on, as root."""
@property
def out_dir(self) -> Path:
"""The directory that screenshots and other artifacts go to."""
...
def execute(self, command: str, /) -> tuple[int, str]:
"""Runs `command` and returns its exit status and its output."""
...
def succeed(self, *commands: str) -> str:
"""Runs each command and fails the test unless it exits with status 0."""
...
def fail(self, *commands: str) -> str:
"""Runs each command and fails the test if it exits with status 0."""
...
def copy_from_machine(self, source: str, /) -> None:
"""Copies the file `source` of the machine into `out_dir`, under its own name."""
...
def screenshot(self, filename: str, /) -> None:
"""Saves a PNG of the machine's display as `filename` in `out_dir`."""
...
def send_key(self, key: str, /) -> None:
"""Presses the keys `key` names together on the machine's keyboard (QEMU's `sendkey`)."""
...