fix: deduplicate cookbook manifest files by path - #46
Open
tas50 wants to merge 1 commit into
Open
Conversation
3 tasks
tas50
force-pushed
the
fix/dedupe-cookbook-manifest
branch
3 times, most recently
from
September 8, 2026 16:53
eaafaea to
0642bd2
Compare
AllFiles concatenated the flat all_files manifest and all nine per-segment slices on the assumption that a server populates one shape or the other. Nothing guarantees that. When both are populated every file is returned twice, and Download turns each entry into a job: two goroutines then race to os.WriteFile the same destination, and each file is fetched from the bookshelf twice. Deduplicate by path during the merge. all_files wins, and within the per-segment slices the first occurrence does. cinc-zero returns only all_files, so the integration suite cannot reach this; the new test drives the merged shape directly. Signed-off-by: Tim Smith <tim@mondoo.com>
tas50
force-pushed
the
fix/dedupe-cookbook-manifest
branch
from
September 10, 2026 16:37
0642bd2 to
8680416
Compare
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.
Cookbook.AllFiles()concatenated the flatall_filesmanifest and all nine per-segment slices, on the strength of a comment asserting that a server populates "one shape or the other". Nothing guarantees that.When both are populated, every file comes back twice — and
Downloadturns each entry into a job handed toparallelForEach:So two goroutines race to
os.WriteFilethe same destination, and each file is fetched from the bookshelf twice. Measured on a one-file cookbook listed in both shapes: 2 fetches, 2 unsynchronised writes.Fixed by deduplicating on
Pathduring the merge —all_fileswins, and within the per-segment slices the first occurrence does.Why the existing tests missed it
cinc-zero returns only
all_files, so the integration suite can't reach this shape. The new test drives the merged manifest directly.Test plan
TestAllFiles_DedupesByPath— a manifest listing two files in both shapes returns 2 refs, not 4 (failed before: returned 4)TestDownload_FetchesEachFileOnce— counts bookshelf fetches (failed before: 2, want 1)go vet ./...cleango test ./... -race -count=2— the race detector is the point herecd integration && go test ./...