fix: 修复 Notion 页面数据源验证逻辑;增加未知父级的异常处理
This commit is contained in:
parent
3db94eba6d
commit
37179e233f
@ -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)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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}`)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user