Files
coder/scripts/releaser/commit_test.go
T
Garrett Delfosse 86a050de43 fix(scripts/releaser): scope breaking-change check to commits since previous release (#29487)
The patch-release breaking-change check in `./scripts/release.sh`
queried every merged PR labeled `release/breaking` against the release
branch with no range filter, so breaking changes shipped in earlier
patches were reported again on every subsequent patch release.

Both the `!` title marker and the `release/breaking` label are now
evaluated only over `prevVersion..HEAD`, using the same PR metadata
lookup the release notes already use (`ghBuildPRMetadataMap` +
`categorizeCommit`). The now-unused `ghListPRsWithLabel` is removed and
the metadata fetch-with-fallback is extracted into `loadPRMetadata` so
both call sites share it.

The GPG signing prompt was already removed on `main` in #27422, so this
PR only covers the breaking-change check. Backporting to `release/2.34`
and `release/2.35` needs both #27422 and this PR; `release/2.36` only
needs this PR.

Supersedes #27065.

---
Generated by Coder Agents on behalf of @f0ssel.
2026-09-17 15:10:26 -04:00

71 lines
2.2 KiB
Go

package main //nolint:testpackage // Tests unexported release helpers.
import (
"testing"
)
func TestFindBreakingCommits(t *testing.T) {
t.Parallel()
// Metadata for PRs that were labeled release/breaking. #10 is
// keyed by merge-commit SHA (direct merge), #20 only by PR
// number (cherry-picked, so the SHA on the release branch
// differs from the merge commit on main). #99 is labeled but
// deliberately absent from the commit list, simulating a
// breaking PR that shipped in an earlier release on the branch.
prMeta := &prMetadataMaps{
bySHA: map[string]prMetadata{
"aaa": {Labels: []string{"release/breaking"}},
},
byNumber: map[int]prMetadata{
10: {Labels: []string{"release/breaking"}},
20: {Labels: []string{"release/breaking"}},
99: {Labels: []string{"release/breaking"}},
},
}
commits := []commitEntry{
{SHA: "aaa", FullSHA: "aaa", Title: "feat: labeled via sha (#10)", PRCount: 10},
{SHA: "bbb", FullSHA: "bbb", Title: "fix: labeled via pr number (#20)", PRCount: 20},
{SHA: "ccc", FullSHA: "ccc", Title: "feat(cli)!: bang title (#30)", PRCount: 30},
{SHA: "ddd", FullSHA: "ddd", Title: "fix: ordinary change (#40)", PRCount: 40},
{SHA: "eee", FullSHA: "eee", Title: "chore: no pr number"},
}
got := findBreakingCommits(commits, prMeta)
want := []string{"aaa", "bbb", "ccc"}
if len(got) != len(want) {
t.Fatalf("got %d breaking commits, want %d: %+v", len(got), len(want), got)
}
for i, c := range got {
if c.SHA != want[i] {
t.Fatalf("breaking[%d] = %s, want %s", i, c.SHA, want[i])
}
}
}
func TestFindBreakingCommitsWithoutMetadata(t *testing.T) {
t.Parallel()
// With no PR metadata (gh unavailable), only "!" titles are
// detected.
prMeta := &prMetadataMaps{
bySHA: map[string]prMetadata{},
byNumber: map[int]prMetadata{},
}
commits := []commitEntry{
{SHA: "aaa", FullSHA: "aaa", Title: "feat!: bang (#1)", PRCount: 1},
{SHA: "bbb", FullSHA: "bbb", Title: "feat: plain (#2)", PRCount: 2},
}
got := findBreakingCommits(commits, prMeta)
if len(got) != 1 || got[0].SHA != "aaa" {
t.Fatalf("got %+v, want only aaa", got)
}
if got := findBreakingCommits(nil, prMeta); got != nil {
t.Fatalf("got %+v for no commits, want nil", got)
}
}