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}`) } /**