Skip to content

Parse external modules from Buf manifests and lockfiles - #173

Merged
andrew merged 2 commits into
git-pkgs:mainfrom
akzarma:feat/buf-external-modules
Dec 2, 2026
Merged

andrew merged 2 commits into
git-pkgs:mainfrom
akzarma:feat/buf-external-modules

Conversation

@akzarma

@akzarma akzarma commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #160. Identify and Parse now recognize buf.yaml and buf.lock and report external Buf Schema Registry modules recorded in deps.

Manifest entries retain their registry-qualified module name and optional label or commit. Lock entries retain the resolved commit and the digest when present, using the remote/owner/repository fields in v1/v1beta1 and the single name field in v2. The parser does not report local workspace paths, plugins, or policies as module dependencies. It leaves the PURL empty rather than inventing a package identity. These formats are documented in Buf’s manifest reference and its v1 and v2 lockfile references.

On unmodified main, the public-API regression tests failed at Identify for all four v1/v2 fixtures. They pass on this branch and cover unpinned dependencies, labels, registry ports, commits, digests, workspace-only and empty inputs, and malformed entries. Verified on macOS/arm64 with Go 1.27.3: go build ./..., go vet ./..., go test -race ./..., and golangci-lint run ./... (no issues). No registry or Buf CLI is needed at runtime.

AI assistance: OpenAI Codex (GPT-6.2 Astra) implemented this change, wrote and ran the tests, and drafted this description.

Extract external BSR module references from buf.yaml and resolved module pins from v1 and v2 buf.lock layouts without reporting local workspace modules as dependencies.
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ebb37731-0d83-466d-98ee-c95999de5181
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. The ref parsing handles labels and commits as well as registry ports, and the layout matches the other parsers. The output has an empty Ecosystem, rejects versionless lockfiles and sets Source on registry deps; a fixture and the shared identify test also need changes.

  1. internal/buf/buf.go:53 sets NoPURL: true on each dependency, and entryEcosystem in manifests.go blanks Ecosystem when that flag is set, so all of them come back with Ecosystem: "". A BSR module name identifies the package, and NoPURL is reserved for source-only entries such as a direct download URL. Drop NoPURL and add buf to the chef/vagrant exclusion in makePURL in manifests.go, so each entry is returned with Ecosystem: "buf" and an empty PURL. Assert Ecosystem == "buf" in buf_test.go and update the README sentence about PURLs to match.

  2. The parser returns a ParseError for a buf.lock that omits the version key, while Buf reads those files as v1beta1: defaultBufLockFileVersion = FileVersionV1Beta1 in buf_lock_file.go, passed to getFileVersionForData with fileVersionRequired false. Treat an empty version as v1beta1 when p.kind == core.Lockfile, and add a test case for it. Buf requires version in buf.yaml, so only the lockfile branch changes.

  3. internal/buf/buf.go:54 sets Source on each dependency, with Value equal to Name and Ref equal to Version. The doc comment on core.Dependency.Source reserves it for dependencies with an explicit source override, and these come from the registry already named in Name. Delete the Source line and its three assertions in buf_test.go. The README mention of Source.Value goes too.

  4. testdata/buf/v1/buf.lock uses a b4: digest prefix, where Buf writes v1 digests as shake256: (DigestTypeB4: "shake256" in digest.go). Change the fixture and the expected value in buf_test.go.

  5. Add buf.yaml and buf.lock to the per-ecosystem blocks in TestIdentifyFiles in manifests_test.go, along with the buf.work.yaml and buf.gen.yaml negatives, and remove the Identify loop at the end of TestBufEmptyAndMalformed.

Keep the ecosystem on registry module dependencies without manufacturing a PURL or source override. Use the legacy lock layout when its version is absent, and align fixtures and identification tests with Buf.
@akzarma

akzarma commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @andrew. I addressed all five points in 6b1a753. Buf dependencies now keep the ecosystem without a PURL or redundant source metadata, versionless lockfiles use v1beta1, and the v1 digest fixture and filename checks are updated. The focused regression tests and full Go race suite, build, vet, and lint passed locally. Could you take another look when you have a chance?

@andrew
andrew merged commit 73db996 into git-pkgs:main Dec 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse Buf manifests and lockfiles

2 participants