mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-10 23:30:53 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
99
tests/test_oclaw_gmail_watcher_lifecycle.py
Normal file
99
tests/test_oclaw_gmail_watcher_lifecycle.py
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from oclaw.runtime.hooks.gmail_watcher import GmailWatcherResult
|
||||
from oclaw.runtime.hooks.gmail_watcher_lifecycle import start_gmail_watcher_with_logs
|
||||
|
||||
|
||||
@dataclass
|
||||
class _Log:
|
||||
infos: list[str] = field(default_factory=list)
|
||||
warns: list[str] = field(default_factory=list)
|
||||
errors: list[str] = field(default_factory=list)
|
||||
|
||||
def info(self, msg: str) -> None:
|
||||
self.infos.append(msg)
|
||||
|
||||
def warn(self, msg: str) -> None:
|
||||
self.warns.append(msg)
|
||||
|
||||
def error(self, msg: str) -> None:
|
||||
self.errors.append(msg)
|
||||
|
||||
|
||||
def test_gmail_lifecycle_logs_startup_success() -> None:
|
||||
log = _Log()
|
||||
start_gmail_watcher_with_logs(
|
||||
cfg={},
|
||||
log=log,
|
||||
starter=lambda _cfg: GmailWatcherResult(started=True),
|
||||
)
|
||||
assert log.infos == ["gmail watcher started"]
|
||||
assert not log.warns
|
||||
assert not log.errors
|
||||
|
||||
|
||||
def test_gmail_lifecycle_logs_actionable_reason() -> None:
|
||||
log = _Log()
|
||||
start_gmail_watcher_with_logs(
|
||||
cfg={},
|
||||
log=log,
|
||||
starter=lambda _cfg: GmailWatcherResult(started=False, reason="auth failed"),
|
||||
)
|
||||
assert log.warns == ["gmail watcher not started: auth failed"]
|
||||
|
||||
|
||||
def test_gmail_lifecycle_suppresses_expected_reason() -> None:
|
||||
log = _Log()
|
||||
start_gmail_watcher_with_logs(
|
||||
cfg={},
|
||||
log=log,
|
||||
starter=lambda _cfg: GmailWatcherResult(started=False, reason="hooks not enabled"),
|
||||
)
|
||||
assert not log.warns
|
||||
|
||||
|
||||
def test_gmail_lifecycle_supports_skip_callback_oclaw_env(monkeypatch) -> None:
|
||||
monkeypatch.setenv("OCLAW_SKIP_GMAIL_WATCHER", "1")
|
||||
monkeypatch.delenv("OPENCLAW_SKIP_GMAIL_WATCHER", raising=False)
|
||||
log = _Log()
|
||||
called = {"skip": 0}
|
||||
start_gmail_watcher_with_logs(
|
||||
cfg={},
|
||||
log=log,
|
||||
on_skipped=lambda: called.__setitem__("skip", called["skip"] + 1),
|
||||
starter=lambda _cfg: GmailWatcherResult(started=True),
|
||||
)
|
||||
assert called["skip"] == 1
|
||||
assert not log.infos
|
||||
|
||||
|
||||
def test_gmail_lifecycle_supports_skip_callback(monkeypatch) -> None:
|
||||
monkeypatch.delenv("OCLAW_SKIP_GMAIL_WATCHER", raising=False)
|
||||
monkeypatch.setenv("OPENCLAW_SKIP_GMAIL_WATCHER", "1")
|
||||
log = _Log()
|
||||
called = {"skip": 0}
|
||||
start_gmail_watcher_with_logs(
|
||||
cfg={},
|
||||
log=log,
|
||||
on_skipped=lambda: called.__setitem__("skip", called["skip"] + 1),
|
||||
starter=lambda _cfg: GmailWatcherResult(started=True),
|
||||
)
|
||||
assert called["skip"] == 1
|
||||
assert not log.infos
|
||||
|
||||
|
||||
def test_gmail_lifecycle_logs_startup_error() -> None:
|
||||
log = _Log()
|
||||
|
||||
def _raise(_cfg):
|
||||
raise RuntimeError("boom")
|
||||
|
||||
start_gmail_watcher_with_logs(
|
||||
cfg={},
|
||||
log=log,
|
||||
starter=_raise,
|
||||
)
|
||||
assert log.errors == ["gmail watcher failed to start: boom"]
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue