fix(config): preserve multiple outputs from the same remote flake#2912
Open
mikeland73 wants to merge 2 commits into
Open
fix(config): preserve multiple outputs from the same remote flake#2912mikeland73 wants to merge 2 commits into
mikeland73 wants to merge 2 commits into
Conversation
Adding two outputs from the same remote flake (for example `git+http://git@host/repo.git#toolA` and `...#toolB`) dropped the first one. `Config.Packages` deduped the package list with `lo.UniqBy` keyed on `Package.Name`, keeping only the last occurrence per name. For flake references that Name is not unique per output: package strings are split on their last `@`, so a "#fragment" ends up in the version and, for URLs containing a `user@host`, the Name is truncated to the part before the `@`. Every output of such a flake therefore shares the same Name and collapsed into a single package. Key the dedup on the full reference (which includes the fragment) when the package looks like a flake installable — detected by a `://` scheme separator or a `#` output fragment — and keep deduping plain packages by name so a later `pkg@v2` still replaces an earlier `pkg@v1`. Fixes #2662 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qk7hyZKVoiy6CrUdA6XknT
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression in Config.Packages() where adding multiple outputs from the same remote flake (distinguished by #fragment) could incorrectly drop earlier entries due to name-based deduplication interacting with user@host URLs.
Changes:
- Adjust package deduplication to key flake-like references by their full reference (
VersionedName()), preserving multiple#fragmentoutputs from the same flake. - Add unit tests covering (1) preserving multiple flake outputs and (2) retaining the existing “last version wins” behavior for plain
name@versionpackages.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/devconfig/config.go | Updates deduplication logic to preserve multiple outputs from the same remote flake reference. |
| internal/devconfig/config_test.go | Adds regression and behavior-preservation tests for the updated deduplication behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback: the length check keyed off a map built from VersionedName(), which would collapse duplicates and could pass even if the dedupe logic regressed to returning duplicate packages. Assert on the returned slice length directly and require each expected package to appear exactly once. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qk7hyZKVoiy6CrUdA6XknT
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.
Summary
Fixes #2662.
Adding two outputs from the same remote flake dropped the first one:
After adding
#getcrds,kubeupdatedisappeared from the environment (only thelast-added output survived).
Root cause
Config.Packages(internal/devconfig/config.go) dedupes the package list withlo.UniqBykeyed onPackage.Name, keeping only the last occurrence per name sothat a later
pkg@v2replaces an earlierpkg@v1.For flake references that key is not unique per output. Package strings are
split on their last
@(searcher.ParseVersionedPackage), so:#fragmentthat distinguishes the outputs is parsed into the version, anduser@host(heregit@company.gitlab.com), theNameistruncated to the part before the
@—git+http://git.So both outputs parse to the same
Name(git+http://git) and collapse into asingle package, dropping the first.
Fix
Key the dedup on the full reference (which includes the
#fragment) when thepackage looks like a flake installable — detected by a
://scheme separator or a#output fragment — and keep deduping plain packages by name so the existing"last version wins" behavior for
pkg@v1/pkg@v2is unchanged.How was it tested?
go build ./...— clean.go vet ./internal/devconfig/— clean;gofmtreports no changes.internal/devconfig/config_test.go:TestPackagesPreservesMultipleFlakeOutputs— two#-fragment outputs from thesame
git+http://git@host/...flake are both retained (fails before this change,passes after).
TestPackagesDedupesByNameForPlainPackages—python@3.10+python@3.11stilldedupe to the last occurrence (
python@3.11), confirming the plain-packagebehavior is preserved.
go test ./internal/devconfig/...passes for the changed code. Two pre-existingTestFindError/*Permissionscases fail in this environment because it runs asroot (a
chmod 0o000file is still readable), independent of this change — theyfail identically on
main.cc @jDmacD (issue reporter) — thanks for the clear, step-by-step reproduction.
Community Contribution License
All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.
By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Qk7hyZKVoiy6CrUdA6XknT
Generated by Claude Code