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
146 lines
4.7 KiB
Nix
146 lines
4.7 KiB
Nix
# checks.<system>.vm-basic -- boot a real machine with the module enabled, point
|
|
# `captureCommand` at a fake capture program, and read the socket.
|
|
#
|
|
# This check is about the module's wiring and the wire contract, not about
|
|
# Hyprland: the fake capture emits one fixed PNG, so "two frames arrived and
|
|
# they are the same image" is a real assertion rather than a coincidence.
|
|
{
|
|
testers,
|
|
hhstream,
|
|
testTools,
|
|
hhsModule,
|
|
width ? 1280,
|
|
height ? 720,
|
|
fps ? 30,
|
|
socketPath ? "/run/hyprland-headless-stream/stream.sock",
|
|
}:
|
|
testers.runNixOSTest {
|
|
name = "hhstream-vm-basic";
|
|
|
|
# KVM is available, so this is a minute or two; cap it so a hang is a failure
|
|
# rather than a wedged builder.
|
|
globalTimeout = 900;
|
|
|
|
nodes.machine = {
|
|
imports = [ hhsModule ];
|
|
|
|
services.hyprland-headless-stream = {
|
|
enable = true;
|
|
# The module declares `package` with no default (see README.dev.md), so the
|
|
# test has to supply the flake's build.
|
|
package = hhstream;
|
|
inherit socketPath;
|
|
frameRate = fps;
|
|
format = "png";
|
|
outputs = [
|
|
{
|
|
name = "HEADLESS-1";
|
|
inherit width height;
|
|
refresh = fps;
|
|
}
|
|
];
|
|
captureCommand = [
|
|
"${testTools}/bin/hhs-fake-capture"
|
|
"--width"
|
|
(toString width)
|
|
"--height"
|
|
(toString height)
|
|
];
|
|
};
|
|
|
|
environment.systemPackages = [
|
|
testTools
|
|
hhstream
|
|
];
|
|
|
|
virtualisation = {
|
|
memorySize = 1024;
|
|
cores = 2;
|
|
diskSize = 3072;
|
|
graphics = false;
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
SOCKET = "${socketPath}"
|
|
ASSERT = "hhs-assert-stream --socket " + SOCKET
|
|
|
|
|
|
def dump(label):
|
|
print(f"########## diagnostics: {label} ##########")
|
|
print(machine.execute("hhs-hyprland-diagnostics")[1])
|
|
|
|
|
|
start_all()
|
|
|
|
with subtest("the module's two units come up"):
|
|
try:
|
|
machine.wait_for_unit("hyprland-headless.service", timeout=120)
|
|
machine.wait_for_unit("hyprland-headless-stream.service", timeout=120)
|
|
except Exception:
|
|
dump("units did not start")
|
|
raise
|
|
|
|
with subtest("the socket exists, owned by the service user, mode 0660"):
|
|
try:
|
|
machine.wait_for_file(SOCKET, timeout=60)
|
|
print(machine.succeed(f"stat -c 'owner=%U group=%G mode=%a type=%F' {SOCKET}"))
|
|
machine.succeed(f"[ \"$(stat -c %a {SOCKET})\" = 660 ]")
|
|
machine.succeed(f"[ \"$(stat -c %U {SOCKET})\" = hhstream ]")
|
|
machine.succeed(f"[ \"$(stat -c %G {SOCKET})\" = hhstream ]")
|
|
machine.succeed(f"[ \"$(stat -c %F {SOCKET})\" = socket ]")
|
|
except Exception:
|
|
dump("socket missing or wrong ownership")
|
|
raise
|
|
|
|
with subtest("the Hello parses, magic is HHS1, size is non-zero"):
|
|
try:
|
|
print(machine.succeed(f"{ASSERT} --frames 1 --timeout 30"))
|
|
except Exception:
|
|
dump("Hello did not parse")
|
|
raise
|
|
|
|
with subtest("two frames arrive, non-empty, byte-identical, matching the Hello"):
|
|
try:
|
|
print(
|
|
machine.succeed(
|
|
f"{ASSERT} --frames 2 --timeout 60"
|
|
" --expect-width ${toString width} --expect-height ${toString height}"
|
|
" --expect-format image/png --expect-fps ${toString fps}"
|
|
" --require-png --identical-frames --min-bytes 1"
|
|
)
|
|
)
|
|
except Exception:
|
|
dump("frames did not satisfy the contract")
|
|
raise
|
|
|
|
with subtest("two clients are served concurrently and independently"):
|
|
try:
|
|
print(
|
|
machine.succeed(
|
|
f"{ASSERT} --frames 3 --timeout 60 --require-png > /tmp/a.log 2>&1 & p1=$!; "
|
|
f"{ASSERT} --frames 3 --timeout 60 --require-png > /tmp/b.log 2>&1 & p2=$!; "
|
|
"wait $p1; r1=$?; wait $p2; r2=$?; "
|
|
"echo '--- client a ---'; cat /tmp/a.log; "
|
|
"echo '--- client b ---'; cat /tmp/b.log; "
|
|
"exit $((r1 + r2))"
|
|
)
|
|
)
|
|
except Exception:
|
|
dump("concurrent clients were not both served")
|
|
raise
|
|
|
|
with subtest("a client dying mid-stream leaves the server serving"):
|
|
try:
|
|
machine.succeed(
|
|
"timeout 5 python3 -c 'import socket;"
|
|
f"s=socket.socket(socket.AF_UNIX);s.connect(\"{SOCKET}\");s.recv(1);s.close()'"
|
|
)
|
|
print(machine.succeed(f"{ASSERT} --frames 2 --timeout 60 --require-png"))
|
|
machine.succeed("systemctl is-active hyprland-headless-stream.service")
|
|
except Exception:
|
|
dump("server did not survive a client dying mid-frame")
|
|
raise
|
|
'';
|
|
}
|