fix: harden wiki delivery and leaderboard performance
This commit is contained in:
1 parent
0c5e2e8cb0
commit
9f29ecae9e
28 files changed
+616
-68
No files matched your search
@@ -7,6 +7,7 @@ from fastapi import HTTPException
|
||||
from starlette.requests import Request
|
||||
|
||||
from app.gateway.routers import llmwiki
|
||||
from app.gateway.weknora_embed import verify_weknora_signed_payload
|
||||
|
||||
|
||||
def _request(store: object) -> Request:
|
||||
@@ -199,6 +200,38 @@ async def test_public_wiki_file_is_authorized_and_streamed(monkeypatch) -> None:
|
||||
assert response.body == b"png-bytes"
|
||||
assert response.media_type == "image/png"
|
||||
assert response.headers["cache-control"] == "public, max-age=300"
|
||||
assert response.headers["content-disposition"] == "inline; filename*=UTF-8''figure.png"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_private_wiki_file_uses_signed_http_access_instead_of_blob_url(monkeypatch) -> None:
|
||||
async def authorized_mapping(*_args, **_kwargs):
|
||||
return _published_row(), "user-one", False
|
||||
|
||||
class Client:
|
||||
async def get_knowledge_base_file(self, knowledge_base_id: str, file_path: str):
|
||||
assert knowledge_base_id == "remote-one"
|
||||
assert file_path == "storage://tenant/resource://wiki/figure.png"
|
||||
return b"png-bytes", "image/png"
|
||||
|
||||
monkeypatch.setattr(llmwiki, "_authorized_mapping", authorized_mapping)
|
||||
monkeypatch.setattr(llmwiki, "_client_or_503", lambda: Client())
|
||||
|
||||
access = await llmwiki.create_wiki_file_access(
|
||||
_request(PublicStore(_published_row())),
|
||||
"kb-one",
|
||||
"storage://tenant/resource://wiki/figure.png",
|
||||
)
|
||||
payload = verify_weknora_signed_payload(access["token"])
|
||||
assert payload["kind"] == "wiki_file"
|
||||
assert payload["mapping_id"] == "kb-one"
|
||||
assert payload["weknora_id"] == "remote-one"
|
||||
assert payload["file_path"] == "storage://tenant/resource://wiki/figure.png"
|
||||
|
||||
response = await llmwiki.get_signed_wiki_file(access["token"])
|
||||
assert response.body == b"png-bytes"
|
||||
assert response.headers["cache-control"] == "private, max-age=3600"
|
||||
assert response.headers["content-disposition"] == "inline; filename*=UTF-8''figure.png"
|
||||
|
||||
|
||||
def test_wiki_file_proxy_rejects_non_weknora_urls() -> None:
|
||||
@@ -208,6 +241,23 @@ def test_wiki_file_proxy_rejects_non_weknora_urls() -> None:
|
||||
assert exc_info.value.status_code == 422
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_wiki_file_proxy_adds_image_extension_for_opaque_resource_ids(monkeypatch) -> None:
|
||||
class Client:
|
||||
async def get_knowledge_base_file(self, knowledge_base_id: str, file_path: str):
|
||||
return b"png-bytes", "image/png"
|
||||
|
||||
monkeypatch.setattr(llmwiki, "_client_or_503", lambda: Client())
|
||||
|
||||
response = await llmwiki._wiki_file_response(
|
||||
{"weknora_id": "remote-one"},
|
||||
"resource://opaque-image-id",
|
||||
public=True,
|
||||
)
|
||||
|
||||
assert response.headers["content-disposition"] == "inline; filename*=UTF-8''opaque-image-id.png"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_public_wiki_index_preserves_weknora_group_and_item_order(monkeypatch) -> None:
|
||||
store = PublicStore(_published_row())
|
||||
|
||||
Reference in new issue
Block a user