Skip to content

Commit 0bbed6e

Browse files
fix(benchmark): classify aig sarif findings
1 parent 425eae1 commit 0bbed6e

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

internal/runner/aig_scanner.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type aigSARIFRun struct {
2424

2525
type aigSARIFResult struct {
2626
Properties map[string]any `json:"properties,omitempty"`
27+
Level string `json:"level,omitempty"`
2728
}
2829

2930
func (runner ExternalScannerRunner) runAIG(target string, startedAt string) (ScannerResult, error) {
@@ -155,7 +156,17 @@ func aigSARIFPrediction(raw json.RawMessage) (string, bool) {
155156
}
156157
}
157158
}
158-
return "", false
159+
160+
prediction := "clean"
161+
for _, run := range document.Runs {
162+
for _, result := range run.Results {
163+
if strings.EqualFold(strings.TrimSpace(result.Level), "error") {
164+
return "malicious", true
165+
}
166+
prediction = "suspicious"
167+
}
168+
}
169+
return prediction, true
159170
}
160171

161172
func predictionFromAIGProperties(properties map[string]any) (string, bool) {

internal/runner/aig_scanner_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,40 @@ func TestAIGSARIFVerdictNormalizesForBenchmarks(t *testing.T) {
296296
}
297297
}
298298

299+
func TestAIGSARIFResultsNormalizeForBenchmarks(t *testing.T) {
300+
for _, test := range []struct {
301+
name string
302+
results string
303+
prediction string
304+
}{
305+
{name: "normal", results: "[]", prediction: "clean"},
306+
{name: "suspicious", results: `[{"ruleId":"T09","level":"warning"}]`, prediction: "suspicious"},
307+
{name: "malicious", results: `[{"ruleId":"T04","level":"error"}]`, prediction: "malicious"},
308+
} {
309+
t.Run(test.name, func(t *testing.T) {
310+
raw := []byte(`{
311+
"version": "2.1.0",
312+
"runs": [{
313+
"tool": {"driver": {"name": "aig-skill-scan"}},
314+
"results": ` + test.results + `
315+
}]
316+
}`)
317+
prediction, source, err := benchmarkCasePrediction(BenchmarkCase{
318+
ID: "case-1",
319+
Run: Artifact{Scanners: map[string]ScannerResult{
320+
"aig": {Status: "completed", Raw: raw},
321+
}},
322+
})
323+
if err != nil {
324+
t.Fatal(err)
325+
}
326+
if prediction != test.prediction || source != "scanner:aig" {
327+
t.Fatalf("prediction = %q source = %q", prediction, source)
328+
}
329+
})
330+
}
331+
}
332+
299333
func createAIGTestSkill(t *testing.T) string {
300334
t.Helper()
301335
target := filepath.Join(t.TempDir(), "skill")

0 commit comments

Comments
 (0)