|
|
@@ -138,6 +138,28 @@ class PipeWireObserverTests(unittest.TestCase):
|
|
|
],
|
|
|
)
|
|
|
|
|
|
+ def test_reports_declared_stale_link_as_would_unlink(self):
|
|
|
+ links = {
|
|
|
+ (CAPTURE_0, AMP_INPUT),
|
|
|
+ (AMP_OUTPUT, CAB_INPUT),
|
|
|
+ (CAB_OUTPUT, MIX_INPUT_0),
|
|
|
+ (CAPTURE_2, MIX_INPUT_2),
|
|
|
+ (MIX_OUTPUT, PLAYBACK_0),
|
|
|
+ (CAPTURE_0, MIX_INPUT_0),
|
|
|
+ }
|
|
|
+
|
|
|
+ self.assertEqual(
|
|
|
+ observe(self.state, links),
|
|
|
+ [
|
|
|
+ {
|
|
|
+ "kind": "unexpected",
|
|
|
+ "from": CAPTURE_0,
|
|
|
+ "to": MIX_INPUT_0,
|
|
|
+ "action": "would-unlink",
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ )
|
|
|
+
|
|
|
def test_reconcile_once_is_noop_when_all_managed_links_exist(self):
|
|
|
calls = []
|
|
|
|
|
|
@@ -196,6 +218,133 @@ class PipeWireObserverTests(unittest.TestCase):
|
|
|
self.assertEqual(result["differences"], [])
|
|
|
self.assertIn(["pw-link", CAPTURE_2, MIX_INPUT_2], calls)
|
|
|
|
|
|
+ def test_reconcile_once_unlinks_only_declared_stale_edge_after_replacement_exists(self):
|
|
|
+ state = copy.deepcopy(self.state)
|
|
|
+ state["routing"]["managed_ports"].append(CAPTURE_3)
|
|
|
+ stale_link = (CAPTURE_0, MIX_INPUT_0)
|
|
|
+ unrelated_link = (CAPTURE_3, MIX_INPUT_2)
|
|
|
+ links = {
|
|
|
+ stale_link,
|
|
|
+ unrelated_link,
|
|
|
+ (CAPTURE_2, MIX_INPUT_2),
|
|
|
+ (MIX_OUTPUT, PLAYBACK_0),
|
|
|
+ }
|
|
|
+ calls = []
|
|
|
+
|
|
|
+ def render_links():
|
|
|
+ return "".join(
|
|
|
+ f"{source}\n |-> {destination}\n"
|
|
|
+ for source, destination in sorted(links)
|
|
|
+ )
|
|
|
+
|
|
|
+ def runner(command, **kwargs):
|
|
|
+ calls.append(command)
|
|
|
+ if command == ["pw-link", "-l"]:
|
|
|
+ return SimpleNamespace(stdout=render_links())
|
|
|
+ if command == ["pw-link", "-o"]:
|
|
|
+ return SimpleNamespace(stdout=(
|
|
|
+ f"{AMP_OUTPUT}\n{CAB_OUTPUT}\n{CAPTURE_0}\n{CAPTURE_2}\n{MIX_OUTPUT}\n"
|
|
|
+ ))
|
|
|
+ if command == ["pw-link", "-i"]:
|
|
|
+ return SimpleNamespace(stdout=(
|
|
|
+ f"{AMP_INPUT}\n{CAB_INPUT}\n{MIX_INPUT_0}\n{MIX_INPUT_2}\n{PLAYBACK_0}\n"
|
|
|
+ ))
|
|
|
+ if len(command) == 3 and command[0] == "pw-link":
|
|
|
+ edge = (command[1], command[2])
|
|
|
+ if edge in {
|
|
|
+ (CAPTURE_0, AMP_INPUT),
|
|
|
+ (AMP_OUTPUT, CAB_INPUT),
|
|
|
+ (CAB_OUTPUT, MIX_INPUT_0),
|
|
|
+ }:
|
|
|
+ links.add(edge)
|
|
|
+ return SimpleNamespace(stdout="")
|
|
|
+ if len(command) == 4 and command[:2] == ["pw-link", "-d"]:
|
|
|
+ links.discard((command[2], command[3]))
|
|
|
+ return SimpleNamespace(stdout="")
|
|
|
+ self.fail(f"unexpected command: {command}")
|
|
|
+
|
|
|
+ result = reconcile_once(state, runner)
|
|
|
+
|
|
|
+ self.assertEqual(
|
|
|
+ result["actions"],
|
|
|
+ [
|
|
|
+ {"kind": "link", "from": CAPTURE_0, "to": AMP_INPUT, "result": "requested"},
|
|
|
+ {"kind": "link", "from": AMP_OUTPUT, "to": CAB_INPUT, "result": "requested"},
|
|
|
+ {"kind": "link", "from": CAB_OUTPUT, "to": MIX_INPUT_0, "result": "requested"},
|
|
|
+ {"kind": "unlink", "from": CAPTURE_0, "to": MIX_INPUT_0, "result": "requested"},
|
|
|
+ ],
|
|
|
+ )
|
|
|
+ self.assertNotIn(stale_link, links)
|
|
|
+ self.assertIn(unrelated_link, links)
|
|
|
+ self.assertEqual(
|
|
|
+ result["differences"],
|
|
|
+ [
|
|
|
+ {
|
|
|
+ "kind": "unexpected",
|
|
|
+ "from": CAPTURE_3,
|
|
|
+ "to": MIX_INPUT_2,
|
|
|
+ "action": "would-review",
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ )
|
|
|
+ self.assertIn(["pw-link", "-d", CAPTURE_0, MIX_INPUT_0], calls)
|
|
|
+ self.assertNotIn(["pw-link", "-d", CAPTURE_3, MIX_INPUT_2], calls)
|
|
|
+
|
|
|
+ def test_reconcile_once_defers_unlink_until_all_desired_links_exist(self):
|
|
|
+ links = {
|
|
|
+ (CAPTURE_0, MIX_INPUT_0),
|
|
|
+ (CAPTURE_2, MIX_INPUT_2),
|
|
|
+ (MIX_OUTPUT, PLAYBACK_0),
|
|
|
+ }
|
|
|
+ calls = []
|
|
|
+
|
|
|
+ def render_links():
|
|
|
+ return "".join(f"{source}\n |-> {destination}\n" for source, destination in sorted(links))
|
|
|
+
|
|
|
+ def runner(command, **kwargs):
|
|
|
+ calls.append(command)
|
|
|
+ if command == ["pw-link", "-l"]:
|
|
|
+ return SimpleNamespace(stdout=render_links())
|
|
|
+ if command == ["pw-link", "-o"]:
|
|
|
+ return SimpleNamespace(stdout=(
|
|
|
+ f"{AMP_OUTPUT}\n{CAB_OUTPUT}\n{CAPTURE_0}\n{CAPTURE_2}\n{MIX_OUTPUT}\n"
|
|
|
+ ))
|
|
|
+ if command == ["pw-link", "-i"]:
|
|
|
+ return SimpleNamespace(stdout=(
|
|
|
+ f"{CAB_INPUT}\n{MIX_INPUT_0}\n{MIX_INPUT_2}\n{PLAYBACK_0}\n"
|
|
|
+ ))
|
|
|
+ if command == ["pw-link", AMP_OUTPUT, CAB_INPUT]:
|
|
|
+ links.add((AMP_OUTPUT, CAB_INPUT))
|
|
|
+ return SimpleNamespace(stdout="")
|
|
|
+ if command == ["pw-link", CAB_OUTPUT, MIX_INPUT_0]:
|
|
|
+ links.add((CAB_OUTPUT, MIX_INPUT_0))
|
|
|
+ return SimpleNamespace(stdout="")
|
|
|
+ self.fail(f"unexpected command: {command}")
|
|
|
+
|
|
|
+ result = reconcile_once(self.state, runner)
|
|
|
+
|
|
|
+ self.assertEqual(
|
|
|
+ result["actions"],
|
|
|
+ [
|
|
|
+ {
|
|
|
+ "kind": "unavailable-port",
|
|
|
+ "from": CAPTURE_0,
|
|
|
+ "to": AMP_INPUT,
|
|
|
+ "result": "not-linked",
|
|
|
+ },
|
|
|
+ {"kind": "link", "from": AMP_OUTPUT, "to": CAB_INPUT, "result": "requested"},
|
|
|
+ {"kind": "link", "from": CAB_OUTPUT, "to": MIX_INPUT_0, "result": "requested"},
|
|
|
+ {
|
|
|
+ "kind": "unlink-deferred",
|
|
|
+ "from": CAPTURE_0,
|
|
|
+ "to": MIX_INPUT_0,
|
|
|
+ "result": "desired managed links are still missing",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ )
|
|
|
+ self.assertIn((CAPTURE_0, MIX_INPUT_0), links)
|
|
|
+ self.assertFalse(any(command[:2] == ["pw-link", "-d"] for command in calls))
|
|
|
+
|
|
|
def test_reconcile_once_restores_all_managed_links_after_service_restart(self):
|
|
|
links = set()
|
|
|
calls = []
|
|
|
@@ -357,6 +506,18 @@ class PipeWireObserverTests(unittest.TestCase):
|
|
|
]
|
|
|
self.assertTrue(any("endpoints must be listed" in error for error in validate_managed_links(state)))
|
|
|
|
|
|
+ def test_managed_link_cannot_also_be_scheduled_for_removal(self):
|
|
|
+ state = copy.deepcopy(self.state)
|
|
|
+ state["routing"]["managed_links"].append(
|
|
|
+ {"from": CAPTURE_0, "to": MIX_INPUT_0, "status": "planned"}
|
|
|
+ )
|
|
|
+ self.assertTrue(
|
|
|
+ any(
|
|
|
+ "link cannot be both managed and scheduled for removal" in error
|
|
|
+ for error in validate_managed_links(state)
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
unittest.main()
|