sync update from LAN repo (source master @ ca48c4ec)
This commit is contained in:
1 parent
8bc8b0e082
commit
ea9dcff9c0
873 files changed
+107866
-14011
No files matched your search
@@ -823,6 +823,32 @@ async def test_weknora_client_resolves_default_embedding_model_inside_weknora()
|
||||
assert created["id"] == "kb-created"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_weknora_wiki_create_reuses_catalog_models_without_debug_probe() -> None:
|
||||
requests: list[tuple[str, str, dict[str, object]]] = []
|
||||
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
payload = json.loads(request.content) if request.content else {}
|
||||
requests.append((request.method, request.url.path, payload))
|
||||
assert request.method == "POST"
|
||||
assert request.url.path == "/api/v1/knowledge-bases"
|
||||
return httpx.Response(201, json={"success": True, "data": {"id": "wiki-created", "name": "Wiki"}})
|
||||
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(handler)) as http_client:
|
||||
client = WeKnoraClient(base_url="http://weknora.local:8080", http_client=http_client)
|
||||
await client.create_knowledge_base(
|
||||
name="Wiki",
|
||||
embedding_model_id="embedding-id",
|
||||
knowledge_qa_model_id="qa-id",
|
||||
wiki_enabled=True,
|
||||
)
|
||||
|
||||
assert len(requests) == 1
|
||||
assert requests[0][2]["embedding_model_id"] == "embedding-id"
|
||||
assert requests[0][2]["summary_model_id"] == "qa-id"
|
||||
assert requests[0][2]["wiki_config"]["synthesis_model_id"] == "qa-id"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gateway_lists_safe_embedding_models_and_uses_explicit_selection(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
@@ -863,6 +889,7 @@ async def test_gateway_lists_safe_embedding_models_and_uses_explicit_selection(
|
||||
"status": "inactive",
|
||||
},
|
||||
{"id": "chat-one", "type": "LLM", "name": "chat"},
|
||||
{"id": "qa-default", "type": "KnowledgeQA", "name": "wiki-answer", "status": "active", "is_default": True},
|
||||
]
|
||||
|
||||
async def create_knowledge_base(self, **kwargs: object) -> dict[str, object]:
|
||||
@@ -913,6 +940,7 @@ async def test_gateway_lists_safe_embedding_models_and_uses_explicit_selection(
|
||||
)
|
||||
|
||||
assert create_calls[0]["embedding_model_id"] == "embed-openai"
|
||||
assert create_calls[0]["knowledge_qa_model_id"] == "qa-default"
|
||||
assert create_calls[0]["wiki_enabled"] is True
|
||||
assert create_calls[0]["wiki_content_instructions"] == "按事件时间线生成页面"
|
||||
assert create_calls[0]["wiki_extraction_instructions"] == "重点提取人物和组织关系"
|
||||
@@ -1328,6 +1356,44 @@ async def test_weknora_client_imports_url_manual_content_and_lists_wiki_pages()
|
||||
assert pages["pages"][0]["slug"] == "guide"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_weknora_client_uses_native_wiki_regex_search_contract() -> None:
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
assert request.method == "GET"
|
||||
assert request.url.path == "/api/v1/knowledgebase/kb-one/wiki/search"
|
||||
assert request.url.params["q"] == "火炬|开幕|闭幕"
|
||||
# WeKnora v0.7.2 caps the endpoint at 50.
|
||||
assert request.url.params["limit"] == "50"
|
||||
return httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"pages": [
|
||||
{
|
||||
"slug": "games/timeline",
|
||||
"title": "赛事时间线",
|
||||
"content": "火炬传递、开幕和闭幕安排。",
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(handler)) as http_client:
|
||||
client = WeKnoraClient(base_url="http://weknora.local:8080", http_client=http_client)
|
||||
pages = await client.search_wiki_pages(
|
||||
"kb-one",
|
||||
"火炬|开幕|闭幕",
|
||||
limit=500,
|
||||
)
|
||||
|
||||
assert pages == [
|
||||
{
|
||||
"slug": "games/timeline",
|
||||
"title": "赛事时间线",
|
||||
"content": "火炬传递、开幕和闭幕安排。",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_weknora_client_reads_ordered_wiki_index_groups() -> None:
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
@@ -1661,7 +1727,11 @@ async def test_listing_conversation_deposit_refreshes_remote_description(monkeyp
|
||||
monkeypatch.setattr(llmwiki_router, "_store", lambda _: store)
|
||||
monkeypatch.setattr(llmwiki_router, "_client_or_503", lambda: Client())
|
||||
|
||||
payload = await llmwiki_router.list_knowledge_bases(object(), scope="public")
|
||||
payload = await llmwiki_router.list_knowledge_bases(
|
||||
object(),
|
||||
scope="public",
|
||||
refresh=True,
|
||||
)
|
||||
|
||||
assert payload["knowledge_bases"][0]["description"] == llmwiki_deposit.CONVERSATION_DEPOSIT_KB_DESCRIPTION
|
||||
assert "DeerFlow" not in json.dumps(payload, ensure_ascii=False)
|
||||
@@ -1691,6 +1761,47 @@ def test_conversation_deposit_history_hides_legacy_brand() -> None:
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_agent_bound_knowledge_base_list_uses_local_mapping_only(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.gateway.routers import llmwiki as llmwiki_router
|
||||
from deerflow.persistence.agents import MemoryAgentStore
|
||||
from deerflow.persistence.llmwiki import MemoryLlmWikiStore
|
||||
|
||||
store = MemoryLlmWikiStore()
|
||||
mapping = await store.create_mapping(
|
||||
weknora_id="remote-agent-kb",
|
||||
owner_user_id="user-a",
|
||||
name="本地目录缓存",
|
||||
description="",
|
||||
kb_type="document",
|
||||
)
|
||||
agent_store = MemoryAgentStore()
|
||||
await agent_store.ensure_builtin({"id": "agent-a", "name": "Agent A", "published": True})
|
||||
|
||||
async def actor(_: object) -> tuple[str, bool]:
|
||||
return "user-a", False
|
||||
|
||||
monkeypatch.setattr(llmwiki_router, "_actor", actor)
|
||||
monkeypatch.setattr(llmwiki_router, "_store", lambda _: store)
|
||||
monkeypatch.setattr(llmwiki_router, "get_agent_store", lambda _: agent_store)
|
||||
monkeypatch.setattr(
|
||||
llmwiki_router,
|
||||
"load_agent_config",
|
||||
lambda _agent_id: SimpleNamespace(llmwiki_knowledge_base_ids=[mapping["id"]]),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
llmwiki_router,
|
||||
"_client_or_503",
|
||||
lambda: (_ for _ in ()).throw(AssertionError("normal listing must not call WeKnora")),
|
||||
)
|
||||
|
||||
payload = await llmwiki_router.list_agent_knowledge_bases(object(), "agent-a")
|
||||
assert [item["id"] for item in payload["knowledge_bases"]] == [mapping["id"]]
|
||||
assert payload["knowledge_bases"][0]["remote_status"] == "cached"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_knowledge_bases_personal_scope_filters_to_actor_for_admin(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
from app.gateway.routers import llmwiki as llmwiki_router
|
||||
|
||||
Reference in new issue
Block a user