feat: complete public wiki and embedded previews
This commit is contained in:
1 parent
bc49df4561
commit
30943159bf
18 files changed
+926
-48
No files matched your search
@@ -38,6 +38,22 @@ class PublicStore:
|
||||
return self.row
|
||||
|
||||
|
||||
class PublicListStore:
|
||||
def __init__(self, rows: list[dict[str, object]]) -> None:
|
||||
self.rows = rows
|
||||
self.calls: list[tuple[str, str, bool]] = []
|
||||
|
||||
async def list_visible(
|
||||
self,
|
||||
user_id: str,
|
||||
*,
|
||||
scope: str,
|
||||
is_admin: bool,
|
||||
) -> list[dict[str, object]]:
|
||||
self.calls.append((user_id, scope, is_admin))
|
||||
return self.rows
|
||||
|
||||
|
||||
def _published_row() -> dict[str, object]:
|
||||
return {
|
||||
"id": "kb-one",
|
||||
@@ -50,6 +66,39 @@ def _published_row() -> dict[str, object]:
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_public_knowledge_base_list_exposes_only_published_wiki_identity() -> None:
|
||||
store = PublicListStore(
|
||||
[
|
||||
{
|
||||
**_published_row(),
|
||||
"id": "1063edee-332a-43b4-bbd9-73bf0a708b94",
|
||||
"owner_user_id": "secret-owner",
|
||||
},
|
||||
{**_published_row(), "id": "private-kb", "publication_status": "private"},
|
||||
{
|
||||
**_published_row(),
|
||||
"id": "conversation-deposit",
|
||||
"owner_user_id": "system",
|
||||
"name": "对话沉淀",
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
payload = await llmwiki.list_public_knowledge_bases(_request(store))
|
||||
|
||||
assert store.calls == [("__public_wiki__", "public", False)]
|
||||
assert payload == {
|
||||
"knowledge_bases": [
|
||||
{
|
||||
"id": "1063edee-332a-43b4-bbd9-73bf0a708b94",
|
||||
"name": "公开知识库",
|
||||
}
|
||||
],
|
||||
"total": 1,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_public_wiki_reader_uses_anonymous_non_admin_authorization(monkeypatch) -> None:
|
||||
store = PublicStore(_published_row())
|
||||
@@ -126,3 +175,81 @@ async def test_public_wiki_page_list_is_normalized(monkeypatch) -> None:
|
||||
|
||||
assert payload["pages"][0]["slug"] == "guide/start"
|
||||
assert payload["pages"][0]["aliases"] == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_public_wiki_index_preserves_weknora_group_and_item_order(monkeypatch) -> None:
|
||||
store = PublicStore(_published_row())
|
||||
calls: list[tuple[tuple[str, ...], str]] = []
|
||||
|
||||
class Client:
|
||||
async def get_wiki_index(
|
||||
self,
|
||||
knowledge_base_id: str,
|
||||
*,
|
||||
types: list[str],
|
||||
limit: int,
|
||||
cursor: str,
|
||||
):
|
||||
assert knowledge_base_id == "remote-one"
|
||||
assert limit == 500
|
||||
page_type = types[0]
|
||||
calls.append((tuple(types), cursor))
|
||||
if page_type == "concept" and not cursor:
|
||||
return {
|
||||
"intro": "# Wiki Index\n\n公开目录",
|
||||
"version": 3,
|
||||
"groups": [
|
||||
{
|
||||
"type": "concept",
|
||||
"total": 2,
|
||||
"next_cursor": "concept-next",
|
||||
"items": [
|
||||
{
|
||||
"slug": "concept/first",
|
||||
"title": "第一项",
|
||||
"summary": "第一项摘要",
|
||||
"category_path": ["流程图", "规范"],
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
if page_type == "concept":
|
||||
return {
|
||||
"intro": "# Wiki Index\n\n公开目录",
|
||||
"version": 3,
|
||||
"groups": [
|
||||
{
|
||||
"type": "concept",
|
||||
"total": 2,
|
||||
"items": [
|
||||
{
|
||||
"slug": "concept/second",
|
||||
"title": "第二项",
|
||||
"summary": "第二项摘要",
|
||||
"category_path": ["流程图", "规范"],
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
return {
|
||||
"intro": "# Wiki Index\n\n公开目录",
|
||||
"version": 3,
|
||||
"groups": [{"type": page_type, "total": 0, "items": []}],
|
||||
}
|
||||
|
||||
monkeypatch.setattr(llmwiki, "_client_or_503", lambda: Client())
|
||||
|
||||
payload = await llmwiki.get_public_wiki_index(_request(store), "kb-one")
|
||||
|
||||
concept = next(group for group in payload["groups"] if group["type"] == "concept")
|
||||
assert payload["intro"] == "# Wiki Index\n\n公开目录"
|
||||
assert payload["version"] == 3
|
||||
assert [item["slug"] for item in concept["items"]] == [
|
||||
"concept/first",
|
||||
"concept/second",
|
||||
]
|
||||
assert concept["total"] == 2
|
||||
assert (("concept",), "concept-next") in calls
|
||||
Reference in new issue
Block a user