CHANGELOG.archied.md and CHANGELOG.archie.md were two version streams that drifted: a release that moved both components had two numbers, two pages and two tags, and a reader had to visit two files to learn what shipped. The merged history holds 65 versions from 64 archied and 34 archie sections -- 33 that both components released, 31 only archied, one only archie -- so 98 published pages become 65. A version's date is the newest of its sections' dates, and a component whose own date differs carries it on its label, because the history has two dates and the merge must not invent one. `## [Unreleased]` is not a release: it gets no page, and it stays at the top of the file. A level-two heading is where the merge could silently drop a section, so the merge is verified by content rather than by the generator: section counts per source, the merged version set against the exact union, and every source `###` title present both as a substring and, after stripping the component prefix, as an identical heading. Counting `##` headings rather than releases overcounts by one here, which is how the empty `[Unreleased]` block was caught. - newsgen reads one file and writes `docs/news/<version>.md`, the index, the canonical `releases.json`, and `docs/news/redirects.json`. The redirect table is what keeps the retired `/news/<component>/<version>/` URLs alive; it is generated beside the pages so it cannot drift from them. - release.sh takes one `--version`, keeps commit and tag (the Woodpecker pipeline that will own them does not exist yet), and exits 3 when the commit set justifies no release, so a pipeline can finish green without tagging. - The consumers of the two files follow: the deploy workflow's tag gate and release-notes extraction, the zip contents, the update check's changelog links, the packaged-path note, the docs skill, and newsgen's tests. The per-component detail survives as labelled sections inside each release, so a reader still learns whether archied or the agent changed; what goes away is the separate numbers and the separate pages.
169 lines
4.5 KiB
Go
169 lines
4.5 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const changelogFixture = `# Changelog
|
|
|
|
## [1.31.0] - 2026-09-22
|
|
|
|
### archied — Gateway
|
|
|
|
- gateway bullet
|
|
`
|
|
|
|
func writeChangelog(t *testing.T, root, body string) {
|
|
t.Helper()
|
|
if err := os.WriteFile(filepath.Join(root, changelogPath), []byte(body), 0o644); err != nil {
|
|
t.Fatalf("write %s: %v", changelogPath, err)
|
|
}
|
|
}
|
|
|
|
func readFile(t *testing.T, root, name string) []byte {
|
|
t.Helper()
|
|
body, err := os.ReadFile(filepath.Join(root, name))
|
|
if err != nil {
|
|
t.Fatalf("read %s: %v", name, err)
|
|
}
|
|
return body
|
|
}
|
|
|
|
func TestWriteThenCheckIsClean(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeChangelog(t, root, changelogFixture)
|
|
|
|
if err := write(root); err != nil {
|
|
t.Fatalf("write error = %v", err)
|
|
}
|
|
if err := check(root); err != nil {
|
|
t.Fatalf("check after write error = %v", err)
|
|
}
|
|
}
|
|
|
|
func TestWriteIsIdempotent(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeChangelog(t, root, changelogFixture)
|
|
|
|
if err := write(root); err != nil {
|
|
t.Fatalf("first write error = %v", err)
|
|
}
|
|
first := readFile(t, root, releasesJSONPath)
|
|
if err := write(root); err != nil {
|
|
t.Fatalf("second write error = %v", err)
|
|
}
|
|
if second := readFile(t, root, releasesJSONPath); string(second) != string(first) {
|
|
t.Fatalf("second write changed %s", releasesJSONPath)
|
|
}
|
|
}
|
|
|
|
func TestCheckReportsAStaleChangelog(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeChangelog(t, root, changelogFixture)
|
|
if err := write(root); err != nil {
|
|
t.Fatalf("write error = %v", err)
|
|
}
|
|
|
|
writeChangelog(t, root, changelogFixture+"\n## [1.32.0] - 2026-09-23\n\n- newer bullet\n")
|
|
|
|
err := check(root)
|
|
if err == nil {
|
|
t.Fatal("check accepted a committed tree that lags the changelog")
|
|
}
|
|
for _, want := range []string{"task news", "docs/news/1.32.0.md"} {
|
|
if !strings.Contains(err.Error(), want) {
|
|
t.Fatalf("error = %q, want it to mention %q", err, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCheckReportsAStaleVersionPage(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeChangelog(t, root, changelogFixture)
|
|
if err := write(root); err != nil {
|
|
t.Fatalf("write error = %v", err)
|
|
}
|
|
|
|
stale := filepath.Join(root, "docs", "news", "9.9.9.md")
|
|
if err := os.WriteFile(stale, []byte("gone from the changelog\n"), 0o644); err != nil {
|
|
t.Fatalf("write stale page: %v", err)
|
|
}
|
|
|
|
err := check(root)
|
|
if err == nil {
|
|
t.Fatal("check ignored a page for a version the changelog does not carry")
|
|
}
|
|
if !strings.Contains(err.Error(), "9.9.9.md") || !strings.Contains(err.Error(), "not generated") {
|
|
t.Fatalf("error = %q, want it to name the stale page", err)
|
|
}
|
|
}
|
|
|
|
func TestCheckReportsTheRetiredComponentLayout(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeChangelog(t, root, changelogFixture)
|
|
if err := write(root); err != nil {
|
|
t.Fatalf("write error = %v", err)
|
|
}
|
|
|
|
retired := filepath.Join(root, "docs", "news", "archied", "1.31.0.md")
|
|
if err := os.MkdirAll(filepath.Dir(retired), 0o755); err != nil {
|
|
t.Fatalf("create retired directory: %v", err)
|
|
}
|
|
if err := os.WriteFile(retired, []byte("old layout\n"), 0o644); err != nil {
|
|
t.Fatalf("write retired page: %v", err)
|
|
}
|
|
|
|
err := check(root)
|
|
if err == nil {
|
|
t.Fatal("check ignored a page left in the retired per-component layout")
|
|
}
|
|
if !strings.Contains(err.Error(), "archied/1.31.0.md") {
|
|
t.Fatalf("error = %q, want it to name the retired page", err)
|
|
}
|
|
}
|
|
|
|
func TestWriteLeavesOtherNewsFilesAlone(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeChangelog(t, root, changelogFixture)
|
|
if err := write(root); err != nil {
|
|
t.Fatalf("write error = %v", err)
|
|
}
|
|
|
|
announcement := filepath.Join(root, "docs", "news", "announcement.md")
|
|
if err := os.WriteFile(announcement, []byte("hand-written\n"), 0o644); err != nil {
|
|
t.Fatalf("write announcement: %v", err)
|
|
}
|
|
if err := write(root); err != nil {
|
|
t.Fatalf("second write error = %v", err)
|
|
}
|
|
if _, err := os.Stat(announcement); err != nil {
|
|
t.Fatalf("write removed a hand-written news page: %v", err)
|
|
}
|
|
if err := check(root); err != nil {
|
|
t.Fatalf("check rejected a hand-written news page it does not own: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestRealChangelogParses(t *testing.T) {
|
|
releases, err := load(filepath.Join("..", ".."))
|
|
if err != nil {
|
|
t.Fatalf("load the real changelog: %v", err)
|
|
}
|
|
if len(releases) == 0 {
|
|
t.Fatal("the real changelog produced no releases")
|
|
}
|
|
seen := map[string]bool{}
|
|
for _, r := range releases {
|
|
if r.Version == "" || r.Date == "" || r.Body == "" {
|
|
t.Fatalf("incomplete release: %+v", r)
|
|
}
|
|
if seen[r.Version] {
|
|
t.Fatalf("version %s appears twice in the merged history", r.Version)
|
|
}
|
|
seen[r.Version] = true
|
|
}
|
|
}
|