The keyboard's only purpose is that a client receives symbols, so a unit
suite alone was testing the shape of a request nobody answered --
docs/TODO/scroll-has-no-compositor-proof.md is the precedent. This is
the compositor proof: two nixosTests, 16 subtests each, real time, no
injected clock.
nix build --no-link -L .#checks.x86_64-linux.vm-keyboard
test script finished in 281.06s (16/16, exit 0)
nix build --no-link -L .#checks.x86_64-linux.vm-keyboard-de
test script finished in 278.15s (16/16, exit 0)
The victim, checks/lib/keyboard_target.py, decodes every keysym from the
keymap the COMPOSITOR forwarded rather than from a table of its own.
That is the mutation rule PLAN §14 asks for: a driver that stopped
uploading leaves the client with nothing to decode with, every key
arrives as `sym=?`, and the character assertions go red. A victim with
its own keymap would decode `hello` either way and the check would be
asserting that the check can spell.
What the client actually reported, which is the point of reading back
the application's state rather than the broker's intention:
type A [(30, 1, 'A'), (30, 0, 'A')] masks [1, 1, 0, 0]
-- evdev 30 decoded as A, so the mask arrived BEFORE the
key, and no code 42 anywhere
key Return [(28, 1, 'Return'), (28, 0, 'Return')]
TTL expiry [(42, 1, 'Shift_L'), (42, 0, 'Shift_L')] masks [1,1,0,0]
-- lifted by the sweeper alone, mask cleared with it
chord depressed mask [4, 4] while Control held, still held
after the type returned
It runs TWICE because `sessions.keyboard.layout` reaches the uploaded
keymap through exactly one path -- `--xkb-layout` on the driver unit's
argv -- and one layout cannot tell that path from a hardcoded `us`:
us: symbols=pc_us_inet(evdev) bytes=35572
type y -> [(21, 1, 'y')] type z -> [(44, 1, 'z')]
type cafü -> exit 2, "scalar 3 (U+00FC) is not typeable", and the
client reported [] -- no prefix typed
de: symbols=pc_de_inet(evdev) bytes=37532
type y -> [(44, 1, 'y')] type z -> [(21, 1, 'z')] (swapped)
type cafü -> {'chars': 4, 'ok': True}
client decoded ['c', 'a', 'f', 'udiaeresis']
Hyprland's own input:kb_layout is left at `us` in BOTH runs, so a client
that ignored our keymap would decode the us answer on the de machine.
The decisive subtest is "acquire takes the KEYBOARD as well as the
cursor". With session B holding keyboard focus because its window mapped
last, acquire on A delivered wl_pointer.enter AND wl_keyboard.enter to A
and wl_keyboard.leave to B, with focus == "warp". A check that asserted
only pointer delivery would have gone green while A had the cursor, B
had the keys, and the first keystroke of the lease went to B -- which is
exactly what one warp does. §B3's "one warp" and the Stage 0 review's
"do not assert enter on acquire" are superseded by the two-warp acquire,
and the header says so.
One deviation from §B3, with reasons in the header: its subtest 4 says
`type y` decodes to sym `z`, which is wrong for a victim that decodes
from the forwarded keymap -- the same paragraph requires that. `type y`
resolves keysym y against the uploaded layout and sends that layout's
code; the client decodes it back to `y`. The sym is `y` on both layouts
by construction. What differs is the CODE, the symbols name, and whether
ü is typeable at all, and those are what this asserts.
── AND A PRE-EXISTING BUG THE FIRST RUN EXPOSED ──────────────────────
checks/lib/session-tools.nix opened a heredoc with `<<EOF` and closed it
with an INDENTED ` EOF`. A delimiter has to be at column zero, so it
never closed: it swallowed the rest of the builder -- both `install`
lines and every self-test -- into the shim's own text. The derivation
built anyway, with `hhs-ipc-watch` alone in $out/bin:
$ ls /nix/store/wy3lp3...-hhstream-session-tools/bin/
hhs-ipc-watch
So hhs-pointer-target has NEVER existed in that derivation either.
vm-pointer execs that absolute path, and vm-keyboard failed the same
way: the broker reported `target exited immediately (exit code 127)`,
which is true about a path that was never created and says nothing about
why. hhs-ipc-watch's own first line was ` #!...`, indented, which is
not a shebang, so vm-ipc is affected too. The build-time self-tests that
exist to catch exactly this had themselves become heredoc text. The
unquoted delimiter also expanded the swallowed text, so the builder ran
`hhstreamd.ipc` as a command.
The shim is a writeTextFile now -- no delimiter to indent wrong -- and
`test -x` on all three programs is the guard that would have caught it.
NOT DONE, and it needs doing: vm-pointer and vm-ipc have not been
re-run. checks/default.nix says one VM at a time on this two-core box
and I did not want to perturb the keyboard runs. That they WOULD have
failed is read off the store listing above, not off a run.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GhNPM6rGcuzxocM1nATnuM
106 lines
5.3 KiB
Nix
106 lines
5.3 KiB
Nix
# The guest programs the session checks need, packaged with the interpreters
|
|
# they actually require.
|
|
#
|
|
# Separate from `test-tools.nix` because these need things that one does not:
|
|
# `hhs-ipc-watch` imports the shipped `hhstreamd.ipc` (so it needs the package
|
|
# on PYTHONPATH -- it is the client under test, not a reimplementation of it),
|
|
# and the two targets are Wayland clients (so they need pywayland, and the
|
|
# keyboard one also xkbcommon).
|
|
#
|
|
# All three are self-tested at build time, for the same reason test-tools.nix
|
|
# does it: a broken helper otherwise surfaces as a baffling VM failure three
|
|
# layers away, long after the thing that would have explained it scrolled past.
|
|
#
|
|
# ─── NO HEREDOC HERE, AND THAT IS NOT A STYLE PREFERENCE ─────────────────────
|
|
# This file used to write the `hhs-ipc-watch` shim with `cat > $out/bin/... <<EOF`
|
|
# and an **indented** `EOF` terminator. A heredoc delimiter has to be at column
|
|
# zero, so that heredoc never ended: it swallowed the rest of the builder --
|
|
# both `install` lines and every self-test below -- into the shim's own text.
|
|
#
|
|
# The derivation still built, and `$out/bin` contained `hhs-ipc-watch` alone.
|
|
# Neither target existed, so every check that launches one failed in the guest
|
|
# with the broker reporting `target exited immediately (exit code 127)`, which
|
|
# is a true statement about a path that was never created and tells you nothing
|
|
# about why. The self-tests that exist to prevent exactly that had themselves
|
|
# become heredoc text, so they never ran.
|
|
#
|
|
# Two more things the unquoted delimiter did, both visible in a build log:
|
|
# `${...}` and backticks inside the swallowed text were expanded, so the
|
|
# builder tried to run `hhstreamd.ipc` as a command (it appears as
|
|
# `line 5: hhstreamd.ipc: command not found`), and the backticked words
|
|
# vanished from the comments it ate.
|
|
#
|
|
# So the shim is a `writeTextFile` now. There is no delimiter to indent wrong,
|
|
# the expansion happens in Nix where it is meant to, and the self-tests are
|
|
# ordinary commands again.
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
{
|
|
runCommandLocal,
|
|
writeTextFile,
|
|
python3,
|
|
hhstream,
|
|
}:
|
|
let
|
|
# pywayland for the pointer client; nothing else, so an import error in the
|
|
# guest is a real missing dependency and not this file being generous.
|
|
waylandPython = python3.withPackages (ps: [ ps.pywayland ]);
|
|
# The keyboard client needs xkbcommon on top, and needs it for a reason the
|
|
# check depends on: it decodes every keysym from the keymap the *compositor*
|
|
# forwarded, so a driver that stopped uploading one cannot leave the check
|
|
# green. A table in the client would decode the same symbols either way.
|
|
keyboardPython = python3.withPackages (ps: [ ps.pywayland ps.xkbcommon ]);
|
|
|
|
# The event-socket subscriber runs the broker's own IPC client, so it is
|
|
# pointed at what nix/package.nix installed rather than at a copy.
|
|
ipcWatch = writeTextFile {
|
|
name = "hhs-ipc-watch";
|
|
executable = true;
|
|
text = ''
|
|
#!${python3}/bin/python3
|
|
import sys
|
|
sys.path.insert(0, "${hhstream}/${python3.sitePackages}")
|
|
sys.argv[0] = "hhs-ipc-watch"
|
|
exec(compile(open("${./ipc_watch.py}").read(), "${./ipc_watch.py}", "exec"))
|
|
'';
|
|
};
|
|
in
|
|
runCommandLocal "hhstream-session-tools"
|
|
{
|
|
nativeBuildInputs = [ python3 ];
|
|
meta.description = "Event-socket witness and input targets for the hhstream session checks";
|
|
} ''
|
|
mkdir -p $out/bin
|
|
|
|
install -Dm755 ${ipcWatch} $out/bin/hhs-ipc-watch
|
|
install -Dm755 ${./pointer_target.py} $out/bin/hhs-pointer-target
|
|
install -Dm755 ${./keyboard_target.py} $out/bin/hhs-keyboard-target
|
|
sed -i '1s|.*|#!${waylandPython}/bin/python3|' $out/bin/hhs-pointer-target
|
|
sed -i '1s|.*|#!${keyboardPython}/bin/python3|' $out/bin/hhs-keyboard-target
|
|
|
|
# Everything below is the self-test, and it is the part that was silently
|
|
# not running. Proof that all three programs exist and start, that the
|
|
# broker's own ipc module is importable through the path in the shim, and
|
|
# that the two Wayland bindings are present.
|
|
test -x $out/bin/hhs-ipc-watch
|
|
test -x $out/bin/hhs-pointer-target
|
|
test -x $out/bin/hhs-keyboard-target
|
|
$out/bin/hhs-ipc-watch --help > /dev/null
|
|
$out/bin/hhs-pointer-target --help > /dev/null
|
|
$out/bin/hhs-keyboard-target --help > /dev/null
|
|
${waylandPython}/bin/python3 -c 'from pywayland.protocol.xdg_shell import XdgWmBase'
|
|
|
|
# xkbcommon, and a keymap that really compiles: the keyboard target decodes
|
|
# every symbol through this, so a broken binding would show up in the guest
|
|
# as every key arriving with an undecodable symbol and no explanation.
|
|
${keyboardPython}/bin/python3 -c 'from xkbcommon import xkb; k = xkb.Context().keymap_new_from_names(rules="evdev", model="pc105", layout="us"); assert xkb.keysym_get_name(k.state_new().key_get_one_sym(38)) == "a"'
|
|
|
|
# Both targets refuse to guess an app id, and the checks depend on that
|
|
# refusal being exit 2 rather than a window with somebody else's class.
|
|
for target in hhs-pointer-target hhs-keyboard-target; do
|
|
if $out/bin/$target; then
|
|
echo "$target started with no app id; it must refuse" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
''
|