You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test: golden-file test for the plugin's generated code #85
Part of #44 (migration to the official Go MCP SDK). This is a safety net that has to exist before the migration, so every generator change shows up as a reviewable diff.
Problem
cmd/protoc-gen-go-mcp/mcp_test.go tests only kindToCastType and unexport. Nothing checks what the plugin actually generates.
Do
Factor the plugin's generation out of main into a function a test can call (e.g. generate(*protogen.Plugin) error). Keep main's behaviour identical.
Add a test that builds a pluginpb.CodeGeneratorRequest for examples/protos/example.protowithout protoc, using protodesc.ToFileDescriptorProto(examplev1.File_example_proto) plus its dependencies. The test runs the generator on it and compares the emitted example_mcp.pb.go byte for byte with the committed examples/gen/example/v1/example_mcp.pb.go.
Add an -update flag (go test ./cmd/protoc-gen-go-mcp -run Golden -update) that rewrites the golden file. Document it in a comment at the top of the test.
Acceptance criteria
go test ./... passes, with the golden test comparing against the committed file.
Changing one emitted line in mcp.go makes the test fail with a readable diff.
No protoc or protoc plugins needed to run the tests.
🤖 Factory: opened PR #96 with the golden-file test.
Note on approach: I deviated from the issue's suggested protodesc.ToFileDescriptorProto(examplev1.File_example_proto) because protoc-gen-go strips SourceCodeInfo (and thus all comments) from the descriptor it embeds in the compiled example package, so that approach can't reproduce the comment-derived strings in the generated output. Instead the test parses example.proto directly with github.com/bufbuild/protocompile (pure Go, no protoc binary/plugin involved), which retains comments. Details and test evidence are in the PR.
Activity
erikist commentedon Oct 8, 2026
🤖 Factory: picked up by dispatcher; working on branch factory/85-test-golden-file-test-for-the.
erikist commentedon Oct 8, 2026
🤖 Factory: opened PR #96 with the golden-file test.
Note on approach: I deviated from the issue's suggested
protodesc.ToFileDescriptorProto(examplev1.File_example_proto)becauseprotoc-gen-gostripsSourceCodeInfo(and thus all comments) from the descriptor it embeds in the compiled example package, so that approach can't reproduce the comment-derived strings in the generated output. Instead the test parsesexample.protodirectly withgithub.com/bufbuild/protocompile(pure Go, no protoc binary/plugin involved), which retains comments. Details and test evidence are in the PR.test: golden-file test for the plugin's generated code (#85) (#96)