The union of main and the four slices cannot be collected by pytest: an
import-file-mismatch on test_protocol.py (the frame wire's, the broker's) and
test_server.py (the frame server's, the pointer driver's). Per-directory runs
never hit it, so this is what the union run is for.
The tempting fix is --import-mode=importlib, and it is wrong: importlib does not
put a test file's directory on sys.path, which the slices' tests rely on for
sibling imports (from conftest import HANG, from test_ops import RecordingSink).
That trades a collection error for an ImportError. Renaming the two colliding
modules keeps the import behaviour and fixes the actual problem:
tests/pointer/test_server.py -> test_pointer_server.py
tests/sessions/unit/test_protocol.py -> test_broker_protocol.py
tests: 551 passed.
Built in an independent worktree against docs/CONTRACT-sessions.md. Reports its
own slice's verification in its final message; the parent re-runs the union.
Built in an independent worktree against docs/CONTRACT-sessions.md. Reports its
own slice's verification in its final message; the parent re-runs the union.
There is one cursor on this compositor build and every virtual pointer
writes to it, so aiming at a session is a matter of serialising input, not
of binding harder. Two pieces, and the split between them is the point.
`hhstreamd/pointer.py` is the lease: one holder, an idle TTL and a hard cap
on an injected clock, tracked buttons, and the window-local-to-normalised
arithmetic that makes "click 40px into this window" mean something on an
output that is not at the layout origin. Pure, so the expiry tests move
time instead of sleeping.
`hhstream_pointer/` is the driver: its own process because a Wayland client
needs its own connection and a blocked one must not stall the broker. It
holds no lease state -- it is told what to do and does it. The manager is
bound at version 2 and pointers are created with
`create_virtual_pointer_with_output`; a version-1-only manager is reported
and refused rather than quietly aiming at the global layout.
The wlr protocol module is vendored scanner output under `_protocol/`, so a
checkout builds without a code generator; `_protocol/regenerate.py` says how
to refresh it and why pywayland's own scanner entry point cannot be used.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011txKimbdkqPFpq6m8KDELu
The broker reported `workspace: null` and `window: null` for every session
because nothing in it could talk to Hyprland. This is that voice, and the
only place that knows the compositor's wire format: one connection per
request on `.socket.sock` (leading `/` so an argument containing a slash is
never read as output flags, `j/` where JSON is wanted), and a held, blocking
stream on `.socket2.sock`.
Every failure is CompositorUnavailable -- no instance directory, two of them
and no signature, a socket that is gone, a peer that refuses or closes
mid-reply, a reply that is not the JSON it promised, an event stream that
ends. Nothing returns an empty list or a None to stand in for "I could not
ask", because a caller that cannot tell those apart writes a guess into a
session record. Inside the defined shape the parse is forgiving instead:
Hyprland's JSON has changed keys across releases, so a missing key is a
defined value and never a KeyError reaching the broker.
Tests bind real AF_UNIX sockets in a temporary directory laid out the way
Hyprland lays one out and serve canned bytes, so they drive the actual
connect, half-close, read-to-EOF and timeout paths rather than a mock that
would pass while the sockets broke.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MLiQAZCmJf66CEcLx8siYF
A session was a process group, so every application landed on whichever
workspace the compositor happened to show: one session's capture caught
another's windows, and a pointer aimed at one could land in the other.
This is the pure half of the fix. containers.py computes the argv lists
that create a session's container (headless output, numbered workspace
bound to it as default and persistent, an anchored window rule pinning
the session's class there, then the mode) and the one that tears it down,
plus the lowest-free allocator for the 1000+slot band and the
quarantine backstop for windows that match no container. It runs
nothing: no subprocess, no socket, no file, no clock, and no import of
ipc.py, so every decision that can be tested without a compositor is
asserted in a unit test.
Validation is a control, not style: these strings reach a compositor
that acts on them, and a rule body is comma-separated, so a session id
outside [a-z0-9-], a class outside [A-Za-z0-9._+-], a non-positive or
fractional size and a blank quarantine name all raise ValueError naming
the value. Releasing a workspace the allocator never handed out raises
rather than no-opping, because the quiet version hands the same
workspace to two sessions minutes later.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QS2JvrgmvXmimKFcqqDVoa
M0 of the sessions design, wired into the flake and gated by a real check.
What is here now:
- `src/hhstreamd/` — the broker: session registry, lifecycle verbs, process-group
teardown, app allowlist, audit log, idle reaper on CLOCK_BOOTTIME.
- `src/hhstream_session/` — the CLI handlers, registered into the one front door.
- `src/hhstream/cli.py` — `hhstream status|shot|run|record|session …`, so the
frame verbs and the session namespace are one binary.
- `nix/module.nix` — `sessions.*` options and the `hhstream-sessions.service`
unit: the operator's own account (never a service account, because launched
applications should see that account's home), the compositor's group as a
supplementary group (without it a launched GUI client cannot open the Wayland
socket), the generated app allowlist, and `--compositor-runtime-dir` so
applications are handed the compositor's session rather than the broker's.
- `checks/vm-sessions.nix` — 18 subtests on a real compositor in a VM.
Two bugs found by driving it, both fixed:
- BUG-01: launched applications could not reach the compositor at all — the
broker spawned them with its own inherited environment, which names the login
session. `hhstreamd/compositor.py` discovers the socket and builds the child
environment; a directory with no usable socket is a startup refusal, not a
warning.
- BUG-02: `kill` refused to signal a live application and said nothing was
wrong. The identity gate hashed `/proc/<pid>/cmdline`, which every `execve`
replaces — and on NixOS applications are reached through wrapper scripts that
do exactly that. The gate now rests on `starttime` (+ boot id, + session id
where it is immutable) and records command-line drift as evidence of nothing.
KillMode=process is set on the unit on purpose: the default control-group kill
would take the applications down with the broker, which would make adoption and
a broker restart pointless.
`nix build .#checks.x86_64-linux.vm-basic` failed because Hyprland 0.56.2
aborted with `CBackend::create() failed!` on every start. Reading aquamarine
0.15.1 rather than guessing at it, that abort had three independent causes on a
NixOS test machine, and none of them is visible in the journal until
`debug:disable_logs = false` is set -- Hyprland mutes aquamarine, so the abort
is all that survives. checks/lib/gpu-session.nix now supplies all three and
records the evidence for each:
* `-vga virtio`, for a DRM render node. `virtualisation.graphics = false`
still leaves QEMU's default bochs-drm adapter, which gives card0 and no
renderD*. Measured in the guest: `-vga virtio` -> card0 + renderD128;
`-device virtio-gpu-pci` only *adds* a card next to bochs-drm, so it would
need `-vga none` beside it.
* `hardware.graphics.enable`, so Mesa's GBM backends exist at all. Without it
gbm_create_device() fails with "MESA-LOADER: failed to open dri:
/run/opengl-driver/lib/gbm/dri_gbm.so" and aquamarine reports "Cannot open
backend: no allocator available".
* `SEATD_VTBOUND=0`, so libseat's embedded seatd hands out a seat with no VT.
`CHeadlessBackend::drmFD()` returns -1 unconditionally, so the *only*
source of an allocator is the DRM backend, which opens /dev/dri/card0
through libseat -- and the default VT-bound seat needs /dev/tty0, which the
unprivileged service user cannot open.
The diagnostics dump grows a "graphics devices" section (`ls -l /dev/dri`,
`cat /proc/fb`) and a "wayland socket vs WAYLAND_DISPLAY" section, so the next
machine that is missing a render node, or that binds a socket the frame server
is not waiting on, says so in three lines instead of timing out mutely.
vm-basic's `dump()` is now vm-hyprland's, which reports the exit status too.
vm-basic also gained `python3` in the guest: its last subtest shells out to a
python one-liner and had been dying on exit code 127 -- invisible until the
compositor got far enough to reach that subtest.
Neither check passes yet, and the two remaining blockers both live in
nix/module.nix, which this slice may not edit, so they are reported rather
than patched:
* vm-basic stops at "the module's two units come up". The compositor is up
and healthy; the frame server sits in ExecStartPre forever. The module
hardcodes `waylandDisplay = "wayland-0"`, but Hyprland's socket loop is
`// get socket, avoid using 0` over candidates 1..32 (src/Compositor.cpp),
so the session binds wayland-1. Forcing WAYLAND_DISPLAY=wayland-1 in the
guest was verified to carry vm-basic through every other subtest.
* vm-hyprland stops at "the compositor reports the configured headless
output" with "hyprctl never reported a HEADLESS-1 monitor". hyprctl reports
`Monitor Virtual-1` at 1280x800 -- the virtio-gpu output. A HEADLESS-N
output only exists after `hyprctl output create headless`, which the module
never issues; Hyprland's own fallback output is named FALLBACK. The
`monitor = HEADLESS-1, ...` line in hyprland.conf is a rule for a monitor
that is never created.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018fJZYyS4pqxt2FC37JsFYd
Fill in the bodies the skeleton left as NotImplementedError, to docs/CONTRACT.md:
- protocol: the `\n`-terminated JSON Hello and the `<ascii length>\n<payload>`
frame, both directions. Malformed input raises (ValueError for a bad length
prefix, EOFError for a truncated payload), never hangs on endless garbage and
never silently truncates; a huge length prefix is not pre-allocated.
- capture: CommandCapture runs the configured command and reports a missing
binary, a non-zero exit, a timeout and empty output as CaptureError, with the
helper's stderr folded into the message so nothing leaks to the server's own
stdio. The Hello's pixel size is read from the frame's PNG/JPEG header, so no
compositor query is needed and an injected fake command behaves the same.
- server: one capture thread holding only the newest frame plus one thread per
client, which is what drops frames for a slow client instead of queueing
them. Survives a client dying mid-write, keeps the socket up across capture
failures, withholds the Hello until a size is known, replaces a stale socket
file (but never a non-socket one) and publishes it mode 0660.
- client: fetch()/read_stream() and the CLI, with --out suffixing per frame.
--capture-command folds its separated form into `--flag=value` before argparse
sees it, so the contract's default `grim -t png -` can actually be passed: its
tokens start with a dash.
Unit tests under tests/unit cover framing round-trips (including a payload
containing `\n` and a zero-length frame), truncated and garbage prefixes, a
stalled client not blocking a second one, a client dying mid-frame, frames being
dropped rather than queued, and every capture failure mode. A fake capture
command stands in for grim, so nothing needs a compositor or a GPU. They are
deliberately not wired into flake.nix: `checks` belongs to another workstream.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYJ8ZQ5AZaDErYTwXZe7N9
Wires a `checks` output into the flake, one file per check under checks/,
all three asserting docs/CONTRACT.md rather than the implementation:
- unit: pytest over tests/unit/ in the build sandbox, against the
nix/package.nix build. Refuses an empty suite -- pytest exits 0 when
every test was skipped or deselected, so checks/lib/check_report.py
parses the JUnit report and fails on zero collected or zero executed.
- vm-basic: nixosTest with captureCommand pointed at tests/fake_capture.py,
which emits one fixed deterministic PNG. Because the image never changes,
"two frames arrived and they are the same bytes" is an assertion about
the framing rather than a coincidence.
- vm-hyprland: the same machine with no captureCommand override, so grim
captures the real compositor. Deliberately impatient -- bounded timeouts,
no retry loops, and a full diagnostics dump (compositor log, hyprctl
monitors, both journals) before any failure propagates.
tests/assert_stream.py is a second, independent reader of the contract: it
shares no code with hhstream.client, so a framing bug present in both the
server's writer and the shipped client's reader still fails. The unit
suite's negative tests use a `rejects` fixture instead of
pytest.raises(Exception), which an unimplemented stub's
NotImplementedError would otherwise satisfy.
Three defects found in code this branch does not own, recorded in
README.dev.md rather than worked around:
- nix/module.nix has no config side, so neither unit exists and both VM
checks fail at their first wait;
- services.hyprland-headless-stream.package is declared with no default,
against docs/CONTRACT.md;
- src/hhstream/*.py is all stubs, so 66 of 70 unit tests fail.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017YXMoCNxzScTaKNr43GQNz