Validate module readiness without a synthetic version

This commit is contained in:
2026-12-06 02:51:56 +00:00
parent 4088923a45
commit 0906cf7094
4 changed files with 89 additions and 38 deletions

View File

@@ -157,6 +157,12 @@ the unintended committed-file requirement.
## 3. Readiness rejects a module major supported by production identity
**Completed:** Resolved source policy is validated directly, without inventing
a release version or rereading the declaration. Shared module tag-prefix logic
preserves ordinary, `/vN`, and `gopkg.in` majors, including `-unstable`.
Working/committed regression cases and identity, readiness, rehearsal, and CLI
readiness suites pass.
**Priority:** P2. **Stages:** 2, 7, 12.
**Relevant code:** `inspectSourceConfiguration` in

View File

@@ -86,3 +86,42 @@ func TestCommittedReadinessUsesCapturedModuleAndMainPackage(t *testing.T) {
t.Fatal("working readiness unexpectedly accepted missing and invalid inputs")
}
}
func TestReadinessSupportsProductionModuleMajors(t *testing.T) {
for _, modulePath := range []string{"example.com/fixture", "example.com/fixture/v2", "gopkg.in/fixture.v2", "gopkg.in/fixture.v2-unstable"} {
t.Run(modulePath, func(t *testing.T) {
repo := t.TempDir()
for _, args := range [][]string{{"init", "--initial-branch=main"}, {"config", "user.name", "ReleaseKit Test"}, {"config", "user.email", "releasekit@example.test"}} {
command := exec.Command("git", args...)
command.Dir = repo
if out, err := command.CombinedOutput(); err != nil {
t.Fatalf("git: %v: %s", err, out)
}
}
if err := os.WriteFile(filepath.Join(repo, "go.mod"), []byte("module "+modulePath+"\n\ngo 1.25.0\n"), 0600); err != nil {
t.Fatal(err)
}
for _, args := range [][]string{{"add", "go.mod"}, {"commit", "-m", "capture module"}} {
command := exec.Command("git", args...)
command.Dir = repo
if out, err := command.CombinedOutput(); err != nil {
t.Fatalf("git: %v: %s", err, out)
}
}
command := exec.Command("git", "rev-parse", "HEAD")
command.Dir = repo
out, err := command.Output()
if err != nil {
t.Fatal(err)
}
for _, commit := range []string{"", strings.TrimSpace(string(out))} {
report := Run(t.Context(), Request{RepositoryDir: repo, Commit: commit, Product: "Example", Context: "local", Offline: true, Operations: []string{"go"}})
for _, check := range report.Checks {
if check.Status == "failed" {
t.Fatalf("commit=%q check=%+v", commit, check)
}
}
}
})
}
}

View File

@@ -16,7 +16,6 @@ import (
"go.maximumdirect.net/releasekit/internal/releaseidentity"
"go.maximumdirect.net/releasekit/internal/validation"
"golang.org/x/mod/modfile"
"golang.org/x/mod/module"
)
type Request struct {
@@ -100,7 +99,7 @@ func Run(ctx context.Context, request Request) Report {
source, sourceErr = releaseidentity.LoadCommittedSource(ctx, repository, request.ModuleDir, request.Commit, request.Source)
}
if sourceErr == nil {
sourceErr = inspectSourceConfiguration(ctx, request, source)
sourceErr = releaseidentity.ValidateSourceConfiguration(ctx, source)
}
report.record("source", "configuration", "configuration", sourceErr)
} else {
@@ -285,38 +284,6 @@ func Run(ctx context.Context, request Request) Report {
return report
}
// inspectSourceConfiguration exercises the selected tag rules with a valid
// representative identifier. It neither selects nor requires a release version.
func inspectSourceConfiguration(ctx context.Context, request Request, source releaseidentity.ResolvedSource) error {
version := source.VersionPrefix + "1.0.0"
if source.Publication == "go-module" {
if source.VersionFormat != "semver" || source.VersionPrefix != "v" {
return errors.New("Go module publication requires prefixed semantic versions")
}
_, major, ok := module.SplitPathVersion(source.ModulePath)
if !ok {
return errors.New("invalid Go module path major")
}
if major != "" {
version = strings.TrimLeft(major, "/.") + ".0.0"
}
} else {
switch source.VersionFormat {
case "date":
version = source.VersionPrefix + "2000-01-01"
case "year-month":
version = source.VersionPrefix + "2000.01.0"
}
}
var err error
if request.Commit == "" {
_, err = releaseidentity.FromWorkingSource(ctx, source.RepositoryDir, request.ModuleDir, version, request.Source)
} else {
_, err = releaseidentity.FromCommittedSource(ctx, source.RepositoryDir, request.ModuleDir, version, request.Commit, request.Source)
}
return err
}
func inspectGo(ctx context.Context, dir string) error {
data, err := os.ReadFile(filepath.Join(dir, "go.mod"))
if err != nil {

View File

@@ -250,10 +250,7 @@ func deriveModule(selection Selection, modulePath, version string) (Identity, er
return identity, fmt.Errorf("version %q is incompatible with module path %q: %w", version, modulePath, err)
}
tagPrefix := selection.ModuleSubdir
if strings.HasPrefix(pathMajor, "/") && tagPrefix != "." && path.Base(tagPrefix) == strings.TrimPrefix(pathMajor, "/") {
tagPrefix = path.Dir(tagPrefix)
}
tagPrefix := moduleTagPrefix(selection, pathMajor)
tag := version
if tagPrefix != "." {
tag = path.Join(tagPrefix, version)
@@ -263,6 +260,14 @@ func deriveModule(selection Selection, modulePath, version string) (Identity, er
return identity, nil
}
func moduleTagPrefix(selection Selection, pathMajor string) string {
tagPrefix := selection.ModuleSubdir
if strings.HasPrefix(pathMajor, "/") && tagPrefix != "." && path.Base(tagPrefix) == strings.TrimPrefix(pathMajor, "/") {
tagPrefix = path.Dir(tagPrefix)
}
return tagPrefix
}
func modulePathFromDeclaration(declaration []byte) (string, error) {
modulePath := modfile.ModulePath(declaration)
if modulePath == "" {
@@ -283,3 +288,37 @@ func moduleFilePath(moduleSubdir string) string {
}
return path.Join(moduleSubdir, "go.mod")
}
// ValidateSourceConfiguration checks publication policy and tag prefixes without
// selecting a release identifier or rereading the resolved declaration.
func ValidateSourceConfiguration(ctx context.Context, source ResolvedSource) error {
prefix := source.ModuleSubdir
if source.Publication == "go-module" {
if source.VersionFormat != "semver" || source.VersionPrefix != "v" {
return fmt.Errorf("Go module publication requires prefixed semantic versions")
}
_, major, ok := module.SplitPathVersion(source.ModulePath)
if !ok {
return fmt.Errorf("invalid Go module path major")
}
prefix = moduleTagPrefix(source.Selection, major)
if prefix == "." {
prefix = ""
}
if source.TagPrefix != nil && *source.TagPrefix != prefix {
return fmt.Errorf("source tag prefix %q conflicts with Go module tag prefix %q", *source.TagPrefix, prefix)
}
} else {
if prefix == "." {
prefix = ""
}
if source.TagPrefix != nil {
prefix = *source.TagPrefix
}
}
tag := "releasekit-validation"
if prefix != "" {
tag = prefix + "/" + tag
}
return git.CheckTagRef(ctx, source.RepositoryDir, tag)
}