test(mcp): the stream through the MCP layer, in the guest
`vm-mcp` asserted 21 tools and the eight resource URIs by name, which the stream
made stale -- and by name is the point, so the lists move with the surface: 23
tools, `hhstream://streams` among the fixed resources,
`hhstream://sessions/{id}/stream` among the templates.
Its machine now enables `sessions.stream`, because two of those tools and two of
those resources are about streams and with no daemon they could only be shown to
*refuse*.
Two subtests, and the first is the one worth having: a session started over MCP
with `stream: true` has to hand back the URL in `structuredContent`, in the text
a model actually reads, and again from `hhstream://sessions/{id}/stream` -- three
places that must agree, because the URL is the daemon's to name, is never stored,
and a reply assembled from the broker's record alone carries a phrase and no URL.
That is exactly how it went wrong once. The second takes the stream away over
MCP and reads both resources again.
What this does not do is read a frame: bytes off the port are `vm-stream`'s
subject. What it owns is that the phrase reaches an agent at all.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE
This commit is contained in:
1 parent
887ed17be2
commit
0c06de4ea7
1 file changed
+63
-2
+63
-2
@@ -11,7 +11,7 @@
|
||||
# WHAT THIS PROVES, AND WHAT IT DOES NOT.
|
||||
#
|
||||
# It proves the *surface*, both halves of it: the handshake completes over a
|
||||
# real pipe, all twenty-one tools and all eight resources are listed, a tool
|
||||
# real pipe, all twenty-three tools and all ten resources are listed, a tool
|
||||
# call reaches the broker and comes back with the broker's own protocol object,
|
||||
# a resource read reaches it the same way, an image arrives as a blob with the
|
||||
# geometry the module configured, `--toolsets` actually narrows what is
|
||||
@@ -119,6 +119,17 @@ testers.runNixOSTest (
|
||||
package = hhstream-mcp;
|
||||
};
|
||||
|
||||
# Enabled because two tools and two resources here are about streams,
|
||||
# and with no daemon they could only be shown to *refuse*. What a stream
|
||||
# actually serves is `vm-stream`'s subject -- it reads JPEGs off the
|
||||
# port; what this check owns is that the URL (with its phrase) comes back
|
||||
# through the MCP layer at all.
|
||||
services.hyprland-headless-stream.sessions.stream = {
|
||||
enable = true;
|
||||
bind = "127.0.0.1";
|
||||
port = 9988;
|
||||
};
|
||||
|
||||
environment.systemPackages = [ client ];
|
||||
};
|
||||
|
||||
@@ -227,10 +238,11 @@ testers.runNixOSTest (
|
||||
listed = mcp("--list")["tools"]
|
||||
names = sorted(tool["name"] for tool in listed)
|
||||
print(f"{len(names)} tools: {', '.join(names)}")
|
||||
assert len(names) == 21, names
|
||||
assert len(names) == 23, names
|
||||
for expected in (
|
||||
"shot", "record", "run",
|
||||
"session_start", "session_touch", "session_kill",
|
||||
"session_stream_enable", "session_stream_disable",
|
||||
"pointer_acquire", "pointer_click", "keyboard_type",
|
||||
):
|
||||
assert expected in names, f"{expected} is missing from the listing"
|
||||
@@ -257,10 +269,12 @@ testers.runNixOSTest (
|
||||
"hhstream://screen",
|
||||
"hhstream://sessions",
|
||||
"hhstream://status",
|
||||
"hhstream://streams",
|
||||
], uris
|
||||
assert templates == [
|
||||
"hhstream://outputs/{name}",
|
||||
"hhstream://sessions/{id}/logs{?lines}",
|
||||
"hhstream://sessions/{id}/stream",
|
||||
"hhstream://sessions/{id}{?events}",
|
||||
], templates
|
||||
by_uri = {r["uri"]: r for r in both["resources"]}
|
||||
@@ -532,6 +546,53 @@ testers.runNixOSTest (
|
||||
except Exception:
|
||||
dump("session_kill over mcp", session_id)
|
||||
raise
|
||||
|
||||
with subtest("a stream asked for at start comes back as a url, twice"):
|
||||
# The two places an agent can learn the phrase, and they have to
|
||||
# agree: the `session_start` reply, and the resource for that
|
||||
# session's stream. A URL is the daemon's to name and is never
|
||||
# stored, so a reply built from the broker's record alone would
|
||||
# carry a phrase and no URL -- which is how this went wrong once
|
||||
# (see `SessionManager.start`).
|
||||
streamed_id = None
|
||||
try:
|
||||
streamed = succeeded(
|
||||
"session_start", {"app": "foot", "stream": True}, timeout=300
|
||||
)
|
||||
streamed_id = streamed["structuredContent"]["id"]
|
||||
stream = streamed["structuredContent"]["stream"]
|
||||
print(f"{streamed_id} -> {stream['url']}")
|
||||
assert stream["url"].startswith("http://127.0.0.1:9988/"), stream
|
||||
# The phrase is IN the URL and is the whole of its protection,
|
||||
# so the text a model reads has to carry it too.
|
||||
assert stream["url"] in text_of(streamed)
|
||||
assert stream["phrase"] in stream["url"]
|
||||
assert streamed["structuredContent"]["stream_error"] is None
|
||||
|
||||
body = json.loads(
|
||||
read(f"hhstream://sessions/{streamed_id}/stream")[0]["text"]
|
||||
)
|
||||
assert body["stream"]["url"] == stream["url"], body
|
||||
assert body["stream"]["attached"] is True, body
|
||||
|
||||
# And the listing resource names it, with the daemon reachable.
|
||||
listed = json.loads(read("hhstream://streams")[0]["text"])
|
||||
assert listed["available"] is True, listed
|
||||
assert [row["id"] for row in listed["streams"]] == [streamed_id], listed
|
||||
except Exception:
|
||||
dump("session_start --stream over mcp", streamed_id)
|
||||
raise
|
||||
|
||||
with subtest("disabling over mcp takes the stream off both resources"):
|
||||
try:
|
||||
succeeded("session_stream_disable", {"id": streamed_id}, timeout=180)
|
||||
body = json.loads(
|
||||
read(f"hhstream://sessions/{streamed_id}/stream")[0]["text"]
|
||||
)
|
||||
assert body["stream"] is None, body
|
||||
assert json.loads(read("hhstream://streams")[0]["text"])["streams"] == []
|
||||
finally:
|
||||
succeeded("session_kill", {"id": streamed_id}, timeout=300)
|
||||
'';
|
||||
}
|
||||
)
|
||||
Reference in new issue
Block a user