Files
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

33 lines
1.5 KiB
Nix

# The helper programs the checks need inside the guest (and, for the fake
# capture, inside the guest's `captureCommand`). Plain python3/sh scripts from
# `tests/`, put on PATH with their shebangs pointing at the store.
{
runCommandLocal,
python3,
coreutils,
gnugrep,
findutils,
systemd,
}:
runCommandLocal "hhstream-test-tools"
{
nativeBuildInputs = [ python3 ];
# hhs-hyprland-diagnostics runs on a failing guest, where PATH is whatever
# systemd left behind; give it the tools it needs explicitly.
diagPath = "${coreutils}/bin:${gnugrep}/bin:${findutils}/bin:${systemd}/bin";
meta.description = "Fake capture backend and contract asserter for the hhstream checks";
} ''
install -Dm755 ${../../tests/fake_capture.py} $out/bin/hhs-fake-capture
install -Dm755 ${../../tests/assert_stream.py} $out/bin/hhs-assert-stream
install -Dm755 ${../../tests/hyprland_diagnostics.sh} $out/bin/hhs-hyprland-diagnostics
patchShebangs $out/bin
substituteInPlace $out/bin/hhs-hyprland-diagnostics --replace-fail '@diagPath@' "$diagPath"
# A broken helper shows up as a baffling test failure three layers away, so
# prove here that both python programs start and produce what they promise.
$out/bin/hhs-fake-capture --width 8 --height 4 > frame.png
python3 -c 'import struct,sys; d=open("frame.png","rb").read(); assert d[:8]==b"\x89PNG\r\n\x1a\n", d[:8]; assert struct.unpack(">II", d[16:24])==(8,4), d[16:24]'
$out/bin/hhs-assert-stream --help > /dev/null
$out/bin/hhs-hyprland-diagnostics --self-test > /dev/null
''