From 23ca16e317a1f49346d0c5134f7a18fc9e06e8ab Mon Sep 17 00:00:00 2001 From: Kacper Paczos Date: Tue, 18 Aug 2026 08:32:53 +0200 Subject: [PATCH] fix(tests): stop test_whispercpp_advanced_persistence clobbering the real config (#694) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestTypedAccessors builds its ConfigManager with __new__ and, unlike TestConfigManager, never patches CONFIG_DIR/CONFIG_FILE. That is fine for the accessor tests, but test_whispercpp_advanced_persistence calls save_config(), which writes the synthetic fixture from setUp over the developer's real ~/.config/vocalinux/config.json — running the suite silently wiped every personal setting. Caught by making the real file read-only and running the suite with live logging; it is the only write to the real path in the entire suite. Redirect the paths to a temp directory for this test, the same way TestConfigManager's setUp already does. Co-authored-by: Jatin K Malik --- tests/test_config_manager.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/test_config_manager.py b/tests/test_config_manager.py index dad2f10..142c9c3 100644 --- a/tests/test_config_manager.py +++ b/tests/test_config_manager.py @@ -604,13 +604,23 @@ class TestTypedAccessors(unittest.TestCase): self.assertEqual(advanced["whispercpp_n_threads"], 0) def test_whispercpp_advanced_persistence(self): - self.config_manager.set("advanced", "whispercpp_temperature", 0.5) - self.config_manager.set("advanced", "whispercpp_no_timestamps", False) - self.config_manager.set("advanced", "whispercpp_initial_prompt", "Meeting notes") - self.config_manager.save_config() + # This class skips ConfigManager.__init__, so unlike TestConfigManager + # nothing has redirected CONFIG_FILE: without the patches below this + # save_config() overwrites the developer's real ~/.config/vocalinux/ + # config.json with the synthetic fixture from setUp. + with tempfile.TemporaryDirectory() as temp_dir: + temp_file = os.path.join(temp_dir, "config.json") + with ( + patch("vocalinux.ui.config_manager.CONFIG_DIR", temp_dir), + patch("vocalinux.ui.config_manager.CONFIG_FILE", temp_file), + ): + self.config_manager.set("advanced", "whispercpp_temperature", 0.5) + self.config_manager.set("advanced", "whispercpp_no_timestamps", False) + self.config_manager.set("advanced", "whispercpp_initial_prompt", "Meeting notes") + self.config_manager.save_config() - new_manager = ConfigManager() - advanced = new_manager.get_settings().get("advanced", {}) - self.assertEqual(advanced["whispercpp_temperature"], 0.5) - self.assertFalse(advanced["whispercpp_no_timestamps"]) - self.assertEqual(advanced["whispercpp_initial_prompt"], "Meeting notes") + new_manager = ConfigManager() + advanced = new_manager.get_settings().get("advanced", {}) + self.assertEqual(advanced["whispercpp_temperature"], 0.5) + self.assertFalse(advanced["whispercpp_no_timestamps"]) + self.assertEqual(advanced["whispercpp_initial_prompt"], "Meeting notes")