Validate derived candidate tags before checks

This commit is contained in:
2026-11-01 21:13:54 +00:00
parent abbab3c8ce
commit b91a0d1914
8 changed files with 54 additions and 14 deletions

View File

@@ -18,6 +18,40 @@ import (
const releaseNote = "# Sample App v1.2.3\n\nA source release.\n\nUpgrade notes stay intact.\n"
func TestCheckRejectsInvalidDerivedTagBeforeValidation(t *testing.T) {
for _, module := range []string{"module space", "module.lock"} {
t.Run(module, func(t *testing.T) {
repo := newPublishFixture(t)
writeFile(t, repo.work, module+"/go.mod", "module example.com/nested\n\ngo 1.25.0\n")
writeFile(t, repo.work, module+"/docs/releases/v1.2.3.md", releaseNote)
gitRun(t, repo.work, "add", module)
gitRun(t, repo.work, "commit", "-m", "add module")
bin := t.TempDir()
marker := filepath.Join(t.TempDir(), "go-ran")
if err := os.WriteFile(filepath.Join(bin, "go"), []byte("#!/bin/sh\nprintf ran > \"$CANDIDATE_GO_MARKER\"\nexit 1\n"), 0o755); err != nil {
t.Fatal(err)
}
t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
t.Setenv("CANDIDATE_GO_MARKER", marker)
called := false
got, err := releasekit.Check(context.Background(), releasekit.ReleaseRequest{
RepositoryDir: repo.work, ModuleDir: module, Product: "Sample App", Version: "v1.2.3",
AdditionalChecks: func(context.Context, releasekit.Candidate) error { called = true; return nil },
Build: &releasekit.BuildSpec{MainPackage: ".", BinaryName: "fixture", Targets: []releasekit.Target{{OS: "linux", Arch: "amd64"}}},
})
if err == nil || errors.Is(err, releasekit.ErrInvalidVersion) || !strings.Contains(err.Error(), "invalid Git tag name") || got.Tag != module+"/v1.2.3" || got.ModulePath != "example.com/nested" {
t.Fatalf("candidate = %#v, error = %v", got, err)
}
if called {
t.Fatal("additional checks ran")
}
if _, err := os.Stat(marker); !os.IsNotExist(err) {
t.Fatalf("Go validation or build ran: %v", err)
}
})
}
}
func TestCandidateOperationsDiscoverGoOnlyWhenLaterWorkNeedsIt(t *testing.T) {
gitPath := mustLookPath(t, "git")
gitOnly := t.TempDir()