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:
1 parent
5f5726c02e
commit
b4abd085cc
10 files changed
+1626
-7
No files matched your search
@@ -117,7 +117,7 @@ def test_tools_list_returns_every_tool_with_a_title_and_a_description(session):
|
||||
|
||||
listed = run(go).tools
|
||||
assert {tool.name for tool in listed} == set(tools.BY_NAME)
|
||||
assert len(listed) == 21
|
||||
assert len(listed) == 23
|
||||
for tool in listed:
|
||||
assert tool.title, tool.name
|
||||
assert tool.description and len(tool.description) > 40, tool.name
|
||||
@@ -524,6 +524,53 @@ def test_a_tool_outside_the_selection_cannot_be_called_by_name(session):
|
||||
assert fake.calls == []
|
||||
|
||||
|
||||
def test_the_stream_url_round_trips_through_a_resource_read(session):
|
||||
"""The phrase reaching an agent is the point of the whole feature."""
|
||||
|
||||
reply = {
|
||||
"ok": True,
|
||||
"id": "s-1",
|
||||
"stream": {
|
||||
"enabled": True,
|
||||
"attached": True,
|
||||
"output": "hh-s-1",
|
||||
"fps": 5,
|
||||
"viewers": 1,
|
||||
"url": "http://127.0.0.1:9988/amber-otter-lantern-harbor-7k2qp/",
|
||||
},
|
||||
}
|
||||
fake, connected = session(stdout=json.dumps(reply, indent=2))
|
||||
|
||||
async def go():
|
||||
async with connected as client:
|
||||
await client.initialize()
|
||||
return await client.read_resource(AnyUrl("hhstream://sessions/s-1/stream"))
|
||||
|
||||
content = run(go).contents[0]
|
||||
assert json.loads(content.text)["stream"]["url"] == reply["stream"]["url"]
|
||||
assert fake.calls == [["session", "stream", "status", "--json", "--", "s-1"]]
|
||||
|
||||
|
||||
def test_enabling_a_stream_through_a_tool_call_returns_its_url(session):
|
||||
reply = {
|
||||
"ok": True,
|
||||
"id": "s-1",
|
||||
"stream": {"attached": True, "url": "http://127.0.0.1:9988/a-b-c-d-12345/"},
|
||||
}
|
||||
fake, connected = session(stdout=json.dumps(reply, indent=2))
|
||||
|
||||
async def go():
|
||||
async with connected as client:
|
||||
await client.initialize()
|
||||
return await client.call_tool("session_stream_enable", {"id": "s-1"})
|
||||
|
||||
result = run(go)
|
||||
assert not result.isError
|
||||
assert result.content[0].text.startswith(reply["stream"]["url"])
|
||||
assert result.structuredContent == reply
|
||||
assert fake.calls == [["session", "stream", "enable", "--json", "--", "s-1"]]
|
||||
|
||||
|
||||
def test_content_for_a_text_only_result_has_no_image_block():
|
||||
blocks = server.content_for(tools.Result(text="hello"))
|
||||
assert [block.type for block in blocks] == ["text"]
|
||||
|
||||
Reference in new issue
Block a user