diff --git a/checks/vm-mcp.nix b/checks/vm-mcp.nix index 30ec763..a33d75d 100644 --- a/checks/vm-mcp.nix +++ b/checks/vm-mcp.nix @@ -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) ''; } )