diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index 9f4f417..6ce0d5f 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -111,6 +111,7 @@ func parseFilesParallel(files []string) []parseResult { localParser.index = NewCheatIndex() localParser.parseLines(path, data) localCheats = append(localCheats, localParser.index.Cheats...) + localDuplicates = append(localDuplicates, localParser.index.Duplicates...) localModules = mergeModules(localModules, &localDuplicates, localParser.index.Modules) localErrors = append(localErrors, localParser.index.Errors...) } diff --git a/pkg/parser/parser_test.go b/pkg/parser/parser_test.go index a39b41d..e2143ef 100644 --- a/pkg/parser/parser_test.go +++ b/pkg/parser/parser_test.go @@ -350,6 +350,32 @@ func TestParseVarDefLiteral(t *testing.T) { } } +func TestDirectoryPreservesFileDuplicates(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, "duplicates.md") + content := "# Modules\n\n\n" + if err := os.WriteFile(path, []byte(content), 0o600); err != nil { + t.Fatal(err) + } + + fileIndex, err := NewParser().ParseSingleFile(path) + if err != nil { + t.Fatal(err) + } + want := []DuplicateExport{{Name: "shared", File1: path, File2: path}} + if !reflect.DeepEqual(fileIndex.Duplicates, want) { + t.Fatalf("file duplicates = %v, want %v", fileIndex.Duplicates, want) + } + + directoryIndex, err := NewParser().ParseDirectory(dir) + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(directoryIndex.Duplicates, fileIndex.Duplicates) { + t.Fatalf("directory duplicates = %v, want file duplicates %v", directoryIndex.Duplicates, fileIndex.Duplicates) + } +} + // TestDuplicateExportDetection verifies that duplicate exports are always // detected regardless of which goroutine processes each file. This is a // regression test for a race condition where two files with the same export