mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-06 19:46:07 +00:00
e1ac5e0fc8
* Document multi-tenant workspace architecture * Add OSS and commercial workspace boundaries * docs: redesign multi-tenant workspace architecture * feat(tenancy): implement workspace isolation * docs(tenancy): record verification evidence * docs(tenancy): revise single-instance SaaS topology * docs(tenancy): refine architecture options * docs: finalize cloud v2 multi-tenant decisions * feat(tenancy): establish cloud isolation foundations * feat(tenancy): harden shared cloud runtime boundaries * docs(tenancy): record final isolation verification * fix(tenancy): close isolation and permission gaps * docs(tenancy): record final isolation verification * feat(tenancy): connect cloud workspace control plane * fix(build): install git for pinned SDK * docs(cloud): update control plane verification * chore: update multi-tenant SDK pin * fix(cloud): skip legacy model sync during startup * test(cloud): preserve minimal model manager fixtures * fix(cloud): preserve authenticated account context * fix(cloud): reuse authenticated account for user info * feat(cloud): complete Workspace settings navigation * test(web): cover Workspace dropdown menu * feat(web): place workspace controls in sidebar * refactor(web): streamline workspace controls * style(web): format workspace layout test * fix(cloud): surface runtime and workspace plan status * fix(plugin): keep runtime identity stable across restarts * fix(ui): widen and center workspace switcher * fix(ui): hide roles from workspace switcher * fix(ui): align workspace switcher with sidebar entries * feat(workspace): add in-product collaboration and direct Cloud launch * style: format collaboration changes * fix(workspace): bind collaboration APIs to tenant UoW * fix(cloud): preserve Core-owned collaboration state * test(cloud): require Space identity for invite registration * feat(cloud): complete secure invitation experience * style(web): format invitation flows * fix(cloud): recover box runtime without unscoped skill reload * feat(oss): enforce invitation account and owner billing flows * style: format OSS account service * test(oss): cover invitation logout handoff * fix(oss): resolve workspace owner in scoped session * feat(cloud): harden multi-tenant runtime resources * fix(cloud): bound runtime restart storms * fix(cloud): eliminate periodic runtime CPU spikes * fix(cloud): enforce instance capacity ceilings * fix(cloud): scope public login capability discovery * fix(cloud): bound tenant maintenance and monitoring work * fix(runtime): bound tenant resource amplification * fix(deps): pin green multi-tenant plugin SDK * fix(cloud): handle unavailable skill capability * fix(security): require authentication for image file endpoint (H-2) - Changed /api/v1/files/image from AuthType.NONE to USER_TOKEN_OR_API_KEY - Added Permission.RESOURCE_VIEW requirement - Prevents unauthenticated cross-tenant file access via leaked keys - Fixes HIGH severity finding from multi-tenant security review docs: add comprehensive database migration guide - Complete migration steps for OSS → multi-tenant - Backup, execution, verification procedures - Rollback scenarios and recovery plans - Performance tuning recommendations * test: add comprehensive cross-tenant isolation tests Added 7 critical test scenarios for multi-tenant boundaries: - Cross-tenant bot access prevention - Viewer role read-only enforcement - Removed member immediate access revocation - Model provider credential isolation - WebSocket message isolation - Invitation token workspace scoping - Multi-workspace context validation These tests address P0-2 coverage gaps for: - workspaces.py (membership & invitation flows) - user.py (authentication & authorization) - websocket_chat.py (real-time isolation) - plugins.py (resource access control) docs: finalize database migration guide * fix(security): resolve M-1, M-2, M-3 security findings M-1: WebSocket authorization TOCTOU race (FIXED) - Changed _revalidate_websocket_authorization to return RequestContext - Ensures validated context is used immediately without race window - Prevents removed members from sending messages during revalidation gap M-2: Model Manager cache workspace isolation (VERIFIED) - Confirmed _CacheKey already uses 4-tuple: (instance, workspace, generation, resource) - Cache is properly scoped per workspace, no cross-tenant leakage possible - No code change needed, documented as working correctly M-3: Invitation lock workspace scoping (FIXED) - Changed lock key from token_digest to workspace_uuid:token_digest - Prevents DoS where attacker locks token in Workspace A to block Workspace B - Locks now isolated per workspace All MEDIUM severity findings from security review now resolved. * fix(cloud): unblock tenant CI and enforce knowledge quotas * fix(tenancy): scope rerank model sync --------- Co-authored-by: dadachann <185672915+dadachann@users.noreply.github.com>
163 lines
5.9 KiB
Python
163 lines
5.9 KiB
Python
"""E2E tests for LangBot startup flow.
|
|
|
|
Tests the complete startup process including:
|
|
- boot.py startup orchestration
|
|
- stages/ (build_app, load_config, migrate, etc.)
|
|
- database initialization
|
|
- API availability
|
|
|
|
Run: uv run pytest tests/e2e/test_startup.py -v -m e2e
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
pytestmark = pytest.mark.e2e
|
|
|
|
|
|
class TestStartupFlow:
|
|
"""Tests for LangBot startup process."""
|
|
|
|
def test_process_is_running(self, langbot_process):
|
|
"""Verify LangBot process is running."""
|
|
assert langbot_process.is_running()
|
|
|
|
def test_health_check(self, langbot_process, e2e_port):
|
|
"""Verify LangBot API is responding."""
|
|
assert langbot_process.health_check()
|
|
|
|
def test_health_check_exposes_bounded_blocking_executor(self, e2e_client):
|
|
"""The production startup path installs blocking-work admission."""
|
|
response = e2e_client.get('/healthz')
|
|
|
|
assert response.status_code == 200
|
|
executor = response.json()['resources']['blocking_executor']
|
|
assert executor['max_workers'] == 8
|
|
assert executor['max_pending'] == 128
|
|
assert executor['max_inflight_per_scope'] == 4
|
|
assert executor['inflight'] >= 0
|
|
assert executor['rejected_total'] >= 0
|
|
event_loop = response.json()['resources']['event_loop']
|
|
assert event_loop['running'] is True
|
|
assert event_loop['recent_max_lag_ms'] >= 0
|
|
|
|
def test_system_info_endpoint(self, e2e_client):
|
|
"""Test /api/v1/system/info endpoint."""
|
|
response = e2e_client.get('/api/v1/system/info')
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
assert data['code'] == 0
|
|
assert 'data' in data
|
|
# System info should contain version info
|
|
assert 'version' in data['data'] or 'edition' in data['data']
|
|
|
|
def test_database_initialized(self, langbot_process, e2e_db_path):
|
|
"""Verify SQLite database was created and initialized."""
|
|
assert e2e_db_path.exists()
|
|
|
|
# Database should have some tables after migration
|
|
import sqlite3
|
|
|
|
conn = sqlite3.connect(str(e2e_db_path))
|
|
cursor = conn.cursor()
|
|
|
|
# Check that core tables exist
|
|
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
|
|
tables = [row[0] for row in cursor.fetchall()]
|
|
|
|
# Core tables should be created by Alembic migrations
|
|
# Note: table names may differ (legacy_pipelines instead of pipelines)
|
|
expected_tables = ['legacy_pipelines', 'bots', 'model_providers', 'llm_models']
|
|
for table in expected_tables:
|
|
assert table in tables, f'Table {table} should exist. Available: {tables}'
|
|
|
|
conn.close()
|
|
|
|
def test_chroma_directory_created(self, e2e_tmpdir):
|
|
"""Verify Chroma vector database directory was created."""
|
|
chroma_path = e2e_tmpdir / 'chroma'
|
|
# Created by the E2E config factory before startup.
|
|
assert chroma_path.exists()
|
|
|
|
def test_pipelines_endpoint(self, e2e_client):
|
|
"""Test /api/v1/pipelines endpoint (requires auth)."""
|
|
# Without auth, should return 401
|
|
response = e2e_client.get('/api/v1/pipelines')
|
|
assert response.status_code == 401
|
|
|
|
def test_auth_endpoint(self, e2e_client, e2e_tmpdir):
|
|
"""Test auth endpoint."""
|
|
# First startup may allow initial setup
|
|
response = e2e_client.post(
|
|
'/api/v1/user/auth',
|
|
json={
|
|
'user': 'admin',
|
|
'password': 'admin',
|
|
},
|
|
)
|
|
|
|
# Response could be:
|
|
# - 200 if auth succeeds
|
|
# - 400 if credentials wrong
|
|
# - 401 if user not initialized
|
|
assert response.status_code in [200, 400, 401]
|
|
|
|
|
|
class TestStartupStages:
|
|
"""Tests that verify individual startup stages worked correctly."""
|
|
|
|
def test_config_loaded(self, e2e_client):
|
|
"""Verify config was loaded correctly by checking API port."""
|
|
# If API responds on e2e_port, config was loaded
|
|
assert e2e_client.get('/api/v1/system/info').status_code == 200
|
|
|
|
def test_migrations_applied(self, langbot_process, e2e_db_path):
|
|
"""Verify database migrations were applied."""
|
|
import sqlite3
|
|
|
|
conn = sqlite3.connect(str(e2e_db_path))
|
|
cursor = conn.cursor()
|
|
|
|
# Check alembic_version table exists and has version
|
|
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='alembic_version';")
|
|
result = cursor.fetchone()
|
|
assert result is not None, 'alembic_version table should exist'
|
|
|
|
cursor.execute('SELECT version_num FROM alembic_version;')
|
|
version = cursor.fetchone()
|
|
assert version is not None, 'Migration version should be set'
|
|
|
|
conn.close()
|
|
|
|
def test_http_controller_initialized(self, e2e_client):
|
|
"""Verify HTTP controller was initialized."""
|
|
# Multiple endpoints should be available
|
|
endpoints = [
|
|
'/api/v1/system/info',
|
|
'/api/v1/pipelines',
|
|
'/api/v1/provider/providers',
|
|
'/api/v1/platform/bots',
|
|
]
|
|
|
|
for endpoint in endpoints:
|
|
response = e2e_client.get(endpoint)
|
|
# Should get a real route response, even if auth is required.
|
|
assert response.status_code in [200, 401, 403], f'{endpoint} should be registered'
|
|
|
|
|
|
class TestMinimalStartupNoLLM:
|
|
"""Tests verifying LangBot can start without LLM providers."""
|
|
|
|
def test_api_available_without_llm(self, e2e_client):
|
|
"""API should be available even without LLM providers configured."""
|
|
response = e2e_client.get('/api/v1/system/info')
|
|
assert response.status_code == 200
|
|
|
|
def test_pipeline_metadata_available(self, e2e_client):
|
|
"""Pipeline metadata endpoint should work without LLM."""
|
|
# Requires auth, but endpoint should exist
|
|
response = e2e_client.get('/api/v1/pipelines/_/metadata')
|
|
assert response.status_code in [200, 401] # Not 404 or 500
|