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.
229 lines
6.7 KiB
Go
229 lines
6.7 KiB
Go
package releaseannounce
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const testChangelog = `# Changelog
|
|
|
|
## [Unreleased]
|
|
|
|
- feat: work in progress
|
|
|
|
## [v0.2.0] - 2026-07-27
|
|
|
|
- feat: improved the /help command
|
|
- fix: model selection now affects live chat
|
|
|
|
## [v0.1.0] - 2026-07-20
|
|
|
|
- feat: initial release
|
|
`
|
|
|
|
func TestAnnouncerBaselinesFirstReleaseWithoutSending(t *testing.T) {
|
|
announcer := newTestAnnouncer(t, "v0.1.0")
|
|
var sent []string
|
|
|
|
if err := announcer.Announce(context.Background(), []int64{7}, func(_ context.Context, _ int64, message string) error {
|
|
sent = append(sent, message)
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatalf("Announce() error = %v", err)
|
|
}
|
|
if len(sent) != 0 {
|
|
t.Fatalf("first release sent %d messages, want baseline only", len(sent))
|
|
}
|
|
|
|
announcer.Components[0].Version = "v0.2.0"
|
|
if err := announcer.Announce(context.Background(), []int64{7}, func(_ context.Context, _ int64, message string) error {
|
|
sent = append(sent, message)
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatalf("Announce(upgrade) error = %v", err)
|
|
}
|
|
if len(sent) != 1 {
|
|
t.Fatalf("upgrade sent %d messages, want 1", len(sent))
|
|
}
|
|
for _, want := range []string{
|
|
"Archie has just been updated.",
|
|
"--- THE GATEWAY ---",
|
|
"v0.2.0 installed - changes:",
|
|
"- feat: improved the /help command",
|
|
"- fix: model selection now affects live chat",
|
|
} {
|
|
if !strings.Contains(sent[0], want) {
|
|
t.Errorf("notification missing %q:\n%s", want, sent[0])
|
|
}
|
|
}
|
|
|
|
if err := announcer.Announce(context.Background(), []int64{7}, func(context.Context, int64, string) error {
|
|
t.Fatal("same version was announced twice")
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatalf("Announce(restart) error = %v", err)
|
|
}
|
|
}
|
|
|
|
func TestAnnouncerSeparatesChangedAndUnchangedComponents(t *testing.T) {
|
|
dir := t.TempDir()
|
|
// One changelog holds every release now; both components read the section
|
|
// for their version from it.
|
|
changelog := filepath.Join(dir, "CHANGELOG.md")
|
|
if err := os.WriteFile(changelog, []byte(testChangelog), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
announcer := Announcer{
|
|
StatePath: filepath.Join(dir, "announced.json"),
|
|
Components: []Component{
|
|
{ID: "gateway", Label: "THE GATEWAY", Version: "v0.1.0", ChangelogPath: changelog},
|
|
{ID: "runtime", Label: "THE RUNTIME", Version: "v0.1.0", ChangelogPath: changelog},
|
|
},
|
|
}
|
|
if err := announcer.Announce(context.Background(), []int64{7}, func(context.Context, int64, string) error {
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
announcer.Components[0].Version = "v0.2.0"
|
|
var message string
|
|
if err := announcer.Announce(context.Background(), []int64{7}, func(_ context.Context, _ int64, text string) error {
|
|
message = text
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, want := range []string{
|
|
"--- THE GATEWAY ---",
|
|
"v0.2.0 installed - changes:",
|
|
"- feat: improved the /help command",
|
|
"--- THE RUNTIME ---",
|
|
"No runtime changes as part of this release.",
|
|
} {
|
|
if !strings.Contains(message, want) {
|
|
t.Errorf("component notification missing %q:\n%s", want, message)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAnnouncerTracksRecipientsIndependentlyAndRetriesFailures(t *testing.T) {
|
|
announcer := newTestAnnouncer(t, "v0.1.0")
|
|
if err := announcer.Announce(context.Background(), []int64{7, 8}, func(context.Context, int64, string) error {
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
announcer.Components[0].Version = "v0.2.0"
|
|
|
|
var attempts []int64
|
|
send := func(_ context.Context, recipient int64, _ string) error {
|
|
attempts = append(attempts, recipient)
|
|
if recipient == 8 {
|
|
return errors.New("telegram unavailable")
|
|
}
|
|
return nil
|
|
}
|
|
if err := announcer.Announce(context.Background(), []int64{7, 8}, send); err == nil {
|
|
t.Fatal("Announce() error = nil, want delivery error")
|
|
}
|
|
|
|
attempts = nil
|
|
if err := announcer.Announce(context.Background(), []int64{7, 8}, func(_ context.Context, recipient int64, _ string) error {
|
|
attempts = append(attempts, recipient)
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatalf("Announce(retry) error = %v", err)
|
|
}
|
|
if len(attempts) != 1 || attempts[0] != 8 {
|
|
t.Fatalf("retry recipients = %v, want only failed recipient 8", attempts)
|
|
}
|
|
}
|
|
|
|
func TestAnnouncerSkipsDevelopmentBuildsAndVersionRollbacks(t *testing.T) {
|
|
announcer := newTestAnnouncer(t, "dev")
|
|
calls := 0
|
|
send := func(context.Context, int64, string) error {
|
|
calls++
|
|
return nil
|
|
}
|
|
if err := announcer.Announce(context.Background(), []int64{7}, send); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(announcer.StatePath); !errors.Is(err, os.ErrNotExist) {
|
|
t.Fatalf("development build created state: %v", err)
|
|
}
|
|
|
|
announcer.Components[0].Version = "v0.2.0"
|
|
if err := announcer.Announce(context.Background(), []int64{7}, send); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
announcer.Components[0].Version = "v0.1.0"
|
|
if err := announcer.Announce(context.Background(), []int64{7}, send); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if calls != 0 {
|
|
t.Fatalf("development/rollback sends = %d, want 0", calls)
|
|
}
|
|
}
|
|
|
|
func TestAnnouncerReportsMissingReleaseSectionWithoutAdvancingState(t *testing.T) {
|
|
announcer := newTestAnnouncer(t, "v0.1.0")
|
|
if err := announcer.Announce(context.Background(), []int64{7}, func(context.Context, int64, string) error {
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
announcer.Components[0].Version = "v9.9.9"
|
|
|
|
if err := announcer.Announce(context.Background(), []int64{7}, func(context.Context, int64, string) error {
|
|
t.Fatal("missing changelog section must not send")
|
|
return nil
|
|
}); err == nil {
|
|
t.Fatal("Announce() error = nil, want missing release section error")
|
|
}
|
|
}
|
|
|
|
func TestAnnouncerReportsStatePersistenceFailure(t *testing.T) {
|
|
dir := t.TempDir()
|
|
changelog := filepath.Join(dir, "CHANGELOG.md")
|
|
if err := os.WriteFile(changelog, []byte(testChangelog), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
notDirectory := filepath.Join(dir, "file")
|
|
if err := os.WriteFile(notDirectory, []byte("occupied"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
announcer := Announcer{
|
|
StatePath: filepath.Join(notDirectory, "announced.json"),
|
|
Components: []Component{
|
|
{ID: "gateway", Label: "THE GATEWAY", Version: "v0.1.0", ChangelogPath: changelog},
|
|
},
|
|
}
|
|
|
|
if err := announcer.Announce(context.Background(), []int64{7}, func(context.Context, int64, string) error {
|
|
return nil
|
|
}); err == nil {
|
|
t.Fatal("Announce() error = nil, want state persistence error")
|
|
}
|
|
}
|
|
|
|
func newTestAnnouncer(t *testing.T, version string) Announcer {
|
|
t.Helper()
|
|
dir := t.TempDir()
|
|
changelog := filepath.Join(dir, "CHANGELOG.md")
|
|
if err := os.WriteFile(changelog, []byte(testChangelog), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return Announcer{
|
|
StatePath: filepath.Join(dir, "announced.json"),
|
|
Components: []Component{
|
|
{ID: "gateway", Label: "THE GATEWAY", Version: version, ChangelogPath: changelog},
|
|
},
|
|
}
|
|
}
|