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.
174 lines
4.2 KiB
Go
174 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func sampleReleases() []release {
|
|
return []release{
|
|
{Version: "1.31.0", Date: "2026-09-22", Body: "### archied — Gateway\n\n- a bullet\n\n### archie-agent\n\n- a runtime bullet"},
|
|
{Version: "1.30.0", Date: "2026-09-20", Body: "Prose."},
|
|
}
|
|
}
|
|
|
|
func TestRenderEmitsTheCanonicalJSON(t *testing.T) {
|
|
files, err := render(sampleReleases())
|
|
if err != nil {
|
|
t.Fatalf("render error = %v", err)
|
|
}
|
|
body, ok := files[releasesJSONPath]
|
|
if !ok {
|
|
t.Fatalf("render produced no %s (files: %v)", releasesJSONPath, keys(files))
|
|
}
|
|
var decoded []release
|
|
if err := json.Unmarshal(body, &decoded); err != nil {
|
|
t.Fatalf("canonical JSON does not decode into []release: %v", err)
|
|
}
|
|
if !reflect.DeepEqual(decoded, sampleReleases()) {
|
|
t.Fatalf("round trip = %+v, want %+v", decoded, sampleReleases())
|
|
}
|
|
}
|
|
|
|
func TestRenderJSONKeepsHTMLCharactersReadable(t *testing.T) {
|
|
releases := []release{{
|
|
Version: "1.0.0", Date: "2026-01-01",
|
|
Body: "a -> b and <memory>",
|
|
}}
|
|
files, err := render(releases)
|
|
if err != nil {
|
|
t.Fatalf("render error = %v", err)
|
|
}
|
|
got := string(files[releasesJSONPath])
|
|
for _, want := range []string{"a -> b", "<memory>"} {
|
|
if !strings.Contains(got, want) {
|
|
t.Fatalf("canonical JSON escaped %q:\n%s", want, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRenderWritesOnePagePerVersion(t *testing.T) {
|
|
files, err := render(sampleReleases())
|
|
if err != nil {
|
|
t.Fatalf("render error = %v", err)
|
|
}
|
|
for _, path := range []string{
|
|
"docs/news/index.md",
|
|
"docs/news/1.31.0.md",
|
|
"docs/news/1.30.0.md",
|
|
"docs/news/releases.json",
|
|
"docs/news/redirects.json",
|
|
} {
|
|
if _, ok := files[path]; !ok {
|
|
t.Fatalf("render did not produce %s (files: %v)", path, keys(files))
|
|
}
|
|
}
|
|
if len(files) != 5 {
|
|
t.Fatalf("render produced %d files, want 5: %v", len(files), keys(files))
|
|
}
|
|
}
|
|
|
|
func TestRenderRedirectsEveryRetiredComponentURL(t *testing.T) {
|
|
files, err := render(sampleReleases())
|
|
if err != nil {
|
|
t.Fatalf("render error = %v", err)
|
|
}
|
|
var table map[string]string
|
|
if err := json.Unmarshal(files[redirectsJSONPath], &table); err != nil {
|
|
t.Fatalf("redirect table does not decode: %v", err)
|
|
}
|
|
want := map[string]string{
|
|
"/news/archied/1.31.0/": "/news/1.31.0/",
|
|
"/news/archie/1.31.0/": "/news/1.31.0/",
|
|
"/news/archied/1.30.0/": "/news/1.30.0/",
|
|
"/news/archie/1.30.0/": "/news/1.30.0/",
|
|
}
|
|
if !reflect.DeepEqual(table, want) {
|
|
t.Fatalf("redirect table = %v, want %v", table, want)
|
|
}
|
|
}
|
|
|
|
func TestRenderIndexGroupsByDate(t *testing.T) {
|
|
files, err := render(sampleReleases())
|
|
if err != nil {
|
|
t.Fatalf("render error = %v", err)
|
|
}
|
|
want := `# News
|
|
|
|
Release notes, newest first.
|
|
|
|
## 2026-09-22
|
|
|
|
- [1.31.0](1.31.0.md)
|
|
|
|
## 2026-09-20
|
|
|
|
- [1.30.0](1.30.0.md)
|
|
`
|
|
if got := string(files["docs/news/index.md"]); got != want {
|
|
t.Fatalf("index markdown =\n%s\nwant\n%s", got, want)
|
|
}
|
|
}
|
|
|
|
func TestRenderReleasePageKeepsTheBodyVerbatim(t *testing.T) {
|
|
files, err := render(sampleReleases())
|
|
if err != nil {
|
|
t.Fatalf("render error = %v", err)
|
|
}
|
|
want := `# 1.31.0
|
|
|
|
Released 2026-09-22. [All news](index.md)
|
|
|
|
### archied — Gateway
|
|
|
|
- a bullet
|
|
|
|
### archie-agent
|
|
|
|
- a runtime bullet
|
|
`
|
|
if got := string(files["docs/news/1.31.0.md"]); got != want {
|
|
t.Fatalf("release page =\n%s\nwant\n%s", got, want)
|
|
}
|
|
}
|
|
|
|
func TestRenderIsDeterministic(t *testing.T) {
|
|
first, err := render(sampleReleases())
|
|
if err != nil {
|
|
t.Fatalf("first render error = %v", err)
|
|
}
|
|
second, err := render(sampleReleases())
|
|
if err != nil {
|
|
t.Fatalf("second render error = %v", err)
|
|
}
|
|
if !reflect.DeepEqual(first, second) {
|
|
t.Fatal("two renders of the same releases differ")
|
|
}
|
|
}
|
|
|
|
func TestRenderHandlesNoReleases(t *testing.T) {
|
|
files, err := render(nil)
|
|
if err != nil {
|
|
t.Fatalf("render error = %v", err)
|
|
}
|
|
if got := string(files[releasesJSONPath]); got != "[]\n" {
|
|
t.Fatalf("empty canonical JSON = %q, want %q", got, "[]\n")
|
|
}
|
|
if got := string(files[redirectsJSONPath]); got != "{}\n" {
|
|
t.Fatalf("empty redirect table = %q, want %q", got, "{}\n")
|
|
}
|
|
if got := string(files["docs/news/index.md"]); got != "# News\n\nRelease notes, newest first.\n" {
|
|
t.Fatalf("empty index = %q", got)
|
|
}
|
|
}
|
|
|
|
func keys(m map[string][]byte) []string {
|
|
out := make([]string, 0, len(m))
|
|
for k := range m {
|
|
out = append(out, k)
|
|
}
|
|
return out
|
|
}
|