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
158 lines
5.2 KiB
Nix
158 lines
5.2 KiB
Nix
# checks.<system>.vm-hyprland -- the real one. Same machine as vm-basic, but no
|
|
# `captureCommand` override, so the server captures the actual headless
|
|
# compositor through grim.
|
|
#
|
|
# This is the check expected to be flaky, so it is deliberately impatient: every
|
|
# wait has a bounded timeout, nothing is retried in a loop, and any failure dumps
|
|
# the compositor's log and `hyprctl monitors` before it propagates. A flake you
|
|
# can read is worth more than a flake that eventually goes green.
|
|
{
|
|
testers,
|
|
hhstream,
|
|
testTools,
|
|
hhsModule,
|
|
hyprland,
|
|
grim,
|
|
width ? 1280,
|
|
height ? 720,
|
|
fps ? 30,
|
|
socketPath ? "/run/hyprland-headless-stream/stream.sock",
|
|
}:
|
|
testers.runNixOSTest {
|
|
name = "hhstream-vm-hyprland";
|
|
|
|
globalTimeout = 1800;
|
|
|
|
nodes.machine = {
|
|
imports = [ hhsModule ];
|
|
|
|
services.hyprland-headless-stream = {
|
|
enable = true;
|
|
package = hhstream;
|
|
hyprlandPackage = hyprland;
|
|
inherit socketPath;
|
|
frameRate = fps;
|
|
format = "png";
|
|
outputs = [
|
|
{
|
|
name = "HEADLESS-1";
|
|
inherit width height;
|
|
refresh = fps;
|
|
}
|
|
];
|
|
# No captureCommand: the module's default (grim) is the point of this check.
|
|
};
|
|
|
|
# hyprctl and grim are here for the diagnostics dump and for the manual
|
|
# cross-check below, not for the code path under test.
|
|
environment.systemPackages = [
|
|
testTools
|
|
hhstream
|
|
hyprland
|
|
grim
|
|
];
|
|
|
|
# The compositor needs more room than the fake capture did, and its software
|
|
# renderer wants a CPU. There is still no GPU: Hyprland runs on its headless
|
|
# backend over llvmpipe.
|
|
virtualisation = {
|
|
memorySize = 2048;
|
|
cores = 2;
|
|
diskSize = 4096;
|
|
graphics = false;
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
SOCKET = "${socketPath}"
|
|
WIDTH, HEIGHT = ${toString width}, ${toString height}
|
|
|
|
|
|
def dump(label):
|
|
print(f"########## diagnostics: {label} ##########")
|
|
status, out = machine.execute("hhs-hyprland-diagnostics", timeout=120)
|
|
print(out)
|
|
print(f"########## end diagnostics (exit {status}) ##########")
|
|
|
|
|
|
start_all()
|
|
|
|
with subtest("the compositor unit comes up"):
|
|
try:
|
|
machine.wait_for_unit("hyprland-headless.service", timeout=180)
|
|
except Exception:
|
|
dump("hyprland-headless.service did not start")
|
|
raise
|
|
|
|
with subtest("the compositor reports the configured headless output"):
|
|
try:
|
|
# Proves the compositor is really running a 1280x720 HEADLESS-1
|
|
# before we blame the capture for a wrong-sized frame.
|
|
out = machine.succeed("hhs-hyprland-diagnostics", timeout=120)
|
|
print(out)
|
|
assert "HEADLESS-1" in out, (
|
|
"hyprctl never reported a HEADLESS-1 monitor; see the dump above"
|
|
)
|
|
assert f"{WIDTH}x{HEIGHT}" in out, (
|
|
f"hyprctl never reported a {WIDTH}x{HEIGHT} mode; see the dump above"
|
|
)
|
|
except Exception:
|
|
dump("compositor output not as configured")
|
|
raise
|
|
|
|
with subtest("the frame server unit comes up and publishes the socket"):
|
|
try:
|
|
machine.wait_for_unit("hyprland-headless-stream.service", timeout=180)
|
|
machine.wait_for_file(SOCKET, timeout=120)
|
|
except Exception:
|
|
dump("frame server did not publish the socket")
|
|
raise
|
|
|
|
with subtest("grim can capture the session at all"):
|
|
# Separates "grim cannot see the compositor" from "the server is wrong",
|
|
# which are the two failures that look identical from the socket.
|
|
try:
|
|
print(
|
|
machine.succeed(
|
|
"systemd-run --pipe --wait --uid=hhstream"
|
|
" --setenv=XDG_RUNTIME_DIR=/run/user/$(id -u hhstream)"
|
|
" grim -t png /tmp/direct.png 2>&1 || true",
|
|
timeout=120,
|
|
)
|
|
)
|
|
print(machine.execute("stat -c '%s bytes' /tmp/direct.png")[1])
|
|
except Exception:
|
|
dump("direct grim capture failed")
|
|
raise
|
|
|
|
with subtest("a frame off the socket is a real PNG of the configured size"):
|
|
try:
|
|
print(
|
|
machine.succeed(
|
|
f"hhs-assert-stream --socket {SOCKET} --frames 1 --timeout 60"
|
|
f" --expect-width {WIDTH} --expect-height {HEIGHT}"
|
|
" --expect-format image/png --require-png --reject-blank",
|
|
timeout=180,
|
|
)
|
|
)
|
|
except Exception:
|
|
dump("frame off the socket failed the PNG assertions")
|
|
raise
|
|
|
|
with subtest("the stream keeps producing frames"):
|
|
try:
|
|
print(
|
|
machine.succeed(
|
|
f"hhs-assert-stream --socket {SOCKET} --frames 3 --timeout 60"
|
|
f" --expect-width {WIDTH} --expect-height {HEIGHT}"
|
|
" --require-png --reject-blank",
|
|
timeout=240,
|
|
)
|
|
)
|
|
machine.succeed("systemctl is-active hyprland-headless-stream.service")
|
|
except Exception:
|
|
dump("the stream stopped after the first frame")
|
|
raise
|
|
'';
|
|
}
|