Skip to content

fix(gomod): auto-append +incompatible for non-module-path major versions#1012

Merged
cpuguy83 merged 2 commits into
project-dalec:mainfrom
kartikjoshi21:kartikjoshi21/gomod-incompatible-replace
Apr 23, 2026
Merged

fix(gomod): auto-append +incompatible for non-module-path major versions#1012
cpuguy83 merged 2 commits into
project-dalec:mainfrom
kartikjoshi21:kartikjoshi21/gomod-incompatible-replace

Conversation

@kartikjoshi21

Copy link
Copy Markdown
Member

Summary

Normalize gomod replacement targets that use a v2+ semver on a module path
without a /vN suffix by automatically appending +incompatible.

This prevents builds from failing for replace targets such as:

  • github.com/docker/cli@v29.2.0

which should be normalized to:

  • github.com/docker/cli@v29.2.0+incompatible

What changed

  • updated GomodReplace.goModEditArg() to normalize replacement targets

Why

Go module versioning requires /vN suffixes for major versions 2 and above.
For repositories that do not follow semantic import versioning, +incompatible
is 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 -v
  • go test --test.short ./...
  • make verify

Copilot AI review requested due to automatic review settings March 31, 2026 09:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 +incompatible for 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.

Comment thread spec.go
@kartikjoshi21 kartikjoshi21 force-pushed the kartikjoshi21/gomod-incompatible-replace branch from ebfc7c5 to b839ee4 Compare March 31, 2026 10:26
@kartikjoshi21 kartikjoshi21 requested a review from Copilot March 31, 2026 10:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread generator_gomod_test.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread spec.go
Comment thread generator_gomod_test.go
@kartikjoshi21 kartikjoshi21 force-pushed the kartikjoshi21/gomod-incompatible-replace branch 2 times, most recently from a4de639 to b839ee4 Compare April 1, 2026 11:02
@kartikjoshi21 kartikjoshi21 requested a review from invidian April 1, 2026 11:06
@cpuguy83

cpuguy83 commented Apr 7, 2026

Copy link
Copy Markdown
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>
@kartikjoshi21 kartikjoshi21 force-pushed the kartikjoshi21/gomod-incompatible-replace branch 2 times, most recently from 4378b96 to 1cb15b2 Compare April 22, 2026 05:12
Signed-off-by: Kartik Joshi <karikjoshi21@gmail.com>
@kartikjoshi21 kartikjoshi21 force-pushed the kartikjoshi21/gomod-incompatible-replace branch from 1cb15b2 to c719da7 Compare April 22, 2026 07:27
@invidian

Copy link
Copy Markdown
Contributor

LGTM, thanks for adding tests.

@cpuguy83 cpuguy83 merged commit 2e16ca8 into project-dalec:main Apr 23, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants