sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)

This commit is contained in:
gozeros committed 2026-10-21 14:51:31 +08:00
1 parent 4f7f07504a
commit 8bc8b0e082
1651 files changed
+278599 -11416

No files matched your search

@@ -2,6 +2,7 @@
from __future__ import annotations
import asyncio
import json
from types import SimpleNamespace
@@ -29,6 +30,7 @@ async def knowledge_api(monkeypatch: pytest.MonkeyPatch):
is_admin=False,
upstream_status=200,
writes=[],
directory_reads=0,
)
async def upstream(request: httpx.Request) -> httpx.Response:
@@ -36,6 +38,8 @@ async def knowledge_api(monkeypatch: pytest.MonkeyPatch):
return httpx.Response(state.upstream_status, json={"message": "知识服务暂不可用"})
if request.url.path == "/api/v1/knowledge-bases":
assert request.method == "GET"
state.directory_reads += 1
await asyncio.sleep(0)
return httpx.Response(200, json={"data": list(state.remote.values())})
remote_id = request.url.path.rsplit("/", 1)[-1]
if remote_id not in state.remote:
@@ -81,14 +85,40 @@ async def test_lists_hide_remote_deleted_bases_without_deleting_mappings(knowled
assert await state.store.get_by_weknora_id("remote-one") is not None
state.remote.clear()
response = await state.api.get("/api/llmwiki/knowledge-bases", params={"scope": scope})
response = await state.api.get("/api/llmwiki/knowledge-bases", params={"scope": scope, "refresh": True})
assert response.json()["knowledge_bases"] == []
state.remote["remote-one"] = deleted
response = await state.api.get("/api/llmwiki/knowledge-bases", params={"scope": scope})
response = await state.api.get("/api/llmwiki/knowledge-bases", params={"scope": scope, "refresh": True})
assert [item["id"] for item in response.json()["knowledge_bases"]] == [state.mapping_id]
@pytest.mark.asyncio
async def test_directory_scopes_share_one_upstream_read_and_keep_visibility_checks(knowledge_api) -> None:
state = knowledge_api
responses = await asyncio.gather(*(state.api.get("/api/llmwiki/knowledge-bases", params={"scope": scope}) for scope in ("personal", "public", "all")))
assert all(response.status_code == 200 for response in responses)
assert state.directory_reads == 1
state.user_id = "another-user"
personal = await state.api.get("/api/llmwiki/knowledge-bases", params={"scope": "personal"})
public = await state.api.get("/api/llmwiki/knowledge-bases", params={"scope": "public"})
assert personal.json()["knowledge_bases"] == []
assert [item["id"] for item in public.json()["knowledge_bases"]] == [state.mapping_id]
assert state.directory_reads == 1
@pytest.mark.asyncio
async def test_manual_directory_refresh_coalesces_and_reloads_remote_changes(knowledge_api) -> None:
state = knowledge_api
await state.api.get("/api/llmwiki/knowledge-bases")
state.remote.clear()
responses = await asyncio.gather(*(state.api.get("/api/llmwiki/knowledge-bases", params={"scope": scope, "refresh": True}) for scope in ("personal", "public", "all")))
assert all(response.json()["knowledge_bases"] == [] for response in responses)
assert state.directory_reads == 2
assert await state.store.get_by_weknora_id("remote-one") is not None
@pytest.mark.asyncio
@pytest.mark.parametrize("status", [502, 504])
async def test_list_upstream_failure_is_not_treated_as_remote_deletion(knowledge_api, status: int) -> None: