feat(assets): 任务测试资产支持 DSL 搜索

任务详情「测试资产」接口/服务多时不好找。复用资产管理页的 DSL
搜索(字段自动补全 + 分页),搜索始终限定在当前任务范围内。

- 抽出共享组件 asset-dsl-search.tsx,资产页与任务页复用,UI/交互一致
- QueryDSL/CountDSL 增加 taskID 参数,taskID>0 时强制 AND $N = ANY(task_ids)
  并补 task 来源信息;即便 DSL 内写 task_id 也无法越出当前任务
- 任务资产 tab 接入搜索框:有 DSL 走 searchTaskAssets,否则走 taskAssets

Closes #107
This commit is contained in:
Autumn-27 committed 2026-09-11 11:59:46 -04:00
1 parent 1f258837f5
commit 557317491b
8 files changed
+491 -393

No files matched your search

+23 -3
View File
@@ -471,7 +471,8 @@ func ValidateDSL(dsl string) error {
// CountDSL returns the total number of assets matching a DSL expression (and optional
// type), for server-side pagination — same WHERE as QueryDSL, without LIMIT/OFFSET.
func (s *AssetStore) CountDSL(dsl, typ string) (int, error) {
// taskID > 0 scopes the count to assets attached to that task.
func (s *AssetStore) CountDSL(dsl, typ string, taskID int64) (int, error) {
node, err := ParseDSL(dsl)
if err != nil {
return 0, err
@@ -484,6 +485,10 @@ func (s *AssetStore) CountDSL(dsl, typ string) (int, error) {
args = append(args, typ)
where += fmt.Sprintf(" AND type = $%d", len(args))
}
if taskID > 0 {
args = append(args, taskID)
where += fmt.Sprintf(" AND $%d = ANY(task_ids)", len(args))
}
var n int
err = s.db.QueryRow("SELECT count(*) FROM assets WHERE "+where, args...).Scan(&n)
return n, err
@@ -491,7 +496,9 @@ func (s *AssetStore) CountDSL(dsl, typ string) (int, error) {
// QueryDSL executes a DSL query string against the asset store.
// typ is an optional asset type filter applied independently of the DSL expression.
func (s *AssetStore) QueryDSL(dsl, typ string, limit, offset int) ([]*Asset, error) {
// taskID > 0 scopes results to assets attached to that task and hydrates each
// row's per-task source metadata (as QueryByTask does).
func (s *AssetStore) QueryDSL(dsl, typ string, taskID int64, limit, offset int) ([]*Asset, error) {
if limit <= 0 {
limit = 50
}
@@ -510,6 +517,10 @@ func (s *AssetStore) QueryDSL(dsl, typ string, limit, offset int) ([]*Asset, err
args = append(args, typ)
where += fmt.Sprintf(" AND type = $%d", len(args))
}
if taskID > 0 {
args = append(args, taskID)
where += fmt.Sprintf(" AND $%d = ANY(task_ids)", len(args))
}
args = append(args, limit, offset)
q := assetSelectCols + " WHERE " + where +
fmt.Sprintf(" ORDER BY last_seen DESC, id DESC LIMIT $%d OFFSET $%d", len(args)-1, len(args))
@@ -518,5 +529,14 @@ func (s *AssetStore) QueryDSL(dsl, typ string, limit, offset int) ([]*Asset, err
return nil, err
}
defer rows.Close()
return scanAssets(rows)
assets, err := scanAssets(rows)
if err != nil {
return nil, err
}
if taskID > 0 {
if err := s.hydrateTaskAssetSources(taskID, assets); err != nil {
return nil, err
}
}
return assets, nil
}
+1 -1
View File
@@ -943,7 +943,7 @@ func TestAssetPaginationUsesStableIDTieBreaker(t *testing.T) {
t.Fatalf("task pagination order=%v want=%v", got, want)
}
if got := collect(func(limit, offset int) ([]*Asset, error) {
return assets.QueryDSL(marker, "root_domain", limit, offset)
return assets.QueryDSL(marker, "root_domain", 0, limit, offset)
}); !slices.Equal(got, want) {
t.Fatalf("DSL pagination order=%v want=%v", got, want)
}