Ver Fonte

modui missing graph: to compile

Johan Le Baut há 4 dias atrás
pai
commit
598a10fd01

+ 18 - 0
build/arm64/mod_ui_pipewire.py

@@ -66,6 +66,14 @@ def resolve_pedalboard_port(port, resolve_host_port):
     return f"effect_{effect_index}:{resolved_symbol}" if resolved_symbol else None
 
 
+def is_rigforge_managed_boundary_port(port):
+    """Identify one of the four Rigforge PipeWire endpoints from either API path."""
+    graph_path = port.removeprefix("/graph/")
+    if "/" in graph_path:
+        return False
+    return graph_path.startswith("capture_") or graph_path.startswith("playback_")
+
+
 def pedalboard_connection(
     port_from,
     port_to,
@@ -84,6 +92,14 @@ def pedalboard_connection(
         captures = {}
     if "/" in destination_path and not destination_is_playback:
         playbacks = {}
+    # mod-ui's HTTP route passes bare hardware symbols ("capture_3"), but the
+    # saved-board loader passes "/graph/capture_3". Preserve the latter marker:
+    # if the opposite endpoint cannot be resolved as a Rigforge plugin port,
+    # never guess a JACK/system alias for a stable PipeWire boundary.
+    boundary_endpoint = (
+        is_rigforge_managed_boundary_port(port_from)
+        or is_rigforge_managed_boundary_port(port_to)
+    )
     pipewire_link = boundary_connection(
         port_from,
         port_to,
@@ -93,6 +109,8 @@ def pedalboard_connection(
     )
     if pipewire_link is not None:
         return "pipewire", pipewire_link
+    if boundary_endpoint:
+        return None
 
     source = resolve_pedalboard_port(port_from, resolve_host_port)
     destination = resolve_pedalboard_port(port_to, resolve_host_port)

+ 12 - 2
build/arm64/patch_mod_ui_rigforge.py

@@ -632,7 +632,7 @@ def apply(source_root):
                     var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
 ''',
     )
-    replace_once(
+    replace_if_present(
         app / "html" / "js" / "pedalboard.js",
         '''                    var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="Hardware Capture ' + i + '">')
 ''',
@@ -646,7 +646,7 @@ def apply(source_root):
                     var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
 ''',
     )
-    replace_once(
+    replace_if_present(
         app / "html" / "js" / "pedalboard.js",
         '''                    var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="Hardware Playback ' + i + '">')
 ''',
@@ -660,6 +660,16 @@ def apply(source_root):
                     var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
 ''',
     )
+    replace_if_present(
+        app / "html" / "js" / "pedalboard.js",
+        "symbol = (i < 3) ? ('/graph/capture_' + i) : ('/graph/audio_from_slave_' + (i-2))",
+        "symbol = '/graph/capture_' + i",
+    )
+    replace_if_present(
+        app / "html" / "js" / "pedalboard.js",
+        "symbol = (i < 3) ? ('/graph/playback_' + i) : ('/graph/audio_to_slave_' + (i-2))",
+        "symbol = '/graph/playback_' + i",
+    )
     js_file = app / "html" / "js" / "pedalboard.js"
     if not js_file.read_bytes().endswith(b"\n"):
         js_file.write_bytes(js_file.read_bytes() + b"\n")

+ 79 - 39
scripts/diagnose_mod_ui.py

@@ -20,9 +20,37 @@ from load_mod_ui_pedalboard import (
 
 def load_mod_ui_board_links(state_path):
     state = yaml.safe_load(Path(state_path).read_text(encoding="utf-8"))
-    processors = state["routing"]["mod_host_chains"]["voice"]["processors"]
+    chains = state["routing"]["mod_host_chains"]
     links = []
-    for previous, current in zip(processors, processors[1:]):
+    guitar_processors = chains["guitar"]["processors"]
+    links.extend(
+        (
+            (
+                "/graph/capture_1",
+                f"/graph/{guitar_processors[0]['mod_ui_instance'].removeprefix('/graph/')}/"
+                f"{guitar_processors[0]['input_port'].split(':', 1)[1]}",
+            ),
+            (
+                f"/graph/{guitar_processors[-1]['mod_ui_instance'].removeprefix('/graph/')}/"
+                f"{guitar_processors[-1]['output_port'].split(':', 1)[1]}",
+                "/graph/playback_1",
+            ),
+        )
+    )
+
+    for channel in (2, 4):
+        links.append((f"/graph/capture_{channel}", f"/graph/playback_{channel}"))
+
+    voice = chains["voice"]
+    voice_processors = voice["processors"]
+    links.append(
+        (
+            f"/graph/{voice['mod_ui_input_port']}",
+            f"/graph/{voice_processors[0]['mod_ui_instance'].removeprefix('/graph/')}/"
+            f"{voice_processors[0]['input_port'].split(':', 1)[1]}",
+        )
+    )
+    for previous, current in zip(voice_processors, voice_processors[1:]):
         links.append(
             (
                 f"/graph/{previous['mod_ui_instance'].removeprefix('/graph/')}/"
@@ -33,9 +61,9 @@ def load_mod_ui_board_links(state_path):
         )
     links.append(
         (
-            f"/graph/{processors[-1]['mod_ui_instance'].removeprefix('/graph/')}/"
-            f"{processors[-1]['output_port'].split(':', 1)[1]}",
-            "/graph/playback_3",
+            f"/graph/{voice_processors[-1]['mod_ui_instance'].removeprefix('/graph/')}/"
+            f"{voice_processors[-1]['output_port'].split(':', 1)[1]}",
+            f"/graph/{voice['mod_ui_output_port']}",
         )
     )
     return tuple(links)
@@ -47,20 +75,12 @@ def _resolve_host_alias(port):
         if graph_path.startswith("capture_"):
             channel = int(graph_path.removeprefix("capture_"))
             if 1 <= channel <= 4:
-                return (
-                    "rigforge.mod-host-input.capture:"
-                    f"capture_AUX{channel - 1}"
-                )
-            return port
+                return f"rigforge.mod-host-input.capture:capture_AUX{channel - 1}"
         if graph_path.startswith("playback_"):
             channel = int(graph_path.removeprefix("playback_"))
             if 1 <= channel <= 4:
-                return (
-                    "rigforge.mod-host-output.playback:"
-                    f"playback_AUX{channel - 1}"
-                )
-            return port
-        return port
+                return f"rigforge.mod-host-output.playback:playback_AUX{channel - 1}"
+        return None
     instance, symbol = graph_path.split("/", 1)
     instance_indices = {
         "rigforge_nam": 0,
@@ -83,15 +103,10 @@ def _resolve_host_alias(port):
     }
     resolved_symbol = effect_ports.get(instance, {}).get(symbol)
     if instance in instance_indices and resolved_symbol:
-        port_aliases = {
-            ("rigforge_nam", "input"): "input",
-            ("rigforge_nam", "output"): "output",
-            ("rigforge_ir", "in"): "in",
-            ("rigforge_ir", "out"): "out",
-        }
-        alias = port_aliases.get((instance, symbol), resolved_symbol)
-        return f"effect_{instance_indices[instance]}:{alias}"
-    return port
+        if instance == "rigforge_voice_reverb" and symbol in ("input_l", "output_l"):
+            return f"effect_5:lv2_audio_{'in' if symbol == 'input_l' else 'out'}_1"
+        return f"effect_{instance_indices[instance]}:{resolved_symbol}"
+    return None
 
 
 def fetch_pedalboard_info(host, port, bundlepath, timeout=5):
@@ -118,12 +133,12 @@ def inspect_runtime(state_path, host, port, runner=subprocess.run, timeout=5):
         return 1, [f"Cannot read mod-ui last-state file {data_root}: {error}"]
 
     board_path = last_state.get("pedalboard")
-    if not board_path:
+    if not board_path or not Path(board_path).is_dir():
         try:
             info = fetch_active_pedalboard_info(host, port, timeout=timeout)
         except Exception as error:
             return 1, [
-                f"No selected pedalboard in {data_root}",
+                f"No readable selected pedalboard in {data_root}",
                 f"Cannot read active pedalboard metadata from mod-ui API: {error}",
             ]
         if not info.get("plugins"):
@@ -138,15 +153,34 @@ def inspect_runtime(state_path, host, port, runner=subprocess.run, timeout=5):
     else:
         try:
             info = fetch_pedalboard_info(host, port, board_path, timeout=timeout)
-        except Exception as error:
-            return 1, [f"Cannot read pedalboard metadata from mod-ui API: {error}"]
+        except Exception as bundle_error:
+            try:
+                info = fetch_active_pedalboard_info(host, port, timeout=timeout)
+            except Exception as api_error:
+                return 1, [
+                    f"Cannot read selected pedalboard metadata: {bundle_error}",
+                    f"Cannot read active pedalboard metadata from mod-ui API: {api_error}",
+                ]
+            if not info.get("plugins"):
+                return 1, [
+                    f"Cannot read selected pedalboard metadata: {bundle_error}",
+                    "mod-ui API reports no active plugins",
+                ]
+            board_path = info.get("bundlepath") or "(active board reported by mod-ui API)"
+            messages = [
+                f"Active pedalboard reported by mod-ui API: {board_path}",
+                f"Bundle metadata: {info.get('title')!r}, "
+                f"{len(info.get('plugins', []))} plugins, "
+                f"{len(info.get('connections', []))} connections",
+            ]
+        else:
+            messages = [
+                f"Host-selected bundle: {board_path}",
+                f"Bundle metadata: {info.get('title')!r}, "
+                f"{len(info.get('plugins', []))} plugins, "
+                f"{len(info.get('connections', []))} connections",
+            ]
 
-        messages = [
-            f"Host-selected bundle: {board_path}",
-            f"Bundle metadata: {info.get('title')!r}, "
-            f"{len(info.get('plugins', []))} plugins, "
-            f"{len(info.get('connections', []))} connections",
-        ]
     failures = []
     if not info.get("plugins"):
         failures.append("The selected bundle contains no plugins according to the mod-ui API")
@@ -167,10 +201,14 @@ def inspect_runtime(state_path, host, port, runner=subprocess.run, timeout=5):
             (source, target)
             for source, target in expected_links
             if (
-                _resolve_host_alias(source),
-                _resolve_host_alias(target),
+                not _resolve_host_alias(source)
+                or not _resolve_host_alias(target)
+                or (
+                    _resolve_host_alias(source),
+                    _resolve_host_alias(target),
+                )
+                not in observed
             )
-            not in observed
         ]
         if missing:
             failures.append(
@@ -178,7 +216,9 @@ def inspect_runtime(state_path, host, port, runner=subprocess.run, timeout=5):
                 + ", ".join(f"{src} -> {dst}" for src, dst in missing)
             )
         else:
-            messages.append(f"All {len(expected_links)} declared voice-chain links are present")
+            messages.append(
+                f"All {len(expected_links)} declared pedalboard links are present"
+            )
 
     return (1 if failures else 0), messages + [
         f"ERROR: {failure}" for failure in failures

+ 54 - 18
scripts/load_mod_ui_pedalboard.py

@@ -76,6 +76,22 @@ def request_load_through_ui(host, port, bundle, timeout):
         # Register as the browser's active session and wait for its initial state.
         receive_initial_state(connection)
 
+        acknowledged = False
+
+        def load_bundle_through_page():
+            nonlocal acknowledged
+            body = urlencode({"bundlepath": str(bundle)}).encode()
+            request = Request(
+                f"http://{host}:{port}/pedalboard/load_bundle/",
+                data=body,
+                method="POST",
+            )
+            with urlopen(request, timeout=timeout) as response:
+                data = response.read().decode("utf-8", errors="replace")
+            if not json.loads(data).get("ok"):
+                raise RuntimeError(f"mod-ui rejected bundle load: {data}")
+            acknowledged = True
+
         from urllib.parse import quote
         page_url = (
             f"http://{host}:{port}/pedalboard.html?v=rigforge&bundlepath="
@@ -85,29 +101,43 @@ def request_load_through_ui(host, port, bundle, timeout):
             html = page.read().decode("utf-8", errors="replace")
         if "fakeLoadFromServerData" not in html:
             raise RuntimeError("mod-ui pedalboard page did not contain its board data")
-        wait_for_message_prefix(connection, "loading_end ")
+        try:
+            wait_for_message_prefix(connection, "loading_end ", timeout=timeout)
+        except TimeoutError:
+            if acknowledged:
+                raise
+            # The server has accepted this socket but no browser has answered its
+            # initial data_ready barrier. Defer the real page load until the UI
+            # acknowledges the empty-board reset below.
 
         reset_request = Request(f"http://{host}:{port}/reset")
         with urlopen(reset_request, timeout=timeout) as response:
             if not json.loads(response.read().decode("utf-8", errors="replace")):
                 raise RuntimeError("mod-ui refused to reset the current pedalboard")
 
-        # Match the active browser's acknowledgement that its reset is complete.
-        # Desktop.loadPedalboard uses POST after reset. The HTTP response only
-        # confirms Host.load(), while browser host.js must consume loading_start
-        # and then its own data_ready round trip before drawing cables.
-        body = urlencode({"bundlepath": str(bundle)}).encode()
-        request = Request(
-            f"http://{host}:{port}/pedalboard/load_bundle/",
-            data=body,
-            method="POST",
-        )
-        with urlopen(request, timeout=timeout) as response:
-            data = response.read().decode("utf-8", errors="replace")
-        if not json.loads(data).get("ok"):
-            raise RuntimeError(f"mod-ui rejected bundle load: {data}")
-        connection.sendall(encode_control_frame(0x1, "data_ready 1"))
-        message = wait_for_message_prefix(connection, "loading_end ")
+        deadline = time.monotonic() + timeout
+        message = None
+        while time.monotonic() < deadline:
+            opcode, payload = receive_frame(connection)
+            if opcode == 0x8:
+                raise RuntimeError("mod-ui closed its WebSocket during pedalboard load")
+            if opcode == 0x9:
+                connection.sendall(encode_control_frame(0xA, payload))
+                continue
+            if opcode != 0x1:
+                continue
+            incoming = payload.decode("utf-8", errors="replace")
+            if incoming == "ping":
+                connection.sendall(encode_control_frame(0x1, "pong"))
+            elif incoming.startswith("data_ready "):
+                connection.sendall(encode_control_frame(0x1, incoming))
+                if not acknowledged:
+                    load_bundle_through_page()
+            elif incoming.startswith("loading_end "):
+                message = incoming
+                break
+        if message is None:
+            raise TimeoutError("mod-ui did not finish loading the pedalboard")
         return message
 
 
@@ -151,8 +181,14 @@ def receive_initial_state(connection):
                 return
 
 
-def wait_for_message_prefix(connection, prefix):
+def wait_for_message_prefix(connection, prefix, timeout=None):
+    deadline = time.monotonic() + timeout if timeout is not None else None
     while True:
+        if deadline is not None:
+            remaining = deadline - time.monotonic()
+            if remaining <= 0:
+                raise TimeoutError(f"timed out waiting for mod-ui message {prefix!r}")
+            connection.settimeout(remaining)
         opcode, payload = receive_frame(connection)
         if opcode == 0x8:
             raise RuntimeError("mod-ui closed WebSocket during pedalboard load")

+ 14 - 1
scripts/mod_ui_websocket.py

@@ -16,10 +16,12 @@ class ModUiWebSocketClient:
         self.timeout = timeout
         self.connection = None
         self.buffer = bytearray()
+        self.session_ready = False
 
     def connect(self):
         if self.connection is not None:
             return
+        self.session_ready = False
         connection = socket.create_connection((self.host, self.port), timeout=self.timeout)
         connection.settimeout(self.timeout)
         key = base64.b64encode(os.urandom(16)).decode("ascii")
@@ -122,6 +124,7 @@ class ModUiWebSocketClient:
         while True:
             opcode, payload = self.receive_frame()
             if opcode == 0x8:
+                self.close()
                 raise RuntimeError("mod-ui closed the WebSocket while loading pedalboard")
             if opcode == 0x9:
                 self._send_frame(0xA, payload)
@@ -129,10 +132,19 @@ class ModUiWebSocketClient:
             if opcode != 0x1:
                 continue
             message = payload.decode("utf-8", errors="replace")
-            if message == "ping" or message.startswith("data_ready "):
+            if message == "ping":
                 self.process_control_message(message)
                 continue
             if message.startswith("loading_start "):
+                # The browser sends loading_start when its initial state was
+                # reported; reply to the corresponding data_ready before declaring
+                # the UI session ready to accept pedalboard connections.
+                continue
+            if message.startswith("data_ready "):
+                self.process_control_message(message)
+                continue
+            if message.startswith("loading_end "):
+                self.session_ready = True
                 return message
 
 
@@ -191,6 +203,7 @@ class ModUiWebSocketClient:
     def close(self):
         connection, self.connection = self.connection, None
         self.buffer.clear()
+        self.session_ready = False
         if connection is None:
             return
         try:

+ 11 - 0
scripts/run_mod_ui_service.py

@@ -80,6 +80,17 @@ def run_service(
                         )
                         next_connect_attempt = time.monotonic() + 0.25
                         continue
+                if not getattr(client, "session_ready", False):
+                    try:
+                        client.wait_for_loading_start()
+                    except (OSError, TimeoutError, ConnectionError):
+                        client.close()
+                        client = ModUiWebSocketClient(
+                            host, port, websocket_path, timeout=2
+                        )
+                        next_connect_attempt = time.monotonic() + 0.25
+                        continue
+                    print("mod-ui WebSocket session initialized")
                 client.serve_once(timeout=0.5)
             except (OSError, TimeoutError, ConnectionError):
                 client.close()

+ 159 - 9
tests/test_diagnose_mod_ui.py

@@ -13,6 +13,40 @@ import diagnose_mod_ui
 
 
 class DiagnoseModUiTests(unittest.TestCase):
+    def test_expected_board_links_cover_all_boundary_and_voice_cables(self):
+        links = diagnose_mod_ui.load_mod_ui_board_links(
+            ROOT / "config" / "desired-state.yaml"
+        )
+        self.assertEqual(
+            links,
+            (
+                ("/graph/capture_1", "/graph/rigforge_nam/input"),
+                ("/graph/rigforge_ir/out", "/graph/playback_1"),
+                ("/graph/capture_2", "/graph/playback_2"),
+                ("/graph/capture_4", "/graph/playback_4"),
+                (
+                    "/graph/capture_3",
+                    "/graph/rigforge_voice_high_pass/in",
+                ),
+                (
+                    "/graph/rigforge_voice_high_pass/out",
+                    "/graph/rigforge_voice_compressor/in",
+                ),
+                (
+                    "/graph/rigforge_voice_compressor/out",
+                    "/graph/rigforge_voice_de_esser/in",
+                ),
+                (
+                    "/graph/rigforge_voice_de_esser/out",
+                    "/graph/rigforge_voice_reverb/input_l",
+                ),
+                (
+                    "/graph/rigforge_voice_reverb/output_l",
+                    "/graph/playback_3",
+                ),
+            ),
+        )
+
     def setUp(self):
         self.temp = tempfile.TemporaryDirectory()
         self.addCleanup(self.temp.cleanup)
@@ -20,8 +54,10 @@ class DiagnoseModUiTests(unittest.TestCase):
         self.state_path = self.root / "state.yaml"
         self.last_state = self.root / ".local" / "share" / "rigforge" / "mod-ui" / "last.json"
         self.last_state.parent.mkdir(parents=True)
+        self.board = self.root / "rigforge.pedalboard"
+        self.board.mkdir()
         self.last_state.write_text(
-            json.dumps({"pedalboard": "/tmp/rigforge.pedalboard"}),
+            json.dumps({"pedalboard": str(self.board)}),
             encoding="utf-8",
         )
         self.state_path.write_text(
@@ -43,12 +79,15 @@ class DiagnoseModUiTests(unittest.TestCase):
             patch.object(
                 diagnose_mod_ui,
                 "load_mod_ui_board_links",
-                return_value=(("/graph/a/out", "/graph/b/in"),),
+                return_value=(("/graph/capture_1", "/graph/rigforge_nam/input"),),
             ),
             patch.object(
                 diagnose_mod_ui,
                 "_resolve_host_alias",
-                side_effect=lambda port: port,
+                side_effect=lambda port: {
+                    "/graph/capture_1": "source:out",
+                    "/graph/rigforge_nam/input": "sink:in",
+                }.get(port),
             ),
         ):
             status, messages = diagnose_mod_ui.inspect_runtime(
@@ -63,7 +102,12 @@ class DiagnoseModUiTests(unittest.TestCase):
 
         self.assertEqual(status, 1)
         self.assertTrue(any("1 plugins, 1 connections" in message for message in messages))
-        self.assertTrue(any("ERROR: Missing declared pedalboard PipeWire links" in message for message in messages))
+        self.assertTrue(
+            any(
+                "ERROR: Missing declared pedalboard PipeWire links" in message
+                for message in messages
+            )
+        )
 
     def test_succeeds_when_bundle_and_all_declared_links_are_present(self):
         info = {
@@ -77,12 +121,15 @@ class DiagnoseModUiTests(unittest.TestCase):
             patch.object(
                 diagnose_mod_ui,
                 "load_mod_ui_board_links",
-                return_value=(("source:out", "sink:in"),),
+                return_value=(("/graph/capture_1", "/graph/rigforge_nam/input"),),
             ),
             patch.object(
                 diagnose_mod_ui,
                 "_resolve_host_alias",
-                side_effect=lambda port: port,
+                side_effect=lambda port: {
+                    "/graph/capture_1": "source:out",
+                    "/graph/rigforge_nam/input": "sink:in",
+                }.get(port),
             ),
         ):
             status, messages = diagnose_mod_ui.inspect_runtime(
@@ -96,7 +143,9 @@ class DiagnoseModUiTests(unittest.TestCase):
             )
 
         self.assertEqual(status, 0)
-        self.assertTrue(any("All 1 declared voice-chain links" in message for message in messages))
+        self.assertTrue(
+            any("All 1 declared pedalboard links" in message for message in messages)
+        )
 
     def test_empty_last_state_falls_back_to_active_mod_ui_api(self):
         self.last_state.write_text(json.dumps({"pedalboard": ""}), encoding="utf-8")
@@ -111,9 +160,16 @@ class DiagnoseModUiTests(unittest.TestCase):
             patch.object(
                 diagnose_mod_ui,
                 "load_mod_ui_board_links",
-                return_value=(("source:out", "sink:in"),),
+                return_value=(("/graph/capture_1", "/graph/rigforge_nam/input"),),
+            ),
+            patch.object(
+                diagnose_mod_ui,
+                "_resolve_host_alias",
+                side_effect=lambda port: {
+                    "/graph/capture_1": "source:out",
+                    "/graph/rigforge_nam/input": "sink:in",
+                }.get(port),
             ),
-            patch.object(diagnose_mod_ui, "_resolve_host_alias", side_effect=lambda port: port),
         ):
             status, messages = diagnose_mod_ui.inspect_runtime(
                 self.state_path,
@@ -128,6 +184,88 @@ class DiagnoseModUiTests(unittest.TestCase):
         self.assertEqual(status, 0)
         self.assertTrue(any("Active pedalboard reported by mod-ui API" in m for m in messages))
 
+    def test_empty_saved_bundle_directory_uses_active_board_info(self):
+        bundle = self.root / "empty.pedalboard"
+        if bundle.exists():
+            bundle.rmdir()
+        bundle.mkdir()
+        self.last_state.write_text(
+            json.dumps({"pedalboard": str(bundle)}),
+            encoding="utf-8",
+        )
+        info = {
+            "title": "Rigforge",
+            "plugins": [{"uri": "urn:test"}],
+            "connections": [{"source": "a", "target": "b"}],
+        }
+        with (
+            patch.object(diagnose_mod_ui.Path, "home", return_value=self.root),
+            patch.object(diagnose_mod_ui, "fetch_pedalboard_info", side_effect=RuntimeError("invalid empty bundle")),
+            patch.object(diagnose_mod_ui, "fetch_active_pedalboard_info", return_value=info),
+            patch.object(
+                diagnose_mod_ui,
+                "load_mod_ui_board_links",
+                return_value=(("/graph/capture_1", "/graph/rigforge_nam/input"),),
+            ),
+            patch.object(
+                diagnose_mod_ui,
+                "_resolve_host_alias",
+                side_effect=lambda port: {
+                    "/graph/capture_1": "source:out",
+                    "/graph/rigforge_nam/input": "sink:in",
+                }.get(port),
+            ),
+        ):
+            status, messages = diagnose_mod_ui.inspect_runtime(
+                self.state_path,
+                "127.0.0.1",
+                8888,
+                runner=lambda *_args, **_kwargs: SimpleNamespace(
+                    returncode=0,
+                    stdout="source:out\n  |-> sink:in\n",
+                ),
+            )
+
+        self.assertEqual(status, 0)
+        self.assertTrue(
+            any("Active pedalboard reported by mod-ui API" in message for message in messages)
+        )
+
+    def test_missing_selected_board_falls_back_to_active_mod_ui_api(self):
+        self.last_state.write_text(
+            json.dumps({"pedalboard": "/missing/selected-board.pedalboard"}),
+            encoding="utf-8",
+        )
+        info = {
+            "title": "Rigforge",
+            "bundlepath": "/runtime/active-board.pedalboard",
+            "plugins": [{"uri": "urn:test"}],
+            "connections": [],
+        }
+        with (
+            patch.object(diagnose_mod_ui.Path, "home", return_value=self.root),
+            patch.object(diagnose_mod_ui, "fetch_active_pedalboard_info", return_value=info),
+            patch.object(
+                diagnose_mod_ui,
+                "load_mod_ui_board_links",
+                return_value=(),
+            ),
+        ):
+            status, messages = diagnose_mod_ui.inspect_runtime(
+                self.state_path,
+                "127.0.0.1",
+                8888,
+                runner=lambda *_args, **_kwargs: SimpleNamespace(
+                    returncode=0,
+                    stdout="",
+                ),
+            )
+
+        self.assertEqual(status, 0)
+        self.assertTrue(
+            any("Active pedalboard reported by mod-ui API: /runtime/active-board.pedalboard" in m for m in messages)
+        )
+
     def test_resolves_guitar_capture_to_nam_audio_port(self):
         self.assertEqual(
             diagnose_mod_ui._resolve_host_alias("/graph/capture_1"),
@@ -137,6 +275,18 @@ class DiagnoseModUiTests(unittest.TestCase):
             diagnose_mod_ui._resolve_host_alias("/graph/rigforge_nam/input"),
             "effect_0:input",
         )
+        self.assertEqual(
+            diagnose_mod_ui._resolve_host_alias(
+                "/graph/rigforge_voice_reverb/input_l"
+            ),
+            "effect_5:lv2_audio_in_1",
+        )
+        self.assertEqual(
+            diagnose_mod_ui._resolve_host_alias(
+                "/graph/rigforge_voice_reverb/output_l"
+            ),
+            "effect_5:lv2_audio_out_1",
+        )
 
 
 if __name__ == "__main__":

+ 71 - 0
tests/test_mod_ui_pipewire.py

@@ -208,6 +208,61 @@ class ModUiPipeWireTests(unittest.TestCase):
             ),
         )
 
+    def test_boundary_failures_never_fall_back_to_guessed_jack_ports(self):
+        def resolve(port):
+            return f"system:{port.rsplit('/', 1)[-1]}"
+
+        self.assertIsNone(
+            pedalboard_connection(
+                "/graph/capture_3",
+                "/graph/rigforge_voice_high_pass/in",
+                {"capture_3": "rigforge.mod-host-input.capture:capture_AUX2"},
+                {},
+                resolve,
+            )
+        )
+        self.assertIsNone(
+            pedalboard_connection(
+                "/graph/rigforge_voice_de_esser/out",
+                "/graph/rigforge_voice_reverb/input_l",
+                {},
+                {},
+                resolve,
+            )
+        )
+        self.assertIsNone(
+            pedalboard_connection(
+                "/capture_3",
+                "/graph/rigforge_voice_high_pass/in",
+                {"capture_3": "rigforge.mod-host-input.capture:capture_AUX2"},
+                {},
+                resolve,
+            )
+        )
+
+    def test_voice_plugin_connections_resolve_to_the_loaded_plugin_ids(self):
+        self.assertEqual(
+            pedalboard_connection(
+                "/graph/rigforge_voice_de_esser/out",
+                "/graph/rigforge_voice_reverb/input_l",
+                {},
+                {},
+                lambda _port: self.fail("Rigforge voice ports should be explicit"),
+            ),
+            ("jack", ("effect_4:out", "effect_5:lv2_audio_in_1")),
+        )
+
+    def test_resolver_preserves_capture_symbols_outside_first_two_channels(self):
+        resolver = lambda port: port
+        self.assertEqual(
+            resolve_pedalboard_port("/graph/capture_3", resolver),
+            "/graph/capture_3",
+        )
+        self.assertEqual(
+            resolve_pedalboard_port("/graph/playback_4", resolver),
+            "/graph/playback_4",
+        )
+
     def test_resolves_guitar_nam_and_ir_ports_without_jack_alias_guessing(self):
         def fail_if_called(_port):
             raise AssertionError("known Rigforge plugin port should resolve explicitly")
@@ -363,6 +418,14 @@ class ModUiPipeWireTests(unittest.TestCase):
             fix_start = patched_text.index("    def _fix_host_connection_port(")
             fix_end = patched_text.index("\n    def ", fix_start + 8)
             resolver_method = patched_text[fix_start:fix_end]
+            self.assertIn(
+                "if port in self.rigforge_capture_ports:",
+                resolver_method,
+            )
+            self.assertIn(
+                "def is_rigforge_managed_boundary_port(port):",
+                (ROOT / "build/arm64/mod_ui_pipewire.py").read_text(encoding="utf-8"),
+            )
             self.assertIn(
                 'if len(data) == 2 and data[0] == ""',
                 resolver_method,
@@ -426,6 +489,14 @@ class ModUiPipeWireTests(unittest.TestCase):
             )
             ast.parse(patched_text)
 
+            helper_artifact = app / "mod/rigforge_pipewire.py"
+            helper_text = helper_artifact.read_text(encoding="utf-8")
+            self.assertIn(
+                "def is_rigforge_managed_boundary_port(port):",
+                helper_text,
+            )
+            self.assertIn("if boundary_endpoint:", helper_text)
+
             patch_mod_ui_rigforge.apply(app)
             self.assertEqual(host.read_bytes(), once)
 

+ 8 - 3
tests/test_mod_ui_websocket.py

@@ -51,18 +51,23 @@ class ModUiWebSocketTests(unittest.TestCase):
     def test_wait_for_loading_start_ignores_unrelated_messages(self):
         client = ModUiWebSocketClient("127.0.0.1", 8888)
         client.connect = lambda: None
+        sent = []
         frames = iter(
             (
-                (0x1, b"data_ready 4"),
+                (0x1, b"stats 1 0"),
                 (0x1, b"loading_start 0 0"),
+                (0x1, b"data_ready 4"),
+                (0x1, b"loading_end 0"),
             )
         )
         client.receive_frame = lambda: next(frames)
-        client.send_text = lambda _message: None
+        client.send_text = sent.append
 
         message = client.wait_for_loading_start()
 
-        self.assertEqual(message, "loading_start 0 0")
+        self.assertEqual(message, "loading_end 0")
+        self.assertTrue(client.session_ready)
+        self.assertEqual(sent, ["data_ready 4"])
 
     def test_server_close_is_reported_as_reconnectable_connection_error(self):
         class FakeConnection:

+ 7 - 0
tests/test_run_mod_ui_service.py

@@ -32,11 +32,17 @@ class FakeWebSocket:
         self.served = 0
         self.closed = False
         self.connection = None
+        self.ready_waited = False
 
     def connect(self):
         self.connected = True
         self.connection = object()
 
+    def wait_for_loading_start(self):
+        self.ready_waited = True
+        self.session_ready = True
+        return "loading_end 0"
+
     def serve_once(self, timeout=1):
         self.served += 1
 
@@ -83,6 +89,7 @@ class ModUiServiceRunnerTests(unittest.TestCase):
 
         websocket = factory.instances[0]
         self.assertTrue(websocket.connected)
+        self.assertTrue(websocket.ready_waited)
         self.assertTrue(websocket.closed)
         self.assertGreaterEqual(websocket.served, 1)
         self.assertFalse(process.terminated)