Files
coder/scripts/releaser/docs_test.go
T
Lisa Fiander 8d3051a928 fix(scripts/releaser): derive ESR calendar statuses from esr_versions.txt (#32905)
The release calendar in `docs/reference/releases.md` still lists 2.29 as
an Extended Support Release after the v2.40.0 release, and lists 2.40 as
plain `Mainline` instead of `Mainline (ESR)`.

`releasetui` (`scripts/releaser/docs.go`) only moves rows along the
Mainline, Stable, Security Support, and Not Supported chain. It never
reads `scripts/release_channels/esr_versions.txt`, so rows marked
`Extended Support Release` never change, and new ESRs never get the
`(ESR)` suffix. #32843 updated that file to replace 2.29 with 2.40
before #32858 regenerated the calendar, but the calendar ignored the
change.

- `updateCalendar` now loads the active ESR set from `esr_versions.txt`,
the same file the backport workflow and
`scripts/update-release-calendar.sh` use, and re-derives the ESR
statuses on every run.
- Fixes the current calendar: 2.29 becomes `Not Supported` and 2.40
becomes `Mainline (ESR)`.
- Adds a regression test that replays the v2.40.0 release against the
calendar from before #32858.

Refs #32843, #32858

<details>
<summary>Implementation notes</summary>

- On each run, `updateCalendar` removes any ESR markers to get each
row's base status, applies the normal channel transitions, and then
re-applies the markers from `esr_versions.txt`. An active ESR shows
`Extended Support Release` once it leaves the standard channels and
`<Channel> (ESR)` while it is still in one. A retired ESR goes back to
`Not Supported`.
- ESR markers are applied before `trimOldestNotSupported`, so an active
ESR such as 2.34 is never trimmed. Retired ESRs are trimmed like any
other unsupported row.
- Patch releases also re-apply the markers, so the calendar corrects
itself after any change to `esr_versions.txt`.
- The broad `strings.Contains(r.Status, "Stable")` match for the old
`Stable + ESR` format is replaced with an exact match, because ESR
suffixes are now removed before the transitions run.
- The hand-edited calendar keeps 2.29 as a `Not Supported` row so
readers can see that it reached end of life. The next minor release
trims it automatically.

</details>

---

> [!NOTE]
> Generated by Coder Agents on behalf of @Lisa-Fiander.
2026-12-02 19:23:44 +00:00

180 lines
5.0 KiB
Go

package main //nolint:testpackage // Tests unexported release helpers.
import (
"fmt"
"strings"
"testing"
)
// TestUpdateCalendarLatestReleaseVersionPrefix checks the formatting of the
// "Latest Release" cell produced by updateCalendar. version.String() already
// includes a leading "v", so the link label must not add a second one, while
// the release tag URL keeps the "v" because tags are prefixed with it.
func TestUpdateCalendarLatestReleaseVersionPrefix(t *testing.T) {
t.Parallel()
tests := []struct {
name string
newVer version
channel string
want string
}{
{
name: "patch release",
newVer: version{Major: 2, Minor: 35, Patch: 1},
channel: "mainline",
want: "[v2.35.1](https://github.com/coder/coder/releases/tag/v2.35.1)",
},
{
name: "minor release",
newVer: version{Major: 2, Minor: 35, Patch: 0},
channel: "mainline",
want: "[v2.35.0](https://github.com/coder/coder/releases/tag/v2.35.0)",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
rows := []calendarRow{{
ReleaseName: "2.35",
Major: 2,
Minor: 35,
ReleaseDate: "February 03, 2026",
Status: "Mainline",
LatestRelease: "N/A",
}}
got := updateCalendar(rows, tt.newVer, tt.channel, nil)
var cell string
for _, r := range got {
if r.Major == tt.newVer.Major && r.Minor == tt.newVer.Minor {
cell = r.LatestRelease
break
}
}
if cell != tt.want {
t.Fatalf("LatestRelease = %q, want %q", cell, tt.want)
}
})
}
}
// TestUpdateCalendarNotReleasedRowName checks that a "Not Released" row is
// promoted to "Mainline" with a major.minor "Release name" link (patch
// omitted) once its minor version is released.
func TestUpdateCalendarNotReleasedRowName(t *testing.T) {
t.Parallel()
rows := []calendarRow{{
ReleaseName: "2.36",
Major: 2,
Minor: 36,
Status: "Not Released",
LatestRelease: "N/A",
}}
got := updateCalendar(rows, version{Major: 2, Minor: 36, Patch: 0}, "mainline", nil)
if got[0].Status != "Mainline" {
t.Errorf("Status = %q, want %q", got[0].Status, "Mainline")
}
const want = "[2.36](https://coder.com/changelog/coder-2-36)"
if got[0].ReleaseName != want {
t.Fatalf("ReleaseName = %q, want %q", got[0].ReleaseName, want)
}
}
// TestRenderCalendarTableSeparatorWidth ensures every separator segment is as
// wide as its header segment, matching what markdown-table-formatter enforces
// in CI. The first column was previously rendered one dash short, which made
// `make fmt` fail on wizard-generated docs PRs.
func TestRenderCalendarTableSeparatorWidth(t *testing.T) {
t.Parallel()
rows := []calendarRow{
{
ReleaseName: "[2.39](https://coder.com/changelog/coder-2-39)",
Major: 2,
Minor: 39,
ReleaseDate: "November 03, 2026",
Status: "Mainline",
LatestRelease: "[v2.39.2](https://github.com/coder/coder/releases/tag/v2.39.2)",
},
{
ReleaseName: "2.40",
Major: 2,
Minor: 40,
Status: "Not Released",
LatestRelease: "N/A",
},
}
lines := strings.Split(strings.TrimSuffix(renderCalendarTable(rows), "\n"), "\n")
if len(lines) < 2 {
t.Fatalf("expected at least header and separator lines, got %d", len(lines))
}
header := strings.Split(lines[0], "|")
sep := strings.Split(lines[1], "|")
if len(header) != len(sep) {
t.Fatalf("header has %d columns, separator has %d", len(header), len(sep))
}
for i := range header {
if len(header[i]) != len(sep[i]) {
t.Errorf("column %d: header width %d, separator width %d", i, len(header[i]), len(sep[i]))
}
}
}
// TestUpdateCalendarESRStatuses checks that ESR statuses follow the active
// ESR set: a retired ESR loses its ESR status and is trimmed like other
// unsupported rows, an active ESR outside the standard channels is kept, and
// a newly designated ESR in a channel gets the "(ESR)" suffix.
func TestUpdateCalendarESRStatuses(t *testing.T) {
t.Parallel()
row := func(minor int, status string) calendarRow {
return calendarRow{
ReleaseName: fmt.Sprintf("2.%d", minor),
Major: 2,
Minor: minor,
Status: status,
}
}
rows := []calendarRow{
row(29, "Extended Support Release"),
row(34, "Extended Support Release"),
row(35, "Not Supported"),
row(36, "Not Supported"),
row(37, "Security Support"),
row(38, "Stable"),
row(39, "Mainline"),
row(40, "Not Released"),
}
esr := map[string]bool{"2.34": true, "2.40": true}
got := updateCalendar(rows, version{Major: 2, Minor: 40, Patch: 0}, "mainline", esr)
want := map[int]string{
34: "Extended Support Release",
35: "Not Supported",
36: "Not Supported",
37: "Not Supported",
38: "Security Support",
39: "Stable",
40: "Mainline (ESR)",
41: "Not Released",
}
if len(got) != len(want) {
t.Fatalf("got %d rows, want %d: %+v", len(got), len(want), got)
}
for _, r := range got {
if r.Status != want[r.Minor] {
t.Errorf("2.%d Status = %q, want %q", r.Minor, r.Status, want[r.Minor])
}
}
}