feat: 推荐问题配置支持按标签搜索并在列表展示标签
- 后端列表接口为每个推荐问题附带 tags,并支持 tag_ids OR 过滤 - 前端配置页新增 TagSearchBar(标题/内容搜索 + 标签筛选),卡片展示标签 - 打标签后失效 recommended-questions 查询,列表即时刷新 - 过滤时禁用拖拽排序,避免破坏 sort_order Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
5182ea5d11
commit
97da7dc87f
6 files changed
+161
-7
No files matched your search
@@ -0,0 +1,79 @@
|
||||
"""Router-level tests for recommended-question tag embedding + filtering.
|
||||
|
||||
The list endpoint coroutine is invoked directly with a stub request whose
|
||||
``app.state`` carries a fake question store and an in-memory tag store, mirroring
|
||||
the lightweight router tests already in this suite (see ``test_tags_api.py``).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from app.gateway.routers import recommended_questions as rq_router
|
||||
from deerflow.persistence.tags import MemoryTagStore
|
||||
|
||||
|
||||
class _FakeQuestionStore:
|
||||
def __init__(self, rows: list[dict]) -> None:
|
||||
self._rows = rows
|
||||
|
||||
async def list_all(self) -> list[dict]:
|
||||
return list(self._rows)
|
||||
|
||||
|
||||
def _request(question_store, tag_store) -> SimpleNamespace:
|
||||
state = SimpleNamespace(
|
||||
user=None,
|
||||
recommended_question_store=question_store,
|
||||
tag_store=tag_store,
|
||||
position_sync=None,
|
||||
)
|
||||
return SimpleNamespace(state=state, app=SimpleNamespace(state=state))
|
||||
|
||||
|
||||
def _rows() -> list[dict]:
|
||||
return [
|
||||
{"id": "q1", "title": "市场分析", "content": "分析一下市场", "sort_order": 0},
|
||||
{"id": "q2", "title": "理赔报告", "content": "生成理赔报告", "sort_order": 1},
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_embeds_assigned_tags() -> None:
|
||||
tag_store = MemoryTagStore()
|
||||
tag = await tag_store.create_tag(
|
||||
{"id": "t1", "name": "理赔", "tag_type": "recommended_question"}
|
||||
)
|
||||
await tag_store.set_target_tags("recommended_question", "q2", [tag["id"]])
|
||||
|
||||
req = _request(_FakeQuestionStore(_rows()), tag_store)
|
||||
resp = await rq_router.list_recommended_questions(req, all=True)
|
||||
|
||||
by_id = {q.id: q for q in resp.questions}
|
||||
assert by_id["q1"].tags == []
|
||||
assert [t["name"] for t in by_id["q2"].tags] == ["理赔"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_filters_by_tag_ids() -> None:
|
||||
tag_store = MemoryTagStore()
|
||||
tag = await tag_store.create_tag(
|
||||
{"id": "t1", "name": "理赔", "tag_type": "recommended_question"}
|
||||
)
|
||||
await tag_store.set_target_tags("recommended_question", "q2", [tag["id"]])
|
||||
|
||||
req = _request(_FakeQuestionStore(_rows()), tag_store)
|
||||
resp = await rq_router.list_recommended_questions(req, all=True, tag_ids=[tag["id"]])
|
||||
|
||||
assert [q.id for q in resp.questions] == ["q2"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_without_tag_store_does_not_break() -> None:
|
||||
req = _request(_FakeQuestionStore(_rows()), None)
|
||||
resp = await rq_router.list_recommended_questions(req, all=True)
|
||||
|
||||
assert [q.id for q in resp.questions] == ["q1", "q2"]
|
||||
assert all(q.tags == [] for q in resp.questions)
|
||||
Reference in new issue
Block a user