Everything below the CLI was merged and green against fakes; none of it was
reachable and none of it had ever met a compositor. This wires it up and then
puts the compositor in a position to disagree.
CLI (src/hhstream/cli.py, src/hhstream_session/**)
session container [ID], session reconcile [ID], and the seven pointer verbs
from PLAN §9. `start` still prints the bare session id and nothing else.
`list` gains WS / OUTPUT / POINTER, with the gap marker where a value is
genuinely unknown rather than a blank that reads as zero -- the POINTER
column needs a second, read-only `pointer.state` call because the `list`
reply carries no lease state.
The lease id is cached in `hhstream_session.lease` (under
$XDG_RUNTIME_DIR), because PLAN §9's gesture verbs take no --lease and the
wire requires a lease_id on every one of them; --lease and $HHSTREAM_LEASE
override it, and a `no_lease` refusal drops the stale entry.
Exit codes are the contract's: a gesture with no lease is 9 and never
reaches the broker, and a compositor failure is 10 with a message that says
the session is still running. `kill` now warns about
`session.container_survivors` -- windows the compositor still shows -- and
distinguishes `null` ("could not ask") from `[]`.
`shot`/`record --output NAME` capture one container through `grim -o`; the
frame socket publishes the main output only, so it cannot do it.
Module (nix/module.nix)
sessions.containers.{enable,max,mode,workspaceBase},
sessions.pointer.{enable,leaseTtl,leaseMax}, rendered into the generated
TOML with §10's key names. hhstream-pointer.service: the operator's account,
supplementary group hhstream, After=/BindsTo= the compositor,
Restart=on-failure, KillMode=process, and the command line §3.4 freezes.
tmpfiles for /run/hhstream plus RuntimeDirectoryPreserve on the broker,
without which restarting the broker deletes the driver's socket out from
under it. The runtime-directory length assertion is untouched.
And ExecStartPost on the compositor, opening its IPC directory to its own
group: Hyprland creates <runtime>/hypr with S_IRWXU, so the broker -- a
different account by design -- could not reach the request or event socket
at all, and degraded silently exactly as it is built to.
Checks (checks/**)
vm-ipc: both sockets at their frozen names, measured against sun_path's 108
bytes, and a socket2 subscriber that receives an openwindow for a window the
test creates. The subscriber is the shipped HyprlandIPC, not a second
implementation: this check exists to prove that this client hears this
compositor.
vm-containers: one hh-* output per session at the container mode, the window
on it, a second window of the same application beside it, an unmatched
window quarantined, grim -o isolating one container, teardown removing the
output and freeing the slot. PLAN experiment 3 is answered: `hyprctl output
create headless` works.
vm-pointer: a version-2 virtual pointer, a warp and a click whose
coordinates the *application* reports, BUSY naming the holder, an expired
lease swept with its held button lifted, and a broker restart that leaves
the lock free, the bookmark intact and the driver reachable.
checks/lib gains the guest the three share, their test-script helpers (no
assertions live there), an event-socket subscriber and a Wayland client that
says where it was clicked -- nothing in nixpkgs both honours
$HHSTREAM_APP_ID and reports pointer events.
Reported, not worked around: the broker reads none of the container or
pointer config (policy.py takes [defaults] and [apps] only), `start` has no
no_container field so --no-container is refused rather than silently ignored,
and nix/hyprland-conf.nix sets input:follow_mouse = 0, which sends pointer
events to the focused window only -- measured, with the cursor at the aimed
pixel and no client told. README.dev.md has the evidence for each.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WQy29x9AfHWyzNd1f7XPGK
220 lines
8.7 KiB
Nix
220 lines
8.7 KiB
Nix
# The test-script helpers the three session checks share: how to run something
|
|
# as the session account, how to call the CLI, how to ask the compositor, and
|
|
# what to dump when an assertion fails.
|
|
#
|
|
# Helpers only. There is not one assertion in this file, deliberately: a shared
|
|
# prelude that asserted things would make each check's own script an incomplete
|
|
# account of what it proves, and the whole point of these scripts is that they
|
|
# can be read top to bottom when one of them goes red.
|
|
{
|
|
hhstream,
|
|
coreutils,
|
|
sessionUser,
|
|
compositorRuntime ? "/run/hypr-stream",
|
|
controlSocket ? "/run/hhstream/control.sock",
|
|
}:
|
|
''
|
|
import json
|
|
import time
|
|
|
|
USER = "${sessionUser}"
|
|
CONTROL = "${controlSocket}"
|
|
CONTROL_DIR = "/run/hhstream"
|
|
COMPOSITOR_RUNTIME = "${compositorRuntime}"
|
|
HHSTREAM = "${hhstream}/bin/hhstream"
|
|
TRUE = "${coreutils}/bin/true"
|
|
FALSE = "${coreutils}/bin/false"
|
|
|
|
# The module pins the compositor's XDG_RUNTIME_DIR; the instance signature
|
|
# under it is the only part not known ahead of time. Root may connect to the
|
|
# IPC socket even though it belongs to `hhstream`. Same shape as
|
|
# vm-hyprland.nix, which asks this for monitors.
|
|
HYPRCTL = (
|
|
"set -eu; "
|
|
f"sig=$(ls -1 {COMPOSITOR_RUNTIME}/hypr | head -n1); "
|
|
f"XDG_RUNTIME_DIR={COMPOSITOR_RUNTIME}"
|
|
" HYPRLAND_INSTANCE_SIGNATURE=$sig hyprctl -j"
|
|
)
|
|
|
|
#: A transient `systemd-run` unit inherits systemd's own minimal PATH, not
|
|
#: the guest's. That is an artefact of how these checks invoke things, not a
|
|
#: property of the system under test: a person's login has the system profile
|
|
#: on PATH, and `hhstream shot --output` looks `grim` up there. Measured, by
|
|
#: a check that failed with the CLI's own "grim is not on PATH, and --output
|
|
#: needs it" -- which is the right message and the wrong environment.
|
|
SYSTEM_PATH = "/run/current-system/sw/bin"
|
|
|
|
|
|
def as_user(command, env=""):
|
|
"""`command` (absolute path plus argv, never a shell) run as USER.
|
|
|
|
A transient unit rather than `su`, because it gives a clean argv with no
|
|
login shell in the middle, and `--pipe --wait` propagates the command's
|
|
own exit status -- which each check proves before anything depends on it.
|
|
"""
|
|
|
|
return (
|
|
"systemd-run --quiet --collect --pipe --wait"
|
|
f" --uid={USER} --setenv=HOME=/home/{USER}"
|
|
f" --setenv=PATH={SYSTEM_PATH} {env} -- {command}"
|
|
)
|
|
|
|
|
|
def background(unit, command, env="", user=None):
|
|
"""A transient unit that keeps running after the call returns.
|
|
|
|
For the programs a check must have running *before* the thing they
|
|
witness happens: the event subscriber, and a window that is not a
|
|
session.
|
|
|
|
No `--collect`: the unit has to stay loaded after it exits, because its
|
|
exit status is part of what is asserted, and a collected unit is
|
|
unloaded the moment it stops.
|
|
|
|
`user=None` means root, which is how the driver already reaches the
|
|
compositor's IPC socket (see HYPRCTL); pass USER for something that
|
|
should be subject to the same permissions an operator has.
|
|
"""
|
|
|
|
who = "" if user is None else f" --uid={user} --setenv=HOME=/home/{user}"
|
|
return (
|
|
f"systemd-run --quiet --unit={unit}{who}"
|
|
f" --setenv=PATH={SYSTEM_PATH} {env} -- {command}"
|
|
)
|
|
|
|
|
|
def compositor_env():
|
|
"""`--setenv` flags that point a Wayland client at this session.
|
|
|
|
The socket name is discovered, never assumed: the compositor binds the
|
|
first free `wayland-N`, and a crashed one leaves `wayland-0` behind.
|
|
"""
|
|
|
|
display = machine.succeed(
|
|
f"cd {COMPOSITOR_RUNTIME} && ls -1 wayland-* | grep -v '[.]lock$' | head -n1"
|
|
).strip()
|
|
assert display, f"no wayland socket in {COMPOSITOR_RUNTIME}"
|
|
return (
|
|
f"--setenv=XDG_RUNTIME_DIR={COMPOSITOR_RUNTIME}"
|
|
f" --setenv=WAYLAND_DISPLAY={display}"
|
|
)
|
|
|
|
|
|
def cli(args):
|
|
"""`hhstream session …` as USER, against the control socket."""
|
|
|
|
return as_user(f"{HHSTREAM} session --socket {CONTROL} {args}")
|
|
|
|
|
|
def cli_json(args, timeout=120):
|
|
"""Run a `--json` verb and parse what it printed. Fails loudly if it did not."""
|
|
|
|
out = machine.succeed(cli(args), timeout=timeout)
|
|
try:
|
|
return json.loads(out)
|
|
except json.JSONDecodeError:
|
|
raise AssertionError(f"not JSON from `session {args}`: {out!r}")
|
|
|
|
|
|
def compositor(resource):
|
|
"""`hyprctl -j <resource>`, parsed. The compositor is the authority here."""
|
|
|
|
return json.loads(machine.succeed(f"{HYPRCTL} {resource}", timeout=120))
|
|
|
|
|
|
def monitor_named(name):
|
|
for entry in compositor("monitors"):
|
|
if entry.get("name") == name:
|
|
return entry
|
|
return None
|
|
|
|
|
|
def wait_for(predicate, timeout, what, interval=1.0):
|
|
"""Poll a *Python* predicate to a deadline, and return its value.
|
|
|
|
`machine.wait_until_succeeds` can only wait on a shell command, which
|
|
forces anything with structure into jq. This is for the waits whose
|
|
condition is a parsed value -- "the client has reported a third button
|
|
event" -- where a shell pipeline would be both unreadable and quietly
|
|
wrong when `grep -c` prints 0 and exits 1.
|
|
|
|
It waits for an *event that must happen*, never for an assertion to come
|
|
good: every caller below asserts after it returns, not inside it.
|
|
"""
|
|
|
|
deadline = time.monotonic() + timeout
|
|
while True:
|
|
value = predicate()
|
|
if value:
|
|
return value
|
|
if time.monotonic() > deadline:
|
|
raise AssertionError(f"timed out after {timeout}s waiting for {what}")
|
|
time.sleep(interval)
|
|
|
|
|
|
def dump(label, session_id=None):
|
|
print(f"########## diagnostics: {label} ##########")
|
|
status, out = machine.execute("hhs-hyprland-diagnostics", timeout=300)
|
|
print(out)
|
|
print(f"----- hhs-hyprland-diagnostics exit {status} -----")
|
|
commands = [
|
|
"systemctl --no-pager --full status hhstream-sessions.service",
|
|
"journalctl --no-pager --boot --lines=200 --unit hhstream-sessions.service",
|
|
"systemctl --no-pager --full status hhstream-pointer.service",
|
|
"journalctl --no-pager --boot --lines=200 --unit hhstream-pointer.service",
|
|
f"ls -la {CONTROL_DIR} /var/lib/hhstream/sessions",
|
|
"ps -eo pid,ppid,pgid,sid,user,stat,comm,args --sort=pid",
|
|
cli("list --all"),
|
|
cli("container"),
|
|
cli("pointer state"),
|
|
]
|
|
if session_id:
|
|
commands += [
|
|
cli(f"status {session_id}"),
|
|
# Every session's captured output, not just the named one: when
|
|
# a pointer event goes to the wrong window, the wrong window's
|
|
# log is the evidence and the named session's is empty.
|
|
cli("list"),
|
|
# The application's own captured output: the only place a failed
|
|
# launch, or a pointer event that never arrived, explains itself.
|
|
cli(f"logs {session_id} --lines 200"),
|
|
]
|
|
for command in commands:
|
|
status, out = machine.execute(f"{command} 2>&1", timeout=180)
|
|
print(f"----- {command} (exit {status}) -----")
|
|
print(out)
|
|
for resource in ("monitors", "workspaces", "clients", "cursorpos"):
|
|
status, out = machine.execute(f"{HYPRCTL} {resource} 2>&1", timeout=180)
|
|
print(f"----- hyprctl {resource} (exit {status}) -----")
|
|
print(out)
|
|
print("########## end diagnostics ##########")
|
|
|
|
|
|
def bring_up(label="the session stack"):
|
|
"""Compositor, then broker, then the socket each exists to serve.
|
|
|
|
`wait_for_unit` alone is not enough for the broker and that is measured,
|
|
not assumed: the unit is `Type=simple` with no readiness protocol, so
|
|
systemd calls it active the instant it has forked. A daemon that exits
|
|
two milliseconds later and is restarted every second passes it. The
|
|
honest test of "it came up" is the socket plus a restart count of zero.
|
|
"""
|
|
|
|
try:
|
|
machine.wait_for_unit("hyprland-headless.service", timeout=300)
|
|
machine.wait_for_file(f"{COMPOSITOR_RUNTIME}/hypr", timeout=120)
|
|
machine.wait_for_unit("hhstream-sessions.service", timeout=180)
|
|
machine.wait_for_file(CONTROL, timeout=120)
|
|
machine.succeed("systemctl is-active hhstream-sessions.service")
|
|
restarts = machine.succeed(
|
|
"systemctl show -p NRestarts --value hhstream-sessions.service"
|
|
).strip()
|
|
assert restarts == "0", (
|
|
f"the broker has restarted {restarts} time(s) already: it is "
|
|
"crash-looping, not running"
|
|
)
|
|
except Exception:
|
|
dump(f"{label} did not come up")
|
|
raise
|
|
''
|