21 Commits
Author SHA1 Message Date
HermenixandClaude Opus 5 94a1f5988e test(mcp): the http transport, its unit and its token, in a guest
`checks.vm-mcp-http` -- the sibling of `vm-mcp`, on the same session
machine.  That one proves the *surface* over a pipe; this one proves the
two things stdio does not have: a unit systemd supervises, and a
credential on the way in.  So there is one tool call and one resource
read here, just enough to show a request reached the broker through an
authenticated session, and the weight is on the refusals, the state
directory's permissions, and the unit's lifecycle.

**The first subtest is the one that justifies the file.** The server
exits 2 while the authorization table is empty, which leaves a freshly
provisioned machine in a failed state on purpose -- and that trade is
only sound because the unit retries, so the first `token mint` brings it
up with no `systemctl start`. That self-heal lives in
`StartLimitIntervalSec = 0` and nothing in Python can test it. If it
regresses, every machine that enables the option comes up dead and stays
dead, and this is the only thing that would notice.

Also asserted, and each for a reason rather than for coverage: the state
directory is 0700 and owned by the account that mints tokens (which is
also the proof an operator *can* mint one on a machine configured this
way); the table is 0600 and does not contain the token; the port is on
loopback and **not** in the firewall, because neither default may become
implied; the refusals are 401 with an empty body and no echo; two tokens
served by one process see different tool budgets, which is the whole
argument for putting toolsets on a token; a revocation takes effect on
the next request with no restart, because an operator who must restart a
service to lock someone out does not have revocation; and revoking
*every* token does not stop the process, since the startup refusal exists
to catch a forgotten mint rather than to police a deliberate one.

`lib/mcp_http_client.py` is raw JSON-RPC over `urllib` and deliberately
not the SDK's client, for the reason `lib/mcp_client.py` is not either --
the SDK on both ends would agree with itself about a framing and a header
neither side had to get right, and the header is half of what this file
is about. It earned that choice immediately: it is what caught the 307 on
the exact path that the SDK-shaped test client had been following
silently.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KchcvnbfhhZhUHy83YL3Ya
2026-10-12 18:13:52 +00:00
HermenixandClaude Opus 5 7eb9afdfa3 test(mcp): the store, the token verbs, and every way a request is refused
373 unit tests, up from 266.  Three files, split the way the modules are:
`test_mcp_authorizations.py` is standard library and touches no SDK,
`test_mcp_http.py` drives a real ASGI stack, and the additions to
`test_mcp_server.py` are about the command line now that it has
subcommands.

Four of these exist for properties that a refactor breaks silently rather
than loudly, which is the only reason they are worth their length:

* **the file never holds a token.**  A store that started writing the
  secret instead of its digest would pass every functional test here, so
  one test reads the bytes on disk and looks for the token and for a
  usable prefix of it.
* **a concurrent mint is not lost.**  Thirty threads mint into one table
  and all thirty tokens must still verify.  The atomic replace stops a
  torn read; it does nothing about two writers loading the same table and
  the second replacing the first's addition.  Without the flock this
  fails.
* **`--toolsets` before the subcommand survives it.**  argparse copies a
  subparser's namespace over the top-level one, so an ordinary default on
  the subcommand's copy would overwrite the value with `None` and
  `hhstream-mcp --toolsets=frames serve` would quietly serve all
  twenty-one tools.  `SUPPRESS` prevents it and this test notices if it
  goes.
* **a token verb never claims the transport.**  `mint` prints a secret on
  stdout, which on stdio *is* the transport, so `claim_transport` is
  monkeypatched to fail the test if it is ever reached.

The refusal tests assert the absence of information as much as the status
code: an empty body, no echo of the token in body or headers, and
unknown/revoked/expired arriving as one answer byte for byte -- telling
them apart would tell someone who guessed a real id that they had. An
unknown path is a 401 before a 404, so an unauthenticated caller does not
learn what is mounted; the token is checked before the Host, so it does
not learn the allowlist either.

`test_resources_are_not_narrowed_by_a_token` asserts a *limit*, on
purpose: a token scoped to `frames` can still read `hhstream://sessions`,
and that is written down rather than left for someone to discover.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KchcvnbfhhZhUHy83YL3Ya
2026-10-12 18:00:05 +00:00
HermenixandClaude Opus 5 9708154eea test(mcp): count the unnarrowed resources against the listing, not a literal
`--toolsets` has to leave the resources alone, and the subtest that says so
asserted `5` and `3` -- so the stream's two resources turned a correct server
into a red check, which is the second literal in this file the surface outgrew
in one day.

Counted against `uris` and `templates` from the listing subtest instead. That
is the comparison the assertion was always about: not "six", but "as many as
this server lists when nothing is narrowed".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
2026-10-11 23:08:13 +00:00
HermenixandClaude Opus 5 0c06de4ea7 test(mcp): the stream through the MCP layer, in the guest
`vm-mcp` asserted 21 tools and the eight resource URIs by name, which the stream
made stale -- and by name is the point, so the lists move with the surface: 23
tools, `hhstream://streams` among the fixed resources,
`hhstream://sessions/{id}/stream` among the templates.

Its machine now enables `sessions.stream`, because two of those tools and two of
those resources are about streams and with no daemon they could only be shown to
*refuse*.

Two subtests, and the first is the one worth having: a session started over MCP
with `stream: true` has to hand back the URL in `structuredContent`, in the text
a model actually reads, and again from `hhstream://sessions/{id}/stream` -- three
places that must agree, because the URL is the daemon's to name, is never stored,
and a reply assembled from the broker's record alone carries a phrase and no URL.
That is exactly how it went wrong once. The second takes the stream away over
MCP and reads both resources again.

What this does not do is read a frame: bytes off the port are `vm-stream`'s
subject. What it owns is that the phrase reaches an agent at all.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
2026-10-11 22:56:57 +00:00
HermenixandClaude Opus 5 b4abd085cc test(stream): both ends of live.sock, the broker's verbs, and a real viewer in a guest
Three layers, because the stream has three and each one can be wrong on its own.

`tests/live/test_live_control.py` (20 tests) runs `Control` against a fake
capture: the four ops, `attach` idempotent on the phrase, the same phrase aimed
at another output refused, a malformed phrase refused *without the value in the
message*, and `fps` defaulting to the daemon's when the broker sends none.

`tests/sessions/unit/test_stream_verbs.py` (24 tests) runs the broker against a
fake daemon, and its subjects are the decisions rather than the plumbing: no
container output is a refusal and never a fallback to the main output; a
re-`enable` returns the same phrase and a different one is exit 8; a down daemon
turns `attached` false rather than failing a read; the sweep touches a watched
session and leaves an unwatched one alone; teardown detaches before the
container is destroyed.

`tests/unit/test_mcp_*` grow the two tools, the two resources and the three
`session_start` arguments, with the read-only half asserted *absent* as a tool
by name -- re-adding one should be a failure, not a silent widening.

`checks/vm-stream.nix` is the new guest check, and it exists for the two things
none of the above can say:

1. **That `grim` captures a real compositor from inside a unit.** It reads
   actual JPEGs off `/<phrase>/stream.mjpg` with `checks/lib/mjpeg_read.py`, a
   hand-rolled multipart reader that shares no code with the server -- a parser
   that did could not tell you the boundary was wrong. It framed on SOI/EOI
   rather than `Content-Length` for the same reason. This is what caught the
   unit's missing `XDG_RUNTIME_DIR`: `frames: [25827, 25827, 25827]` now, ten
   capture failures and a stream that gave up before.
2. **That a connected viewer moves the idle clock.** That needs the broker's
   real sweep, on a real timer, with a client genuinely still there a minute
   later -- hence `--hold`, and hence a check that spends ~90 seconds twice. The
   negative control runs first, because if the sweep touched an unwatched stream
   the positive case would pass for the wrong reason. Measured in the guest:
   with nobody watching `580s -> 502s` remaining, with a viewer `499s -> 596s`.

It also asserts the phrase is in neither the audit log nor a 404 body, that the
old URL stops serving after `disable`, that `disable` then `enable` rotates it,
that `kill` takes the stream down and leaves the daemon up, and that
`start --stream` yields an id and a URL that serves frames.

No clock is injected anywhere in this check. An injected one would prove the
arithmetic, which the unit tests already do, and not the daemon.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
2026-10-11 22:49:18 +00:00
HermenixandClaude Opus 5 56493721f0 test(mcp): the resource routing, the toolsets, and the guest check for both
46 more unit tests, and `vm-mcp` rewritten around the new split (21 subtests,
up from 14).

`test_mcp_resources.py` is the new file and its subject is what the resource
layer actually decides: which entry a URI resolves to, which query parameters
it will accept, and the argv each read builds. The cases that matter are the
ones a reshuffle would quietly break -- a literal route beating a template
(`hhstream://sessions` is the listing, not a session with a blank id), a
switch parameter becoming a bare flag or nothing at all (`--all=false` is not
something the CLI takes), an undeclared parameter being refused rather than
dropped, a frame's media type being sniffed rather than assumed, and a refusal
being *raised* instead of returned as the body.

One test exists only to stop a future kindness: there must be no resource for
the reconciling container read, because that one writes.

`test_mcp_server.py` grows the protocol-level half -- both listings, a read
that returns JSON, a read that returns a blob, a refused read arriving as
`McpError`, and a toolset selection that narrows the tools while leaving the
resources alone. The tool and toolset tests move with the surface: the
read-only verbs are asserted *absent* by name rather than merely missing, so
re-adding one is a failure instead of a silent widening of what mcp-v2
narrowed.

In the guest, the subtest the whole surface turns on is now measured rather
than described: two reads of `hhstream://sessions/<id>` must NOT move the idle
deadline, and `session_touch` must. It also asks for the same container two
ways and checks the answers agree, reads one output's frame as a blob and
confirms the `shot` tool reports the same geometry, and proves `--toolsets`
makes an omitted tool unreachable and not merely unlisted.

`checks/lib/mcp_client.py` gains `--resources`, `--read` and `--server-arg`,
and exits 3 rather than 2 on a protocol error -- so "the server refused this
read" stays distinguishable from "the server did not answer at all", which is
the distinction that keeps the refusal subtests from passing for the wrong
reason.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
2026-10-11 11:50:12 +00:00
HermenixandClaude Opus 5 fea55eecde test(mcp): the argv each tool builds, the mapping, and the server in a guest
101 unit tests under `tests/unit/` and one new VM check.

The unit suite's subject is the only thing this layer decides: the argv list.
`mcp_fake.FakeCli` is a recording stand-in put where the CLI goes, so every
test can assert on the exact argv a tool handed over -- the `=` form of each
flag, the `--` before each positional, the omission of a flag the caller did
not give. Three tests drive the **real** entry point against a control socket
that does not exist, which proves the dispatch, the capture and the exit-code
mapping against the CLI's actual parser with no daemon standing up: argparse's
exit 2 for a bad `--button`, exit 5 for the unreachable broker, exit 9 for a
gesture with no lease.

`test_mcp_server.py` imports the MCP SDK unconditionally and runs the server
in process over the SDK's memory transport. It is not allowed to skip: the tool
table is stdlib and tested without the SDK, but whether every schema validates
and every name is one the specification allows is a question only the SDK can
answer, and a file that skipped when it was absent would be green in exactly
the build where that mattered. `checks/unit.nix` therefore puts `mcp` in the
test environment and `hhstream-mcp` on PYTHONPATH beside `hhstream`.

`checks/vm-mcp.nix` boots the session machine with `mcp.enable = true` and
drives the real binary over a real pipe with `checks/lib/mcp_client.py` -- raw
JSON-RPC, deliberately not the SDK's client, for the reason
`tests/assert_stream.py` is a second implementation of the frame contract. It
asserts the handshake, the 26-tool listing with its annotations and its two
rules, a call that reaches the live broker, `shot` as image content, the lease
granted/used/returned against the real driver, and exits 9 and 3 arriving as
tool errors.

The geometry assertion in that check is one it got wrong first time and now
records: the published frame is 2560x720 on a guest configured for 1280x720,
because the publisher's default capture takes the whole compositor layout and a
session's container is a second output beside the main one. `shot` with the
container's own `output` is the one that is exactly 1280x720.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
2026-10-11 06:32:55 +00:00
HermenixandClaude Opus 5 5f94833a76 Merge origin/main into feat/keyboard-input: keep both the stream and the
keyboard sides

origin/main brought the session live-stream feature (stage 1): the
`hhstream_live` router, its phrase generator and wordlist, the
`sessions.stream.*` module options with their loopback-vs-openFirewall
assertion and the one firewall port, the `vm-stream-firewall` check, and
`tests/live/`. This branch adds keyboard input: the `key`/`type` ops, the
uploaded XKB keymap, `sessions.keyboard.{layout,model,variant,options}`
and the four `--xkb-*` flags on the driver unit, `vm-keyboard` and
`vm-keyboard-de`, and their docs.

The two features are independent, so every conflict wanted both sides.
Four files, resolved as follows.

checks/default.nix -- both the header list and the attribute set take all
three new checks: `vm-keyboard`, `vm-keyboard-de` (the same file with
`keyboardLayout = "de"`, because the layout reaches the keymap only
through the driver unit's argv) and `vm-stream-firewall`, which stays a
non-`sessionArgs` consumer with main's comment saying why. Neither side's
check list is reduced; the flake now exposes ten.

nix/package.nix -- one `pythonImportsCheck` list with both sides' entries:
`hhstream_pointer.keymap` and the vendored
`virtual_keyboard_unstable_v1` from here, `hhstream_live.server` from
main. The surrounding hunks were not in conflict, so the branch's
xkbcommon dependency and main's wordlist `postFixup` both survive, and
both ran in this merge's `checks.unit` build (`wordlist ok: 7772 words`).

nix/module.nix -- the sole conflict was textual: both sides open a new
sub-option block immediately after `sessions.pointer`. Both blocks are
kept, `keyboard` then `stream`, each with its own closing. Everything
else in the file merged cleanly, so `loopbackBinds`, the
openFirewall-on-loopback assertion and
`networking.firewall.allowedTCPPorts` are present alongside the driver
unit's `--xkb-layout`/`--xkb-model`/`--xkb-variant`/`--xkb-options`.

README.dev.md -- the `checks/` layout listing keeps both entries in the
file's existing order, `vm-keyboard.nix` then `vm-stream-firewall.nix`.

Verified: `nix flake check --no-build` evaluates every output green, and
`nix build .#checks.x86_64-linux.unit` passes -- 977 passed, 2 skipped,
0 failed, over both sides' suites. The VM checks were not run (they boot
a software-rendered compositor and must run one at a time).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PjpHyir6hxyjdw2o1RwQmn
2026-10-11 02:57:55 +00:00
Hermenix 7141900070 module: declare the stream's port, and the one hole it needs
`sessions.stream { port, bind, openFirewall }` -- the piece of stage 3 that
does not need the broker. It exists because a machine had to be able to *reach*
a stream before the rest of the app is settled: the operator asked for the port
to be open on the deployment machine, where the app still runs by hand, and a
bare `networking.firewall.allowedTCPPorts` line in one machine's config is the
wrong place for a fact about this flake.

- `openFirewall` defaults false and is deliberately not implied by
  `sessions.enable`: a live view of the desktop is readable by anyone who can
  reach the port, the phrase in the URL is its only credential, and there is no
  TLS. It opens exactly one port -- the one the option names.
- `bind` defaults to loopback and is *checked*: `openFirewall = true` beside a
  loopback bind is refused, because that is a hole with no service behind it.
- `checks/vm-stream-firewall.nix` boots the module with a configured port that
  is not the module's default, puts listeners on that port and on a neighbour,
  and asserts from a second machine on the same VLAN that the peer reaches the
  configured port and is refused on the other -- while both answer on loopback
  inside the guest, so the refusal is the firewall's doing and not an empty
  socket. The peer is a second machine because a probe from the test driver
  proves nothing: the driver is not on the test VLAN.

Nothing here turns a stream on -- no unit, no phrases, no `session stream`
verbs, which stay stage 2+3 -- and docs/plans/2026-10-04-session-stream-webapp.md
now records which part of its stage 3 landed and why out of order.
2026-10-11 02:22:00 +00:00
HermenixandClaude Opus 5 54dd109dde checks(vm-pointer): the two-warp acquire invalidated a premise, not a property
Found by running vm-pointer after fixing the helper derivation, which is
the only reason it could be found: the heredoc bug meant this check had
not run, so nothing noticed that Stage 2 had broken it. Two bugs hiding
each other.

The subtest "the cursor reaches a session that does not hold focus"
needed the lease holder and the focused window to be different sessions,
and used to get that for free -- the second session's window took focus
when it opened, and `acquire` left it there, because one warp moves the
cursor and not keyboard focus. `pointer acquire` now takes the keyboard
too, so after the acquire the focused window IS the holder's and the
precondition assertion fired:

  this subtest needs the OTHER session focused; ['hh-target-epoqmb'] is

The property is still worth proving, so it is still proved: the premise
is now arranged with one `hyprctl dispatch focuswindow` on the other
session. That is SETUP and not the thing under test -- what is measured
is which client the compositor hands the warp to, which is unaffected by
how focus came to be where it is. Asserting "acquire takes focus" here
as well would make the subtest about the acquire rather than about
routing, and vm-keyboard already asserts that against both layouts.

Re-run, and the discriminator is intact:

  nix build --no-link -L .#checks.x86_64-linux.vm-pointer
    test script finished in 181.53s   (12/12, exit 0)

  the compositor's focused window belongs to: ['hh-target-qnly47']
  aimed at target-awyant: it reports [..., (747.0, 267.0)]
  focused is  target-qnly47: it reports []

The warp went to the session it was aimed at and the focused one was
told nothing, which is what this check exists to catch.

One behavioural consequence of the two-warp acquire, visible in that
same log and worth knowing: the focus nudge is delivered to the client
as a real motion. `[(299.0, 521.88), (299.0, 519.0), ...]` is the nudge
and then the target, about 3 px apart, so an application sees a small
cursor jiggle on every acquire.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GhNPM6rGcuzxocM1nATnuM
2026-10-05 01:32:58 +00:00
HermenixandClaude Opus 5 a6a4094e6a Stage 3: vm-keyboard, and the helper derivation that never built
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
2026-10-04 20:23:14 +00:00
HermenixandClaude Opus 5 7890315cf6 checks(unit): xkbcommon in the suite's env, and the two-warp acquire
Two gaps found by running more than the gate command.

`checks/unit.nix` builds its own `python3.withPackages` and had only
pytest and pywayland in it, so `nix build .#checks.unit` would have
collected tests/pointer/test_keymap.py and failed on the import. The
dev shell has xkbcommon through nix/package.nix and the gate command
therefore never noticed. It is not an optional dependency: that file
compiles a real `us` keymap and a real `de` one, because only xkbcommon
can say `é` is unmappable on `us` and that `@` on `de` needs a
level-three mask.

And two integration tests asserted acquire's single warp, which is now
two. They are the whole-gesture trace and the bookmark-survives-a-
restart case, and both now assert the pair -- with the restored
position as the SECOND warp, since the bookmark is where the cursor is
left and the reverse order would restore every session a few pixels
off.

  nix develop -c python -m pytest tests -q
  905 passed in 65.91s

  nix build --no-link .#checks.x86_64-linux.unit
  903 passed, 2 skipped in 73.24s
  unit suite: 905 collected, 903 executed, 0 failed, 0 errored, 2 skipped

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GhNPM6rGcuzxocM1nATnuM
2026-10-04 04:16:46 +00:00
HermenixandClaude Opus 5 e6f4c3bb3f Stage 1 review fixes, and Stage 2: the broker, the CLI and the module
The Stage 1 review (docs/reviews/2026-10-04-stage1-review.md, verdict
yes-with-fixes) found a real bug, and it was the kind Stage 2 would have
cemented. All five findings:

(1) HIGH, and reproduced before fixing: `key` resolved the action and
    then used only its `code`. So `keyboard key A` sent a bare code 30
    and the window received `a`; on `de`, `at` lost its level-three mask
    and typed `q`. `type` was the only path that used the mask, which is
    why every `type` test stayed green. `key` now sends
    modifiers(baseline | mask) before the down and restores the baseline
    on the up -- the one-character `type` sequence -- and `Shift_L`
    keeps its key-then-mask order, which is the other path on purpose.

    The same hole aliased two names onto one keycode: `down A` then
    `down a` recorded both and pressed 30 twice, Hyprland dropped the
    second, and the held set lied until the lease ended. A second name
    for a code already down is now refused.

(2) HIGH: the shutdown comment claimed hyprland-conf.nix sets
    input:virtualkeyboard:release_pressed_on_close. It did not. The line
    is there now, with the note that it releases keys and still never
    clears a mask -- which is why release_all zeroes the mask on every
    path we control rather than relying on it.

(3) MEDIUM: nothing would have noticed the keymap upload stopping. A
    `main` that connected and listened without uploading passed every
    test in the tree. Now asserted on the real sink: uploaded once,
    before `listen` (one shared ordering log across both stand-ins), the
    payload NUL-terminated with `size == len(utf8) + 1` read back
    through the fd, format 1, one terminator not two, and modifiers(0)
    straight after.

(4) LOW: `key` up now forgets the name only after a successful send,
    like `button` -- otherwise a raise between the two leaves us
    believing a key is up that the compositor still has down, and
    release_all will not try again.

(5) LOW: `\r` no longer aliases to Return (CRLF would have become two
    newlines silently), and an empty layout is refused -- xkbcommon
    compiles "" as the same keymap as `us`, so `--xkb-layout ''` looked
    configured and typed `us`.

Several of the review's named false passes are closed too: Control's
mask is compared against mod_get_index("Control") rather than merely
"not Shift's"; the keymap text assertion names pc_us_inet/pc_de_inet
instead of substring-matching "us"; the capital-under-Control case
asserts the whole sequence; the exit-code mirror is compared against
hhstreamd.protocol; and the module's defaults are read out of
nix/module.nix rather than asserted against themselves.

Stage 2 proper:

  * broker verbs keyboard.key / keyboard.type, both in the mutation set,
    both through _refresh (so they refresh the lease and, like every
    pointer verb, do NOT count as activity)
  * the driver's `kind` token mapped: a bad keysym or character is
    invalid_argument (exit 2), a missing keyboard global stays
    driver_refused (exit 10). The 4096-scalar cap and the shape checks
    are broker-side, because only a broker-side invalid_argument is 2
  * keys[] on pointer.state, keys_lifted[] on pointer.release and on
    pointer_lease_timeout, one release_all for both halves
  * CLI `session keyboard type|key|down|up`, reusing the pointer lease
    and its cache; `type` takes one raw argument and interprets nothing;
    the audit records a character count and never the text
  * sessions.keyboard.{layout,model,variant,options} on the unit's argv,
    layout defaulting to "us" with a type that refuses a comma. NO
    [keyboard] TOML table: hhstreamd reads that file and the driver is a
    different unit, so it would be a setting with no effect
  * CONTRACT-sessions.md bumped to v3; README.dev.md item 3 and
    vm-pointer.nix's header corrected (both still said the conf ships
    follow_mouse = 0 and that the keyboard work would choose)

And the operator decision that acquire grabs both devices: it now sends
two warps a real pixel apart, because one warp onto an idle cursor moves
the cursor and not keyboard focus. follow_mouse_threshold = 0 is set
explicitly in hyprland-conf.nix since the second warp depends on it,
`dispatch focuswindow` is the fallback when the nudge cannot be sent,
and the reply and audit carry which mechanism ran. The acquire test
asserts the pair and that they floor to different pixels -- a test that
only saw wl_pointer.enter would pass while the first keystroke went to
the wrong window.

  nix develop -c python -m pytest tests/pointer tests/sessions/unit -q
  605 passed in 27.11s

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GhNPM6rGcuzxocM1nATnuM
2026-10-04 04:11:24 +00:00
HermenixandClaude Opus 5 de408e4b7f the surface: CLI verbs, the module's options, and three checks the compositor votes in
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
2026-10-03 06:58:44 +00:00
Hermenix 20b2aee109 unit check: run the whole tests/ tree, not just tests/unit
The check took ../tests/unit alone, so the broker's, the pointer driver's and the
sessions suites were collected by no check at all -- 432 of 551 tests ran only
when someone happened to enter the dev shell. It now takes ../tests, which
surfaced two real defects in the harness rather than in the code:

- tests/sessions/integration/test_lifecycle.py locates the repository by looking
  upward for a pyproject.toml, which a build has no reason to contain; it raised
  at import and took the whole run down as a collection error. The check now
  copies the marker in, which is what the test documents it needs.

- That file also REPLACED PYTHONPATH for the daemon it spawns instead of
  prepending to it. In a checkout src/ is the package, so it worked; under a
  build it discarded the package under test, and 'python -m hhstreamd' died at
  startup with an ImportError -- reported as a daemon failure on every test in
  the file. Prepending is the fix, and the right behaviour anywhere.

pywayland joins the test environment because the pointer driver imports it.

unit: 551 collected, 550 passed, 1 skipped (a deliberate skip).
2026-10-02 18:14:48 +00:00
Hermenix e8b3855a05 move every live default to /run/hypr-stream, and resolve the slices' contract gaps
Slice A renamed the runtime directory in the module, but the old path was still
live in the code and checks it does not own, so the VM gates pointed at a
directory the module no longer creates. This moves the 21 remaining live
occurrences (client/server defaults, the unit tests that pin them, all three VM
checks, the diagnostics script, both READMEs) and deliberately leaves the three
mentions that are history rather than configuration: the plan's problem
statement, module.nix's note about the previous name, and cli.py's explanation
for spelling its default out.

Also here: docs/CONTRACT-sessions.md is now v2 with every gap the four slices
reported resolved as a decision (Monitor.id, stable_id, pid -1, Event.data,
mark(), the quarantine argv type, the corrected wlr XML path, and the state
dir/frame socket rows), and docs/CONTRACT.md is v2 because its documented socket
default moved -- wire format unchanged.

Two comments that stated the old, wrong diagnosis (a 'misnamed' IPC socket) now
state the measured one: the event socket did not fit in sun_path.
2026-10-02 18:11:46 +00:00
HermenixandClaude Opus 5 7a81f9f334 checks/vm-sessions: size the negative control's window for its own cleanup
`a session touched inside the window is not reaped` was racing itself. The
idle window restarts at the *last* touch, so everything the subtest does
after the loop -- the `status --json` round trip, `kill -0`, and the `kill`
that clears the session away -- has to finish inside one whole window. With
`--idle-timeout 6s` and a `systemd-run --wait` round trip costing several
seconds in this guest, it did not: the session was reaped 6.3 s after the
last touch, legitimately, and the cleanup `kill` arrived ~13.5 s after it
and returned 4 ("not in a usable state"). The daemon was right and the test
was wrong.

The window is now 45 s, which is the margin the cleanup gets. The assertion
is unchanged in meaning and stricter in degree: nine touches 15 s apart --
a third of a window -- keep the session alive for 135 s, three whole
windows of real time, so a `touch` that did not reset the deadline would
have let the reaper fire two windows before the loop ended. Nothing in the
cleanup stamps activity (`registry.touch` has exactly one caller,
`manager.touch`), so the margin is slack and not a hidden touch.

Two details keep it honest rather than lucky: the loop ends with a touch
instead of a trailing sleep, so the cleanup gets a whole window and not a
window less one gap; and it runs under `set -e`, so a `touch` that fails --
exit 4 against an already-reaped session -- fails the loop where it happens
instead of being swallowed by the sleep that used to end each iteration.

Verified both ways: the check passes (258 s; cleanup finished 4.1 s after
the last touch, against the 45 s window), and with `manager.touch`
temporarily not calling `registry.touch` it goes red here, on the touch
that follows the reap, with the diagnostics dump naming the failure mode.
That break is reverted.

The positive control (`the idle reaper fires for real`, 5 s) needs no such
margin and is unchanged: it waits for `reaped`, which is terminal and held
for the tombstone TTL, so time passing only confirms it, and it runs no
cleanup that needs a usable session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F8R9yNgHeHMnY4nDQwaLtu
2026-10-01 12:49:18 +00:00
Hermenix 30f456c07e integrate the session broker: one CLI, a module unit, and a VM check
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.
2026-10-01 12:23:16 +00:00
HermenixandClaude Opus 5 6510e315d4 module: make outputs monitor rules for real connectors, and own the seat flag
A machine running this module has a GPU. aquamarine's headless backend has
no allocator of its own -- `CHeadlessBackend::drmFD()` returns -1 and
`CBackend::start()` takes the allocator from the first backend with a drm fd
-- so the session always rides on the DRM backend and always has the host's
own connectors. `HEADLESS-1` is a name no connector will ever have, which
made the shipped default a monitor rule Hyprland silently ignored, and made
`vm-hyprland`'s assertion on that name unsatisfiable.

`outputs` now means "monitor rules applied to whatever outputs the machine
has". `name` is a regex against the real connector names and defaults to the
empty string -- Hyprland's own wildcard form, as in its shipped
`monitor=,preferred,auto,1` -- so `enable = true` alone gives a session at a
known size on any host. Nothing else about the option changed.

SEATD_VTBOUND=0 moves from checks/lib/gpu-session.nix into the compositor
unit, where it belongs: libseat finds no seatd socket and no logind session
for a system service, falls back to its embedded seatd, and that seat is
VT-bound by default -- so it opens /dev/tty0, which the service user cannot,
and every device open is refused. That is true on any host, not just in the
test. gpu-session.nix keeps only the two things that really are the test
machine's business: a render node and Mesa.

vm-hyprland now asserts over `hyprctl -j monitors` that at least one monitor
exists at the configured mode, with no monitor name anywhere in the check.
It also gains a wallpaper, because `--reject-blank` could not otherwise mean
anything: the session the module configures by default is a flat black
field, which grim captures as an all-zero 1280x720 RGBA PNG of exactly 3653
bytes -- `blank_png_size()` to the byte. Runs that passed that assertion were
reading Hyprland's startup notification overlay, which expires after about
fifteen seconds. With `misc:force_default_wallpaper` on, the frame is 85267
bytes with all 921600 pixels non-zero and is byte-identical at +15s, +30s and
+60s.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M5GEju6XhoRXDWvEiaAX2r
2026-09-28 21:51:24 +00:00
HermenixandClaude Opus 5 a37b3dd485 checks: give both VM machines a virtio GPU, and say why when it is not enough
`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
2026-09-28 12:28:01 +00:00
HermenixandClaude Opus 5 75a05cd72f tests: checks.{unit,vm-basic,vm-hyprland} + the harness behind them
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
2026-09-28 05:25:37 +00:00