fix(cmd): preserve protobuf raw descriptor blocks during template copy#3805
Open
NepetaLemon wants to merge 3 commits into
Open
fix(cmd): preserve protobuf raw descriptor blocks during template copy#3805NepetaLemon wants to merge 3 commits into
NepetaLemon wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates kratos new template-copy behavior to avoid corrupting protobuf raw descriptor payloads in newer protoc-gen-go-generated .pb.go files where descriptors are emitted as concatenated string-literal blocks.
Changes:
- Add protobuf raw-descriptor block detection and skip module-path replacements within those blocks while still replacing elsewhere.
- Refactor replacement logic into
replaceTemplateContent/applyReplacements. - Add regression tests for preserving string-literal raw descriptors and keeping legacy
[]bytebehavior unchanged.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cmd/kratos/internal/base/path.go |
Preserves matched protobuf raw descriptor string blocks during template copying while applying replacements to other content. |
cmd/kratos/internal/base/path_test.go |
Adds tests validating preservation of string-literal raw descriptors, full replacement when no raw desc exists, and legacy []byte behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description (what this PR does / why we need it):
kratos newcurrently performs repository-wide string replacement when copying a template into a new project.For
.pb.gofiles generated by newerprotoc-gen-goversions, the protobuf raw descriptor is emitted as a string literal block. Replacing the template module path inside that block can corrupt the embedded descriptor payload and cause generated projects topanic during protobuf descriptor initialization.
This change preserves protobuf raw descriptor string blocks during template copy while keeping normal module-path replacement behavior for the rest of the file.
The change is backward-compatible with legacy generated files:
[]byteraw descriptors continue to follow the existing replacement pathThis PR also adds regression tests covering:
[]bytedescriptor outputWhich issue(s) this PR fixes (resolves / be part of):
part of #
Other special notes for the reviewers:
Validated with:
go test ./internal/base ./internal/projectundercmd/kratoskratos newrun against a localftgo-layouttemplateAffected
protoc-gen-gorange verified locally:v1.36.5and earlier still emit[]byteraw descriptorsv1.36.6through at leastv1.36.11emit string-literal raw descriptors