diff --git a/cmd/generate-stable-protos/corpus_test.go b/cmd/generate-stable-protos/corpus_test.go index 057c8d312..55e1560bd 100644 --- a/cmd/generate-stable-protos/corpus_test.go +++ b/cmd/generate-stable-protos/corpus_test.go @@ -1,6 +1,29 @@ package main -import "testing" +import ( + "testing" + + "github.com/temporalio/api/cmd/generate-stable-protos/internal/oracle" +) + +// TestRepoAPINext generates the stable tree from the repository's own api_next tree and +// checks it against the oracle, so real-world declarations, options and comments are +// covered beyond the hand-written fixtures. +func TestRepoAPINext(t *testing.T) { + t.Parallel() + const root = "../.." + out := t.TempDir() + if err := testConfig.stableProtosGenerator(t.Context(), root, out); err != nil { + t.Fatal(err) + } + result, err := oracle.Check(root, out) + if err != nil { + t.Fatal(err) + } + for _, problem := range result.AllProblems() { + t.Error(problem) + } +} // TestRepoAPINextIdempotent checks that the stable tree generated from the repository's // api_next tree is a fixed point of the generator. diff --git a/cmd/generate-stable-protos/fixtures_test.go b/cmd/generate-stable-protos/fixtures_test.go index 785de0025..15263e7bd 100644 --- a/cmd/generate-stable-protos/fixtures_test.go +++ b/cmd/generate-stable-protos/fixtures_test.go @@ -12,11 +12,15 @@ import ( "slices" "strings" "testing" + + "github.com/temporalio/api/cmd/generate-stable-protos/internal/oracle" ) -// TestFixtures runs the generator on every fixture under testdata. A fixture is a -// directory with an input/ api_next tree, and optionally an expected.json and an -// expected/ tree holding the raw generator output without its generated header. +// TestFixtures runs every fixture under testdata. A fixture is a directory with an +// input/ api_next tree, and optionally an expected.json and an expected/ tree holding the +// raw generator output without its generated header. A fixture with an output/ tree +// tests the oracle instead of the generator: output/ stands in for the generator's +// output, and the oracle must report exactly the expected problems. func TestFixtures(t *testing.T) { t.Parallel() for _, fixture := range findFixtures(t) { @@ -37,6 +41,11 @@ type fixtureExpectation struct { Annotations draftAnnotations `json:"annotations"` // ValidationOnly limits the fixture to source validation until projection supports it. ValidationOnly bool `json:"validation_only"` + // Problems are substrings of the problems the oracle must report, one each; any + // other problem fails the fixture. + Problems []string `json:"problems"` + // DeclarationChanges lists the exact descriptor additions or removals the oracle must report. + DeclarationChanges []oracle.DeclarationChange `json:"declaration_changes"` } // findFixtures returns the fixture directories under testdata, relative to it. @@ -75,11 +84,47 @@ func runFixture(t *testing.T, dir string) { t.Fatal(err) } root := filepath.Join(dir, "input") - out := t.TempDir() + out := filepath.Join(dir, "output") + if _, err := os.Stat(out); errors.Is(err, fs.ErrNotExist) { + out = t.TempDir() + if !generateFixture(t, dir, root, out, expected) { + return + } + } else if err != nil { + t.Fatal(err) + } + + result, err := oracle.Check(root, out) + if err != nil { + t.Fatal(err) + } + problems := result.AllProblems() + if len(expected.DeclarationChanges) > 0 { + if !slices.Equal(result.DeclarationChanges, expected.DeclarationChanges) || result.DescriptorDiff == "" { + t.Errorf("want declaration changes %v, got %v\n%s", expected.DeclarationChanges, result.DeclarationChanges, result.DescriptorDiff) + } + problems = result.Problems + } + for _, want := range expected.Problems { + i := slices.IndexFunc(problems, func(problem string) bool { return strings.Contains(problem, want) }) + if i < 0 { + t.Errorf("want an oracle problem containing %q", want) + continue + } + problems = slices.Delete(problems, i, i+1) + } + for _, problem := range problems { + t.Errorf("unexpected oracle problem: %s", problem) + } +} +// generateFixture runs the generator on root into out and checks the result against +// the fixture's expectations. It reports whether out holds output for the oracle. +func generateFixture(t *testing.T, dir, root, out string, expected fixtureExpectation) bool { + t.Helper() if expected.ValidationOnly { checkFixtureAnnotations(t, root, expected.Annotations) - return + return false } if expected.Error != "" { before := readTree(t, out) @@ -93,7 +138,7 @@ func runFixture(t *testing.T, dir string) { if !maps.Equal(before, readTree(t, out)) { t.Fatal("generation failure modified output") } - return + return false } if err := testConfig.stableProtosGenerator(t.Context(), root, out); err != nil { @@ -127,6 +172,7 @@ func runFixture(t *testing.T, dir string) { } } } + return true } func checkFixtureAnnotations(t *testing.T, root string, expected draftAnnotations) { diff --git a/cmd/generate-stable-protos/go.mod b/cmd/generate-stable-protos/go.mod index 55e1495ba..d8786569e 100644 --- a/cmd/generate-stable-protos/go.mod +++ b/cmd/generate-stable-protos/go.mod @@ -4,6 +4,7 @@ go 1.26.7 require ( github.com/bufbuild/protocompile v0.14.2-0.20260825174057-3dfa26e2df9b + github.com/google/go-cmp v0.7.0 google.golang.org/protobuf v1.36.12 pgregory.net/rapid v1.3.0 ) diff --git a/cmd/generate-stable-protos/internal/oracle/comments.go b/cmd/generate-stable-protos/internal/oracle/comments.go new file mode 100644 index 000000000..0d91e707c --- /dev/null +++ b/cmd/generate-stable-protos/internal/oracle/comments.go @@ -0,0 +1,288 @@ +package oracle + +import ( + "fmt" + "maps" + "slices" + "strings" + + "google.golang.org/protobuf/types/descriptorpb" +) + +// checkComments requires every input comment to appear in the output, except the +// comments inside or attached to a removed declaration or a pruned import, and no other +// comment to appear. The source scan also covers comments without SourceCodeInfo +// locations, such as comments inside option values. +func checkComments(inputTexts, outputTexts map[string]string, input, output *descriptorpb.FileDescriptorSet, removed map[string][][]int32) ([]string, error) { + outputFiles := map[string]*descriptorpb.FileDescriptorProto{} + for _, fd := range output.GetFile() { + outputFiles[fd.GetName()] = fd + } + var problems []string + for _, fd := range input.GetFile() { + if fd.GetName() == draftFile { + continue + } + stable := stablePath(fd.GetName()) + projected := outputFiles[stable] + locations := map[string]*descriptorpb.SourceCodeInfo_Location{} + for _, loc := range fd.GetSourceCodeInfo().GetLocation() { + if key := fmt.Sprint(loc.GetPath()); locations[key] == nil { + locations[key] = loc + } + } + gone := slices.Clone(removed[fd.GetName()]) + importIndices := map[int32]int32{} + for i, dep := range fd.GetDependency() { + index := slices.Index(projected.GetDependency(), stablePath(dep)) + if index < 0 { + gone = append(gone, []int32{fileDependenciesTag, int32(i)}) + } + importIndices[int32(i)] = int32(index) + } + + var spans [][]int32 + // surplus counts each comment line in the output minus its count in the input. + surplus := map[string]int{} + inputComments := scanComments(inputTexts[fd.GetName()]) + for _, path := range gone { + loc := locations[fmt.Sprint(path)] + if loc == nil { + // Synthetic map entries have no source location. + continue + } + start := comment{line: int(loc.GetSpan()[0]), col: int(loc.GetSpan()[1]), lastCodeCol: -1} + if slices.ContainsFunc(spans, start.within) { + // A removed container already covers comments on the declarations inside it. + continue + } + spans = append(spans, loc.GetSpan()) + // Leading comments sit before the span, so the scan below counts them. Trailing + // comments are left to the scan, including after a closing brace where + // protoc attaches nothing. + for _, text := range append(slices.Clone(loc.GetLeadingDetachedComments()), loc.GetLeadingComments()) { + for _, line := range normalizeComment(text) { + surplus[line]++ + } + } + if path[0] == fileDependenciesTag { + for _, line := range trailingImportLines(loc, inputComments) { + surplus[line]++ + } + } + } + for _, c := range inputComments { + if !slices.ContainsFunc(spans, c.within) { + for _, line := range commentLines([]comment{c}) { + surplus[line]-- + } + } + } + + text, ok := strings.CutPrefix(outputTexts[stable], generatedHeader) + if !ok { + problems = append(problems, fmt.Sprintf("%s: missing generated header", stable)) + continue + } + for _, line := range commentLines(scanComments(text)) { + surplus[line]++ + } + var diffs []string + for line, n := range surplus { + if n != 0 { + diffs = append(diffs, fmt.Sprintf("%+d %q", n, line)) + } + } + if len(diffs) > 0 { + slices.Sort(diffs) + problems = append(problems, fmt.Sprintf("%s: comment lines differ from the input less removed declarations (+leaked, -lost):\n%s", stable, strings.Join(diffs, "\n"))) + continue + } + want := map[string][]string{} + for _, loc := range fd.GetSourceCodeInfo().GetLocation() { + if path, kept := remapCommentPath(loc.GetPath(), gone, importIndices); kept { + recordAttachedComments(want, path, loc, nil) + } + } + got := map[string][]string{} + header := commentLines(scanComments(generatedHeader)) + for _, loc := range projected.GetSourceCodeInfo().GetLocation() { + recordAttachedComments(got, loc.GetPath(), loc, header) + } + paths := maps.Clone(want) + maps.Copy(paths, got) + for _, key := range slices.Sorted(maps.Keys(paths)) { + if !slices.Equal(want[key], got[key]) { + diffs = append(diffs, fmt.Sprintf("%s: want %q, got %q", key, want[key], got[key])) + } + } + if len(diffs) > 0 { + problems = append(problems, fmt.Sprintf("%s: attached comments differ by descriptor path:\n%s", stable, strings.Join(diffs, "\n"))) + } + } + return problems, nil +} + +// trailingImportLines returns the attached trailing lines outside the import's +// span and last line, which the raw source scan would otherwise count as retained. +func trailingImportLines(loc *descriptorpb.SourceCodeInfo_Location, comments []comment) []string { + lines := normalizeComment(loc.GetTrailingComments()) + if len(lines) == 0 { + return nil + } + span := loc.GetSpan() + endLine := span[0] + if len(span) == 4 { + endLine = span[2] + } + endCol := span[len(span)-1] + for _, c := range comments { + if int32(c.line) != endLine || int32(c.col) < endCol || !c.within(span) { + continue + } + for _, line := range commentLines([]comment{c}) { + if i := slices.Index(lines, line); i >= 0 { + lines = slices.Delete(lines, i, i+1) + } + } + } + return lines +} + +// remapCommentPath adjusts retained declaration indexes after projection. +func remapCommentPath(path []int32, removed [][]int32, imports map[int32]int32) ([]int32, bool) { + if len(path) >= 2 && path[0] == fileDependenciesTag { + index := imports[path[1]] + if index < 0 { + return nil, false + } + result := slices.Clone(path) + result[1] = index + return result, true + } + result := slices.Clone(path) + for _, gone := range removed { + index := len(gone) - 1 + if index >= len(path) || !slices.Equal(gone[:index], path[:index]) { + continue + } + if gone[index] == path[index] { + return nil, false + } + if gone[index] < path[index] { + result[index]-- + } + } + return result, true +} + +func recordAttachedComments(byPath map[string][]string, path []int32, loc *descriptorpb.SourceCodeInfo_Location, header []string) { + var lines []string + for _, text := range append(slices.Clone(loc.GetLeadingDetachedComments()), loc.GetLeadingComments(), loc.GetTrailingComments()) { + lines = append(lines, normalizeComment(text)...) + } + // Protoc attaches the generated header to the syntax declaration. + if len(path) == 1 && path[0] == fileSyntaxTag && len(lines) >= len(header) && slices.Equal(lines[:len(header)], header) { + lines = lines[len(header):] + } + if len(lines) > 0 { + key := fmt.Sprint(path) + byPath[key] = append(byPath[key], lines...) + } +} + +type comment struct { + line, col, lastCodeCol int // Columns are zero-based, with tabs advancing to a multiple of 8. + text string +} + +// within reports whether c starts inside a SourceCodeInfo span or trails it without intervening code. +func (c comment) within(span []int32) bool { + startLine, startCol, endLine, endCol := span[0], span[1], span[0], span[2] + if len(span) == 4 { + endLine, endCol = span[2], span[3] + } + pos := []int32{int32(c.line), int32(c.col)} + return slices.Compare(pos, []int32{startLine, startCol}) >= 0 && + (slices.Compare(pos, []int32{endLine, endCol}) < 0 || + pos[0] == endLine && c.lastCodeCol >= 0 && int32(c.lastCodeCol) < endCol) +} + +// scanComments returns the comments in proto source, skipping string literals. +func scanComments(src string) []comment { + var comments []comment + line, col, lastCodeCol := 0, 0, -1 + advance := func(n int, i int) int { + for _, b := range []byte(src[i : i+n]) { + switch b { + case '\n': + line, col, lastCodeCol = line+1, 0, -1 + case '\t': + col += 8 - col%8 + default: + col++ + } + } + return i + n + } + for i := 0; i < len(src); { + rest := src[i:] + switch { + case rest[0] == '"' || rest[0] == '\'': + n := 1 + for n < len(rest) && rest[n] != rest[0] && rest[n] != '\n' { + if rest[n] == '\\' { + n++ + } + n++ + } + i = advance(min(n+1, len(rest)), i) + lastCodeCol = col - 1 + case strings.HasPrefix(rest, "//"), strings.HasPrefix(rest, "/*"): + end := len(rest) + if rest[1] == '/' { + if n := strings.IndexByte(rest, '\n'); n >= 0 { + end = n + } + } else if n := strings.Index(rest[2:], "*/"); n >= 0 { + end = n + 4 + } + comments = append(comments, comment{line, col, lastCodeCol, rest[:end]}) + i = advance(end, i) + default: + if !strings.ContainsRune(" \t\r\n\v\f", rune(rest[0])) { + lastCodeCol = col + } + i = advance(1, i) + } + } + return comments +} + +// commentLines strips the comment delimiters and normalizes each line. +func commentLines(comments []comment) []string { + var lines []string + for _, c := range comments { + text, block := strings.CutPrefix(c.text, "/*") + if block { + text = strings.TrimSuffix(text, "*/") + } else { + text = strings.TrimPrefix(text, "//") + } + lines = append(lines, normalizeComment(text)...) + } + return lines +} + +// normalizeComment splits comment text into trimmed, nonempty lines without the leading +// "*" of block comment margins, matching both raw comments and protoc's stripped ones. +func normalizeComment(text string) []string { + var lines []string + for _, line := range strings.Split(text, "\n") { + line = strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(line), "*")) + if line != "" { + lines = append(lines, line) + } + } + return lines +} diff --git a/cmd/generate-stable-protos/internal/oracle/oracle.go b/cmd/generate-stable-protos/internal/oracle/oracle.go new file mode 100644 index 000000000..da8873e33 --- /dev/null +++ b/cmd/generate-stable-protos/internal/oracle/oracle.go @@ -0,0 +1,170 @@ +// Package oracle checks the output of generate-stable-protos against an independent +// reference: protoc compiles the api_next input and the stable output, and the stable +// descriptors must equal the input descriptors with the draft declarations projected +// out. The projection works on descriptors, where removing a declaration is simple, so +// it shares no logic with the generator's AST editing. +package oracle + +import ( + "fmt" + "maps" + "slices" + "strings" + + "github.com/google/go-cmp/cmp" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/testing/protocmp" + "google.golang.org/protobuf/types/descriptorpb" +) + +const ( + nextPrefix = "temporal/api_next/" + stablePrefix = "temporal/api/" + draftFile = nextPrefix + "protometa/v1/draft.proto" + generatedHeader = "// Code generated by generate-stable-protos. DO NOT EDIT. \n // @generated \n\n" +) + +// DeclarationChange identifies a declaration added to or removed from the expected projection. +type DeclarationChange struct { + Kind string `json:"kind"` + File string `json:"file"` + Path string `json:"path"` +} + +// Result contains the oracle's diagnostics and its structured declaration changes. +type Result struct { + Problems []string + DescriptorDiff string + DeclarationChanges []DeclarationChange +} + +// AllProblems returns the diagnostics, including any descriptor diff. +func (r Result) AllProblems() []string { + if r.DescriptorDiff == "" { + return r.Problems + } + return append(slices.Clone(r.Problems), r.DescriptorDiff) +} + +// Check compares the stable tree under outputRoot with the api_next tree under +// inputRoot and returns every deviation from the projection. The error reports a +// failure to run the check itself. +func Check(inputRoot, outputRoot string) (Result, error) { + inputTexts, err := readTree(inputRoot, nextPrefix) + if err != nil { + return Result{}, err + } + outputTexts, err := readTree(outputRoot, stablePrefix) + if err != nil { + return Result{}, err + } + input, _, err := compile([]string{inputRoot}, slices.Sorted(maps.Keys(inputTexts))) + if err != nil { + return Result{}, fmt.Errorf("compile input: %w", err) + } + // The output directory comes first so it shadows any stable tree checked in under inputRoot. + output, warnings, err := compile([]string{outputRoot, inputRoot}, slices.Sorted(maps.Keys(outputTexts))) + if err != nil { + return Result{}, fmt.Errorf("compile output: %w", err) + } + var problems []string + if strings.Contains(warnings, "is unused") { + problems = append(problems, fmt.Sprintf("stable output has unused imports:\n%s", warnings)) + } + + p, err := newProjector(input) + if err != nil { + return Result{}, err + } + expected := map[string]*descriptorpb.FileDescriptorProto{} + removed := map[string][][]int32{} + inputDeps := map[string]bool{} + for _, fd := range input.GetFile() { + if fd.GetName() == draftFile { + continue + } + projected, paths := p.projectFile(fd) + expected[projected.GetName()] = projected + removed[fd.GetName()] = paths + for _, dep := range fd.GetDependency() { + inputDeps[stablePath(dep)] = true + } + } + actual := map[string]*descriptorpb.FileDescriptorProto{} + for _, fd := range output.GetFile() { + // Import pruning needs cross-file usage analysis, which would re-implement the + // generator; the unused-import warning check above covers it instead. + for _, dep := range fd.GetDependency() { + if !inputDeps[dep] { + problems = append(problems, fmt.Sprintf("%s: import %s is not an import of the input", fd.GetName(), dep)) + } + } + actual[fd.GetName()] = normalize(fd) + } + if diff := cmp.Diff(expected, actual, protocmp.Transform()); diff != "" { + // Comment differences would only repeat the declarations that differ. + return Result{ + Problems: problems, + DescriptorDiff: fmt.Sprintf("stable descriptors differ from the oracle projection (-expected +actual):\n%s", diff), + DeclarationChanges: compareDeclarations(expected, actual), + }, nil + } + commentProblems, err := checkComments(inputTexts, outputTexts, input, output, removed) + if err != nil { + return Result{}, err + } + return Result{Problems: append(problems, commentProblems...)}, nil +} + +func compareDeclarations(expected, actual map[string]*descriptorpb.FileDescriptorProto) []DeclarationChange { + var changes []DeclarationChange + for _, side := range []struct { + kind string + files, against map[string]*descriptorpb.FileDescriptorProto + }{ + {"added", actual, expected}, + {"removed", expected, actual}, + } { + for _, file := range slices.Sorted(maps.Keys(side.files)) { + paths, against := map[string]bool{}, map[string]bool{} + collectDeclarationPaths(side.files[file].ProtoReflect(), "", paths) + if fd := side.against[file]; fd != nil { + collectDeclarationPaths(fd.ProtoReflect(), "", against) + } + for _, path := range slices.Sorted(maps.Keys(paths)) { + if !against[path] { + changes = append(changes, DeclarationChange{Kind: side.kind, File: file, Path: path}) + } + } + } + } + return changes +} + +// collectDeclarationPaths walks named descriptor children, using names instead of list indexes. +func collectDeclarationPaths(message protoreflect.Message, prefix string, paths map[string]bool) { + message.Range(func(field protoreflect.FieldDescriptor, v protoreflect.Value) bool { + if !field.IsList() || field.Message() == nil { + return true + } + name := field.Message().Fields().ByName("name") + if name == nil { + return true + } + list := v.List() + for i := range list.Len() { + child := list.Get(i).Message() + path := prefix + string(field.Name()) + "." + child.Get(name).String() + paths[path] = true + collectDeclarationPaths(child, path+".", paths) + } + return true + }) +} + +func stablePath(path string) string { + if rest, ok := strings.CutPrefix(path, nextPrefix); ok { + return stablePrefix + rest + } + return path +} diff --git a/cmd/generate-stable-protos/internal/oracle/projector.go b/cmd/generate-stable-protos/internal/oracle/projector.go new file mode 100644 index 000000000..de0295a59 --- /dev/null +++ b/cmd/generate-stable-protos/internal/oracle/projector.go @@ -0,0 +1,243 @@ +package oracle + +import ( + "fmt" + "slices" + + "google.golang.org/protobuf/encoding/protowire" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/descriptorpb" +) + +// Source paths, per the field numbers in descriptor.proto. +const ( + fileDependenciesTag = 3 + fileMessagesTag = 4 + fileEnumsTag = 5 + fileServicesTag = 6 + fileSyntaxTag = 12 + messageFieldsTag = 2 + messageNestedTag = 3 + messageEnumsTag = 4 + messageOneofsTag = 8 + enumValuesTag = 2 + serviceMethodsTag = 2 +) + +// projector projects draft declarations out of protoc-compiled descriptors. +type projector struct { + fieldExt, messageExt, enumExt, enumValueExt, oneofExt protowire.Number + serviceExt, methodExt protowire.Number +} + +func newProjector(set *descriptorpb.FileDescriptorSet) (*projector, error) { + p := &projector{} + type extension struct{ name, extendee string } + numbers := map[extension]*protowire.Number{ + {"draft", ".google.protobuf.FieldOptions"}: &p.fieldExt, + {"draft_message", ".google.protobuf.MessageOptions"}: &p.messageExt, + {"draft_enum", ".google.protobuf.EnumOptions"}: &p.enumExt, + {"draft_enum_value", ".google.protobuf.EnumValueOptions"}: &p.enumValueExt, + {"draft_oneof", ".google.protobuf.OneofOptions"}: &p.oneofExt, + {"draft_service", ".google.protobuf.ServiceOptions"}: &p.serviceExt, + {"draft_method", ".google.protobuf.MethodOptions"}: &p.methodExt, + } + for _, fd := range set.GetFile() { + if fd.GetName() != draftFile { + continue + } + for _, ext := range fd.GetExtension() { + if num := numbers[extension{ext.GetName(), ext.GetExtendee()}]; num != nil { + *num = protowire.Number(ext.GetNumber()) + } + } + } + if p.fieldExt == 0 || p.messageExt == 0 { + return nil, fmt.Errorf("draft and draft_message extensions not found in %s", draftFile) + } + return p, nil +} + +// projectFile returns fd without its draft declarations, and the source paths of the +// declarations it removed. +func (p *projector) projectFile(fd *descriptorpb.FileDescriptorProto) (*descriptorpb.FileDescriptorProto, [][]int32) { + fd = proto.Clone(fd).(*descriptorpb.FileDescriptorProto) + fd.Name = new(stablePath(fd.GetName())) + prefix := packagePrefix(fd) + var msgs []*descriptorpb.DescriptorProto + var removed [][]int32 + for i, m := range fd.GetMessageType() { + path := []int32{fileMessagesTag, int32(i)} + if hasOption(m.GetOptions(), p.messageExt) { + removed = append(removed, path) + continue + } + msgs = append(msgs, p.projectMessage(prefix, m, path, &removed)) + } + fd.MessageType = msgs + fd.EnumType = p.projectEnums(fd.GetEnumType(), []int32{fileEnumsTag}, &removed) + var services []*descriptorpb.ServiceDescriptorProto + for i, s := range fd.GetService() { + path := []int32{fileServicesTag, int32(i)} + if hasOption(s.GetOptions(), p.serviceExt) { + removed = append(removed, path) + continue + } + var methods []*descriptorpb.MethodDescriptorProto + for j, m := range s.GetMethod() { + if hasOption(m.GetOptions(), p.methodExt) { + removed = append(removed, slices.Concat(path, []int32{serviceMethodsTag, int32(j)})) + continue + } + methods = append(methods, m) + } + s.Method = methods + services = append(services, s) + } + fd.Service = services + return normalize(fd), removed +} + +func (p *projector) projectEnums(enums []*descriptorpb.EnumDescriptorProto, path []int32, removed *[][]int32) []*descriptorpb.EnumDescriptorProto { + var stable []*descriptorpb.EnumDescriptorProto + for i, e := range enums { + enumPath := slices.Concat(path, []int32{int32(i)}) + if hasOption(e.GetOptions(), p.enumExt) { + *removed = append(*removed, enumPath) + continue + } + var values []*descriptorpb.EnumValueDescriptorProto + for j, v := range e.GetValue() { + if hasOption(v.GetOptions(), p.enumValueExt) { + *removed = append(*removed, slices.Concat(enumPath, []int32{enumValuesTag, int32(j)})) + continue + } + values = append(values, v) + } + e.Value = values + stable = append(stable, e) + } + return stable +} + +func (p *projector) projectMessage(prefix string, m *descriptorpb.DescriptorProto, path []int32, removed *[][]int32) *descriptorpb.DescriptorProto { + name := prefix + "." + m.GetName() + var fields []*descriptorpb.FieldDescriptorProto + var draftFields []int + droppedTypes := map[string]bool{} + kept := map[int32]int{} + for i, f := range m.GetField() { + draftOneof := f.OneofIndex != nil && hasOption(m.GetOneofDecl()[f.GetOneofIndex()].GetOptions(), p.oneofExt) + if draftOneof || hasOption(f.GetOptions(), p.fieldExt) { + droppedTypes[f.GetTypeName()] = true + draftFields = append(draftFields, i) + continue + } + if f.OneofIndex != nil { + kept[f.GetOneofIndex()]++ + } + fields = append(fields, f) + } + // A oneof whose branches are all draft goes too, including proto3 optional's + // synthetic oneof; the remaining oneof indexes shift down. + remap := map[int32]int32{} + var oneofs []*descriptorpb.OneofDescriptorProto + for i, od := range m.GetOneofDecl() { + if kept[int32(i)] > 0 { + remap[int32(i)] = int32(len(oneofs)) + oneofs = append(oneofs, od) + } else if !isSyntheticOneof(m, int32(i)) { + // A synthetic oneof has no source of its own; its field is recorded below. + *removed = append(*removed, slices.Concat(path, []int32{messageOneofsTag, int32(i)})) + } + } + for _, i := range draftFields { + // Record fields for path remapping even when a removed oneof's span already covers them. + *removed = append(*removed, slices.Concat(path, []int32{messageFieldsTag, int32(i)})) + } + for _, f := range fields { + if f.OneofIndex != nil { + f.OneofIndex = new(remap[f.GetOneofIndex()]) + } + } + var nested []*descriptorpb.DescriptorProto + for i, n := range m.GetNestedType() { + nestedName := name + "." + n.GetName() + nestedPath := slices.Concat(path, []int32{messageNestedTag, int32(i)}) + switch { + case hasOption(n.GetOptions(), p.messageExt): + *removed = append(*removed, nestedPath) + case n.GetOptions().GetMapEntry() && droppedTypes[nestedName]: + // A map entry is synthetic and has no source; its field is recorded above. + *removed = append(*removed, nestedPath) + default: + nested = append(nested, p.projectMessage(name, n, nestedPath, removed)) + } + } + m.Field, m.OneofDecl, m.NestedType = fields, oneofs, nested + m.EnumType = p.projectEnums(m.GetEnumType(), slices.Concat(path, []int32{messageEnumsTag}), removed) + return m +} + +// isSyntheticOneof reports whether oneof i only exists for a proto3 optional field. +func isSyntheticOneof(m *descriptorpb.DescriptorProto, i int32) bool { + for _, f := range m.GetField() { + if f.OneofIndex != nil && f.GetOneofIndex() == i && !f.GetProto3Optional() { + return false + } + } + return true +} + +// normalize drops what the oracle does not compare: source info, which holds positions +// and comments, and the import lists, which Check checks separately. +func normalize(fd *descriptorpb.FileDescriptorProto) *descriptorpb.FileDescriptorProto { + fd = proto.Clone(fd).(*descriptorpb.FileDescriptorProto) + fd.SourceCodeInfo = nil + fd.Dependency, fd.PublicDependency, fd.WeakDependency = nil, nil, nil + normalizeSyntheticOneofNames(fd.GetMessageType()) + return fd +} + +func normalizeSyntheticOneofNames(messages []*descriptorpb.DescriptorProto) { + for _, message := range messages { + for _, field := range message.GetField() { + if field.GetProto3Optional() && field.OneofIndex != nil { + message.OneofDecl[field.GetOneofIndex()].Name = new(field.GetName()) + } + } + normalizeSyntheticOneofNames(message.GetNestedType()) + } +} + +// hasOption reports whether opts sets the extension num. The draft extensions are not +// registered with the Go runtime, so their values stay in the unknown fields. +func hasOption(opts proto.Message, num protowire.Number) bool { + if opts == nil || !opts.ProtoReflect().IsValid() { + return false + } + b := opts.ProtoReflect().GetUnknown() + for len(b) > 0 { + n, typ, size := protowire.ConsumeTag(b) + if size < 0 { + return false + } + b = b[size:] + if n == num { + return true + } + size = protowire.ConsumeFieldValue(n, typ, b) + if size < 0 { + return false + } + b = b[size:] + } + return false +} + +func packagePrefix(fd *descriptorpb.FileDescriptorProto) string { + if fd.GetPackage() == "" { + return "" + } + return "." + fd.GetPackage() +} diff --git a/cmd/generate-stable-protos/internal/oracle/protoc.go b/cmd/generate-stable-protos/internal/oracle/protoc.go new file mode 100644 index 000000000..d62015b13 --- /dev/null +++ b/cmd/generate-stable-protos/internal/oracle/protoc.go @@ -0,0 +1,62 @@ +package oracle + +import ( + "fmt" + "io/fs" + "os" + "os/exec" + "path" + "path/filepath" + + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/descriptorpb" +) + +// compile compiles files with protoc and returns the descriptors and protoc's output. +func compile(includes, files []string) (*descriptorpb.FileDescriptorSet, string, error) { + dir, err := os.MkdirTemp("", "oracle") + if err != nil { + return nil, "", err + } + defer os.RemoveAll(dir) + out := filepath.Join(dir, "set.binpb") + args := []string{"--include_source_info", "--descriptor_set_out=" + out} + for _, include := range includes { + args = append(args, "-I"+include) + } + output, err := exec.Command("protoc", append(args, files...)...).CombinedOutput() + if err != nil { + return nil, "", fmt.Errorf("protoc: %w\n%s", err, output) + } + data, err := os.ReadFile(out) + if err != nil { + return nil, "", err + } + set := &descriptorpb.FileDescriptorSet{} + if err := proto.Unmarshal(data, set); err != nil { + return nil, "", err + } + return set, string(output), nil +} + +// readTree reads the files under root/prefix, keyed by their slash-separated path +// relative to root. +func readTree(root, prefix string) (map[string]string, error) { + files := map[string]string{} + err := filepath.WalkDir(filepath.Join(root, filepath.FromSlash(prefix)), func(p string, entry fs.DirEntry, err error) error { + if err != nil || entry.IsDir() { + return err + } + relative, err := filepath.Rel(root, p) + if err != nil { + return err + } + data, err := os.ReadFile(p) + if err != nil { + return err + } + files[path.Clean(filepath.ToSlash(relative))] = string(data) + return nil + }) + return files, err +} diff --git a/cmd/generate-stable-protos/random_test.go b/cmd/generate-stable-protos/random_test.go index 49aa081d3..49b044cdb 100644 --- a/cmd/generate-stable-protos/random_test.go +++ b/cmd/generate-stable-protos/random_test.go @@ -6,11 +6,12 @@ import ( "strings" "testing" + "github.com/temporalio/api/cmd/generate-stable-protos/internal/oracle" "pgregory.net/rapid" ) // TestRandomSchemas generates random api_next trees with all draft placements and -// requires the generator to accept each one and a +// requires the generator to accept each one, its output to pass the oracle, and a // second pass to reproduce it. Comments only sit where the generator accepts them: // directly above a declaration or on the same line as its opening or closing token. func TestRandomSchemas(t *testing.T) { @@ -22,6 +23,13 @@ func TestRandomSchemas(t *testing.T) { if err := testConfig.stableProtosGenerator(t.Context(), root, out); err != nil { rt.Fatalf("generator rejected the schema: %v", err) } + result, err := oracle.Check(root, out) + if err != nil { + rt.Fatal(err) + } + if problems := result.AllProblems(); len(problems) > 0 { + rt.Fatalf("oracle problems:\n%s", strings.Join(problems, "\n")) + } checkIdempotent(t.Context(), rt, root, out, t.TempDir()) }) } diff --git a/cmd/generate-stable-protos/testdata/oracle/correct/expected.json b/cmd/generate-stable-protos/testdata/oracle/correct/expected.json new file mode 100644 index 000000000..14ee6ea75 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/correct/expected.json @@ -0,0 +1,3 @@ +{ + "problems": [] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/correct/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/correct/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..09b963d37 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/correct/input/temporal/api_next/fixture.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Example { + string stable = 1; + // DRAFT leading a + string a = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; + StableChild stable_child = 3; // trailing stable_child + Draft draft = 4 [(temporal.api.protometa.v1.draft) = "feature-b"]; +} + +message StableChild { + string value = 1; +} + +// DRAFT leading comment of draft message. +message Draft { + option (temporal.api.protometa.v1.draft_message) = "feature-b"; + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/correct/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/correct/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..9405515c2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/correct/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FieldOptions { + string draft = 98111; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/correct/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/correct/output/temporal/api/fixture.proto new file mode 100644 index 000000000..ffee5a05a --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/correct/output/temporal/api/fixture.proto @@ -0,0 +1,16 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; + +package fixture; + +// Stable doc. +message Example { + string stable = 1; + StableChild stable_child = 3; // trailing stable_child +} + +message StableChild { + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/foreign-import/expected.json b/cmd/generate-stable-protos/testdata/oracle/foreign-import/expected.json new file mode 100644 index 000000000..1a198a137 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/foreign-import/expected.json @@ -0,0 +1,6 @@ +{ + "problems": [ + "import google/protobuf/descriptor.proto is not an import of the input", + "warning: Import google/protobuf/descriptor.proto is unused." + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/foreign-import/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/foreign-import/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..09b963d37 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/foreign-import/input/temporal/api_next/fixture.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Example { + string stable = 1; + // DRAFT leading a + string a = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; + StableChild stable_child = 3; // trailing stable_child + Draft draft = 4 [(temporal.api.protometa.v1.draft) = "feature-b"]; +} + +message StableChild { + string value = 1; +} + +// DRAFT leading comment of draft message. +message Draft { + option (temporal.api.protometa.v1.draft_message) = "feature-b"; + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/foreign-import/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/foreign-import/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..9405515c2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/foreign-import/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FieldOptions { + string draft = 98111; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/foreign-import/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/foreign-import/output/temporal/api/fixture.proto new file mode 100644 index 000000000..3489c1512 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/foreign-import/output/temporal/api/fixture.proto @@ -0,0 +1,18 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; + +package fixture; + +import "google/protobuf/descriptor.proto"; + +// Stable doc. +message Example { + string stable = 1; + StableChild stable_child = 3; // trailing stable_child +} + +message StableChild { + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/expected.json b/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/expected.json new file mode 100644 index 000000000..808d5878c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/expected.json @@ -0,0 +1,5 @@ +{ + "problems": [ + "name:\"modes\"" + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..389eba92d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/input/temporal/api_next/fixture.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +enum Mode { + option (temporal.api.protometa.v1.draft_enum) = "preview"; + ZERO = 0; +} + +message Config { + map modes = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/output/temporal/api/fixture.proto new file mode 100644 index 000000000..66623416c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/implicitly-removed-field/output/temporal/api/fixture.proto @@ -0,0 +1,6 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; +package fixture; +message Config {} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/expected.json b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/expected.json new file mode 100644 index 000000000..63dc19153 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/expected.json @@ -0,0 +1,5 @@ +{ + "problems": [ + "+1 \"DRAFT leading a\"" + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..09b963d37 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/input/temporal/api_next/fixture.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Example { + string stable = 1; + // DRAFT leading a + string a = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; + StableChild stable_child = 3; // trailing stable_child + Draft draft = 4 [(temporal.api.protometa.v1.draft) = "feature-b"]; +} + +message StableChild { + string value = 1; +} + +// DRAFT leading comment of draft message. +message Draft { + option (temporal.api.protometa.v1.draft_message) = "feature-b"; + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..9405515c2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FieldOptions { + string draft = 98111; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/output/temporal/api/fixture.proto new file mode 100644 index 000000000..7fab5ac35 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-comment/output/temporal/api/fixture.proto @@ -0,0 +1,17 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; + +package fixture; + +// Stable doc. +message Example { + string stable = 1; + StableChild stable_child = 3; // trailing stable_child +} + +// DRAFT leading a +message StableChild { + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/expected.json b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/expected.json new file mode 100644 index 000000000..484b7d048 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/expected.json @@ -0,0 +1,9 @@ +{ + "declaration_changes": [ + { + "kind": "added", + "file": "temporal/api/fixture.proto", + "path": "enum_type.Mode.value.PREVIEW" + } + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..1fce0fd96 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/input/temporal/api_next/fixture.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +enum Mode { + ZERO = 0; + PREVIEW = 2 [(temporal.api.protometa.v1.draft_enum_value) = "preview"]; + STABLE = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/output/temporal/api/fixture.proto new file mode 100644 index 000000000..097f305ae --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-enum-value/output/temporal/api/fixture.proto @@ -0,0 +1,11 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; +package fixture; + +enum Mode { + ZERO = 0; + PREVIEW = 2; + STABLE = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/expected.json b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/expected.json new file mode 100644 index 000000000..db821b683 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/expected.json @@ -0,0 +1,5 @@ +{ + "problems": [ + "name:\"a\"" + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..09b963d37 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/input/temporal/api_next/fixture.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Example { + string stable = 1; + // DRAFT leading a + string a = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; + StableChild stable_child = 3; // trailing stable_child + Draft draft = 4 [(temporal.api.protometa.v1.draft) = "feature-b"]; +} + +message StableChild { + string value = 1; +} + +// DRAFT leading comment of draft message. +message Draft { + option (temporal.api.protometa.v1.draft_message) = "feature-b"; + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..9405515c2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FieldOptions { + string draft = 98111; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/output/temporal/api/fixture.proto new file mode 100644 index 000000000..1fff4673d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-field/output/temporal/api/fixture.proto @@ -0,0 +1,17 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; + +package fixture; + +// Stable doc. +message Example { + string stable = 1; + string a = 2; + StableChild stable_child = 3; // trailing stable_child +} + +message StableChild { + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/expected.json b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/expected.json new file mode 100644 index 000000000..c414741a0 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/expected.json @@ -0,0 +1,5 @@ +{ + "problems": [ + "+1 \"Call invokes the preview behavior.\"" + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..1848f5173 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/input/temporal/api_next/fixture.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +// Request starts the preview call. +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +// Response reports the preview result. +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message StableRequest {} +message StableResponse {} +// Service provides both stable and preview calls. +service Service { + // Call invokes the preview behavior. + rpc Call(Request) returns (Response) { + // This option applies only to Call. + option (temporal.api.protometa.v1.draft_method) = "preview"; + } + // Stable invokes the stable behavior. + rpc Stable(StableRequest) returns (StableResponse); +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/output/temporal/api/fixture.proto new file mode 100644 index 000000000..0bb1f10c9 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method-comment/output/temporal/api/fixture.proto @@ -0,0 +1,14 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; +package fixture; + +message StableRequest {} +message StableResponse {} +// Service provides both stable and preview calls. +service Service { + // Call invokes the preview behavior. + // Stable invokes the stable behavior. + rpc Stable(StableRequest) returns (StableResponse); +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/expected.json b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/expected.json new file mode 100644 index 000000000..b45130f6a --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/expected.json @@ -0,0 +1,9 @@ +{ + "declaration_changes": [ + { + "kind": "added", + "file": "temporal/api/fixture.proto", + "path": "service.Service.method.Call" + } + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..1982182b8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/input/temporal/api_next/fixture.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +message Request {} +message Response {} +message StableRequest {} +message StableResponse {} + +service Service { + rpc Call(Request) returns (Response) { + option (temporal.api.protometa.v1.draft_method) = "preview"; + } + rpc Stable(StableRequest) returns (StableResponse); +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/output/temporal/api/fixture.proto new file mode 100644 index 000000000..6499598f3 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/leaked-draft-method/output/temporal/api/fixture.proto @@ -0,0 +1,15 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; +package fixture; + +message Request {} +message Response {} +message StableRequest {} +message StableResponse {} + +service Service { + rpc Call(Request) returns (Response); + rpc Stable(StableRequest) returns (StableResponse); +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/expected.json b/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/expected.json new file mode 100644 index 000000000..69e35f15c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/expected.json @@ -0,0 +1,5 @@ +{ + "problems": [ + "-1 \"Stable doc.\"" + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..09b963d37 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/input/temporal/api_next/fixture.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Example { + string stable = 1; + // DRAFT leading a + string a = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; + StableChild stable_child = 3; // trailing stable_child + Draft draft = 4 [(temporal.api.protometa.v1.draft) = "feature-b"]; +} + +message StableChild { + string value = 1; +} + +// DRAFT leading comment of draft message. +message Draft { + option (temporal.api.protometa.v1.draft_message) = "feature-b"; + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..9405515c2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FieldOptions { + string draft = 98111; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/output/temporal/api/fixture.proto new file mode 100644 index 000000000..f61a3e994 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-stable-comment/output/temporal/api/fixture.proto @@ -0,0 +1,15 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; + +package fixture; + +message Example { + string stable = 1; + StableChild stable_child = 3; // trailing stable_child +} + +message StableChild { + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/expected.json b/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/expected.json new file mode 100644 index 000000000..ea783a6e3 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/expected.json @@ -0,0 +1,5 @@ +{ + "problems": [ + "name:\"stable_child\"" + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..09b963d37 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/input/temporal/api_next/fixture.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Example { + string stable = 1; + // DRAFT leading a + string a = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; + StableChild stable_child = 3; // trailing stable_child + Draft draft = 4 [(temporal.api.protometa.v1.draft) = "feature-b"]; +} + +message StableChild { + string value = 1; +} + +// DRAFT leading comment of draft message. +message Draft { + option (temporal.api.protometa.v1.draft_message) = "feature-b"; + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..9405515c2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FieldOptions { + string draft = 98111; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/output/temporal/api/fixture.proto new file mode 100644 index 000000000..839c884a8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-stable-field/output/temporal/api/fixture.proto @@ -0,0 +1,15 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; + +package fixture; + +// Stable doc. +message Example { + string stable = 1; +} + +message StableChild { + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/expected.json b/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/expected.json new file mode 100644 index 000000000..c6e864a30 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/expected.json @@ -0,0 +1,5 @@ +{ + "problems": [ + "-1 \"trailing stable_child\"" + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..09b963d37 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/input/temporal/api_next/fixture.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Example { + string stable = 1; + // DRAFT leading a + string a = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; + StableChild stable_child = 3; // trailing stable_child + Draft draft = 4 [(temporal.api.protometa.v1.draft) = "feature-b"]; +} + +message StableChild { + string value = 1; +} + +// DRAFT leading comment of draft message. +message Draft { + option (temporal.api.protometa.v1.draft_message) = "feature-b"; + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..9405515c2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FieldOptions { + string draft = 98111; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/output/temporal/api/fixture.proto new file mode 100644 index 000000000..595e08e1f --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/lost-trailing-comment/output/temporal/api/fixture.proto @@ -0,0 +1,16 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; + +package fixture; + +// Stable doc. +message Example { + string stable = 1; + StableChild stable_child = 3; +} + +message StableChild { + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/missing-header/expected.json b/cmd/generate-stable-protos/testdata/oracle/missing-header/expected.json new file mode 100644 index 000000000..eade16285 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/missing-header/expected.json @@ -0,0 +1,5 @@ +{ + "problems": [ + "missing generated header" + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/missing-header/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/missing-header/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..09b963d37 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/missing-header/input/temporal/api_next/fixture.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package fixture; + +import "temporal/api_next/protometa/v1/draft.proto"; + +// Stable doc. +message Example { + string stable = 1; + // DRAFT leading a + string a = 2 [(temporal.api.protometa.v1.draft) = "feature-a"]; + StableChild stable_child = 3; // trailing stable_child + Draft draft = 4 [(temporal.api.protometa.v1.draft) = "feature-b"]; +} + +message StableChild { + string value = 1; +} + +// DRAFT leading comment of draft message. +message Draft { + option (temporal.api.protometa.v1.draft_message) = "feature-b"; + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/missing-header/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/missing-header/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..9405515c2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/missing-header/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FieldOptions { + string draft = 98111; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/missing-header/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/missing-header/output/temporal/api/fixture.proto new file mode 100644 index 000000000..04cc9d2bd --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/missing-header/output/temporal/api/fixture.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package fixture; + +// Stable doc. +message Example { + string stable = 1; + StableChild stable_child = 3; // trailing stable_child +} + +message StableChild { + string value = 1; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/expected.json b/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/expected.json new file mode 100644 index 000000000..fd40f4bd2 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/expected.json @@ -0,0 +1,5 @@ +{ + "problems": [ + "[4 0]: want [], got [\"This comment is unattached.\"]" + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..917ac5dc8 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/input/temporal/api_next/fixture.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; +package fixture; + +message Example {} + +// This comment is unattached. diff --git a/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/output/temporal/api/fixture.proto new file mode 100644 index 000000000..1bf707689 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/newly-attached-comment/output/temporal/api/fixture.proto @@ -0,0 +1,8 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; +package fixture; + +// This comment is unattached. +message Example {} diff --git a/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/expected.json b/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/expected.json new file mode 100644 index 000000000..8b2217032 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/expected.json @@ -0,0 +1,9 @@ +{ + "declaration_changes": [ + { + "kind": "removed", + "file": "temporal/api/fixture.proto", + "path": "service.Service.method.Stable" + } + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..1848f5173 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/input/temporal/api_next/fixture.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; +package fixture; +import "temporal/api_next/protometa/v1/draft.proto"; + +// Request starts the preview call. +message Request { option (temporal.api.protometa.v1.draft_message) = "preview"; } +// Response reports the preview result. +message Response { option (temporal.api.protometa.v1.draft_message) = "preview"; } +message StableRequest {} +message StableResponse {} +// Service provides both stable and preview calls. +service Service { + // Call invokes the preview behavior. + rpc Call(Request) returns (Response) { + // This option applies only to Call. + option (temporal.api.protometa.v1.draft_method) = "preview"; + } + // Stable invokes the stable behavior. + rpc Stable(StableRequest) returns (StableResponse); +} diff --git a/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..def18ac5d --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package temporal.api.protometa.v1; +import "google/protobuf/descriptor.proto"; +extend google.protobuf.FieldOptions { string draft = 98008; } +extend google.protobuf.MessageOptions { string draft_message = 98008; } +extend google.protobuf.EnumOptions { string draft_enum = 98008; } +extend google.protobuf.EnumValueOptions { string draft_enum_value = 98008; } +extend google.protobuf.ServiceOptions { string draft_service = 98008; } +extend google.protobuf.MethodOptions { string draft_method = 98008; } +extend google.protobuf.OneofOptions { string draft_oneof = 98009; } diff --git a/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/output/temporal/api/fixture.proto new file mode 100644 index 000000000..a02ff5d9c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/removed-stable-method/output/temporal/api/fixture.proto @@ -0,0 +1,11 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; +package fixture; + +message StableRequest {} +message StableResponse {} +// Service provides both stable and preview calls. +service Service { +} diff --git a/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/expected.json b/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/expected.json new file mode 100644 index 000000000..bdd20773e --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/expected.json @@ -0,0 +1,5 @@ +{ + "problems": [ + "[6 0 2 0]: want [\"First handles the first call.\"], got [\"Second handles the second call.\"]" + ] +} diff --git a/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/input/temporal/api_next/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/input/temporal/api_next/fixture.proto new file mode 100644 index 000000000..f09fff262 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/input/temporal/api_next/fixture.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package fixture; + +message FirstRequest {} +message FirstResponse {} +message SecondRequest {} +message SecondResponse {} + +service Service { + // First handles the first call. + rpc First(FirstRequest) returns (FirstResponse); + // Second handles the second call. + rpc Second(SecondRequest) returns (SecondResponse); +} diff --git a/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/input/temporal/api_next/protometa/v1/draft.proto b/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/input/temporal/api_next/protometa/v1/draft.proto new file mode 100644 index 000000000..4ca06461c --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/input/temporal/api_next/protometa/v1/draft.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package temporal.api.protometa.v1; + +option go_package = "go.temporal.io/api/protometa/v1;protometa"; +option java_package = "io.temporal.api.protometa.v1"; +option java_multiple_files = true; +option java_outer_classname = "DraftProto"; +option ruby_package = "Temporalio::Api::Protometa::V1"; +option csharp_namespace = "Temporalio.Api.Protometa.V1"; + +import "google/protobuf/descriptor.proto"; + +// Tags for draft declarations. + +extend google.protobuf.FieldOptions { + string draft = 98008; +} + +extend google.protobuf.MessageOptions { + string draft_message = 98008; +} + +extend google.protobuf.EnumOptions { + string draft_enum = 98008; +} + +extend google.protobuf.EnumValueOptions { + string draft_enum_value = 98008; +} + +extend google.protobuf.OneofOptions { + string draft_oneof = 98009; +} + +extend google.protobuf.ServiceOptions { + string draft_service = 98008; +} + +extend google.protobuf.MethodOptions { + string draft_method = 98008; +} diff --git a/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/output/temporal/api/fixture.proto b/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/output/temporal/api/fixture.proto new file mode 100644 index 000000000..968e28e86 --- /dev/null +++ b/cmd/generate-stable-protos/testdata/oracle/swapped-rpc-docs/output/temporal/api/fixture.proto @@ -0,0 +1,17 @@ +// Code generated by generate-stable-protos. DO NOT EDIT. + // @generated + +syntax = "proto3"; +package fixture; + +message FirstRequest {} +message FirstResponse {} +message SecondRequest {} +message SecondResponse {} + +service Service { + // Second handles the second call. + rpc First(FirstRequest) returns (FirstResponse); + // First handles the first call. + rpc Second(SecondRequest) returns (SecondResponse); +}