feat: 前端页面优化与入库任务重试/删除
- 概览与检索合并为单一概览页 - 类目/文档管理/入库整合为树形目录知识库页(Library),支持文档搜索 - 入库进度改为右侧 Drawer,支持任务详情、重试、删除 - 后端新增任务重试与删除接口
This commit is contained in:
@@ -19,6 +19,8 @@ class FakeManager:
|
||||
self.tasks = tasks or {}
|
||||
self.task_id = task_id
|
||||
self.submitted: list[DocumentInput] = []
|
||||
self.retry_result: str | None = None
|
||||
self.delete_result: bool = False
|
||||
|
||||
async def submit(self, doc: DocumentInput) -> str:
|
||||
self.submitted.append(doc)
|
||||
@@ -27,6 +29,12 @@ class FakeManager:
|
||||
async def get(self, task_id: str) -> dict[str, Any] | None:
|
||||
return self.tasks.get(task_id)
|
||||
|
||||
async def retry(self, task_id: str) -> str | None:
|
||||
return self.retry_result
|
||||
|
||||
async def delete(self, task_id: str) -> bool:
|
||||
return self.delete_result
|
||||
|
||||
|
||||
def _task(task_id: str, status: str, **extra: Any) -> dict[str, Any]:
|
||||
"""构造一条任务记录(时间字段为固定 ISO8601 字符串)"""
|
||||
@@ -159,3 +167,44 @@ def test_post_empty_text_creates_no_task(client: TestClient, monkeypatch: pytest
|
||||
body = resp.json()
|
||||
assert body["code"] == 1001
|
||||
assert manager.submitted == []
|
||||
|
||||
|
||||
def test_retry_task_returns_202(client: TestClient, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""POST tasks/{id}/retry:HTTP 202,返回新 task_id 与 pending 状态"""
|
||||
manager = FakeManager()
|
||||
manager.retry_result = "new-task-7"
|
||||
_inject_manager(monkeypatch, manager)
|
||||
|
||||
resp = client.post("/api/v1/documents/tasks/t-failed/retry")
|
||||
|
||||
assert resp.status_code == 202
|
||||
body = resp.json()
|
||||
assert body["code"] == 0
|
||||
assert body["data"]["task_id"] == "new-task-7"
|
||||
assert body["data"]["status"] == "pending"
|
||||
|
||||
|
||||
def test_retry_task_not_found(client: TestClient, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""POST tasks/{id}/retry:manager 返回 None → code=1004"""
|
||||
manager = FakeManager()
|
||||
manager.retry_result = None
|
||||
_inject_manager(monkeypatch, manager)
|
||||
|
||||
resp = client.post("/api/v1/documents/tasks/nope/retry")
|
||||
|
||||
body = resp.json()
|
||||
assert body["code"] == 1004
|
||||
|
||||
|
||||
def test_delete_task(client: TestClient, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""DELETE tasks/{id}:删除成功 → deleted=true"""
|
||||
manager = FakeManager()
|
||||
manager.delete_result = True
|
||||
_inject_manager(monkeypatch, manager)
|
||||
|
||||
resp = client.delete("/api/v1/documents/tasks/t-x")
|
||||
|
||||
body = resp.json()
|
||||
assert body["code"] == 0
|
||||
assert body["data"]["task_id"] == "t-x"
|
||||
assert body["data"]["deleted"] is True
|
||||
|
||||
Reference in New Issue
Block a user