Skip to content

test: golden-file test for the plugin's generated code #85

Closed

Description

@erikist

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.proto without 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.
  • Generated output is unchanged by this PR.

Activity

  1. erikist commented on Oct 8, 2026

    @erikist
    ContributorAuthor

    🤖 Factory: picked up by dispatcher; working on branch factory/85-test-golden-file-test-for-the.

  2. erikist commented on Oct 8, 2026

    @erikist
    ContributorAuthor

    🤖 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions