feat: enable local docker demo mode
Some checks failed
Build and Push Docker Images / changes (push) Has been cancelled
Build and Push Docker Images / build-backend (push) Has been cancelled
Build and Push Docker Images / build-frontend (push) Has been cancelled
Build and Push Docker Images / build-admin-frontend (push) Has been cancelled

This commit is contained in:
2026-04-18 12:01:27 +08:00
parent 0613238a37
commit 44405ff7ac
12 changed files with 341 additions and 36 deletions

View File

@@ -125,6 +125,70 @@ class TestProviderFailover:
data="测试",
)
@pytest.mark.asyncio
async def test_default_provider_skips_fk_backed_metrics(self):
"""环境变量/default provider 没有 providers 表记录,不写带外键的指标表。"""
from app.services import provider_router
mock_result = StoryOutput(
mode="generated",
title="本地演示故事",
story_text="内容",
cover_prompt_suggestion="prompt",
)
class MockAdapter:
estimated_cost = 0.0
def __init__(self, config):
self.config = config
async def execute(self, **kwargs):
return mock_result
with patch.object(
provider_router,
"_get_providers_with_config",
new_callable=AsyncMock,
) as mock_providers:
mock_providers.return_value = [("demo", AdapterConfig(api_key=""), None)]
with patch.object(provider_router.AdapterRegistry, "get", return_value=MockAdapter):
with patch.object(
provider_router.health_checker,
"is_healthy",
new_callable=AsyncMock,
) as mock_is_healthy:
with patch.object(
provider_router.metrics_collector,
"record_call",
new_callable=AsyncMock,
) as mock_record_call:
with patch.object(
provider_router.health_checker,
"record_call_result",
new_callable=AsyncMock,
) as mock_record_call_result:
with patch.object(
provider_router.cost_tracker,
"record_cost",
new_callable=AsyncMock,
) as mock_record_cost:
result = await provider_router._route_with_failover(
"text",
db=AsyncMock(),
user_id="user-1",
input_type="keywords",
data="测试",
)
assert result == mock_result
mock_is_healthy.assert_not_called()
mock_record_call.assert_not_called()
mock_record_call_result.assert_not_called()
mock_record_cost.assert_awaited_once()
assert mock_record_cost.await_args.kwargs["provider_id"] is None
class TestProviderConfigFromDB:
"""从 DB 加载 provider 配置测试。"""
@@ -187,7 +251,10 @@ class TestProviderCacheStartup:
mock_factory.return_value.__aenter__ = AsyncMock(return_value=mock_session)
mock_factory.return_value.__aexit__ = AsyncMock()
with patch("app.services.provider_cache.reload_providers", new_callable=AsyncMock) as mock_reload:
with patch(
"app.services.provider_cache.reload_providers",
new_callable=AsyncMock,
) as mock_reload:
mock_reload.return_value = {"text": [], "image": [], "tts": []}
await _load_provider_cache()