M3b:世谱激活接入组装管线(关键词命中/常驻/预算/符文展开)与前端记忆治理页(候选箱/重忆确认/正影/删除/实录溯源)

This commit is contained in:
chenxin committed 2026-08-27 09:22:20 +08:00
1 parent eb0027757d
commit e914aec9c4
8 files changed
+569 -1

No files matched your search

+52
View File
@@ -255,3 +255,55 @@ async def test_recalled_memory_injected_into_prompt(client: AsyncClient) -> None
prompt = requested["payload"]["request"]["messages"][-1]["content"]
assert "【获准记忆(来源可查)】" in prompt
_ = json # 保留 json 引用供调试断言使用
# ── M3b:世谱激活进入投影 ──────────────────────────────────────────────
async def test_lorebook_activation_injected_into_prompt(client: AsyncClient) -> None:
tree_id, _q, answer_id, character_id = await _tree_with_answer(client, "世谱树")
# 为人物建世谱书 + 关键词条目 + 常驻条目
book = (
await client.post(
"/api/v1/lorebooks",
json={"name": "测试世谱", "character_id": character_id},
)
)
if book.status_code >= 400: # 端点形态兼容:老 CRUD 可能要求别的字段
book = (await client.post("/api/v1/lorebooks", json={"name": "测试世谱"}))
assert book.status_code < 400, book.text
book_id = book.json()["id"]
keyed = (
await client.post(
f"/api/v1/lorebooks/{book_id}/entries",
json={"keys": ["星穹图书馆"], "content": "星穹图书馆只在午后开放"},
)
)
if keyed.status_code >= 400: # 兼容批量/单条两种端点形态
keyed = await client.post(
f"/api/v1/lorebooks/{book_id}/entries",
json=[{"keys": ["星穹图书馆"], "content": "星穹图书馆只在午后开放"}],
)
assert keyed.status_code < 400, keyed.text
await client.post(f"/api/v1/trees/{tree_id}/adopt", json={"node_id": answer_id})
q2 = (
await client.post(
f"/api/v1/trees/{tree_id}/nodes", json={"content": "带我去星穹图书馆看看"}
)
).json()
spawned = (await client.post(f"/api/v1/nodes/{q2['id']}/answers", json={})).json()
for _ in range(300):
if (await client.get(f"/api/v1/runs/{spawned['run_id']}")).json()["status"] in (
"completed",
"interrupted",
):
break
await asyncio.sleep(0.02)
events = (await client.get(f"/api/v1/runs/{spawned['run_id']}/events")).json()
requested = next(e for e in events if e["type"] == "llm.requested")
prompt = requested["payload"]["request"]["messages"][-1]["content"]
assert "【世界认知(世谱命中)】" in prompt
assert "星穹图书馆只在午后开放" in prompt