Doubao-powered voice input for Linux, Wayland and Omarchy
fix(settings): 1.7.0 发布前补齐凭证保存提示 (#80)
Leyang19e46bf99f60
diff --git a/src/doubao_input/ui/settings_window.py b/src/doubao_input/ui/settings_window.pyindex 86bd67d..3abcefa 100644--- a/src/doubao_input/ui/settings_window.py+++ b/src/doubao_input/ui/settings_window.py@@ -500,6 +500,8 @@ class SettingsWindow:self._save_asr(key)except (ValueError, OSError) as error:self.asr_status.set_text(str(error))+ self.status.set_text(tr(+ "API key could not be saved. Try again.", "API Key 保存失败,请重试。"))return Falseself._asr_has_key = Trueself._updating = True@@ -510,6 +512,7 @@ class SettingsWindow:finally:self._updating = Falseself.asr_status.set_text(tr("API key saved automatically.", "API Key 已自动保存。"))+ self.status.set_text(tr("API key saved automatically.", "API Key 已自动保存。"))return Truedef flush_edits(self):@@ -536,12 +539,14 @@ class SettingsWindow:finally:self._updating = Falseself.asr_status.set_text(tr("API key cleared.", "API Key 已清除。"))+ self.status.set_text(tr("API key cleared.", "API Key 已清除。"))def _test_asr_clicked(self, *_):if self._asr_testing:return- if not self._save_asr_key_now() or not (- self._asr_has_key or self.asr_key.get_text().strip()):+ if not self.flush_edits():+ return+ if not (self._asr_has_key or self.asr_key.get_text().strip()):self.asr_status.set_text(tr("Enter an API key first.", "请先填写 API Key。"))returnself._asr_testing = Truediff --git a/tests/e2e/cases/onboarding-regressions.yaml b/tests/e2e/cases/onboarding-regressions.yamlindex b2d79dc..864fad3 100644--- a/tests/e2e/cases/onboarding-regressions.yaml+++ b/tests/e2e/cases/onboarding-regressions.yaml@@ -222,14 +222,14 @@ cases:- aiWaitFor:prompt: The API key is accepted by the synthetic endpoint and the speech API is ready.options: { timeoutMs: 30000, checkIntervalMs: 1000 }- - aiAct: Switch the Recognition service to Volcengine API.+ - aiAct: Switch the Recognition service to Volcengine API. Then scroll within the Recognition page until the API Key entry, Test API key button, and credential status beneath it are visible.- aiWaitFor:- prompt: Volcengine is selected, the empty API Key entry says Enter speech API key, and Test API key is disabled.+ prompt: The Volcengine API credential instructions are visible, the empty API Key entry says Enter speech API key, and Test API key is disabled.options: { timeoutMs: 30000, checkIntervalMs: 1000 }- aiAssert: The page says no API key is saved for this service and does not show the previous accepted result.- - aiAct: Switch the Recognition service back to Deepgram Nova-3 (English).+ - aiAct: Switch the Recognition service back to Deepgram Nova-3 (English). Then scroll within the Recognition page until the API Key entry and Test API key button are visible.- aiWaitFor:- prompt: Deepgram is selected, the empty API Key entry says Saved — leave blank to keep, and Test API key is enabled.+ prompt: The Deepgram API credential instructions are visible, the empty API Key entry says Saved — leave blank to keep, and Test API key is enabled.options: { timeoutMs: 30000, checkIntervalMs: 1000 }- aiAct: Test the saved Deepgram API key.- aiWaitFor:diff --git a/tests/manual/asr_key_ui.py b/tests/manual/asr_key_ui.pyindex 928321a..b236e64 100644--- a/tests/manual/asr_key_ui.py+++ b/tests/manual/asr_key_ui.py@@ -112,6 +112,11 @@ def main():assert window.window.get_visible()assert window.asr_key.get_text() == "synthetic-deepgram-replacement"assert DeepgramCredentialsStore.load().api_key == "synthetic-deepgram-original"+ assert window.status.get_text() == tr(+ "API key could not be saved. Try again.", "API Key 保存失败,请重试。")+ window.asr_test_button.emit("clicked")+ assert window.asr_status.get_text() == "Synthetic save failure"+ assert not window._asr_testing and app._asr_probe is Nonecapture("settings-save-failure")assert window.flush_edits()assert DeepgramCredentialsStore.load().api_key == "synthetic-deepgram-replacement"diff --git a/tests/unit/test_asr_key_persistence.py b/tests/unit/test_asr_key_persistence.pyindex bfbe372..859fe6f 100644--- a/tests/unit/test_asr_key_persistence.py+++ b/tests/unit/test_asr_key_persistence.py@@ -17,7 +17,7 @@ class ASRKeyPersistenceTest(TestCase):entry.set_text.side_effect = lambda text: setattr(self, "draft", text)view = SimpleNamespace(_updating=False, _asr_save_source=0, _asr_has_key=False, _asr_testing=False,- asr_key=entry, asr_status=Mock(), asr_provider=Mock(),+ asr_key=entry, asr_status=Mock(), asr_provider=Mock(), status=Mock(),_sync_provider_details=Mock(), _restore_controls=Mock(),_save_asr=lambda key: self.saved.__setitem__(self.provider, key),_asr_has_key_func=lambda: self.provider in self.saved,@@ -31,6 +31,14 @@ class ASRKeyPersistenceTest(TestCase):setattr(view, name, MethodType(getattr(SettingsWindow, name), view))return view+ def test_successful_key_clear_replaces_footer_error(self):+ view = self.view()+ view._clear_asr = Mock()+ view.status.set_text("API key could not be saved. Try again.")+ SettingsWindow._clear_asr_clicked(view)+ self.assertFalse(view._asr_has_key)+ view.status.set_text.assert_called_with("API key cleared.")+def test_saved_and_pending_drafts_never_overwrite_other_provider(self):for already_saved in (False, True):with self.subTest(already_saved=already_saved):@@ -56,6 +64,16 @@ class ASRKeyPersistenceTest(TestCase):view._restore_controls.assert_called_once()self.assertEqual(self.draft, "synthetic-volcengine")self.assertEqual(self.saved, {"deepgram": "synthetic-deepgram"})+ view.status.set_text.assert_called_with("API key could not be saved. Try again.")++ def test_key_test_preserves_save_error_and_does_not_start_probe(self):+ view = self.view()+ view._save_asr = Mock(side_effect=OSError("synthetic write failure"))+ view._test_asr = Mock()+ SettingsWindow._test_asr_clicked(view)+ view._test_asr.assert_not_called()+ view.asr_status.set_text.assert_called_with("synthetic write failure")+ self.assertFalse(view._asr_testing)def test_failed_key_save_keeps_settings_open(self):view = self.view()diff --git a/tests/unit/test_setup_actions.py b/tests/unit/test_setup_actions.pyindex f5a25a1..7a222f8 100644--- a/tests/unit/test_setup_actions.py+++ b/tests/unit/test_setup_actions.py@@ -236,16 +236,19 @@ class SetupActionsTest(unittest.TestCase):def test_official_key_test_saves_first_and_has_adjacent_feedback(self):view = SimpleNamespace(_asr_testing=False,+ _asr_save_source=0,asr_provider=Mock(),_asr_has_key=False,_save_asr=Mock(),_test_asr=Mock(),asr_key=Mock(),asr_status=Mock(),+ status=Mock(),asr_test_button=Mock(),)view.asr_key.get_text.return_value = "test-key"view._save_asr_key_now = lambda: SettingsWindow._save_asr_key_now(view)+ view.flush_edits = lambda: SettingsWindow.flush_edits(view)view._asr_tested = lambda result, error: SettingsWindow._asr_tested(view, result, error)