feat(coverage): 资产测试覆盖度(task_scope 范围 + fact 派生已测)

按 docs/任务覆盖度设计-最终版.md 实现(轻量版,粗估供 agent 参考):
- 新表 task_scope(覆盖度分母 + per-task 授权边界):CREATE TABLE IF NOT EXISTS 进
  schema.sql,随 db.go 每次启动 Exec,旧库自动生效。
- db/task_scope.go:AddAutoScope(insertAssets 按资产类型保守入范围)、AddAgentScope
  (add_task_scope 工具:company/root_domain/subdomain/ip/cidr)、ListTaskScope、
  TaskCoverage(范围内资产中被 fact 节点锚定过的占比 + backlog 取样)。
- insertAssets 顶层循环按 worker 显式插入的资产类型自动入范围(source=auto);
  side-effect 派生的资产不触发(钩子在 handler 顶层、派生在 db 层内部),范围不盲目扩大。
- add_task_scope 工具绑 planner,随 BuiltinToolSeeds 播种(新库/旧库皆 seed)。
- graph_overview 注入 coverage(denominator/tested/backlog_sample + 粗估提示)供 planner 参考。
- HTTP:GET /api/tasks/{id}/coverage、/scope;任务总览页覆盖度卡(含 backlog)。
- 修 toolcatalog_test(record_fact 绑定断言,早前 mainagent 加 recordFact 后未同步)。

验证:go build / vet / agent test / 前端 tsc 均通过。注:DB 层 SQL 尚未经 live Postgres 运行验证。

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Autumn-27andClaude Opus 5 committed 2026-08-08 09:09:38 -04:00
1 parent 58e057a3f2
commit aeadd0d48b
8 files changed
+499 -4

No files matched your search

+14 -3
View File
@@ -22,9 +22,20 @@ func TestBuiltinToolSeeds(t *testing.T) {
}
byKey[s.Key] = s
}
// record_fact is worker-only.
if rf, ok := byKey["record_fact"]; !ok || len(rf.Agents) != 1 || rf.Agents[0] != "worker" {
t.Errorf("record_fact agents = %v, want [worker]", rf.Agents)
// record_fact is bound to worker (also mainagent, which can log confirmed facts).
rf, ok := byKey["record_fact"]
hasWorker := false
for _, a := range rf.Agents {
if a == "worker" {
hasWorker = true
}
}
if !ok || !hasWorker {
t.Errorf("record_fact agents = %v, want to include worker", rf.Agents)
}
// add_task_scope is bound to the planner (deliberate scope widening).
if ts, ok := byKey["add_task_scope"]; !ok || len(ts.Agents) == 0 {
t.Errorf("add_task_scope not seeded / has no agent binding: %v", ts.Agents)
}
// SDK generic tools (incl. sleep, now part of DefaultTools) are deliberately NOT
// seeded — every agent owns them; they flow through ToolResolve untouched.