From 7cf7d2f7849936e3c84ee431433c2e8bcb6706ac Mon Sep 17 00:00:00 2001 From: historia Date: Wed, 26 Aug 2026 00:21:28 -0400 Subject: fix: harden server start/stop guards --- app/tests/test_backends_faster.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'app/tests/test_backends_faster.py') diff --git a/app/tests/test_backends_faster.py b/app/tests/test_backends_faster.py index 7e27b47..55d617c 100644 --- a/app/tests/test_backends_faster.py +++ b/app/tests/test_backends_faster.py @@ -203,6 +203,31 @@ class MainTests(unittest.TestCase): self.assertTrue(custom.exists()) self.assertFalse(self.output.exists()) + def test_fresh_install_defaults_voices_json_into_the_checkout(self): + # Regression: on a fresh machine the clone runs as part of this + # same setup run, so voices.json must be written where detect() + # and the server launch read it (the checkout) — not the wav dir. + checkout = Path(self._tmp.name) / "faster-qwen3-tts" + + def fake_clone(url, target, emit=None, cancel=None): + checkout.mkdir(parents=True, exist_ok=True) # what git would do + return 0 + + with patch.object(make_voices, "_is_installed", return_value=False), \ + patch.object(make_voices, "_checkout", + return_value=checkout), \ + patch.object(make_voices.common, "pip_install", + return_value=0), \ + patch.object(make_voices.common, "git_clone", + side_effect=fake_clone) as mk_clone: + exit_code = self._run([str(self.folder)]) + self.assertEqual(exit_code, 0) + mk_clone.assert_called_once() + voices = json.loads( + (checkout / "voices.json").read_text(encoding="utf-8")) + self.assertEqual(list(voices), ["alpha", "narrator"]) + self.assertFalse((self.folder / "voices.json").exists()) + def test_invalid_language_errors_before_work(self): with patch.object(make_voices, "transcribe_reference_audio") as mock_transcribe: with self.assertRaises(SystemExit) as ctx: @@ -288,6 +313,8 @@ class UninstallTests(unittest.TestCase): checkout.mkdir() with patch.object(make_voices, "_checkout", return_value=checkout), \ + patch.object(make_voices.servers, "pid_for", + return_value=1234), \ patch.object(make_voices.servers, "stop") as mk_stop, \ patch.object(make_voices.common, "pip_uninstall", return_value=0) as mk_pip: @@ -301,17 +328,23 @@ class UninstallTests(unittest.TestCase): def test_no_checkout_still_uninstalls_the_package(self): with patch.object(make_voices, "_checkout", return_value=Path("/no/such/dir")), \ - patch.object(make_voices.servers, "stop"), \ + patch.object(make_voices.servers, "pid_for", + return_value=None), \ + patch.object(make_voices.servers, "stop") as mk_stop, \ patch.object(make_voices.common, "pip_uninstall", return_value=0) as mk_pip: rc = make_voices.uninstall() self.assertEqual(rc, 0) + # No pid file: no stop attempt (and no noise about it). + mk_stop.assert_not_called() mk_pip.assert_called_once_with(["faster-qwen3-tts"], emit=None) def test_cancel_before_pip_skips_everything_after_stopping(self): cancel = threading.Event() cancel.set() - with patch.object(make_voices.servers, "stop") as mk_stop, \ + with patch.object(make_voices.servers, "pid_for", + return_value=1234), \ + patch.object(make_voices.servers, "stop") as mk_stop, \ patch.object(make_voices.common, "pip_uninstall") as mk_pip: rc = make_voices.uninstall(cancel=cancel) self.assertEqual(rc, 130) @@ -328,6 +361,8 @@ class UninstallTests(unittest.TestCase): cancel.set() with patch.object(make_voices, "_checkout", return_value=checkout), \ + patch.object(make_voices.servers, "pid_for", + return_value=1234), \ patch.object(make_voices.servers, "stop"), \ patch.object(make_voices.common, "pip_uninstall", return_value=0): -- cgit v1.2.3