test(stream): both ends of live.sock, the broker's verbs, and a real viewer in a guest

Three layers, because the stream has three and each one can be wrong on its own.

`tests/live/test_live_control.py` (20 tests) runs `Control` against a fake
capture: the four ops, `attach` idempotent on the phrase, the same phrase aimed
at another output refused, a malformed phrase refused *without the value in the
message*, and `fps` defaulting to the daemon's when the broker sends none.

`tests/sessions/unit/test_stream_verbs.py` (24 tests) runs the broker against a
fake daemon, and its subjects are the decisions rather than the plumbing: no
container output is a refusal and never a fallback to the main output; a
re-`enable` returns the same phrase and a different one is exit 8; a down daemon
turns `attached` false rather than failing a read; the sweep touches a watched
session and leaves an unwatched one alone; teardown detaches before the
container is destroyed.

`tests/unit/test_mcp_*` grow the two tools, the two resources and the three
`session_start` arguments, with the read-only half asserted *absent* as a tool
by name -- re-adding one should be a failure, not a silent widening.

`checks/vm-stream.nix` is the new guest check, and it exists for the two things
none of the above can say:

1. **That `grim` captures a real compositor from inside a unit.** It reads
   actual JPEGs off `/<phrase>/stream.mjpg` with `checks/lib/mjpeg_read.py`, a
   hand-rolled multipart reader that shares no code with the server -- a parser
   that did could not tell you the boundary was wrong. It framed on SOI/EOI
   rather than `Content-Length` for the same reason. This is what caught the
   unit's missing `XDG_RUNTIME_DIR`: `frames: [25827, 25827, 25827]` now, ten
   capture failures and a stream that gave up before.
2. **That a connected viewer moves the idle clock.** That needs the broker's
   real sweep, on a real timer, with a client genuinely still there a minute
   later -- hence `--hold`, and hence a check that spends ~90 seconds twice. The
   negative control runs first, because if the sweep touched an unwatched stream
   the positive case would pass for the wrong reason. Measured in the guest:
   with nobody watching `580s -> 502s` remaining, with a viewer `499s -> 596s`.

It also asserts the phrase is in neither the audit log nor a 404 body, that the
old URL stops serving after `disable`, that `disable` then `enable` rotates it,
that `kill` takes the stream down and leaves the daemon up, and that
`start --stream` yields an id and a URL that serves frames.

No clock is injected anywhere in this check. An injected one would prove the
arithmetic, which the unit tests already do, and not the daemon.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
This commit is contained in:
HermenixandClaude Opus 5 committed 2026-10-11 22:49:18 +00:00
1 parent 5f5726c02e
commit b4abd085cc
10 files changed
+1626 -7

No files matched your search

+47 -1
View File
@@ -42,11 +42,13 @@ EXPECTED_FIXED = {
"hhstream://sessions",
"hhstream://pointer",
"hhstream://containers",
"hhstream://streams",
"hhstream://screen",
}
EXPECTED_TEMPLATES = {
"hhstream://sessions/{id}{?events}",
"hhstream://sessions/{id}/logs{?lines}",
"hhstream://sessions/{id}/stream",
"hhstream://outputs/{name}",
}
@@ -76,7 +78,8 @@ def test_a_template_is_exactly_an_entry_with_a_capture():
def test_the_three_reads_the_activity_rule_names_say_so_themselves():
"""The rule has to be where it is read, and these are read, not called."""
for name in ("sessions", "session", "session-logs", "pointer", "containers"):
for name in ("sessions", "session", "session-logs", "pointer", "containers",
"streams", "session-stream"):
description = resources.BY_NAME[name].description
assert "does NOT reset" in description, name
assert "`session_touch`" in description, name
@@ -109,6 +112,7 @@ def test_each_fixed_resource_runs_the_verb_it_names(read):
"hhstream://sessions": ["session", "list", "--json"],
"hhstream://pointer": ["session", "pointer", "state", "--json"],
"hhstream://containers": ["session", "container", "--json"],
"hhstream://streams": ["session", "stream", "list", "--json"],
}
for uri, argv in cases.items():
_, calls = read(uri, stdout=mcp_fake.reply(ok=True))
@@ -290,6 +294,48 @@ def test_a_refused_capture_carries_the_cli_s_own_words(read):
assert "hh-gone" in str(caught.value)
# ── the stream ─────────────────────────────────────────────────────────────
def test_one_session_s_stream_reads_through_its_own_route(read):
_, calls = read("hhstream://sessions/foot-abc/stream", stdout=mcp_fake.reply(ok=True))
assert calls == [["session", "stream", "status", "--json", "--", "foot-abc"]]
def test_the_stream_routes_do_not_collide_with_the_logs_route():
"""Three templates under `sessions/{id}`; each must resolve to its own."""
assert resources.resolve("hhstream://sessions/x")[0].name == "session"
assert resources.resolve("hhstream://sessions/x/logs")[0].name == "session-logs"
assert resources.resolve("hhstream://sessions/x/stream")[0].name == "session-stream"
def test_reading_a_stream_never_enables_one(read):
"""The read is `status`, not `enable` -- switching one on is a tool."""
_, calls = read("hhstream://sessions/x/stream", stdout=mcp_fake.reply(ok=True))
assert "enable" not in calls[0]
_, calls = read("hhstream://streams", stdout=mcp_fake.reply(ok=True))
assert "enable" not in calls[0]
def test_both_stream_reads_warn_that_the_url_carries_its_credential():
"""The URL is in these bodies, so the warning has to be on them."""
for name in ("streams", "session-stream"):
description = resources.BY_NAME[name].description
assert "PHRASE" in description, name
assert "only thing protecting" in resources.BY_NAME["streams"].description
def test_the_streams_listing_says_a_viewer_is_the_activity_exception():
"""The one exception to `session_touch`, where somebody will read it."""
description = resources.BY_NAME["streams"].description
assert "does NOT reset" in description
assert "connected viewer" in description
# ── the one read that must not be a resource ───────────────────────────────