refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)

配置 SSOT(TOML + .env)
统一错误契约
Auth 与事务边界
Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client
可观测性(OpenTelemetry + LGTM)
This commit is contained in:
Sully
2026-05-22 13:44:50 +08:00
committed by GitHub
parent f09ae248f9
commit 53e0065e3e
298 changed files with 15247 additions and 4344 deletions

View File

@@ -6,6 +6,7 @@ import pytest
from app.features.memoir.memoir_images.prompting import MemoirImagePromptService
from app.features.memoir.memoir_images.settings import MemoirImageSettings
from app.features.memoir.constants import memoir
def _svc(llm=None) -> MemoirImagePromptService:
@@ -26,7 +27,7 @@ def test_story_primary_fallback_uses_placeholder_when_llm_disabled():
def test_story_primary_fallback_disabled_requires_brief(monkeypatch):
monkeypatch.setattr(
"app.features.memoir.memoir_images.prompting.settings.image_prompt_fallback_disabled",
"app.features.memoir.memoir_images.prompting.memoir.image_prompt_fallback_disabled",
True,
)
with pytest.raises(RuntimeError, match="prompt_brief"):
@@ -46,7 +47,7 @@ def test_story_primary_style_from_chat_stage_when_no_intent_style():
def test_story_primary_fallback_disabled_requires_llm(monkeypatch):
monkeypatch.setattr(
"app.features.memoir.memoir_images.prompting.settings.image_prompt_fallback_disabled",
"app.features.memoir.memoir_images.prompting.memoir.image_prompt_fallback_disabled",
True,
)
with pytest.raises(RuntimeError, match="requires LLM"):
@@ -99,7 +100,7 @@ def test_cover_fallback_uses_service_template_when_llm_disabled():
def test_cover_fallback_when_excerpt_empty(monkeypatch):
monkeypatch.setattr(
"app.features.memoir.memoir_images.prompting.settings.image_prompt_fallback_disabled",
"app.features.memoir.memoir_images.prompting.memoir.image_prompt_fallback_disabled",
False,
)
out = _svc(llm=None).build_cover_prompt(
@@ -112,7 +113,7 @@ def test_cover_fallback_when_excerpt_empty(monkeypatch):
def test_cover_fallback_disabled_requires_excerpt(monkeypatch):
monkeypatch.setattr(
"app.features.memoir.memoir_images.prompting.settings.image_prompt_fallback_disabled",
"app.features.memoir.memoir_images.prompting.memoir.image_prompt_fallback_disabled",
True,
)
with pytest.raises(RuntimeError, match="context_excerpt"):
@@ -131,7 +132,7 @@ def test_image_prompt_orchestrator_provider_failure_uses_fallback(monkeypatch):
raise RuntimeError("provider missing")
monkeypatch.setattr(
"app.agents.image_prompt.orchestrator.settings.image_prompt_fallback_disabled",
"app.agents.image_prompt.orchestrator.memoir.image_prompt_fallback_disabled",
False,
)
monkeypatch.setattr("app.core.llm_gateway.LlmGateway", lambda: BoomGateway())
@@ -155,7 +156,7 @@ def test_image_prompt_orchestrator_provider_failure_raises_when_disabled(
raise RuntimeError("provider missing")
monkeypatch.setattr(
"app.agents.image_prompt.orchestrator.settings.image_prompt_fallback_disabled",
"app.agents.image_prompt.orchestrator.memoir.image_prompt_fallback_disabled",
True,
)
monkeypatch.setattr("app.core.llm_gateway.LlmGateway", lambda: BoomGateway())