【架构优化】合并 catalog/assistant handler 中重复的资产引用查找为包级 helper

Đang mở
#444 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@fx-kurumi đang làm issue này rồi.

Từ ngày 13/11/2026.

  • #445 của @fx-kurumi — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
15/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
go
Lĩnh vực
backend

Hướng nghiên cứu

The three duplicated lookups are the agentNamesReferencing, sandboxNamesReferencing and workflowNamesReferencingSandbox methods on catalogHandlers in internal/httpapi/catalog.go and assistantHandlers in internal/httpapi/assistant_approval.go. Pull request #445 is already open against this issue, so check it before starting. Done means the package-level helpers in asset_references.go are used by both handlers, the new asset_references_test.go passes, and go test ./internal/httpapi/ is green.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

现状问题

internal/httpapi/catalog.go(catalogHandlers)与 internal/httpapi/assistant_approval.go(assistantHandlers)各自定义了一份逐字相同的资产引用查找方法:

  • agentNamesReferencing(kind, id):列出引用某规则/技能的角色名
  • sandboxNamesReferencing(kind, id):列出引用某 Dockerfile/环境脚本的沙箱名
  • workflowNamesReferencingSandbox(id):列出引用某沙箱的流程名

两份实现共约 45 行重复,只依赖 *repo.Store 的只读查询,与各自 handler 的其它状态无关。目录删除校验(catalog)和助手删除审批预警(assistant)判断"是否仍被引用"的口径本应一致,重复实现容易在后续修改时只改一边而出现偏差。

重构方案

  • 新建包级 helper 文件 internal/httpapi/asset_references.go,提供三个无 receiver 的函数 agentNamesReferencing(st *repo.Store, kind, id)、sandboxNamesReferencing(st, kind, id)、workflowNamesReferencingSandbox(st, id),实现与现有代码逐行一致(符合 AGENTS.md「纯共享的包级 helper 可以放独立 helper 文件」)。
  • 删除两个 handler 上的重复方法,调用处改为传 h.repo。
  • 现有测试中对旧方法的调用同步改为调用包级函数。

影响范围

仅 internal/httpapi 包内部未导出函数;不涉及 HTTP 接口、错误文案、返回值或排序,行为不变。

验证方式

  • 新增 asset_references_test.go 覆盖三个函数(重复引用只计一次、kind 区分、未引用返回空)。
  • gofmt、go vet ./internal/httpapi/、go test ./internal/httpapi/ 通过(本机缺 Chromium 的浏览器用例除外,与 main 一致)。
Ngôn ngữ chính
Go
Star
141
Fork
28
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
113

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Tencent/LoopForge

Tất cả issue của Tencent/LoopForge

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.