fix(scanner): leave failed scanner results out of the merge

A scanner that returns a result with status error now counts as a failed
scanner, like one that returns an error. Its result no longer joins the
merge, and the manager counts it as an infrastructure failure or another
failure by its cause.

The merged status is error only when every applicable scanner failed.
The fail_closed setting then decides that case as before. One scanner
failing while another returns clean now reads clean.
This commit is contained in:
2026-11-23 18:06:54 +00:00
parent 8adb1e0c87
commit 3731ca05ce
7 changed files with 274 additions and 49 deletions
+2 -3
View File
@@ -13,6 +13,7 @@ import (
"github.com/lukaszraczylo/gohoarder/pkg/config"
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
"github.com/lukaszraczylo/gohoarder/pkg/scanner/scanerr"
"github.com/lukaszraczylo/gohoarder/pkg/uuid"
"github.com/rs/zerolog/log"
)
@@ -140,9 +141,7 @@ func (s *Scanner) Scan(ctx context.Context, registry, packageName, version strin
Scanner: s.Name(),
ScannedAt: time.Now(),
Status: metadata.ScanStatusError,
Details: map[string]interface{}{
"error": "scan timeout",
},
Details: scanerr.ErrorDetails("scan timeout", true),
}, nil
}
+24
View File
@@ -0,0 +1,24 @@
package trivy
import (
"context"
"testing"
"time"
"github.com/lukaszraczylo/gohoarder/pkg/config"
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
"github.com/lukaszraczylo/gohoarder/pkg/scanner/scanerr"
"github.com/lukaszraczylo/gohoarder/pkg/scanner/scannertest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestScanTimeoutIsAnInfrastructureErrorResult(t *testing.T) {
scannertest.Script(t, "trivy", "exec sleep 5")
res, err := New(config.TrivyConfig{Timeout: 100 * time.Millisecond}).Scan(context.Background(), "npm", "p", "1", "/x")
require.NoError(t, err)
assert.Equal(t, metadata.ScanStatusError, res.Status)
assert.Equal(t, true, res.Details[scanerr.DetailInfrastructure])
}