Skip to content

Commit bd0a16e

Browse files
committed
fix(profiles): preserve ClawHub gate behavior
1 parent 2954e46 commit bd0a16e

3 files changed

Lines changed: 12 additions & 157 deletions

File tree

‎cmd/clawscan/main_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,8 @@ profiles:
221221
"profiles:",
222222
"clawhub:",
223223
"clawhub-aig:",
224-
"- id: skillspector",
225-
"id: do-not-install",
226-
"- risk_assessment.recommendation",
227-
"equals: DO_NOT_INSTALL",
228-
"normalize: identifier",
224+
"- skillspector",
225+
"- clawscan-static",
229226
"- aig",
230227
} {
231228
if !strings.Contains(stdout, want) {
@@ -238,6 +235,9 @@ profiles:
238235
if strings.Contains(stdout, "local-review:") {
239236
t.Fatalf("verbose profiles output should not include project profile:\n%s", stdout)
240237
}
238+
if strings.Contains(stdout, "gate:") {
239+
t.Fatalf("embedded profiles should preserve their existing gate-free contract:\n%s", stdout)
240+
}
241241
}
242242

243243
func TestRunCommandBenchmarkListPrintsCatalogTable(t *testing.T) {

‎internal/profiles/clawhub/clawscan.yml‎

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,8 @@ version: 1
33
profiles:
44
clawhub:
55
scanners:
6-
- id: skillspector
7-
gate:
8-
rules: &skillspector-gate-rules
9-
- id: do-not-install
10-
path:
11-
- risk_recommendation|riskRecommendation|recommendation
12-
- risk_assessment.recommendation|risk_recommendation|riskRecommendation
13-
- riskAssessment.recommendation|risk_recommendation|riskRecommendation
14-
equals: DO_NOT_INSTALL
15-
normalize: identifier
16-
action: block
17-
- id: critical-finding
18-
path:
19-
- filtered_findings[].severity|risk_severity|level
20-
- filteredFindings[].severity|risk_severity|level
21-
- findings[].severity|risk_severity|level
22-
- issues[].severity|risk_severity|level
23-
- vulnerabilities[].severity|risk_severity|level
24-
equals: CRITICAL
25-
normalize: identifier
26-
fallback: root
27-
action: block
28-
- id: high-finding
29-
path:
30-
- filtered_findings[].severity|risk_severity|level
31-
- filteredFindings[].severity|risk_severity|level
32-
- findings[].severity|risk_severity|level
33-
- issues[].severity|risk_severity|level
34-
- vulnerabilities[].severity|risk_severity|level
35-
equals: HIGH
36-
normalize: identifier
37-
fallback: root
38-
action: warn
39-
- id: clawscan-static
40-
gate:
41-
rules:
42-
- id: any-finding
43-
path: findings[]
44-
exists: true
45-
action: warn
6+
- skillspector
7+
- clawscan-static
468
sandbox:
479
env:
4810
- OPENAI_API_KEY
@@ -67,9 +29,7 @@ profiles:
6729
- < {{ prompt:prompt.md }}
6830
clawhub-aig:
6931
scanners:
70-
- id: skillspector
71-
gate:
72-
rules: *skillspector-gate-rules
32+
- skillspector
7333
- aig
7434
sandbox:
7535
env:

‎internal/profiles/resolver_test.go‎

Lines changed: 4 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ func TestResolveArgsUsesEmbeddedClawHubProfile(t *testing.T) {
3232
if got := strings.Join(opts.Scanners, ","); got != "skillspector,clawscan-static" {
3333
t.Fatalf("scanners = %q", got)
3434
}
35-
if got := len(opts.GateRules["skillspector"].JSONRules); got != 3 {
36-
t.Fatalf("skillspector JSON gate rules = %#v", opts.GateRules["skillspector"].JSONRules)
37-
}
38-
if got := len(opts.GateRules["clawscan-static"].JSONRules); got != 1 {
39-
t.Fatalf("static JSON gate rules = %#v", opts.GateRules["clawscan-static"].JSONRules)
35+
if len(opts.GateRules) != 0 {
36+
t.Fatalf("embedded clawhub profile changed its existing gate contract: %#v", opts.GateRules)
4037
}
4138
if opts.Judge == nil {
4239
t.Fatal("expected embedded clawhub judge")
@@ -85,8 +82,8 @@ func TestResolveArgsUsesEmbeddedClawHubAIGCandidateProfile(t *testing.T) {
8582
if got := strings.Join(candidate.Scanners, ","); got != "skillspector,aig" {
8683
t.Fatalf("scanners = %q", got)
8784
}
88-
if got := len(candidate.GateRules["skillspector"].JSONRules); got != 3 {
89-
t.Fatalf("skillspector JSON gate rules = %#v", candidate.GateRules["skillspector"].JSONRules)
85+
if len(candidate.GateRules) != 0 {
86+
t.Fatalf("embedded clawhub-aig profile changed its existing gate contract: %#v", candidate.GateRules)
9087
}
9188
if candidate.Judge == nil || clawhub.Judge == nil {
9289
t.Fatal("missing embedded ClawHub judge")
@@ -983,108 +980,6 @@ profiles:
983980
}
984981
}
985982

986-
func TestEmbeddedClawHubGateCoversSupportedSkillSpectorShapes(t *testing.T) {
987-
tests := []struct {
988-
name string
989-
raw json.RawMessage
990-
want string
991-
path string
992-
}{
993-
{
994-
name: "top-level recommendation",
995-
raw: json.RawMessage(`{"recommendation":"do-not-install","issues":[]}`),
996-
want: "block",
997-
path: "risk_recommendation|riskRecommendation|recommendation",
998-
},
999-
{
1000-
name: "null recommendation alias falls through",
1001-
raw: json.RawMessage(`{"risk_recommendation":null,"recommendation":"DO_NOT_INSTALL","issues":[]}`),
1002-
want: "block",
1003-
path: "risk_recommendation|riskRecommendation|recommendation",
1004-
},
1005-
{
1006-
name: "nested recommendation behind empty top-level alias",
1007-
raw: json.RawMessage(`{"recommendation":"","risk_assessment":{"recommendation":"DO_NOT_INSTALL"},"issues":[]}`),
1008-
want: "block",
1009-
path: "risk_assessment.recommendation|risk_recommendation|riskRecommendation",
1010-
},
1011-
{
1012-
name: "risk recommendation has precedence",
1013-
raw: json.RawMessage(`{"recommendation":"SAFE","risk_recommendation":"DO_NOT_INSTALL","issues":[]}`),
1014-
want: "block",
1015-
path: "risk_recommendation|riskRecommendation|recommendation",
1016-
},
1017-
{
1018-
name: "empty preferred recommendation group falls back to nested",
1019-
raw: json.RawMessage(`{"risk_recommendation":"","recommendation":"SAFE","risk_assessment":{"recommendation":"DO_NOT_INSTALL"},"issues":[]}`),
1020-
want: "block",
1021-
path: "risk_assessment.recommendation|risk_recommendation|riskRecommendation",
1022-
},
1023-
{
1024-
name: "camel-case report",
1025-
raw: json.RawMessage(`{"riskAssessment":{"recommendation":"CAUTION"},"filteredFindings":[{"severity":"CRITICAL"}]}`),
1026-
want: "block",
1027-
path: "filteredFindings[].severity|risk_severity|level",
1028-
},
1029-
{
1030-
name: "alternate issue fields",
1031-
raw: json.RawMessage(`{"findings":[{"level":"high"}]}`),
1032-
want: "warn",
1033-
path: "findings[].severity|risk_severity|level",
1034-
},
1035-
{
1036-
name: "empty filtered findings override raw findings",
1037-
raw: json.RawMessage(`{"filtered_findings":[],"findings":[{"severity":"CRITICAL"}]}`),
1038-
want: "pass",
1039-
},
1040-
{
1041-
name: "null filtered findings fall through to raw findings",
1042-
raw: json.RawMessage(`{"filtered_findings":null,"findings":[{"severity":"CRITICAL"}]}`),
1043-
want: "block",
1044-
path: "findings[].severity|risk_severity|level",
1045-
},
1046-
{
1047-
name: "nonmatching filtered findings override raw findings",
1048-
raw: json.RawMessage(`{"filtered_findings":[{"severity":"LOW"}],"findings":[{"severity":"CRITICAL"}]}`),
1049-
want: "pass",
1050-
},
1051-
{
1052-
name: "finding field aliases resolve per item",
1053-
raw: json.RawMessage(`{"filtered_findings":[{"severity":"LOW"},{"risk_severity":"CRITICAL"}]}`),
1054-
want: "block",
1055-
path: "filtered_findings[].severity|risk_severity|level",
1056-
},
1057-
}
1058-
for _, test := range tests {
1059-
t.Run(test.name, func(t *testing.T) {
1060-
opts, err := ResolveArgs([]string{"./skill", "--profile", "clawhub", "--sandbox", "off"}, t.TempDir())
1061-
if err != nil {
1062-
t.Fatal(err)
1063-
}
1064-
opts.Judge = nil
1065-
artifact, err := runner.Run(opts, runner.RunContext{
1066-
Env: map[string]string{},
1067-
ScannerRunner: profileScannerResultRunner{results: map[string]runner.ScannerResult{
1068-
"skillspector": {Status: "completed", Raw: test.raw},
1069-
"clawscan-static": {Status: "completed", Raw: json.RawMessage(`{"findings":[]}`)},
1070-
}},
1071-
})
1072-
if err != nil {
1073-
t.Fatal(err)
1074-
}
1075-
if artifact.Gate != test.want {
1076-
t.Fatalf("gate = %q, rules = %#v", artifact.Gate, artifact.GateRules)
1077-
}
1078-
if test.path == "" && len(artifact.GateRules) != 0 {
1079-
t.Fatalf("gate rules = %#v", artifact.GateRules)
1080-
}
1081-
if test.path != "" && (len(artifact.GateRules) != 1 || artifact.GateRules[0].Path != test.path) {
1082-
t.Fatalf("gate rules = %#v", artifact.GateRules)
1083-
}
1084-
})
1085-
}
1086-
}
1087-
1088983
func TestCommandScannerDeclarativeJSONRuleGatesUnchangedOutput(t *testing.T) {
1089984
dir := t.TempDir()
1090985
target := filepath.Join(dir, "skill")

0 commit comments

Comments
 (0)