sync update from LAN repo (source dhk-1 @ c21a2a4a)

This commit is contained in:
gozeros committed 2026-11-10 14:04:00 +08:00
1 parent 264e2200d6
commit a1fa13a238
122 files changed
+8881 -623

No files matched your search

@@ -355,10 +355,7 @@ async def test_weknora_session_endpoint_sets_cookie_and_returns_platform_path(mo
return {"id": "local-kb", "weknora_id": "remote-kb"}
async def list_visible(self, *_: object, **__: object) -> list[dict[str, str]]:
return [
{"id": "local-kb", "weknora_id": "remote-kb"},
{"id": "public-kb", "weknora_id": "other-public-kb"},
]
raise AssertionError("creating an iframe session must not load every visible knowledge base")
monkeypatch.setattr(llmwiki_router, "_runtime_for_iframe_proxy", lambda _: object())
monkeypatch.setattr(llmwiki_router, "_authorized_mapping", authorized_mapping)
@@ -387,7 +384,39 @@ async def test_weknora_session_endpoint_sets_cookie_and_returns_platform_path(mo
assert ctx.mapping_id == "local-kb"
assert ctx.weknora_id == "remote-kb"
assert ctx.can_write is True
assert ctx.allowed_weknora_ids == ("remote-kb", "other-public-kb")
assert ctx.allowed_weknora_ids == ()
assert len(raw) < 1024
@pytest.mark.asyncio
async def test_weknora_embed_picker_hydrates_visible_bases_server_side(monkeypatch: pytest.MonkeyPatch) -> None:
from app.gateway.routers import llmwiki as llmwiki_router
calls: list[dict[str, object]] = []
class Store:
async def list_visible(self, user_id: str, *, scope: str, is_admin: bool) -> list[dict[str, str]]:
calls.append({"user_id": user_id, "scope": scope, "is_admin": is_admin})
return [
{"id": "local-kb", "weknora_id": "remote-kb"},
{"id": "public-kb", "weknora_id": "other-public-kb"},
]
monkeypatch.setattr(llmwiki_router, "_store", lambda _: Store())
ctx = llmwiki_router.WeKnoraEmbedContext(
mapping_id="local-kb",
weknora_id="remote-kb",
user_id="user-a",
is_admin=False,
can_write=True,
exp=4_102_444_800,
)
hydrated = await llmwiki_router._with_visible_embed_knowledge_bases(_request("/platform/knowledge-bases/remote-kb"), ctx)
assert calls == [{"user_id": "user-a", "scope": "all", "is_admin": False}]
assert hydrated.allowed_weknora_ids == ("remote-kb", "other-public-kb")
assert "allowed_weknora_ids" not in llmwiki_router._embed_context_payload(hydrated)
@pytest.mark.asyncio
@@ -2079,6 +2108,9 @@ async def test_prefixed_weknora_proxy_serves_page_static_assets_and_api_without_
async def get_authorized(self, *_: object, **__: object) -> dict[str, str]:
return {"id": "local-kb", "weknora_id": "remote-kb"}
async def list_visible(self, *_: object, **__: object) -> list[dict[str, str]]:
return [{"id": "local-kb", "weknora_id": "remote-kb"}]
runtime = SimpleNamespace(
web_base_url="http://weknora-web.test",
api_base_url="http://weknora-api.test",
@@ -2207,9 +2239,28 @@ async def test_prefixed_weknora_proxy_serves_page_static_assets_and_api_without_
api = await client.get("/deerflow/api/llmwiki/weknora-embed/api/v1/auth/me")
assert api.status_code == 200
directory = await client.get("/deerflow/api/llmwiki/weknora-embed/api/v1/knowledge-bases")
assert directory.status_code == 200
assert directory.json() == {
"success": True,
"data": [
{
"id": "remote-kb",
"name": "",
"description": "",
"type": "document",
"status": "active",
"created_at": None,
"updated_at": None,
}
],
"total": 1,
}
api_request = next(request for request in upstream_requests if request[1].startswith(runtime.api_base_url))
assert api_request[2]["Authorization"] == "Bearer admin-token"
assert api_request[2]["X-Tenant-ID"] == "tenant-1"
assert not any(request[1].endswith("/api/v1/knowledge-bases") for request in upstream_requests)
def test_weknora_iframe_hides_current_outer_sidebar_shell() -> None:
@@ -2334,7 +2385,6 @@ async def test_weknora_iframe_switch_rechecks_selected_mapping_permissions(
is_admin=False,
can_write=True,
exp=4_102_444_800,
allowed_weknora_ids=("remote-kb", "other-visible-kb"),
)
selected = await llmwiki_router._switch_embed_context(
@@ -2382,12 +2432,16 @@ async def test_weknora_platform_proxy_reissues_cookie_for_native_kb_switch(
seen["target"] = weknora_id
return selected
async def hydrate_visible_bases(_: Request, ctx: object) -> object:
return ctx
async def proxy_request(*_: object, **kwargs: object) -> Response:
seen.update(kwargs)
return Response("ok")
monkeypatch.setattr(llmwiki_router, "_read_embed_context", read_context)
monkeypatch.setattr(llmwiki_router, "_switch_embed_context", switch_context)
monkeypatch.setattr(llmwiki_router, "_with_visible_embed_knowledge_bases", hydrate_visible_bases)
monkeypatch.setattr(
llmwiki_router,
"_runtime_for_iframe_proxy",