feat(subscription): enable observation mode

This commit is contained in:
chengma
2026-07-23 14:37:00 +08:00
parent a2b57db715
commit 594592c9b2
6 changed files with 129 additions and 22 deletions
+81 -6
View File
@@ -11180,28 +11180,103 @@ class GuiTests(TempDirMixin, unittest.TestCase):
self.addCleanup(window.close)
status = subscription.SubscriptionStatus(subscription.STATUS_EXPIRED)
window._apply_subscription_status(status)
with mock.patch.object(
main_window,
"SUBSCRIPTION_ENFORCEMENT_ENABLED",
True,
):
window._apply_subscription_status(status)
for index, title in enumerate(TAB_TITLES):
self.assertEqual(title == "设置", window.tabs.isTabEnabled(index))
self.assertEqual(TAB_TITLES.index("设置"), window.tabs.currentIndex())
def test_main_window_temporarily_bypasses_subscription_checks(self):
self.assertFalse(main_window.SUBSCRIPTION_CHECK_ENABLED)
def test_main_window_observation_mode_checks_without_restricting_workflows(self):
self.assertTrue(main_window.SUBSCRIPTION_CHECK_ENABLED)
self.assertFalse(main_window.SUBSCRIPTION_ENFORCEMENT_ENABLED)
class _Signal:
def __init__(self):
self.callbacks = []
def connect(self, callback):
self.callbacks.append(callback)
class _Worker:
def __init__(self):
self.finished = _Signal()
self.cancelled = _Signal()
self.cancelled_requested = False
def cancel(self):
self.cancelled_requested = True
class _Thread:
def __init__(self):
self.finished = _Signal()
self.started = False
def start(self):
self.started = True
with self.make_temp_dir() as temp_dir:
window = MainWindow(config=self.make_config(temp_dir))
self.addCleanup(window.close)
worker = _Worker()
thread = _Thread()
with mock.patch("app.gui.main_window.SubscriptionCheckWorker") as worker:
with mock.patch(
"app.gui.main_window.SubscriptionCheckWorker",
return_value=worker,
) as worker_factory, mock.patch(
"app.gui.main_window.run_worker",
return_value=thread,
):
window.begin_subscription_check()
worker.assert_not_called()
self.assertEqual("会员:订阅检测已暂停", window._subscription_label.text())
worker_factory.assert_called_once()
self.assertTrue(thread.started)
self.assertEqual("会员:正在验证", window._subscription_label.text())
self.assertTrue(
all(window.tabs.isTabEnabled(index) for index in range(window.tabs.count()))
)
expired = subscription.SubscriptionStatus(subscription.STATUS_EXPIRED)
with mock.patch.object(window, "_show_subscription_notice_once") as notice:
window._apply_subscription_status(expired)
notice.assert_not_called()
self.assertIn("当前不影响使用", window._subscription_label.text())
self.assertIn("当前不影响使用", window.statusBar().currentMessage())
self.assertTrue(
all(window.tabs.isTabEnabled(index) for index in range(window.tabs.count()))
)
self.assertTrue(window.ensure_subscription_for_new_submit("开始 AI 生成"))
def test_main_window_observation_mode_suppresses_notice_and_rechecks_after_save(self):
with self.make_temp_dir() as temp_dir:
window = MainWindow(config=self.make_config(temp_dir))
self.addCleanup(window.close)
status = subscription.SubscriptionStatus(
subscription.STATUS_ACTIVE,
account_name="主账号",
plan_name="测试",
expires_at="2026-08-21T23:59:59+08:00",
notice_id="subscription-test-plan",
)
with mock.patch.object(window, "_show_subscription_notice_once") as notice:
window._apply_subscription_status(status)
notice.assert_not_called()
self.assertIn("主账号 · 测试 · 有效至2026-08-21", window._subscription_label.text())
self.assertIn("观察模式", window.statusBar().currentMessage())
with mock.patch.object(window, "begin_subscription_check") as check:
window._on_settings_saved("cmhub")
check.assert_called_once_with()
def test_generate_and_suite_preflight_can_stop_new_submissions(self):
with self.make_temp_dir() as temp_dir:
config = self.make_config(temp_dir)