fix(gomod): auto-append +incompatible for non-module-path major versions#1012
Merged
cpuguy83 merged 2 commits intoApr 23, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Dalec’s gomod replace handling by normalizing replacement targets that specify a v2+ semantic version on a module path that does not use semantic import versioning (/vN)—automatically appending +incompatible to prevent Go module resolution failures.
Changes:
- Added normalization logic for
GomodReplace.goModEditArg()to append+incompatiblefor v2+ versions when the module path has no major-version suffix. - Introduced targeted unit tests covering the new normalization behavior and key non-rewrite cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
spec.go |
Adds normalizeGomodReplaceTarget() and applies it when generating go mod edit -replace arguments. |
generator_gomod_test.go |
Adds/extends tests to validate +incompatible normalization and ensure no rewrites for /vN paths and local replacements. |
ebfc7c5 to
b839ee4
Compare
invidian
reviewed
Mar 31, 2026
a4de639 to
b839ee4
Compare
cpuguy83
approved these changes
Apr 6, 2026
Collaborator
|
@invidian LGTY? |
Automatically normalize gomod replace targets for v2+ module versions that do not use a /vN module path suffix by appending +incompatible. Adds regression coverage for incompatible-version normalization and ensures existing valid replace forms remain unchanged." Signed-off-by: Kartik Joshi <karikjoshi21@gmail.com>
4378b96 to
1cb15b2
Compare
Signed-off-by: Kartik Joshi <karikjoshi21@gmail.com>
1cb15b2 to
c719da7
Compare
invidian
approved these changes
Apr 22, 2026
Contributor
|
LGTM, thanks for adding tests. |
cpuguy83
approved these changes
Apr 23, 2026
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
Normalize gomod replacement targets that use a v2+ semver on a module path
without a
/vNsuffix by automatically appending+incompatible.This prevents builds from failing for replace targets such as:
github.com/docker/cli@v29.2.0which should be normalized to:
github.com/docker/cli@v29.2.0+incompatibleWhat changed
GomodReplace.goModEditArg()to normalize replacement targetsWhy
Go module versioning requires
/vNsuffixes for major versions 2 and above.For repositories that do not follow semantic import versioning,
+incompatibleis required. This change makes Dalec handle that case automatically instead of
requiring each spec author to know and write the normalized version manually.
Testing
go test ./... -run TestGomodReplaceGoModEditArg -vgo test --test.short ./...make verify