Add Chef metadata and Berksfile support - #84
Open
abhinavgautam01 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds static (non-evaluating) Chef cookbook manifest parsing support for metadata.rb, metadata.json, and Berksfile, and extends the result model to preserve manifest-level source declarations and per-dependency source overrides without implying resolution.
Changes:
- Add a Chef parser (
internal/chef) that extracts literal identity, dependencies, and Berksfile sources while skipping dynamic Ruby expressions. - Extend the core/public result types with
SourceKind,Source, andParseResult.Sources, plus per-dependency/per-declarationSourceoverrides. - Add fixtures, unit tests, parser registration/imports, and README updates documenting the new Chef ecosystem and source model.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| testdata/chef/metadata.rb | Adds Chef metadata.rb fixture for identity + dependency constraints. |
| testdata/chef/metadata.json | Adds Chef metadata.json fixture mirroring Ruby metadata semantics. |
| testdata/chef/Berksfile | Adds Berksfile fixture covering sources, cookbook declarations, and overrides. |
| README.md | Documents Chef ecosystem support and the new Source fields/section. |
| manifests.go | Re-exports SourceKind/Source, adds ParseResult.Sources, and special-cases Chef PURLs to remain empty. |
| manifests_test.go | Adds ecosystem/fixture coverage and asserts candidate Chef PURLs remain empty; verifies metadata directive doesn’t read FS. |
| internal/core/types.go | Introduces SourceKind/Source and adds Source fields on Dependency/Declaration/Result. |
| internal/chef/chef.go | Implements static Ruby/JSON metadata parsing and Berksfile parsing without executing Ruby. |
| internal/chef/chef_test.go | Adds thorough unit tests for identity, constraints, sources, multiline, and dynamic-skip behavior. |
| imports.go | Registers the Chef parser package. |
| benchmark_test.go | Adds Chef fixtures to benchmark coverage. |
Suppressed comments (1)
manifests.go:63
ParseResultgained a new exported field (Sources). That can break downstream code using unkeyed composite literals (e.g.,manifests.ParseResult{...}) and is hard to undo. At minimum, it’s worth documenting that callers should use keyed field names when constructingParseResultvalues.
// ParseResult contains the parsed dependencies from a manifest or lockfile.
type ParseResult struct {
Ecosystem string
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Closes #71
Summary
Add static Chef cookbook parsers for:
metadata.rbmetadata.jsonBerksfileThe Ruby DSL parsers extract literal declarations without executing Ruby, loading adjacent files, expanding constants or evaluating dynamic expressions.
Implementation
Cookbook metadata
Parse cookbook identity from
metadata.rbandmetadata.json:The JSON and Ruby formats produce equivalent dependency representations.
Berksfile
Parse literal Berksfile declarations for:
A bare
metadatadirective is intentionally ignored and never reads an adjacentmetadata.rb.Source representation
Add source declaration types so the result model can preserve source configuration without claiming that dependency resolution occurred:
ParseResult.Sourcesretains manifest-level sources in declaration orderDependency.Sourceretains an explicit source overrideDeclaration.Sourceretains the same source-level informationRegistryURLChef dependency PURLs remain empty because
chefis still only a candidate Package URL type without accepted name or namespace rules.Static parsing and safety
The Ruby parser accepts:
It skips declarations containing:
A dynamic or malformed declaration does not prevent later valid declarations from being parsed.
Testing
Added fixtures and tests covering:
metadatafilesystem isolationValidation
gofmtgit diff --checkgo build ./...go vet ./...go test -count=1 ./...go test -race -count=1 ./...golangci-lint v2.13.2— 0 issues