test_pipewire_observer.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. import io
  2. import copy
  3. import sys
  4. import unittest
  5. from contextlib import redirect_stdout
  6. from pathlib import Path
  7. from types import SimpleNamespace
  8. from unittest.mock import patch
  9. ROOT = Path(__file__).resolve().parents[1]
  10. sys.path.insert(0, str(ROOT / "scripts"))
  11. from observe_pipewire import (
  12. load_state,
  13. observe,
  14. parse_pw_link_output,
  15. reconcile_once,
  16. main,
  17. validate_managed_links,
  18. )
  19. CAPTURE_0 = "alsa_input.hw_U192k_0:capture_AUX0"
  20. CAPTURE_2 = "alsa_input.hw_U192k_0:capture_AUX2"
  21. CAPTURE_3 = "alsa_input.hw_U192k_0:capture_AUX3"
  22. AMP_INPUT = "effect_0:input"
  23. AMP_OUTPUT = "effect_0:output"
  24. CAB_INPUT = "effect_1:in"
  25. CAB_OUTPUT = "effect_1:out"
  26. MIX_INPUT_0 = "rigforge.direct-mix.input:playback_AUX0"
  27. MIX_INPUT_2 = "rigforge.direct-mix.input:playback_AUX2"
  28. MIX_OUTPUT = "rigforge.direct-mix.output:capture_FL"
  29. PLAYBACK_0 = "alsa_output.hw_U192k_0:playback_AUX0"
  30. class PipeWireObserverTests(unittest.TestCase):
  31. @classmethod
  32. def setUpClass(cls):
  33. cls.state = load_state(ROOT / "config" / "desired-state.yaml")
  34. def test_empty_managed_set_ignores_wireplumber_hardware_links(self):
  35. state = copy.deepcopy(self.state)
  36. state["routing"]["managed_ports"] = []
  37. state["routing"]["managed_links"] = []
  38. observed = parse_pw_link_output(
  39. "alsa_output.usb-umc:Line1.split:output_AUX0\n"
  40. f" |-> {PLAYBACK_0}\n"
  41. f"{CAPTURE_0}\n"
  42. " |-> alsa_input.usb-umc:Mic1.split:input_AUX0\n"
  43. )
  44. self.assertEqual(observe(state, observed), [])
  45. def test_reports_missing_and_unexpected_managed_links_without_mutating(self):
  46. state = copy.deepcopy(self.state)
  47. state["routing"]["managed_ports"] = [CAPTURE_0, CAPTURE_2, CAPTURE_3, PLAYBACK_0]
  48. state["routing"]["managed_links"] = [
  49. {"from": CAPTURE_0, "to": PLAYBACK_0, "status": "planned"},
  50. {"from": CAPTURE_2, "to": PLAYBACK_0, "status": "observed"},
  51. ]
  52. observed = {
  53. (CAPTURE_2, PLAYBACK_0),
  54. (CAPTURE_3, PLAYBACK_0),
  55. }
  56. reports = observe(state, observed)
  57. self.assertEqual(
  58. reports,
  59. [
  60. {"kind": "missing", "from": CAPTURE_0, "to": PLAYBACK_0, "action": "would-link"},
  61. {"kind": "unexpected", "from": CAPTURE_3, "to": PLAYBACK_0, "action": "would-review"},
  62. ],
  63. )
  64. self.assertEqual(state["routing"]["managed_links"][0]["status"], "planned")
  65. def test_parser_handles_incoming_and_outgoing_link_views(self):
  66. links = parse_pw_link_output(
  67. f"{CAPTURE_0}\n"
  68. f" |-> {PLAYBACK_0}\n"
  69. f"{PLAYBACK_0}\n"
  70. f" |<- {CAPTURE_0}\n"
  71. )
  72. self.assertEqual(links, {(CAPTURE_0, PLAYBACK_0)})
  73. def test_quiet_reconcile_suppresses_output_only_when_clean(self):
  74. with (
  75. patch("observe_pipewire.load_state", return_value=self.state),
  76. patch(
  77. "observe_pipewire.reconcile_once",
  78. return_value={
  79. "actions": [],
  80. "differences": [],
  81. },
  82. ),
  83. ):
  84. output = io.StringIO()
  85. with redirect_stdout(output):
  86. result = main(["--reconcile-once", "--quiet-if-clean"])
  87. self.assertEqual(result, 0)
  88. self.assertEqual(output.getvalue(), "")
  89. def test_rejects_logical_mix_endpoint(self):
  90. state = copy.deepcopy(self.state)
  91. state["routing"]["managed_ports"] = [PLAYBACK_0]
  92. state["routing"]["managed_links"] = [
  93. {"from": "direct_mix", "to": PLAYBACK_0, "status": "planned"}
  94. ]
  95. self.assertTrue(any("approved observed Rigforge or UMC port" in error for error in validate_managed_links(state)))
  96. def test_declared_guitar_effect_chain_and_voice_mix_links_match_observed_graph(self):
  97. links = {
  98. (CAPTURE_0, AMP_INPUT),
  99. (AMP_OUTPUT, CAB_INPUT),
  100. (CAB_OUTPUT, MIX_INPUT_0),
  101. (CAPTURE_2, MIX_INPUT_2),
  102. (MIX_OUTPUT, PLAYBACK_0),
  103. }
  104. self.assertEqual(validate_managed_links(self.state), [])
  105. self.assertEqual(observe(self.state, links), [])
  106. def test_reports_missing_voice_mix_link_without_expectation_of_dry_guitar(self):
  107. links = {
  108. (CAPTURE_0, AMP_INPUT),
  109. (AMP_OUTPUT, CAB_INPUT),
  110. (CAB_OUTPUT, MIX_INPUT_0),
  111. (MIX_OUTPUT, PLAYBACK_0),
  112. }
  113. reports = observe(self.state, links)
  114. self.assertEqual(
  115. reports,
  116. [
  117. {
  118. "kind": "missing",
  119. "from": CAPTURE_2,
  120. "to": MIX_INPUT_2,
  121. "action": "would-link",
  122. }
  123. ],
  124. )
  125. def test_reports_unexpected_link_between_managed_filter_ports(self):
  126. state = copy.deepcopy(self.state)
  127. state["routing"]["managed_ports"].append(CAPTURE_3)
  128. links = {
  129. (CAPTURE_0, AMP_INPUT),
  130. (AMP_OUTPUT, CAB_INPUT),
  131. (CAB_OUTPUT, MIX_INPUT_0),
  132. (CAPTURE_2, MIX_INPUT_2),
  133. (MIX_OUTPUT, PLAYBACK_0),
  134. (CAPTURE_3, MIX_INPUT_2),
  135. }
  136. reports = observe(state, links)
  137. self.assertEqual(
  138. reports,
  139. [
  140. {
  141. "kind": "unexpected",
  142. "from": CAPTURE_3,
  143. "to": MIX_INPUT_2,
  144. "action": "would-review",
  145. }
  146. ],
  147. )
  148. def test_reports_declared_stale_link_as_would_unlink(self):
  149. links = {
  150. (CAPTURE_0, AMP_INPUT),
  151. (AMP_OUTPUT, CAB_INPUT),
  152. (CAB_OUTPUT, MIX_INPUT_0),
  153. (CAPTURE_2, MIX_INPUT_2),
  154. (MIX_OUTPUT, PLAYBACK_0),
  155. (CAPTURE_0, MIX_INPUT_0),
  156. }
  157. self.assertEqual(
  158. observe(self.state, links),
  159. [
  160. {
  161. "kind": "unexpected",
  162. "from": CAPTURE_0,
  163. "to": MIX_INPUT_0,
  164. "action": "would-unlink",
  165. }
  166. ],
  167. )
  168. def test_reconcile_once_is_noop_when_all_managed_links_exist(self):
  169. calls = []
  170. def runner(command, **kwargs):
  171. calls.append(command)
  172. return SimpleNamespace(stdout=(
  173. f"{CAPTURE_0}\n |-> {AMP_INPUT}\n"
  174. f"{AMP_OUTPUT}\n |-> {CAB_INPUT}\n"
  175. f"{CAB_OUTPUT}\n |-> {MIX_INPUT_0}\n"
  176. f"{CAPTURE_2}\n |-> {MIX_INPUT_2}\n"
  177. f"{MIX_OUTPUT}\n |-> {PLAYBACK_0}\n"
  178. ))
  179. result = reconcile_once(self.state, runner)
  180. self.assertEqual(result["actions"], [])
  181. self.assertEqual(result["differences"], [])
  182. self.assertEqual(calls, [["pw-link", "-l"], ["pw-link", "-l"]])
  183. def test_reconcile_once_links_only_declared_missing_edges_and_verifies(self):
  184. state = copy.deepcopy(self.state)
  185. links = {
  186. (CAPTURE_0, AMP_INPUT),
  187. (AMP_OUTPUT, CAB_INPUT),
  188. (CAB_OUTPUT, MIX_INPUT_0),
  189. (MIX_OUTPUT, PLAYBACK_0),
  190. }
  191. calls = []
  192. def render_links():
  193. return "".join(f"{source}\n |-> {destination}\n" for source, destination in sorted(links))
  194. def runner(command, **kwargs):
  195. calls.append(command)
  196. if command == ["pw-link", "-l"]:
  197. return SimpleNamespace(stdout=render_links())
  198. if command == ["pw-link", "-o"]:
  199. return SimpleNamespace(stdout=(
  200. f"{AMP_OUTPUT}\n{CAB_OUTPUT}\n{CAPTURE_0}\n{CAPTURE_2}\n{MIX_OUTPUT}\n"
  201. ))
  202. if command == ["pw-link", "-i"]:
  203. return SimpleNamespace(stdout=(
  204. f"{AMP_INPUT}\n{CAB_INPUT}\n{MIX_INPUT_0}\n{MIX_INPUT_2}\n{PLAYBACK_0}\n"
  205. ))
  206. if command == ["pw-link", CAPTURE_2, MIX_INPUT_2]:
  207. links.add((CAPTURE_2, MIX_INPUT_2))
  208. return SimpleNamespace(stdout="")
  209. self.fail(f"unexpected command: {command}")
  210. result = reconcile_once(state, runner)
  211. self.assertEqual(
  212. result["actions"],
  213. [{"kind": "link", "from": CAPTURE_2, "to": MIX_INPUT_2, "result": "requested"}],
  214. )
  215. self.assertEqual(result["differences"], [])
  216. self.assertIn(["pw-link", CAPTURE_2, MIX_INPUT_2], calls)
  217. def test_reconcile_once_unlinks_only_declared_stale_edge_after_replacement_exists(self):
  218. state = copy.deepcopy(self.state)
  219. state["routing"]["managed_ports"].append(CAPTURE_3)
  220. stale_link = (CAPTURE_0, MIX_INPUT_0)
  221. unrelated_link = (CAPTURE_3, MIX_INPUT_2)
  222. links = {
  223. stale_link,
  224. unrelated_link,
  225. (CAPTURE_2, MIX_INPUT_2),
  226. (MIX_OUTPUT, PLAYBACK_0),
  227. }
  228. calls = []
  229. def render_links():
  230. return "".join(
  231. f"{source}\n |-> {destination}\n"
  232. for source, destination in sorted(links)
  233. )
  234. def runner(command, **kwargs):
  235. calls.append(command)
  236. if command == ["pw-link", "-l"]:
  237. return SimpleNamespace(stdout=render_links())
  238. if command == ["pw-link", "-o"]:
  239. return SimpleNamespace(stdout=(
  240. f"{AMP_OUTPUT}\n{CAB_OUTPUT}\n{CAPTURE_0}\n{CAPTURE_2}\n{MIX_OUTPUT}\n"
  241. ))
  242. if command == ["pw-link", "-i"]:
  243. return SimpleNamespace(stdout=(
  244. f"{AMP_INPUT}\n{CAB_INPUT}\n{MIX_INPUT_0}\n{MIX_INPUT_2}\n{PLAYBACK_0}\n"
  245. ))
  246. if len(command) == 3 and command[0] == "pw-link":
  247. edge = (command[1], command[2])
  248. if edge in {
  249. (CAPTURE_0, AMP_INPUT),
  250. (AMP_OUTPUT, CAB_INPUT),
  251. (CAB_OUTPUT, MIX_INPUT_0),
  252. }:
  253. links.add(edge)
  254. return SimpleNamespace(stdout="")
  255. if len(command) == 4 and command[:2] == ["pw-link", "-d"]:
  256. links.discard((command[2], command[3]))
  257. return SimpleNamespace(stdout="")
  258. self.fail(f"unexpected command: {command}")
  259. result = reconcile_once(state, runner)
  260. self.assertEqual(
  261. result["actions"],
  262. [
  263. {"kind": "link", "from": CAPTURE_0, "to": AMP_INPUT, "result": "requested"},
  264. {"kind": "link", "from": AMP_OUTPUT, "to": CAB_INPUT, "result": "requested"},
  265. {"kind": "link", "from": CAB_OUTPUT, "to": MIX_INPUT_0, "result": "requested"},
  266. {"kind": "unlink", "from": CAPTURE_0, "to": MIX_INPUT_0, "result": "requested"},
  267. ],
  268. )
  269. self.assertNotIn(stale_link, links)
  270. self.assertIn(unrelated_link, links)
  271. self.assertEqual(
  272. result["differences"],
  273. [
  274. {
  275. "kind": "unexpected",
  276. "from": CAPTURE_3,
  277. "to": MIX_INPUT_2,
  278. "action": "would-review",
  279. }
  280. ],
  281. )
  282. self.assertIn(["pw-link", "-d", CAPTURE_0, MIX_INPUT_0], calls)
  283. self.assertNotIn(["pw-link", "-d", CAPTURE_3, MIX_INPUT_2], calls)
  284. def test_reconcile_once_defers_unlink_until_all_desired_links_exist(self):
  285. links = {
  286. (CAPTURE_0, MIX_INPUT_0),
  287. (CAPTURE_2, MIX_INPUT_2),
  288. (MIX_OUTPUT, PLAYBACK_0),
  289. }
  290. calls = []
  291. def render_links():
  292. return "".join(f"{source}\n |-> {destination}\n" for source, destination in sorted(links))
  293. def runner(command, **kwargs):
  294. calls.append(command)
  295. if command == ["pw-link", "-l"]:
  296. return SimpleNamespace(stdout=render_links())
  297. if command == ["pw-link", "-o"]:
  298. return SimpleNamespace(stdout=(
  299. f"{AMP_OUTPUT}\n{CAB_OUTPUT}\n{CAPTURE_0}\n{CAPTURE_2}\n{MIX_OUTPUT}\n"
  300. ))
  301. if command == ["pw-link", "-i"]:
  302. return SimpleNamespace(stdout=(
  303. f"{CAB_INPUT}\n{MIX_INPUT_0}\n{MIX_INPUT_2}\n{PLAYBACK_0}\n"
  304. ))
  305. if command == ["pw-link", AMP_OUTPUT, CAB_INPUT]:
  306. links.add((AMP_OUTPUT, CAB_INPUT))
  307. return SimpleNamespace(stdout="")
  308. if command == ["pw-link", CAB_OUTPUT, MIX_INPUT_0]:
  309. links.add((CAB_OUTPUT, MIX_INPUT_0))
  310. return SimpleNamespace(stdout="")
  311. self.fail(f"unexpected command: {command}")
  312. result = reconcile_once(self.state, runner)
  313. self.assertEqual(
  314. result["actions"],
  315. [
  316. {
  317. "kind": "unavailable-port",
  318. "from": CAPTURE_0,
  319. "to": AMP_INPUT,
  320. "missing_ports": [{"port": AMP_INPUT, "direction": "input"}],
  321. "result": "not-linked",
  322. "reason": "required PipeWire port(s) are not present in the current graph",
  323. "hint": (
  324. "mod-host must be running and load the NAM/IR plugins to expose "
  325. "effect_0/effect_1 ports"
  326. ),
  327. },
  328. {"kind": "link", "from": AMP_OUTPUT, "to": CAB_INPUT, "result": "requested"},
  329. {"kind": "link", "from": CAB_OUTPUT, "to": MIX_INPUT_0, "result": "requested"},
  330. {
  331. "kind": "unlink-deferred",
  332. "from": CAPTURE_0,
  333. "to": MIX_INPUT_0,
  334. "result": "desired managed links are still missing",
  335. },
  336. ],
  337. )
  338. self.assertIn((CAPTURE_0, MIX_INPUT_0), links)
  339. self.assertFalse(any(command[:2] == ["pw-link", "-d"] for command in calls))
  340. def test_reconcile_once_restores_all_managed_links_after_service_restart(self):
  341. links = set()
  342. calls = []
  343. def render_links():
  344. return "".join(f"{source}\n |-> {destination}\n" for source, destination in sorted(links))
  345. def runner(command, **kwargs):
  346. calls.append(command)
  347. if command == ["pw-link", "-l"]:
  348. return SimpleNamespace(stdout=render_links())
  349. if command == ["pw-link", "-o"]:
  350. return SimpleNamespace(stdout=(
  351. f"{AMP_OUTPUT}\n{CAB_OUTPUT}\n{CAPTURE_0}\n{CAPTURE_2}\n{MIX_OUTPUT}\n"
  352. ))
  353. if command == ["pw-link", "-i"]:
  354. return SimpleNamespace(stdout=(
  355. f"{AMP_INPUT}\n{CAB_INPUT}\n{MIX_INPUT_0}\n{MIX_INPUT_2}\n{PLAYBACK_0}\n"
  356. ))
  357. if tuple(command) in {
  358. ("pw-link", AMP_OUTPUT, CAB_INPUT),
  359. ("pw-link", CAB_OUTPUT, MIX_INPUT_0),
  360. ("pw-link", CAPTURE_0, AMP_INPUT),
  361. ("pw-link", CAPTURE_2, MIX_INPUT_2),
  362. ("pw-link", MIX_OUTPUT, PLAYBACK_0),
  363. }:
  364. links.add((command[1], command[2]))
  365. return SimpleNamespace(stdout="")
  366. self.fail(f"unexpected command: {command}")
  367. result = reconcile_once(self.state, runner)
  368. self.assertEqual(
  369. result["actions"],
  370. [
  371. {"kind": "link", "from": CAPTURE_0, "to": AMP_INPUT, "result": "requested"},
  372. {"kind": "link", "from": CAPTURE_2, "to": MIX_INPUT_2, "result": "requested"},
  373. {"kind": "link", "from": AMP_OUTPUT, "to": CAB_INPUT, "result": "requested"},
  374. {"kind": "link", "from": CAB_OUTPUT, "to": MIX_INPUT_0, "result": "requested"},
  375. {"kind": "link", "from": MIX_OUTPUT, "to": PLAYBACK_0, "result": "requested"},
  376. ],
  377. )
  378. self.assertEqual(result["differences"], [])
  379. self.assertEqual(
  380. [command for command in calls if len(command) == 3 and command[0] == "pw-link"],
  381. [
  382. ["pw-link", CAPTURE_0, AMP_INPUT],
  383. ["pw-link", CAPTURE_2, MIX_INPUT_2],
  384. ["pw-link", AMP_OUTPUT, CAB_INPUT],
  385. ["pw-link", CAB_OUTPUT, MIX_INPUT_0],
  386. ["pw-link", MIX_OUTPUT, PLAYBACK_0],
  387. ],
  388. )
  389. def test_reconcile_once_does_not_link_when_endpoint_is_unavailable(self):
  390. state = copy.deepcopy(self.state)
  391. links = {
  392. (CAPTURE_0, AMP_INPUT),
  393. (AMP_OUTPUT, CAB_INPUT),
  394. (CAB_OUTPUT, MIX_INPUT_0),
  395. (CAPTURE_2, MIX_INPUT_2),
  396. (MIX_OUTPUT, PLAYBACK_0),
  397. }
  398. links.remove((CAPTURE_2, MIX_INPUT_2))
  399. calls = []
  400. def render_links():
  401. return "".join(f"{source}\n |-> {destination}\n" for source, destination in sorted(links))
  402. def runner(command, **kwargs):
  403. calls.append(command)
  404. if command == ["pw-link", "-l"]:
  405. return SimpleNamespace(stdout=render_links())
  406. if command == ["pw-link", "-o"]:
  407. return SimpleNamespace(stdout=f"{AMP_OUTPUT}\n{CAB_OUTPUT}\n{CAPTURE_0}\n{MIX_OUTPUT}\n")
  408. if command == ["pw-link", "-i"]:
  409. return SimpleNamespace(stdout=(
  410. f"{AMP_INPUT}\n{CAB_INPUT}\n{MIX_INPUT_0}\n{MIX_INPUT_2}\n{PLAYBACK_0}\n"
  411. ))
  412. self.fail(f"unexpected command: {command}")
  413. result = reconcile_once(state, runner)
  414. self.assertEqual(
  415. result["actions"],
  416. [{
  417. "kind": "unavailable-port",
  418. "from": CAPTURE_2,
  419. "to": MIX_INPUT_2,
  420. "missing_ports": [{"port": CAPTURE_2, "direction": "output"}],
  421. "result": "not-linked",
  422. "reason": "required PipeWire port(s) are not present in the current graph",
  423. }],
  424. )
  425. self.assertTrue(result["differences"])
  426. self.assertFalse(any(command[:2] == ["pw-link", CAPTURE_2] for command in calls))
  427. def test_reconcile_once_preserves_unexpected_managed_links(self):
  428. state = copy.deepcopy(self.state)
  429. state["routing"]["managed_ports"].append(CAPTURE_3)
  430. links = {
  431. (CAPTURE_0, AMP_INPUT),
  432. (AMP_OUTPUT, CAB_INPUT),
  433. (CAB_OUTPUT, MIX_INPUT_0),
  434. (CAPTURE_2, MIX_INPUT_2),
  435. (MIX_OUTPUT, PLAYBACK_0),
  436. (CAPTURE_3, MIX_INPUT_2),
  437. }
  438. calls = []
  439. def runner(command, **kwargs):
  440. calls.append(command)
  441. return SimpleNamespace(
  442. stdout="".join(f"{source}\n |-> {destination}\n" for source, destination in sorted(links))
  443. )
  444. result = reconcile_once(state, runner)
  445. self.assertEqual(result["actions"], [])
  446. self.assertEqual(len(result["differences"]), 1)
  447. self.assertEqual(result["differences"][0]["kind"], "unexpected")
  448. self.assertEqual(calls, [["pw-link", "-l"], ["pw-link", "-l"]])
  449. def test_reconcile_once_reports_link_still_missing_after_request(self):
  450. state = copy.deepcopy(self.state)
  451. links = {
  452. (CAPTURE_0, AMP_INPUT),
  453. (AMP_OUTPUT, CAB_INPUT),
  454. (CAB_OUTPUT, MIX_INPUT_0),
  455. (MIX_OUTPUT, PLAYBACK_0),
  456. }
  457. def render_links():
  458. return "".join(f"{source}\n |-> {destination}\n" for source, destination in sorted(links))
  459. def runner(command, **kwargs):
  460. if command == ["pw-link", "-l"]:
  461. return SimpleNamespace(stdout=render_links())
  462. if command == ["pw-link", "-o"]:
  463. return SimpleNamespace(stdout=(
  464. f"{AMP_OUTPUT}\n{CAB_OUTPUT}\n{CAPTURE_0}\n{CAPTURE_2}\n{MIX_OUTPUT}\n"
  465. ))
  466. if command == ["pw-link", "-i"]:
  467. return SimpleNamespace(stdout=(
  468. f"{AMP_INPUT}\n{CAB_INPUT}\n{MIX_INPUT_0}\n{MIX_INPUT_2}\n{PLAYBACK_0}\n"
  469. ))
  470. if command == ["pw-link", CAPTURE_2, MIX_INPUT_2]:
  471. return SimpleNamespace(stdout="")
  472. self.fail(f"unexpected command: {command}")
  473. result = reconcile_once(state, runner)
  474. self.assertEqual(len(result["differences"]), 1)
  475. self.assertEqual(result["differences"][0]["kind"], "missing")
  476. def test_managed_links_must_use_declared_ports(self):
  477. state = copy.deepcopy(self.state)
  478. state["routing"]["managed_ports"].remove(PLAYBACK_0)
  479. state["routing"]["managed_links"] = [
  480. {"from": CAPTURE_0, "to": PLAYBACK_0, "status": "planned"}
  481. ]
  482. self.assertTrue(any("endpoints must be listed" in error for error in validate_managed_links(state)))
  483. def test_managed_link_cannot_also_be_scheduled_for_removal(self):
  484. state = copy.deepcopy(self.state)
  485. state["routing"]["managed_links"].append(
  486. {"from": CAPTURE_0, "to": MIX_INPUT_0, "status": "planned"}
  487. )
  488. self.assertTrue(
  489. any(
  490. "link cannot be both managed and scheduled for removal" in error
  491. for error in validate_managed_links(state)
  492. )
  493. )
  494. if __name__ == "__main__":
  495. unittest.main()