Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(config): validate all enabled platforms have credentials, not just primary

cyhhao2e48991d3767
diff --git a/config/v2_config.py b/config/v2_config.py
index ec4ae021d..b923a94e2 100644
--- a/config/v2_config.py
+++ b/config/v2_config.py
@@ -259,8 +259,6 @@ class V2Config:
if discord_payload is not None:
discord = DiscordConfig(**_filter_dataclass_fields(DiscordConfig, discord_payload))
discord.validate()
- if platform == "discord" and discord is None:
- raise ValueError("Config 'discord' must be provided when platform is discord")
lark_payload = payload.get("lark")
if lark_payload is not None and not isinstance(lark_payload, dict):
@@ -269,8 +267,6 @@ class V2Config:
if lark_payload is not None:
lark = LarkConfig(**_filter_dataclass_fields(LarkConfig, lark_payload))
lark.validate()
- if platform == "lark" and lark is None:
- raise ValueError("Config 'lark' must be provided when platform is lark")
wechat_payload = payload.get("wechat")
if wechat_payload is not None and not isinstance(wechat_payload, dict):
@@ -279,8 +275,19 @@ class V2Config:
if wechat_payload is not None:
wechat = WeChatConfig(**_filter_dataclass_fields(WeChatConfig, wechat_payload))
wechat.validate()
- if platform == "wechat" and wechat is None:
- raise ValueError("Config 'wechat' must be provided when platform is wechat")
+
+ # Validate that every enabled platform has its config section present.
+ # The old single-platform check (``if platform == "discord"``) only
+ # guarded the primary; with multi-platform enabled we must ensure ALL
+ # enabled platforms have valid credentials so that the runtime won't
+ # crash on startup with a config that was already persisted to disk.
+ for _ep in platforms.enabled:
+ if _ep == "discord" and discord is None:
+ raise ValueError("Config 'discord' must be provided when discord is enabled")
+ if _ep == "lark" and lark is None:
+ raise ValueError("Config 'lark' must be provided when lark is enabled")
+ if _ep == "wechat" and wechat is None:
+ raise ValueError("Config 'wechat' must be provided when wechat is enabled")
gateway_payload = payload.get("gateway")
if gateway_payload is not None and not isinstance(gateway_payload, dict):
diff --git a/config/v2_sessions.py b/config/v2_sessions.py
index afb0bf60d..3dbad493d 100644
--- a/config/v2_sessions.py
+++ b/config/v2_sessions.py
@@ -121,7 +121,8 @@ class SessionsStore:
# Migrate unscoped settings_key → platform::key
sk = data.get("settings_key", "")
if sk and "::" not in sk:
- data["settings_key"] = f"{default_platform}::{sk}"
+ prefix = data.get("platform") or default_platform
+ data["settings_key"] = f"{prefix}::{sk}"
migrated = True
if migrated:
self.save()
diff --git a/tests/test_api_save_config_merge.py b/tests/test_api_save_config_merge.py
index 8085c7e5b..dfe6339e7 100644
--- a/tests/test_api_save_config_merge.py
+++ b/tests/test_api_save_config_merge.py
@@ -111,6 +111,13 @@ def test_save_config_preserves_platforms_metadata(monkeypatch, tmp_path):
updated = api.save_config(
{
**_full_config_payload(),
+ "wechat": {
+ "corp_id": "wk123",
+ "agent_id": "agent1",
+ "secret": "sec",
+ "token": "tok",
+ "aes_key": "aes",
+ },
"platforms": {"enabled": ["slack", "discord", "wechat"], "primary": "discord"},
}
)
@@ -129,3 +136,18 @@ def test_save_config_migrates_legacy_single_platform(monkeypatch, tmp_path):
assert updated.platforms.primary == "discord"
assert updated.platforms.enabled == ["discord"]
assert payload["platforms"] == {"enabled": ["discord"], "primary": "discord"}
+
+
+def test_save_config_rejects_enabled_platform_without_credentials(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+
+ import pytest
+
+ with pytest.raises(ValueError, match="wechat.*must be provided"):
+ api.save_config(
+ {
+ **_full_config_payload(),
+ "platforms": {"enabled": ["slack", "discord", "wechat"], "primary": "discord"},
+ # wechat config intentionally omitted
+ }
+ )