fix(lint): normalise empty orchestration outputs

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-01 10:53:06 +00:00
parent 23c5d20b1b
commit ebc2c04c3d
4 changed files with 26 additions and 1 deletions

View file

@ -35,7 +35,7 @@ func Detect(path string) []string {
seen := make(map[string]bool)
info, err := os.Stat(path)
if err != nil {
return nil
return []string{}
}
if !info.IsDir() {
@ -113,5 +113,8 @@ func sortedDetectedLanguages(seen map[string]bool) []string {
languages = append(languages, language)
}
slices.Sort(languages)
if languages == nil {
return []string{}
}
return languages
}

View file

@ -42,3 +42,7 @@ func TestDetectFromFiles_Good(t *testing.T) {
detectFromFiles(files),
)
}
func TestDetect_MissingPathReturnsEmptySlice(t *testing.T) {
assert.Equal(t, []string{}, Detect(filepath.Join(t.TempDir(), "missing")))
}

View file

@ -144,6 +144,15 @@ func (s *Service) Run(ctx context.Context, input RunInput) (Report, error) {
findings = dedupeFindings(findings)
sortToolRuns(toolRuns)
sortFindings(findings)
if languages == nil {
languages = []string{}
}
if toolRuns == nil {
toolRuns = []ToolRun{}
}
if findings == nil {
findings = []Finding{}
}
report := Report{
Project: projectName(input.Path),
@ -179,6 +188,9 @@ func (s *Service) Tools(languages []string) []ToolInfo {
slices.SortFunc(tools, func(left ToolInfo, right ToolInfo) int {
return strings.Compare(left.Name, right.Name)
})
if tools == nil {
return []ToolInfo{}
}
return tools
}

View file

@ -373,6 +373,12 @@ func TestServiceRun_Good_DeduplicatesMergedFindings(t *testing.T) {
assert.Equal(t, 1, report.Summary.Total)
}
func TestServiceTools_EmptyInventoryReturnsEmptySlice(t *testing.T) {
tools := (&Service{}).Tools(nil)
require.NotNil(t, tools)
assert.Empty(t, tools)
}
type duplicateAdapter struct {
name string
finding Finding