Repository navigation
Parse external modules from Buf manifests and lockfiles - #173
Conversation
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.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
andrew
left a comment
There was a problem hiding this comment.
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.
-
internal/buf/buf.go:53setsNoPURL: trueon each dependency, andentryEcosysteminmanifests.goblanksEcosystemwhen that flag is set, so all of them come back withEcosystem: "". A BSR module name identifies the package, andNoPURLis reserved for source-only entries such as a direct download URL. DropNoPURLand addbufto the chef/vagrant exclusion inmakePURLinmanifests.go, so each entry is returned withEcosystem: "buf"and an empty PURL. AssertEcosystem == "buf"inbuf_test.goand update the README sentence about PURLs to match. -
The parser returns a
ParseErrorfor abuf.lockthat omits theversionkey, while Buf reads those files as v1beta1:defaultBufLockFileVersion = FileVersionV1Beta1inbuf_lock_file.go, passed togetFileVersionForDatawithfileVersionRequiredfalse. Treat an empty version asv1beta1whenp.kind == core.Lockfile, and add a test case for it. Buf requiresversioninbuf.yaml, so only the lockfile branch changes. -
internal/buf/buf.go:54setsSourceon each dependency, withValueequal toNameandRefequal toVersion. The doc comment oncore.Dependency.Sourcereserves it for dependencies with an explicit source override, and these come from the registry already named inName. Delete theSourceline and its three assertions inbuf_test.go. The README mention ofSource.Valuegoes too. -
testdata/buf/v1/buf.lockuses ab4:digest prefix, where Buf writes v1 digests asshake256:(DigestTypeB4: "shake256"indigest.go). Change the fixture and the expected value inbuf_test.go. -
Add
buf.yamlandbuf.lockto the per-ecosystem blocks inTestIdentifyFilesinmanifests_test.go, along with thebuf.work.yamlandbuf.gen.yamlnegatives, and remove theIdentifyloop at the end ofTestBufEmptyAndMalformed.
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.
|
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? |
Fixes #160.
IdentifyandParsenow recognizebuf.yamlandbuf.lockand report external Buf Schema Registry modules recorded indeps.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/repositoryfields in v1/v1beta1 and the singlenamefield 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
Identifyfor 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 ./..., andgolangci-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.