From 37179e233f35bf2ab5b6309b63931f798d00bcf1 Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Tue, 19 May 2026 14:48:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Notion=20=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=95=B0=E6=8D=AE=E6=BA=90=E9=AA=8C=E8=AF=81=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=9B=E5=A2=9E=E5=8A=A0=E6=9C=AA=E7=9F=A5=E7=88=B6?= =?UTF-8?q?=E7=BA=A7=E7=9A=84=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yuxi/knowledge/implementations/notion.py | 2 +- backend/test/unit/plugins/test_notion_kb.py | 14 ++++++++++++++ web/src/apis/tool_api.js | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/backend/package/yuxi/knowledge/implementations/notion.py b/backend/package/yuxi/knowledge/implementations/notion.py index e3488e61..900a755c 100644 --- a/backend/package/yuxi/knowledge/implementations/notion.py +++ b/backend/package/yuxi/knowledge/implementations/notion.py @@ -406,7 +406,7 @@ class NotionKB(ReadOnlyConnectors): async with _NotionClient(token, notion_version) as client: page = await client.retrieve_page(page_id) - if not self._page_belongs_to_data_source(page, data_source_id, allow_unknown_parent=True): + if not self._page_belongs_to_data_source(page, data_source_id): raise ValueError(f"Notion 页面 {page_id} 不属于当前 Data Source") markdown = await self._page_to_markdown(client, page_id, page) diff --git a/backend/test/unit/plugins/test_notion_kb.py b/backend/test/unit/plugins/test_notion_kb.py index 4300a789..a6392b98 100644 --- a/backend/test/unit/plugins/test_notion_kb.py +++ b/backend/test/unit/plugins/test_notion_kb.py @@ -78,6 +78,12 @@ class _FailingNotionClient(_FakeNotionClient): raise NotionAPIError("boom") +class _UnknownParentNotionClient(_FakeNotionClient): + async def retrieve_page(self, page_id: str) -> dict: + page = await super().retrieve_page(page_id) + return {**page, "parent": {"type": "page_id", "page_id": "other-page"}} + + @pytest.fixture def notion_kb(tmp_path): kb = NotionKB(str(tmp_path)) @@ -175,6 +181,14 @@ async def test_notion_find_file_content_uses_page_markdown(monkeypatch, notion_k assert "reasoning models" in result["windows"][0]["content"] +@pytest.mark.asyncio +async def test_notion_open_file_content_rejects_unknown_parent(monkeypatch, notion_kb): + monkeypatch.setattr("yuxi.knowledge.implementations.notion._NotionClient", _UnknownParentNotionClient) + + with pytest.raises(ValueError, match="不属于当前 Data Source"): + await notion_kb.open_file_content("kb_notion", PAGE_ID) + + @pytest.mark.asyncio async def test_notion_kb_aquery_error_returns_empty(monkeypatch, notion_kb): monkeypatch.setattr("yuxi.knowledge.implementations.notion._NotionClient", _FailingNotionClient) diff --git a/web/src/apis/tool_api.js b/web/src/apis/tool_api.js index ca84c3db..25c3a1da 100644 --- a/web/src/apis/tool_api.js +++ b/web/src/apis/tool_api.js @@ -13,8 +13,8 @@ const BASE_URL = '/api/system/tools' * @returns {Promise} - 工具列表 */ export const getTools = async (category = null) => { - const params = category ? { category } : {} - return apiAdminGet(BASE_URL, params) + const query = category ? `?${new URLSearchParams({ category }).toString()}` : '' + return apiAdminGet(`${BASE_URL}${query}`) } /**