From bcc58ce36158b7be04f96ad334c9ddfd1235c999 Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Wed, 21 Oct 2026 02:56:27 -0400 Subject: [PATCH] Mark checktest FilePaths in subdirectories as non-imports on Windows checktest compiled FilePaths with OS separators, so on Windows a file in a subdirectory was named with backslashes and didn't match the forward-slash names used to tell FilePaths from imports, which marked it as an import. Co-Authored-By: Claude Opus 5.5 --- check/checktest/checktest.go | 11 ++++++---- .../buf-plugin-syntax-specified/main_test.go | 22 +++++++++++++++++++ .../subdirectory_failure/sub/simple.proto | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 check/internal/example/cmd/buf-plugin-syntax-specified/testdata/subdirectory_failure/sub/simple.proto diff --git a/check/checktest/checktest.go b/check/checktest/checktest.go index f2f4350..6d0e641 100644 --- a/check/checktest/checktest.go +++ b/check/checktest/checktest.go @@ -336,10 +336,13 @@ func compile( moduleName descriptor.ModuleName, ) ([]descriptor.FileDescriptor, error) { dirPaths = fromSlashPaths(dirPaths) - filePaths = fromSlashPaths(filePaths) + // The compiler names each file by the path it is given, and .proto file + // names use forward slashes even on Windows. + toSlashFilePaths := make([]string, len(filePaths)) toSlashFilePathMap := make(map[string]struct{}, len(filePaths)) - for _, filePath := range filePaths { - toSlashFilePathMap[filepath.ToSlash(filePath)] = struct{}{} + for i, filePath := range fromSlashPaths(filePaths) { + toSlashFilePaths[i] = filepath.ToSlash(filePath) + toSlashFilePathMap[toSlashFilePaths[i]] = struct{}{} } var warningErrorsWithPos []reporter.ErrorWithPos @@ -360,7 +363,7 @@ func compile( // This is what buf uses. SourceInfoMode: protocompile.SourceInfoExtraOptionLocations, } - files, err := compiler.Compile(ctx, filePaths...) + files, err := compiler.Compile(ctx, toSlashFilePaths...) if err != nil { return nil, err } diff --git a/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go b/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go index 77f7f85..742a7d4 100644 --- a/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go +++ b/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go @@ -60,3 +60,25 @@ func TestSimpleFailure(t *testing.T) { }, }.Run(t) } + +func TestSubdirectoryFailure(t *testing.T) { + t.Parallel() + + checktest.CheckTest{ + Request: &checktest.RequestSpec{ + Files: &checktest.ProtoFileSpec{ + DirPaths: []string{"testdata/subdirectory_failure"}, + FilePaths: []string{"sub/simple.proto"}, + }, + }, + Spec: spec, + ExpectedAnnotations: []checktest.ExpectedAnnotation{ + { + RuleID: syntaxSpecifiedRuleID, + FileLocation: &checktest.ExpectedFileLocation{ + FileName: "sub/simple.proto", + }, + }, + }, + }.Run(t) +} diff --git a/check/internal/example/cmd/buf-plugin-syntax-specified/testdata/subdirectory_failure/sub/simple.proto b/check/internal/example/cmd/buf-plugin-syntax-specified/testdata/subdirectory_failure/sub/simple.proto new file mode 100644 index 0000000..322a627 --- /dev/null +++ b/check/internal/example/cmd/buf-plugin-syntax-specified/testdata/subdirectory_failure/sub/simple.proto @@ -0,0 +1 @@ +package simple;