Files
ARTEX/agent/coverage_params_test.go
T
Autumn-27 22ae280584 feat(insert_assets): 资产可标记是否与当前任务相关(related)
insert_assets 每条资产新增 related 入参(默认 true):仅在任务开启资产
覆盖度功能时生效——true 才自动纳入覆盖度(测试范围分母),false 则只入
共享资产库、不计入本任务覆盖度(如顺带发现的旁站/无关资产)。

- Call 内部按 related + coverageDisabled 双重 gate 决定是否 AddAutoScope
- 覆盖度关闭时 related 无意义,经 StripCoverageParams 从最终工具 schema
  剔除(必须在 ToolResolve 的 DB schema 覆盖之后做,故在装配链末端处理)
- 旧库经 refreshBuiltinToolSchemas(flag v6) 刷新 insert_assets schema,
  否则首插入only 的 seed 收不到新参数
- 补 StripCoverageParams 回归测试(开启保留/关闭隐藏/不改原始 schema)

Claude-Session: https://claude.ai/code/session_01Jm87Gr5fq5aso6SfLyguhx
2026-08-22 10:26:11 -04:00

47 lines
1.5 KiB
Go

package agent
import (
"testing"
actool "github.com/Autumn-27/norma/tool"
)
// hasRelatedParam reports whether insert_assets' schema still advertises the
// per-item `related` parameter (properties.assets.items.properties.related).
func hasRelatedParam(tool actool.CoreTool) bool {
props, ok := nestedMap(tool.InputSchema(), "properties", "assets", "items", "properties")
if !ok {
return false
}
_, ok = props["related"]
return ok
}
// TestStripCoverageParams verifies the insert_assets `related` param is visible
// while coverage is on and hidden once it's off, and that stripping never mutates
// the original tool's schema (deep copy).
func TestStripCoverageParams(t *testing.T) {
ts := NewToolSet(nil, "")
insert := ts.insertAssets()
if !hasRelatedParam(insert) {
t.Fatal("insert_assets 应默认带 related 参数")
}
// Enabled (default): schema unchanged, related still present.
ts.SetCoverageEnabled(true)
if got := ts.StripCoverageParams([]actool.CoreTool{insert}); !hasRelatedParam(got[0]) {
t.Error("覆盖度开启时不应剔除 related 参数")
}
// Disabled: related stripped from the model-facing schema.
ts.SetCoverageEnabled(false)
out := ts.StripCoverageParams([]actool.CoreTool{insert})
if hasRelatedParam(out[0]) {
t.Error("覆盖度关闭时应隐藏 related 参数")
}
// The original tool must be untouched (deep copy, no shared-map mutation).
if !hasRelatedParam(insert) {
t.Error("StripCoverageParams 不应修改原始 tool 的 schema")
}
}