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 enabled platform transitions

cyh5c83ef698a6b
diff --git a/tests/test_api_save_config_merge.py b/tests/test_api_save_config_merge.py
index 45fab57c0..9787368e8 100644
--- a/tests/test_api_save_config_merge.py
+++ b/tests/test_api_save_config_merge.py
@@ -460,6 +460,48 @@ def test_save_config_rejects_enabled_platform_without_runtime_credentials(monkey
)
+def test_save_config_rejects_setup_completion_with_enabled_platform_without_runtime_credentials(
+ monkeypatch, tmp_path
+):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+
+ import pytest
+
+ payload = _full_config_payload()
+ payload["platform"] = "avibe"
+ payload["platforms"] = {"enabled": [], "primary": "avibe"}
+ created = api.save_config(payload)
+ assert created.platforms.enabled == []
+
+ with pytest.raises(ValueError, match="Config 'lark.app_id', 'lark.app_secret' must be provided"):
+ api.save_config(
+ {
+ "platform": "lark",
+ "platforms": {"enabled": ["lark"], "primary": "lark"},
+ "lark": {"domain": "feishu"},
+ "setup_completed": True,
+ }
+ )
+
+
+def test_save_config_allows_unrelated_save_for_legacy_enabled_platform_without_runtime_credentials(
+ monkeypatch, tmp_path
+):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+
+ payload = _full_config_payload()
+ payload["platform"] = "slack"
+ payload["platforms"] = {"enabled": ["slack"], "primary": "slack"}
+ payload["slack"] = {"bot_token": "", "app_token": ""}
+ V2Config.from_payload(payload).save()
+
+ updated = api.save_config({"remote_access": {"vibe_cloud": {"enabled": False}}})
+
+ assert updated.platforms.enabled == ["slack"]
+ assert updated.slack.bot_token == ""
+ assert updated.remote_access.vibe_cloud.enabled is False
+
+
def test_save_config_preserves_disabled_platform_credentials(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
diff --git a/tests/test_ui_server_mutation_protection.py b/tests/test_ui_server_mutation_protection.py
index 7d2117523..3414471e2 100644
--- a/tests/test_ui_server_mutation_protection.py
+++ b/tests/test_ui_server_mutation_protection.py
@@ -2,7 +2,7 @@ from __future__ import annotations
from http.cookies import SimpleCookie
-from config.v2_config import AgentsConfig, RuntimeConfig, SlackConfig, V2Config
+from config.v2_config import AgentsConfig, PlatformsConfig, RuntimeConfig, SlackConfig, V2Config
from vibe.ui_server import app, protect_mutating_ui_requests
from tests.ui_server_test_helpers import csrf_headers
@@ -151,6 +151,37 @@ def test_config_post_allows_forwarded_origin(monkeypatch, tmp_path):
assert response.status_code == 200
+def test_config_post_returns_400_for_enabled_platform_missing_credentials(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ V2Config(
+ mode="self_host",
+ version="v2",
+ platform="avibe",
+ platforms=PlatformsConfig(enabled=[], primary="avibe"),
+ slack=SlackConfig(bot_token=""),
+ runtime=RuntimeConfig(default_cwd="."),
+ agents=AgentsConfig(),
+ ).save()
+ client = app.test_client()
+ headers = csrf_headers(client, "http://127.0.0.1:15131")
+
+ response = client.post(
+ "/api/config",
+ json={
+ "platform": "lark",
+ "platforms": {"enabled": ["lark"], "primary": "lark"},
+ "lark": {"domain": "feishu"},
+ },
+ headers=headers,
+ base_url="http://127.0.0.1:15131",
+ )
+
+ body = response.get_json()
+ assert response.status_code == 400
+ assert "lark.app_id" in body["error"]
+ assert body["message"] == body["error"]
+
+
def test_mutation_guard_exempts_e2e_simulation_endpoint(monkeypatch):
monkeypatch.setenv("E2E_TEST_MODE", "true")
with app.test_request_context("/e2e/simulate-interaction", method="POST"):
diff --git a/ui/src/components/Wizard.tsx b/ui/src/components/Wizard.tsx
index 9a5770be3..6b6f2e77b 100644
--- a/ui/src/components/Wizard.tsx
+++ b/ui/src/components/Wizard.tsx
@@ -236,18 +236,31 @@ export const Wizard: React.FC = () => {
const persistStep = async (stepData: any, mergedData: any) => {
if (!mergedData) return;
- if (
- mergedData.agents ||
- mergedData.slack ||
- mergedData.discord ||
- mergedData.telegram ||
- mergedData.lark ||
- mergedData.wechat ||
- mergedData.mode ||
- mergedData.platforms ||
- mergedData.platform ||
- mergedData.channelConfigsByPlatform
- ) {
+ const platformSelectionOnly =
+ Boolean(stepData.platforms || stepData.platform) &&
+ !stepData.agents &&
+ !stepData.slack &&
+ !stepData.discord &&
+ !stepData.telegram &&
+ !stepData.lark &&
+ !stepData.wechat &&
+ !stepData.mode &&
+ !stepData.channelConfigsByPlatform;
+ const shouldPersistConfig =
+ !platformSelectionOnly &&
+ Boolean(
+ mergedData.agents ||
+ mergedData.slack ||
+ mergedData.discord ||
+ mergedData.telegram ||
+ mergedData.lark ||
+ mergedData.wechat ||
+ mergedData.mode ||
+ mergedData.platforms ||
+ mergedData.platform ||
+ mergedData.channelConfigsByPlatform
+ );
+ if (shouldPersistConfig) {
await api.saveConfig(buildConfigPayload(mergedData));
}
const discordGuildAllowlist = stepData?.discordGuildAllowlist;
diff --git a/ui/src/components/steps/PlatformSelection.tsx b/ui/src/components/steps/PlatformSelection.tsx
index 7586bdde9..0abba3693 100644
--- a/ui/src/components/steps/PlatformSelection.tsx
+++ b/ui/src/components/steps/PlatformSelection.tsx
@@ -124,9 +124,7 @@ export const PlatformSelection: React.FC<PlatformSelectionProps> = ({ data, onNe
// force a fallback platform into the enabled set.
const normalized = selected;
const resolvedPrimary = normalized.includes(primary) ? primary : (normalized[0] ?? '');
- const nextData = {
- ...credentialDraft,
- discord_client_id: credentialDraft.discord?.client_id || '',
+ const selectionData = {
platform: resolvedPrimary,
platforms: {
enabled: normalized,
@@ -135,11 +133,16 @@ export const PlatformSelection: React.FC<PlatformSelectionProps> = ({ data, onNe
};
if (isPage && onSave) {
+ const nextData = {
+ ...credentialDraft,
+ discord_client_id: credentialDraft.discord?.client_id || '',
+ ...selectionData,
+ };
await onSave(nextData);
return;
}
- onNext(nextData);
+ onNext(selectionData);
};
const activeDescriptor = platformCatalog.find((item) => item.id === activeCredentialPlatform) || platformCatalog[0];
diff --git a/vibe/api.py b/vibe/api.py
index a3c3f9a7f..461ec0330 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -674,7 +674,38 @@ def _mark_explicit_audio_asr_enabled(payload: dict) -> dict:
return {**payload, "audio_asr": {**audio_asr, "enabled_configured": True}}
-def _validate_enabled_platform_runtime_credentials(config: V2Config) -> None:
+def _platforms_requiring_runtime_credential_validation(
+ config: V2Config,
+ payload: dict,
+ base_config: Optional[V2Config],
+) -> set[str]:
+ enabled = set(config.platforms.enabled)
+ previous_enabled = set(base_config.platforms.enabled) if base_config is not None else set()
+ platforms = enabled - previous_enabled if "platforms" in payload or "platform" in payload else set()
+
+ # Finishing setup promotes the saved config to a runnable runtime config, so
+ # every enabled adapter must be bootable at that boundary.
+ if payload.get("setup_completed") is True:
+ platforms.update(enabled)
+
+ # If a save edits credential fields for an already-enabled platform, reject
+ # partial clears or mismatched edits before they are persisted.
+ for platform in enabled:
+ required_fields = _PLATFORM_RUNTIME_CREDENTIAL_FIELDS.get(platform)
+ if not required_fields:
+ continue
+ descriptor = get_platform_descriptor(platform)
+ section = payload.get(descriptor.config_key)
+ if isinstance(section, dict) and any(field in section for field in required_fields):
+ platforms.add(platform)
+ return platforms
+
+
+def _validate_enabled_platform_runtime_credentials(
+ config: V2Config,
+ payload: dict,
+ base_config: Optional[V2Config],
+) -> None:
"""Reject enabled IM transports that cannot start after config save.
``V2Config.from_payload`` intentionally allows empty credential fields so
@@ -683,7 +714,7 @@ def _validate_enabled_platform_runtime_credentials(config: V2Config) -> None:
WeChat is the existing exception: its runtime idles without a token while
the QR-login flow completes.
"""
- for platform in config.platforms.enabled:
+ for platform in _platforms_requiring_runtime_credential_validation(config, payload, base_config):
required_fields = _PLATFORM_RUNTIME_CREDENTIAL_FIELDS.get(platform)
if not required_fields:
continue
@@ -736,7 +767,7 @@ def save_config(payload: dict) -> V2Config:
merged_payload = _merge_legacy_discord_guild_scope_fields(merged_payload, payload, base_config)
sanitized_payload, guild_scope_update = _extract_settings_scopes_from_config_payload(merged_payload)
config = V2Config.from_payload(sanitized_payload)
- _validate_enabled_platform_runtime_credentials(config)
+ _validate_enabled_platform_runtime_credentials(config, payload, base_config)
if guild_scope_update is not None:
_save_discord_guild_scope_update(*guild_scope_update)
elif base_config is not None:
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 71fda8202..49c309b2d 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -2195,7 +2195,11 @@ def config_post():
should_reconcile_remote_access = False
with CONFIG_LOCK:
previous_config = _load_remote_access_config() if "remote_access" in payload else None
- config = api.save_config(payload)
+ try:
+ config = api.save_config(payload)
+ except ValueError as exc:
+ message = str(exc)
+ return jsonify({"ok": False, "error": message, "message": message}), 400
if _remote_access_settings_changed(previous_config, config, payload):
if _should_rotate_remote_session_secret(previous_config, config, payload):
remote_access.rotate_session_secret(config)