修复: MCP list_tasks 默认排除终态 + read_skill 隔离围栏

- list_tasks 无 status 过滤时默认排除 done/cancelled, 终态存量(260+条)挤占分页窗口致活跃任务被挤出视图; 显式传 status 不干预
- df-storage TaskQuery 新增 status_not_in 字段 + SQL NOT IN 下推(占位符先拼后绑, 防序号/值错位)
- read_skill 返回内容外包 skill_documentation XML 围栏+隔离声明, 防技能文档内容与系统指令混淆
- df-mcp 64 passed(含新增终态排除测试)
This commit is contained in:
lxy
2026-10-06 23:48:11 +08:00
parent 9ff26f0c8f
commit 9520c198a2
3 changed files with 77 additions and 2 deletions
+47 -1
View File
@@ -547,9 +547,18 @@ fn list_tasks(ctx: &Ctx, args: Value) -> BoxFuture<'static, CallToolResult> {
Box::pin(async move {
let repo = TaskRepo::new(&db);
// 分页:取 limit+1 条探测是否有下一页(has_more),再截断到 limit。
// 缺陷修复(1eff911c,登记于 2026-08-08):无 status 过滤时默认排除 done/cancelled——
// 终态任务是存量大头(本库 260+ 条),不过滤会挤占分页窗口,活跃任务被
// created_at DESC + limit 截断挤出视图(表象=「过滤失效/他项目任务混入」)。
// 显式传 status(含 done)不干预,保留查终态能力。
let query = TaskQuery {
project_id: project_id_filter,
status: status_filter,
status: status_filter.clone(),
status_not_in: if status_filter.is_some() {
None
} else {
Some(vec!["done".to_string(), "cancelled".to_string()])
},
limit: Some(limit + 1),
offset: Some(offset),
..Default::default()
@@ -1740,6 +1749,43 @@ mod tests {
assert_eq!(v["has_more"], false, "3 条 < 100,无下一页");
}
/// 1eff911c 缺陷修复:无 status 过滤时默认排除 done/cancelled 终态任务;
/// 显式传 status=done 仍可查终态。
#[tokio::test]
async fn list_tasks_excludes_terminal_status_by_default() {
let ctx = test_ctx().await;
let pid = seed_project(&ctx, "终态过滤").await;
let done_id = seed_task(&ctx, &pid, "已完成任务").await;
seed_task(&ctx, &pid, "进行中任务").await;
// 把第一条推进到 done
let repo = TaskRepo::new(&ctx.db);
repo.advance_status_atomic(&done_id, "todo", "done", false).await.unwrap();
// 无 status 过滤:done 应被排除,只返回活跃任务
let r = list_tasks(&ctx, json!({ "project_id": pid })).await;
assert!(r.is_error.is_none(), "{:?}", text_of(&r));
let v = json_of(&r);
let titles: Vec<&str> = v["tasks"]
.as_array()
.unwrap()
.iter()
.map(|t| t["title"].as_str().unwrap())
.collect();
assert!(
!titles.contains(&"已完成任务"),
"done 任务不应出现在默认结果: {titles:?}"
);
assert!(titles.contains(&"进行中任务"), "活跃任务应保留: {titles:?}");
// 显式 status=done:仍可查终态(能力不回退)
let r = list_tasks(&ctx, json!({ "project_id": pid, "status": "done" })).await;
assert!(r.is_error.is_none(), "{:?}", text_of(&r));
let v = json_of(&r);
let arr = v["tasks"].as_array().unwrap();
assert_eq!(arr.len(), 1, "显式查 done 应命中 1 条");
assert_eq!(arr[0]["title"], "已完成任务");
}
/// list_projects 分页:offset 生效 + has_more 标记。
#[tokio::test]
async fn list_projects_pagination_offset_and_has_more() {