Files
hyprland-headless-stream-pl…/checks/default.nix
T
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

90 lines
3.8 KiB
Nix

# The flake's `checks` output. One file per check; this is only the wiring.
#
# unit -- pytest over tests/, against the nix/package.nix build
# vm-mcp -- the MCP server over stdio, against a live broker
# vm-stream -- the per-session live stream, with a real HTTP viewer
# vm-basic -- nixosTest with a fake capture backend: module + wire contract
# vm-hyprland -- nixosTest with the real compositor and grim
# vm-sessions -- nixosTest with the real compositor and the session broker
# vm-ipc -- the compositor's IPC sockets, and an event that arrives
# vm-containers -- one output and one workspace per session
# vm-pointer -- the lease, the driver, and a click the application saw
# vm-keyboard -- the uploaded keymap, keyboard focus, and a decoded symbol
# vm-keyboard-de -- the same check with sessions.keyboard.layout = "de"
# vm-stream-firewall -- the stream's port in the guest's own running firewall
#
# What the guests need lives in checks/lib: `test-tools.nix` for the fake
# capture and the contract asserter, `session-tools.nix` for the event
# subscriber and the two input targets, `session-machine.nix` for the guest the
# session checks share, and `session-prelude.nix` for their test-script
# helpers.
#
# `vm-keyboard` and `vm-keyboard-de` are one file twice over, and that is the
# point: `sessions.keyboard.layout` reaches the uploaded keymap only through
# the driver unit's argv, and a single-layout check cannot tell that path from
# a hardcoded `us`. See the header of vm-keyboard.nix.
#
# Run them ONE AT A TIME. Each boots a VM with a software-rendered compositor;
# two at once on a two-core machine make the timing-sensitive assertions flake,
# and a flaky green is worth less than a slow one.
{
pkgs,
self,
system,
}:
let
hhstream = self.packages.${system}.hhstream;
hhstream-mcp = self.packages.${system}.hhstream-mcp;
hhsModule = self.nixosModules.default;
testTools = pkgs.callPackage ./lib/test-tools.nix { };
# The session checks take the same arguments; naming them once keeps a new
# check from being wired up with a different compositor or a different
# package than its neighbours.
sessionArgs = {
inherit hhstream hhsModule testTools;
};
in
{
unit = pkgs.callPackage ./unit.nix { inherit hhstream hhstream-mcp; };
vm-basic = pkgs.callPackage ./vm-basic.nix {
inherit hhstream hhsModule testTools;
};
vm-hyprland = pkgs.callPackage ./vm-hyprland.nix {
inherit hhstream hhsModule testTools;
};
vm-sessions = pkgs.callPackage ./vm-sessions.nix {
inherit hhstream hhsModule testTools;
};
vm-ipc = pkgs.callPackage ./vm-ipc.nix sessionArgs;
vm-containers = pkgs.callPackage ./vm-containers.nix sessionArgs;
vm-pointer = pkgs.callPackage ./vm-pointer.nix sessionArgs;
vm-keyboard = pkgs.callPackage ./vm-keyboard.nix sessionArgs;
vm-keyboard-de = pkgs.callPackage ./vm-keyboard.nix (
sessionArgs // { keyboardLayout = "de"; }
);
# Not a `sessionArgs` consumer: this one is about the module's own options,
# not about the broker or the compositor (see the file's header).
vm-stream-firewall = pkgs.callPackage ./vm-stream-firewall.nix {
inherit hhstream hhsModule testTools;
};
# The session machine again, plus `mcp.enable`, driven over stdio by a
# JSON-RPC client the check writes itself. `sessionArgs` plus the one package
# the others have no reason to carry.
vm-mcp = pkgs.callPackage ./vm-mcp.nix (sessionArgs // { inherit hhstream-mcp; });
# The live stream: `stream enable`, a real HTTP viewer inside the guest, and
# the one thing no in-process test can say -- that a connected viewer moves
# the idle clock. Spends real time on purpose; see the file's header.
vm-stream = pkgs.callPackage ./vm-stream.nix sessionArgs;
}