feat: PromptProvider 化 + $DEFLECTION_POOL 单一事实源注入 + runtime 必填化
- PromptProvider(app/engine/services/ai_service.py): 租户提示词四件套 from_dir 加载;build_system 把 system.md 的 $DEFLECTION_POOL 占位符替换为 wall.json deflections 话术池(按语言分组一行,EN/ZH/ES)再拼事实卡; extractor/evaluator 的 $existing_info/$messages/$profile/$recent_messages 替换逻辑自 AIService 原样搬入(行为等价);删模块级 import 时读文件的 PROMPTS_DIR 与四个常量,保留 DEFAULT_PROVIDER(jiancai 出厂,__file__ 锚定) - 两租户 system.md「三类请求的处理」第2条的迂回话术枚举 → $DEFLECTION_POOL 占位符(保留段落说明文字),话术只存 wall.json 一份,改一处两边同步变 - TenantRuntime 加 prompts 字段(加载期 from_dir(seed_dir/prompts)); ConversationManager 的 runtime 转必填(keyword-only),默认 AIService 用 runtime.prompts + compiled_wall.deflections 组装 - app/engine/prompts/ 删除(grep 无代码消费方,jiancai 出厂由 seed_profiles/jiancai/prompts 承接);test_company_facts/ test_system_prompt_dual_contact 的 cwd 相对路径改 Path(__file__) 锚定, test_extractor_evaluator_prompts 断言对象改 DEFAULT_PROVIDER(语义等价) - 新增 tests/test_prompt_provider.py(14 用例): 加载/注入/格式/占位符防漂移/ extractor-evaluator 组装/registry 接线/runtime 必填/池线过两墙 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -61,6 +61,38 @@ def _reset_rate_limit():
|
||||
_reset_for_test()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def jiancai_runtime():
|
||||
"""直连测试用的 jiancai TenantRuntime(Task 6: manager 的 runtime 必填)。
|
||||
|
||||
委托 build_jiancai_runtime()(见其注释: 只走加载期,无 engine 无句柄,
|
||||
跨测试共享单例安全)。
|
||||
"""
|
||||
return build_jiancai_runtime()
|
||||
|
||||
|
||||
_JIANCAI_RUNTIME = None
|
||||
|
||||
|
||||
def build_jiancai_runtime():
|
||||
"""(非夹具)jiancai TenantRuntime——给批量集成测试的 _setup 辅助线用,
|
||||
免去百处测试签名逐一加夹具。
|
||||
|
||||
只走加载期(config/prompts/compiled_wall 就位),从不 ensure_ready——
|
||||
engine/session_factory 保持 None: 直连测试自管 async_db(NullPool 跨
|
||||
循环纪律),manager.session_factory 为 None 时 lead_push_service 回退
|
||||
模块级兜底,与旧 runtime=None 行为一致。无 engine 即无句柄,无需清理;
|
||||
data_dir 仅拼 db_path 字符串(无 IO),模块级缓存单例跨测试复用。
|
||||
"""
|
||||
global _JIANCAI_RUNTIME
|
||||
if _JIANCAI_RUNTIME is None:
|
||||
reg = TenantRegistry.load_from_dir(
|
||||
SEED_DIR, data_dir=REPO_ROOT / "tenants")
|
||||
_JIANCAI_RUNTIME = next(
|
||||
rt for rt in reg.runtimes() if rt.config.slug == "jiancai")
|
||||
return _JIANCAI_RUNTIME
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(tmp_path):
|
||||
"""TestClient + 每测试独立 Registry(tmp_path 作 data_dir)。
|
||||
|
||||
Reference in New Issue
Block a user