Files
hyprland-headless-stream-pl…/tests/live/test_live_phrase.py
T
Hermenix 9744d35945 feat(live): one port, a router, and a phrase per session (stage 1)
The session-stream web app: a single HTTP listener (9988) that serves a page
per enabled session, keyed by a spoken phrase. Off by default, so a stream
exists only for the sessions it was enabled on.

  src/hhstream_live/phrase.py     four EFF-large words + a 5-char base-36 tail
                                  (~77.5 bits); the phrase is the password
  src/hhstream_live/publisher.py  one capture thread + one frame slot per
                                  output; one slot/no queue; capture paused at
                                  zero viewers
  src/hhstream_live/server.py     the router: /, /<phrase>/, /stream.mjpg,
                                  /frame.jpg, /status.json; unknown phrase is
                                  an empty 404, rate-limited
  src/hhstream_live/pages.py      the built-in dark pages (no CDN, no build)
  src/hhstream_live/__main__.py   hhstream-live serve|phrase, standalone

The root page is a form, never a list: the phrase is known only by whoever
enabled the stream. Transport is MJPEG (multipart/x-mixed-replace), reusing
the JPEG grim already produces. Not yet wired to the broker -- that is
stage 2. Tests: tests/live (51).
2026-10-06 13:32:00 +00:00

64 lines
1.9 KiB
Python

"""The phrase: shape, entropy, and the rejection of anything unusable."""
from __future__ import annotations
import re
import pytest
from hhstream_live import phrase
SHAPE = re.compile(r"^[a-z]+(-[a-z]+){3}-[a-z0-9]{5}$")
def test_generated_phrase_has_the_agreed_shape():
for _ in range(50):
generated = phrase.generate()
assert SHAPE.match(generated), generated
head, _, tail = generated.rpartition("-")
assert len(tail) == 5
assert all(word in phrase.words() for word in head.split("-"))
def test_entropy_is_what_the_plan_claims():
# Four EFF-large words plus a five-character base-36 tail, ~77.5 bits.
assert phrase.entropy_bits() > 75
def test_wordlist_is_the_eff_large_list():
words = phrase.words()
assert len(words) == 7776
assert len(set(words)) == 7776
assert "abacus" in words
def test_generate_is_not_reproducible_from_a_seed():
# SystemRandom/secrets: seeding the module RNG must not pin the output.
import random
random.seed(1234)
first = phrase.generate()
random.seed(1234)
second = phrase.generate()
assert first != second
def test_normalize_lowercases_and_trims():
assert phrase.normalize(" Amber-Otter-7K2 ") == "amber-otter-7k2"
def test_validate_accepts_a_good_phrase_and_returns_the_normalized_form():
assert phrase.validate("Amber-Otter-Lantern-7K2QP") == "amber-otter-lantern-7k2qp"
@pytest.mark.parametrize("bad", ["", "single", "two-tokens", "has space-phrase-x",
"dash--double-phrase", "-leading-hyphen",
"trailing-hyphen-", "under_score-in-phrase"])
def test_validate_rejects_a_phrase_that_is_not_the_shape(bad):
with pytest.raises(ValueError):
phrase.validate(bad)
def test_validate_rejects_an_overlong_phrase():
with pytest.raises(ValueError):
phrase.validate("-".join(["averyverylongword"] * 8))