diff --git a/src/hhstreamd/manager.py b/src/hhstreamd/manager.py index d37a6f8..ce8c9fc 100644 --- a/src/hhstreamd/manager.py +++ b/src/hhstreamd/manager.py @@ -1018,6 +1018,9 @@ class SessionManager: if session.live: await self._read_back(session, app_id) stream_error: str | None = None + #: The daemon's view of the stream, which is the only place a `url` + #: exists. Locals and not attributes, for the reason below. + stream_public: dict[str, Any] | None = None if stream and session.live: # After the read-back, because that is what settles the container's # output, and a stream has to have one to publish @@ -1032,9 +1035,10 @@ class SessionManager: # be the wrong trade; the refusal is reported on the session's # `stream_error` and the caller can retry `stream.enable`. try: - await self.stream_enable( + enabled = await self.stream_enable( session.id, phrase=stream_phrase, fps=stream_fps ) + stream_public = enabled.get("stream") except ManagerError as exc: log.warning("could not enable %s's stream: %s", session.id, exc.reason) session.last_error = session.last_error or exc.reason @@ -1049,6 +1053,19 @@ class SessionManager: # a key that appears only on failure is a key every caller has to # remember to look for. record["stream_error"] = stream_error + if stream_public is not None: + # The daemon's view, not the record's. `Session.public()` + # reports what was stored, and a `url` is never stored -- + # naming one is the daemon's (§3.5), and a URL on disk is a URL + # that lies after the listener moves. So a successful + # `start --stream` that answered with `session.public()` alone + # handed back a stream with no URL, which a caller cannot tell + # from one that failed to open. + # + # MEASURED in checks/vm-stream.nix: the daemon attached, the + # broker recorded it, and the CLI printed "the session is + # running but its stream was not enabled". + record["stream"] = stream_public if session.state == State.EXITED: # The app exited during the settle: surface it rather than handing # back a healthy-looking id (DESIGN.md §7 #3). diff --git a/tests/sessions/unit/test_stream_verbs.py b/tests/sessions/unit/test_stream_verbs.py index ad70784..76484fd 100644 --- a/tests/sessions/unit/test_stream_verbs.py +++ b/tests/sessions/unit/test_stream_verbs.py @@ -217,6 +217,28 @@ def test_enabling_mints_a_phrase_the_daemon_accepts_and_publishes(harness): assert harness.daemon.outputs() == ["hh-foot-aaaaaa"] +def test_the_url_is_the_daemon_s_and_is_not_in_the_record(harness): + """So anything answering with the record alone must merge the reply in. + + REGRESSION. `start --stream` built its answer from `Session.public()`, + which reports what was *stored* -- and a `url` is never stored, because + naming one is the daemon's (CONTRACT-sessions.md §3.5). The result was a + successful start whose stream had no URL, which the CLI could not tell + from a stream that failed to open: it printed "the session is running but + its stream was not enabled" over a stream the daemon had just attached. + Found by checks/vm-stream.nix, which is also where the `start --stream` + path is proven end to end -- there is no launcher here. + """ + + harness.add() + reply = harness.run(harness.manager.stream_enable("foot-aaaaaa")) + + assert reply["stream"]["url"] + stored = harness.manager.registry.get("foot-aaaaaa").public(harness.clock.boottime()) + assert stored["stream"]["phrase"] == reply["stream"]["phrase"] + assert "url" not in stored["stream"] + + def test_the_phrase_is_in_the_record_so_it_survives_a_restart(harness): harness.add() first = harness.run(harness.manager.stream_enable("foot-aaaaaa"))["stream"]