import asyncio import pytest from beaver.foundation.config.schema import AuthzConfig, BackendIdentityConfig, BeaverConfig from beaver.integrations import outlook class _FakeAuthzClient: async def get_outlook_settings(self, backend_id: str) -> dict: assert backend_id == "steven" return { "configured": True, "email": "steven.yx.li@boardware.com", "server": "mail.boardware.com.mo", } def _authz_config() -> BeaverConfig: return BeaverConfig( authz=AuthzConfig( enabled=True, base_url="http://authz.example", outlook_mcp_url="http://outlook-mcp.example/mcp", ), backend_identity=BackendIdentityConfig( backend_id="steven", client_id="steven", client_secret="secret", ), ) def test_outlook_status_does_not_probe_mcp_by_default(monkeypatch: pytest.MonkeyPatch, tmp_path) -> None: monkeypatch.setattr(outlook, "_authz_client", lambda _config: _FakeAuthzClient()) async def fail_if_called(*_args, **_kwargs): raise AssertionError("status should not call Outlook MCP by default") monkeypatch.setattr(outlook, "_call_outlook_mcp_tool", fail_if_called) result = asyncio.run(outlook.outlook_status(_authz_config(), tmp_path)) assert result["configured"] is True assert result["connected"] is False assert result["auth_status"] is None assert result["error"] is None def test_outlook_overview_loads_sections_serially(monkeypatch: pytest.MonkeyPatch, tmp_path) -> None: monkeypatch.setattr(outlook, "_authz_client", lambda _config: _FakeAuthzClient()) active_calls = 0 max_active_calls = 0 tool_names: list[str] = [] async def fake_call(_config, tool_name: str, _arguments, **_kwargs): nonlocal active_calls, max_active_calls tool_names.append(tool_name) active_calls += 1 max_active_calls = max(max_active_calls, active_calls) await asyncio.sleep(0.01) active_calls -= 1 return {"value": []} monkeypatch.setattr(outlook, "_call_outlook_mcp_tool", fake_call) result = asyncio.run(outlook.get_overview(_authz_config(), tmp_path)) assert result["warnings"] == [] assert tool_names == ["mail_list_messages", "mail_list_messages", "calendar_list_events"] assert max_active_calls == 1