From ebc2c04c3de4a56b3c5abb4b9c38040e56b3ccff Mon Sep 17 00:00:00 2001 From: Virgil Date: Wed, 1 Apr 2026 10:53:06 +0000 Subject: [PATCH] fix(lint): normalise empty orchestration outputs Co-Authored-By: Virgil --- pkg/lint/detect_project.go | 5 ++++- pkg/lint/detect_project_test.go | 4 ++++ pkg/lint/service.go | 12 ++++++++++++ pkg/lint/service_test.go | 6 ++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/lint/detect_project.go b/pkg/lint/detect_project.go index 80b411e..8006c44 100644 --- a/pkg/lint/detect_project.go +++ b/pkg/lint/detect_project.go @@ -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 } diff --git a/pkg/lint/detect_project_test.go b/pkg/lint/detect_project_test.go index 3fa8d43..0576622 100644 --- a/pkg/lint/detect_project_test.go +++ b/pkg/lint/detect_project_test.go @@ -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"))) +} diff --git a/pkg/lint/service.go b/pkg/lint/service.go index 6887545..902d58d 100644 --- a/pkg/lint/service.go +++ b/pkg/lint/service.go @@ -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 } diff --git a/pkg/lint/service_test.go b/pkg/lint/service_test.go index cf061fe..5708182 100644 --- a/pkg/lint/service_test.go +++ b/pkg/lint/service_test.go @@ -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