Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e89b89d
gitattributes: mark temporal/api as generated
stephanos Nov 21, 2026
ed9a2a9
Makefile: run stable-tree readers after stable-api
stephanos Nov 20, 2026
2f34711
api_next: renumber the demo user draft fields
stephanos Nov 20, 2026
33f185a
README: describe the api_next workflow and draft annotations
stephanos Nov 20, 2026
f93b950
generate-stable-protos: pass context into stableProtosGenerator
stephanos Nov 20, 2026
7bc8f17
generate-stable-protos: list one draft extendee per line
stephanos Nov 20, 2026
1d19a9e
generate-stable-protos: extract loadAPINext from stripDrafts
stephanos Nov 21, 2026
dd7bd5c
generate-stable-protos: normalize comment style
stephanos Nov 21, 2026
5d0850d
generate-stable-protos: clarify generator comment details
stephanos Nov 21, 2026
75d047f
generate-stable-protos: return sorted paths from draft stripping
stephanos Nov 21, 2026
088ad8b
generate-stable-protos: rename jErr to errs
stephanos Nov 21, 2026
06e1907
generate-stable-protos: run tests in parallel
stephanos Nov 21, 2026
1b691f3
generate-stable-protos: assert classified draft annotations
stephanos Nov 21, 2026
ee22728
generate-stable-protos: run every fixture through one runner
stephanos Nov 21, 2026
5af8d3e
ci: install protoc for the generate-stable-protos tests
stephanos Nov 20, 2026
90633b1
generate-stable-protos: extract commentTokenWords from commentWords
stephanos Nov 21, 2026
19e603f
generate-stable-protos: keep the quote style of rewritten import paths
stephanos Nov 20, 2026
5504bbc
README: compile temporal/api or temporal/api_next, never both
stephanos Nov 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# temporal/api is generated from temporal/api_next by make stable-api.
temporal/api/** linguist-generated=true
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- uses: actions/setup-go@7b8cf10d4e4a01d4992d18a89f4d7dc5a3e6d6f4 # v4.3.0
with:
go-version: '^1.25'
- uses: arduino/setup-protoc@a8b67ba40b37d35169e222f3bb352603327985b6 # v2.1.0
- name: Install buf
run: make buf-install
- name: Test generate-stable
Expand Down
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ stable-api:
stable-api-test:
printf $(COLOR) "Run generate-stable tests..."
@cd cmd/generate-stable-protos/ && go test ./...
printf $(COLOR) "Check that both Buf modules exclude fixture protos..."
files=$$(buf ls-files && buf ls-files --config buf.next.yaml) && ! grep '^cmd/' <<<"$$files"
printf $(COLOR) "Check that each Buf module excludes fixture protos and the other API tree..."
buf ls-files | awk '/^(cmd|temporal\/api_next)\// { print; forbidden = 1 } END { if (forbidden) exit 1 }'
buf ls-files --config buf.next.yaml | awk '/^(cmd|temporal\/api)\// { print; forbidden = 1 } END { if (forbidden) exit 1 }'

##### Compile proto files for go #####
grpc: stable-api buf-lint api-linter resource-id-lint buf-breaking clean go-grpc fix-path

go-grpc: clean $(PROTO_OUT)
go-grpc: clean $(PROTO_OUT) | stable-api
printf $(COLOR) "Compile for go-gRPC..."
protogen \
--root=$(PROTO_ROOT) \
Expand All @@ -79,7 +80,7 @@ fix-path:
# We need to rewrite bits of this to support our shorthand payload format
# We use both yq and jq here as they preserve comments and the ordering of the original
# document
http-api-docs:
http-api-docs: | stable-api
protoc -I $(PROTO_ROOT) \
--openapi_out=$(OAPI_OUT) \
--openapi_opt=enum_type=string \
Expand Down Expand Up @@ -125,15 +126,15 @@ sync-nexus-annotations:
##### Linters #####
API_LINTER_FMT = 'map(select(.problems != []) | . as $$file | .problems[] | {rule: .rule_doc_uri, location: "\($$file.file_path):\(.location.start_position.line_number)"}) | group_by(.rule) | .[] | .[0].rule + ":\n" + (map("\t" + .location) | join("\n"))'

api-linter:
api-linter: | stable-api
printf $(COLOR) "Run api-linter on temporal/api_next..."
@api-linter --set-exit-status $(PROTO_IMPORTS) --config $(PROTO_ROOT)/api-linter.yaml --output-format json $(PROTO_FILES_NEXT) | gojq -r $(API_LINTER_FMT)
printf $(COLOR) "Run api-linter on temporal/api..."
@api-linter --set-exit-status $(PROTO_IMPORTS) --config $(PROTO_ROOT)/api-linter.yaml --output-format json $(PROTO_FILES) | gojq -r $(API_LINTER_FMT)

# Every RPC needs a temporal-resource-id request_header annotation for routing, or an entry in
# cmd/protoc-gen-resource-id-lint/exemptions.go.
resource-id-lint: resource-id-lint-install
resource-id-lint: resource-id-lint-install | stable-api
printf $(COLOR) "Check temporal-resource-id annotations..."
protoc $(PROTO_IMPORTS) \
--resource-id-lint_out=. \
Expand All @@ -146,24 +147,24 @@ resource-id-lint-install:
$(STAMPDIR):
mkdir $@

$(STAMPDIR)/buf-dep-prune: $(STAMPDIR) buf.yaml
$(STAMPDIR)/buf-dep-prune: $(STAMPDIR) buf.yaml | stable-api
printf $(COLOR) "Pruning buf module"
buf dep prune
touch $@

buf-lint: $(STAMPDIR)/buf-dep-prune
buf-lint: $(STAMPDIR)/buf-dep-prune | stable-api
printf $(COLOR) "Run buf linter..."
(cd $(PROTO_ROOT) && buf lint)

buf-breaking:
buf-breaking: | stable-api
@printf $(COLOR) "Run buf breaking changes check for stable API against main branch..."
@(cd $(PROTO_ROOT) && buf breaking --against '$(BUF_BREAKING_AGAINST)')
@printf $(COLOR) "Run buf breaking changes check for api_next against main branch..."
@(cd $(PROTO_ROOT) && buf breaking --config buf.next.yaml --against '$(BUF_BREAKING_AGAINST)' --against-config buf.yaml)
@printf $(COLOR) "Run buf breaking changes check for api_next against previous api_next..."
@(cd $(PROTO_ROOT) && bash scripts/check-api-next-breaking.sh '$(BUF_BREAKING_AGAINST)')

nexus-rpc-yaml: nexus-rpc-yaml-install
nexus-rpc-yaml: nexus-rpc-yaml-install | stable-api
printf $(COLOR) "Generate nexus/temporal-proto-models-nexusrpc.yaml..."
mkdir -p nexus
protoc -I $(PROTO_ROOT) \
Expand All @@ -180,7 +181,7 @@ nexus-rpc-yaml-install:
@cd cmd/protoc-gen-nexus-rpc-yaml && go install .

##### Compile system Nexus WIT files #####
system-nexus-wit: system-nexus-wit-install nex-gen-install
system-nexus-wit: system-nexus-wit-install nex-gen-install | stable-api
printf $(COLOR) "Generate system Nexus WIT..."
tmp=$$(mktemp -d); trap 'rm -rf "$$tmp"' EXIT; \
protoc -I $(PROTO_ROOT) --include_imports \
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@ This repository contains both the protobuf descriptors and OpenAPI documentation

Install as git submodule to the project.

## Consumers

Compile either `temporal/api` (stable) or `temporal/api_next` (preview). Never compile both together.
The trees declare the same proto packages, so compiling both causes duplicate symbols.
The default Buf module in `buf.yaml` excludes `temporal/api_next`.
Use `buf.next.yaml` to compile the preview tree.

## Contribution

Make your change to the temporal/api_next/proto files, and run `make` to update the openapi definitions.
Edit proto files under `temporal/api_next/`. Run `make stable-api` to regenerate `temporal/api/`, or run
`make` to also update the OpenAPI definitions. Do not edit `temporal/api/` by hand. Commit the regenerated
tree with your changes because CI fails if it is stale.

Use the `draft` field option or the `draft_message` message option from
[`temporal/api_next/protometa/v1/draft.proto`](temporal/api_next/protometa/v1/draft.proto) to mark draft
declarations. For example, `string user = 7 [(temporal.api.protometa.v1.draft) = "update-user-tagging"];`
is a draft field. The generator removes annotated declarations from the stable tree.

Rust is also required because `make` installs and runs `nex-gen` when regenerating system Nexus WIT files.

## Breaking changes
Expand Down
4 changes: 4 additions & 0 deletions cmd/generate-stable-protos/breaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestDraftBreakingReservations(t *testing.T) {
t.Parallel()
config, err := filepath.Abs("../../buf.next.yaml")
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -47,6 +48,7 @@ message Example { %s }
{"promoted", "string value = 1;", nil},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
after := image(t, tc.field)
out, err := exec.Command("buf", "breaking", after, "--against", before, "--config", config).CombinedOutput()
if len(tc.want) == 0 {
Expand All @@ -68,6 +70,7 @@ message Example { %s }
}

func TestDraftBreakingBootstrap(t *testing.T) {
t.Parallel()
root, err := filepath.Abs("../..")
if err != nil {
t.Fatal(err)
Expand All @@ -82,6 +85,7 @@ func TestDraftBreakingBootstrap(t *testing.T) {
{"invalid draft history naming the bootstrap phrase", "temporal/api_next/no .proto files/example.proto", "invalid proto", false},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
baseline := t.TempDir()
path := filepath.Join(baseline, tc.path)
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
Expand Down
44 changes: 24 additions & 20 deletions cmd/generate-stable-protos/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ func findDraftComments(f *ir.File, dels []ast.DeclAny) (draftComments, error) {
}

// checkCommentsAfter rejects comments between a removed declaration and the next code.
// protoc attaches such comments to the removed declaration or to nothing, and the printer
// then keeps them. Only a comment on the declaration's own last line, or the doc block
// directly above the next surviving declaration, may sit there.
// The protoc compiler attaches such comments to the removed declaration or to nothing,
// and the printer then keeps them. Only a comment on the declaration's own last line,
// or the doc block directly above the next surviving declaration, may sit there.
func checkCommentsAfter(f *ir.File, dels []ast.DeclAny) error {
removed := func(offset int) bool {
return slices.ContainsFunc(dels, func(d ast.DeclAny) bool { return d.Span().Start <= offset && offset < d.Span().End })
}
// LeafSpan, because the Span of a brace pair covers its whole body.
// Use LeafSpan because the Span of a brace pair covers its whole body.
line := func(tok token.Token) int { return tok.LeafSpan().StartLoc().Line }
lastLine := func(c token.Token) int {
return line(c) + strings.Count(strings.TrimRight(c.Text(), "\n"), "\n")
Expand All @@ -81,7 +81,7 @@ func checkCommentsAfter(f *ir.File, dels []ast.DeclAny) error {
}
}
if found && removed(next.LeafSpan().Start) {
continue // these belong to the next removed declaration and are checked through it
continue // These comments are checked with the next removed declaration, to which they belong.
}
doc := len(gap)
if found && !closesScope(next) {
Expand All @@ -98,8 +98,8 @@ func checkCommentsAfter(f *ir.File, dels []ast.DeclAny) error {
return nil
}

// closesScope reports whether tok is the closing token of a pair such as "}"; Text
// returns the open token's text for both ends.
// closesScope reports whether tok is the closing token of a pair such as "}".
// Text returns the open token's text for both ends.
func closesScope(tok token.Token) bool {
if tok.IsLeaf() {
return false
Expand Down Expand Up @@ -134,20 +134,24 @@ func commentWords(stream *token.Stream) map[string]int {
if tok.Kind() != token.Comment {
continue
}
text, block := strings.CutPrefix(tok.Text(), "/*")
if block {
text = strings.TrimSuffix(text, "*/")
} else {
text = strings.TrimPrefix(text, "//")
}
for i, line := range strings.Split(text, "\n") {
if block && i > 0 {
line = strings.TrimPrefix(strings.TrimSpace(line), "*")
}
for _, w := range strings.Fields(line) {
counts[w]++
}
for _, w := range commentTokenWords(tok.Text()) {
counts[w]++
}
}
return counts
}

func commentTokenWords(text string) []string {
text, block := strings.CutPrefix(text, "/*")
if !block {
return strings.Fields(strings.TrimPrefix(text, "//"))
}
var words []string
for i, line := range strings.Split(strings.TrimSuffix(text, "*/"), "\n") {
if i > 0 {
line = strings.TrimPrefix(strings.TrimSpace(line), "*")
}
words = append(words, strings.Fields(line)...)
}
return words
}
4 changes: 3 additions & 1 deletion cmd/generate-stable-protos/comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
// after it that protoc attaches to nothing. The passing case also pins the raw printer
// output, which TestStableProjection cannot see because it runs buf format first.
func TestDraftCommentOwnership(t *testing.T) {
t.Parallel()
const fixture = "temporal/api_next/fixture.proto"
const after = `after a removed draft declaration would survive in the stable output; move it directly above a declaration, or delete it`
input, err := os.ReadFile(filepath.Join("testdata/comments/input", fixture))
Expand Down Expand Up @@ -58,6 +59,7 @@ func TestDraftCommentOwnership(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
root, out := t.TempDir(), t.TempDir()
if err := os.CopyFS(root, os.DirFS("testdata/comments/input")); err != nil {
t.Fatal(err)
Expand All @@ -68,7 +70,7 @@ func TestDraftCommentOwnership(t *testing.T) {
if err := os.WriteFile(filepath.Join(root, fixture), []byte(strings.Replace(string(input), tc.old, tc.new, 1)), 0600); err != nil {
t.Fatal(err)
}
err := stableProtosGenerator(root, out)
err := stableProtosGenerator(t.Context(), root, out)
if tc.want != "" {
if err == nil || !strings.Contains(err.Error(), tc.want) {
t.Fatalf("want %q, got %v", tc.want, err)
Expand Down
136 changes: 136 additions & 0 deletions cmd/generate-stable-protos/fixtures_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package main

import (
"encoding/json"
"errors"
"io/fs"
"maps"
"os"
"path/filepath"
"reflect"
"slices"
"strings"
"testing"
)

// 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.
func TestFixtures(t *testing.T) {
t.Parallel()
for _, fixture := range findFixtures(t) {
t.Run(fixture, func(t *testing.T) {
t.Parallel()
runFixture(t, filepath.Join("testdata", fixture))
})
}
}

// fixtureExpectation is a fixture's expected.json.
type fixtureExpectation struct {
// Error is a substring of the expected generator error; empty means success.
Error string `json:"error"`
// Annotations are the draft annotations the generator must accept.
Annotations draftAnnotations `json:"annotations"`
}

// findFixtures returns the fixture directories under testdata, relative to it.
func findFixtures(t *testing.T) []string {
t.Helper()
var fixtures []string
if err := filepath.WalkDir("testdata", func(path string, entry fs.DirEntry, err error) error {
if err != nil || !entry.IsDir() {
return err
}
for _, marker := range []string{"input", "expected.json"} {
if _, err := os.Stat(filepath.Join(path, marker)); err == nil {
relative, err := filepath.Rel("testdata", path)
if err != nil {
return err
}
fixtures = append(fixtures, filepath.ToSlash(relative))
return filepath.SkipDir
}
}
return nil
}); err != nil {
t.Fatal(err)
}
return fixtures
}

func runFixture(t *testing.T, dir string) {
t.Helper()
var expected fixtureExpectation
if data, err := os.ReadFile(filepath.Join(dir, "expected.json")); err == nil {
if err := json.Unmarshal(data, &expected); err != nil {
t.Fatal(err)
}
} else if !errors.Is(err, fs.ErrNotExist) {
t.Fatal(err)
}
root := filepath.Join(dir, "input")
out := t.TempDir()

if expected.Error != "" {
sentinel := map[string]string{"retained": "old"}
if err := os.WriteFile(filepath.Join(out, "retained"), []byte("old"), 0o600); err != nil {
t.Fatal(err)
}
err := stableProtosGenerator(t.Context(), root, out)
if err == nil || !strings.Contains(err.Error(), expected.Error) {
t.Fatalf("want error %q, got %v", expected.Error, err)
}
if !reflect.DeepEqual(sentinel, readTree(t, out)) {
t.Fatal("generation failure modified output")
}
return
}

if err := stableProtosGenerator(t.Context(), root, out); err != nil {
t.Fatal(err)
}
actual := readTree(t, out)
again := t.TempDir()
if err := stableProtosGenerator(t.Context(), root, again); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(actual, readTree(t, again)) {
t.Fatal("generator output is not deterministic")
}

paths, err := getAPINextPaths(root)
if err != nil {
t.Fatal(err)
}
_, _, annotations, err := loadAPINext(t.Context(), root, paths)
if err != nil {
t.Fatal(err)
}
if !maps.Equal(expected.Annotations, annotations) {
t.Errorf("draft annotations differ\nexpected: %v\nactual: %v", expected.Annotations, annotations)
}

if _, err := os.Stat(filepath.Join(dir, "expected")); err == nil {
bodies := map[string]string{}
for path, text := range actual {
body, ok := strings.CutPrefix(text, generatedHeader)
if !ok {
t.Fatalf("%s: missing generated header", path)
}
bodies[path] = body
}
golden := readTree(t, filepath.Join(dir, "expected"))
for _, path := range sortedKeys(golden, bodies) {
if golden[path] != bodies[path] {
t.Errorf("%s differs from the golden\nexpected:\n%s\nactual:\n%s", path, golden[path], bodies[path])
}
}
}
}

func sortedKeys(a, b map[string]string) []string {
keys := maps.Clone(a)
maps.Copy(keys, b)
return slices.Sorted(maps.Keys(keys))
}
Loading