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
75 lines
2.0 KiB
Nix
75 lines
2.0 KiB
Nix
# checks.<system>.unit -- the Python unit suite from tests/unit/, run against the
|
|
# package built by nix/package.nix, inside the build sandbox.
|
|
#
|
|
# nix/package.nix sets doCheck = false deliberately, so this is the only place
|
|
# the suite runs in a build.
|
|
{
|
|
lib,
|
|
runCommand,
|
|
python3,
|
|
hhstream,
|
|
}:
|
|
let
|
|
pytestEnv = python3.withPackages (ps: [ ps.pytest ]);
|
|
|
|
# Only the suite itself, so an editor's droppings or a local .pytest_cache
|
|
# cannot change the derivation's hash.
|
|
testSrc = lib.cleanSourceWith {
|
|
name = "hhstream-unit-tests";
|
|
src = ../tests/unit;
|
|
filter =
|
|
path: type:
|
|
let
|
|
base = baseNameOf (toString path);
|
|
in
|
|
!(type == "directory" && (base == "__pycache__" || base == ".pytest_cache"))
|
|
&& !lib.hasSuffix ".pyc" base;
|
|
};
|
|
in
|
|
runCommand "hhstream-unit"
|
|
{
|
|
nativeBuildInputs = [ pytestEnv ];
|
|
passthru.testSrc = testSrc;
|
|
meta.description = "hhstream unit tests (pytest)";
|
|
} ''
|
|
cp -r ${testSrc} suite
|
|
chmod -R u+w suite
|
|
|
|
# The package is an application, so its library is not on the default path:
|
|
# point PYTHONPATH at what nix/package.nix installed. Importing it here rather
|
|
# than letting pytest do it makes a packaging problem distinguishable from a
|
|
# test failure.
|
|
export PYTHONPATH=${hhstream}/${python3.sitePackages}
|
|
export PYTHONDONTWRITEBYTECODE=1
|
|
export HOME=$PWD
|
|
python3 -c 'import hhstream; print("testing hhstream", hhstream.__version__, "from", hhstream.__file__)'
|
|
|
|
set +e
|
|
pytest suite \
|
|
--color=no -rf -q \
|
|
--junit-xml=report.xml \
|
|
-p no:cacheprovider \
|
|
--strict-markers \
|
|
--strict-config
|
|
pytest_rc=$?
|
|
set -e
|
|
|
|
echo
|
|
set +e
|
|
python3 ${./lib/check_report.py} report.xml
|
|
report_rc=$?
|
|
set -e
|
|
|
|
if [ "$report_rc" -eq 1 ]; then
|
|
echo "unit check: the suite is empty or its report is unusable -- failing." >&2
|
|
exit 1
|
|
fi
|
|
if [ "$report_rc" -ne 0 ] || [ "$pytest_rc" -ne 0 ]; then
|
|
echo "unit check: the suite ran but did not pass (pytest exit $pytest_rc)." >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p $out
|
|
cp report.xml $out/junit.xml
|
|
''
|