代码评审(2026-06-01 全链路报告)中 Manager 侧自主可修项: - P2 交付物判定: runtimeArtifactsAreSummaryOnly 改为优先读结构化字段 (artifact_type + files_modified 信号),修复 Runtime 新 uri scheme 与 artifact_type=document 被旧 /artifacts/summary 字符串启发式漏判的回归。 - P6a: Resource CRUD(normalizeResourcePayload)强制 secret_ref 必须 azkv://, 与 agnet 部署/审批路径一致,堵住直写任意 secret_ref 的旁路。 - P6b: 明文密钥检测从仅按字段名升级为同时扫字符串值(sk-/ghp_/AKIA/JWT/PEM 等高置信模式),containsPlaintextSecret 与 containsSensitiveGrantField 均覆盖。 - P5 默认模型收敛: 新增单一来源 defaultAgnetModelID()(env AGNET_DEFAULT_MODEL_ID, 默认生产已验证的 gpt-5.4);移除 draft 构造器两处 agnet-model-<role> 占位回退 (生产 NewAPI "No available channel" 根因)与角色模板硬编码 claude-* 默认。 - P3 文档: 对接文档状态枚举补 completed 终态、runtime_state 镜像说明与未知值兜底; role-templates 示例占位名改为 gpt-5.4。 新增 controller/agnet_deliverable_secret_test.go 覆盖以上行为。 go build ./... 与 go test ./controller/ 全绿。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
153 lines
4.8 KiB
Go
153 lines
4.8 KiB
Go
package controller
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// P2: deliverable judgment must read structured artifact_type / file signals,
|
|
// not just the legacy title/summary/uri string heuristics.
|
|
func TestRuntimeArtifactsAreSummaryOnly_StructuredFields(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
artifacts []gin.H
|
|
want bool
|
|
}{
|
|
{
|
|
name: "empty list is not summary-only",
|
|
artifacts: nil,
|
|
want: false,
|
|
},
|
|
{
|
|
// The regression the review flagged: Runtime now emits
|
|
// artifact_type=document under runtime://.../artifacts/<task>,
|
|
// which the old "/artifacts/summary" uri heuristic missed.
|
|
name: "document type with new uri scheme and no files is summary-only",
|
|
artifacts: []gin.H{{
|
|
"artifact_id": "art_1",
|
|
"artifact_type": "document",
|
|
"title": "Backend delivery",
|
|
"summary": "下面是方案总结",
|
|
"uri": "runtime://swm_x/artifacts/backend_1",
|
|
}},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "code_patch is a real deliverable",
|
|
artifacts: []gin.H{{
|
|
"artifact_type": "code_patch",
|
|
"uri": "runtime://swm_x/artifacts/backend_1",
|
|
}},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "deployment_manifest is a real deliverable",
|
|
artifacts: []gin.H{{"artifact_type": "deployment_manifest"}},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "document type but with file-change signal is a deliverable",
|
|
artifacts: []gin.H{{
|
|
"artifact_type": "document",
|
|
"metadata": map[string]any{"files_modified": float64(2)},
|
|
}},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "mixed set with one real deliverable is not summary-only",
|
|
artifacts: []gin.H{
|
|
{"artifact_type": "document"},
|
|
{"artifact_type": "code_patch"},
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "legacy runtime execution summary marker still detected",
|
|
artifacts: []gin.H{{
|
|
"artifact_type": "other",
|
|
"title": "Runtime execution summary",
|
|
}},
|
|
want: true,
|
|
},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
require.Equal(t, tc.want, runtimeArtifactsAreSummaryOnly(tc.artifacts))
|
|
})
|
|
}
|
|
}
|
|
|
|
// P6a: Resource CRUD must reject a secret_ref that is not an azkv:// reference.
|
|
func TestNormalizeResourcePayload_SecretRefMustBeAzkv(t *testing.T) {
|
|
base := func(secretRef string) resourcePayload {
|
|
return resourcePayload{Name: "repo", ResourceType: "git", SecretRef: secretRef}
|
|
}
|
|
|
|
_, err := normalizeResourcePayload(base("https://example.com/token"))
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "azkv://")
|
|
|
|
_, err = normalizeResourcePayload(base("sk-live-plaintext-leak"))
|
|
require.Error(t, err)
|
|
|
|
got, err := normalizeResourcePayload(base("azkv://heicode-kv.vault.azure.net/secrets/repo"))
|
|
require.NoError(t, err)
|
|
require.Equal(t, "azkv://heicode-kv.vault.azure.net/secrets/repo", got.SecretRef)
|
|
|
|
// Empty secret_ref stays allowed (secret can be set later via UpsertResourceSecret).
|
|
_, err = normalizeResourcePayload(base(""))
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
// P6b: plaintext-secret detection must scan string VALUES, not only key names.
|
|
func TestValueLooksLikeSecretAndPlaintextScan(t *testing.T) {
|
|
positives := []string{
|
|
"sk-abcdefghij1234567890",
|
|
"sk-live-abcdefghijklmnopqrst",
|
|
"ghp_abcdefghijklmnopqrstuvwxyz0123",
|
|
"AKIAIOSFODNN7EXAMPLE",
|
|
"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjMifQ.s5h6Qk0c5Qx2hQ",
|
|
"-----BEGIN OPENSSH PRIVATE KEY-----\nabc\n-----END",
|
|
}
|
|
for _, s := range positives {
|
|
require.Truef(t, valueLooksLikeSecret(s), "expected secret-like: %q", s)
|
|
}
|
|
|
|
negatives := []string{
|
|
"",
|
|
"main",
|
|
"https://github.com/org/repo.git",
|
|
"azkv://heicode-kv.vault.azure.net/secrets/repo",
|
|
"a normal sentence with sk in it",
|
|
}
|
|
for _, s := range negatives {
|
|
require.Falsef(t, valueLooksLikeSecret(s), "expected NOT secret-like: %q", s)
|
|
}
|
|
|
|
// Value hidden under an innocuous key must now be caught.
|
|
require.True(t, containsPlaintextSecret(map[string]any{"note": "sk-abcdefghij1234567890"}))
|
|
require.False(t, containsPlaintextSecret(map[string]any{"repo_url": "https://github.com/o/r.git"}))
|
|
}
|
|
|
|
// P5: a single source of truth for the default model; no placeholder fallback.
|
|
func TestDefaultAgnetModelID_SingleSourceNoPlaceholder(t *testing.T) {
|
|
def := defaultAgnetModelID()
|
|
require.Equal(t, "gpt-5.4", def)
|
|
|
|
// Draft builder must use the single default, never agnet-model-<role>.
|
|
plan := buildAgnetDraftAgentPlan("backend", "", nil)
|
|
require.Equal(t, def, plan.DefaultModelID)
|
|
require.NotContains(t, plan.DefaultModelID, "agnet-model-")
|
|
|
|
// Explicit client model is still honored.
|
|
plan = buildAgnetDraftAgentPlan("backend", "gpt-5.4-mini", nil)
|
|
require.Equal(t, "gpt-5.4-mini", plan.DefaultModelID)
|
|
|
|
// Every role template resolves to the single default, no claude-* hardcoding.
|
|
for _, tpl := range agnetRoleTemplates() {
|
|
require.Equal(t, def, tpl.DefaultModel, "role %s", tpl.Key)
|
|
}
|
|
}
|