feat(data-process): 返回任务文档数量

This commit is contained in:
caoxiaozhu
2026-07-27 09:50:19 +08:00
parent 680fa905f8
commit 895983ac20
3 changed files with 109 additions and 10 deletions

View File

@@ -316,6 +316,54 @@ class _TaskDetailStore(DataProcessStore):
yield self._conn
class _TaskListConnection:
def __init__(self) -> None:
self.task = {
**_regeneration_task(
status="pending",
output_dataset_id=None,
output_count=17,
),
"created_at": "2026-07-25T18:00:00Z",
"deleted_at": None,
}
self.sources = [
{"task_id": "task-1", "deleted_at": None},
{"task_id": "task-1", "deleted_at": None},
{"task_id": "task-1", "deleted_at": "2026-07-26T00:00:00Z"},
]
def execute(self, sql: str, params: Any = None) -> _Result:
normalized = " ".join(sql.split())
if normalized.startswith("SELECT COUNT(*) AS count FROM data_process_tasks task"):
assert "task.deleted_at IS NULL" in normalized
return _Result(row={"count": 1})
assert normalized.startswith("SELECT task.*")
assert "source_file.task_id=task.id" in normalized
assert "source_file.deleted_at IS NULL" in normalized
source_file_count = sum(
item["task_id"] == self.task["id"] and item["deleted_at"] is None
for item in self.sources
)
return _Result(
rows=[
{
**self.task,
"source_file_count": source_file_count,
}
]
)
class _TaskListStore(DataProcessStore):
def __init__(self, conn: _TaskListConnection) -> None:
self._conn = conn
@contextmanager
def connect(self) -> Iterator[_TaskListConnection]:
yield self._conn
def test_decode_row_serializes_postgres_numeric_values_as_json_numbers() -> None:
decoded = _decode_row(
{
@@ -461,6 +509,19 @@ def _regeneration_task(**updates: Any) -> dict[str, Any]:
return task
def test_list_tasks_exposes_source_and_generation_counts() -> None:
page = _TaskListStore(_TaskListConnection()).list_tasks(page=1, page_size=20)
assert page["total"] == 1
assert page["page"] == 1
assert page["page_size"] == 20
item = page["items"][0]
assert item["status"] == "pending"
assert item["source_file_count"] == 2
assert item["output_count"] == 17
assert item["output_dataset_id"] is None
def _legacy_published_datasets(task_id: str = "task-1") -> list[dict[str, Any]]:
specs = (
("dataset_train", "制度问答-训练集", "train", "train", 22),