Say when a newer NixOS release is out

router-upgrade releases asks the channel server which stable releases exist
(daily timer, and on every check). The Overview and Packages pages tell a
router that follows a stable release when a newer one is out, and offer the
newest two releases as channels instead of a fixed list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 22:10:27 +01:00
co-authored by Claude Sonnet 5.5
parent 2e4a596fdc
commit 048b53fe33
9 changed files with 241 additions and 27 deletions
+50 -3
View File
@@ -24,18 +24,65 @@ func TestReleaseOfAndChannelChoices(t *testing.T) {
}
return strings.Join(v, ",")
}
if got := values(channelChoices("")); got != ",unstable,26.05" {
stable := supportedReleases(nil)
if got := values(channelChoices("", stable)); got != ",unstable,26.05" {
t.Fatalf("choices: %q", got)
}
// A configured channel that is not offered (a release that is gone) is not lost.
if got := values(channelChoices("25.11")); got != ",unstable,26.05,25.11" {
if got := values(channelChoices("25.11", stable)); got != ",unstable,26.05,25.11" {
t.Fatalf("choices: %q", got)
}
if got := values(channelChoices("unstable")); got != ",unstable,26.05" {
if got := values(channelChoices("unstable", stable)); got != ",unstable,26.05" {
t.Fatalf("choices: %q", got)
}
}
func TestReleaseNotice(t *testing.T) {
seen := []string{"25.05", "25.11", "26.05", "26.11"}
if got := supportedReleases(seen); strings.Join(got, ",") != "26.05,26.11" {
t.Fatalf("supported: %v", got)
}
for _, c := range []struct{ current, want string }{
{"26.05", "26.11"}, {"25.11", "26.11"}, {"26.11", ""}, {"unstable", ""}, {"", ""},
} {
if got := newerRelease(c.current, seen); got != c.want {
t.Errorf("following %q: %q, want %q", c.current, got, c.want)
}
}
if got := newerRelease("26.05", nil); got != "" {
t.Errorf("nothing seen: %q", got)
}
if releaseCmp("9.05", "10.05") >= 0 || releaseCmp("26.11", "26.05") <= 0 || releaseCmp("26.05", "26.05") != 0 {
t.Error("releaseCmp")
}
}
func TestReleaseNoticeShows(t *testing.T) {
a, sys := newTestApp(t)
s, _ := loadSettings(sys.settingsPath())
obj(obj(s, "router"), "update")["channel"] = "26.05"
if err := s.save(sys.settingsPath()); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(sys.upgradeDir(), 0o755); err != nil {
t.Fatal(err)
}
h := a.routes()
cookie := do(h, "POST", "/login", url.Values{"password": {"hunter2hunter2"}}, nil).Result().Cookies()[0]
if body := do(h, "GET", "/upgrade", nil, cookie).Body.String(); strings.Contains(body, "is out") {
t.Fatalf("a notice before the channel server was asked:\n%s", body)
}
os.WriteFile(filepath.Join(sys.upgradeDir(), "releases.json"), []byte(`{"time":"2026-11-19T00:00:00Z","releases":["26.05","26.11"]}`), 0o644)
for _, path := range []string{"/", "/upgrade"} {
if body := do(h, "GET", path, nil, cookie).Body.String(); !strings.Contains(body, "NixOS 26.11 is out") {
t.Errorf("%s has no notice:\n%s", path, body)
}
}
if body := do(h, "GET", "/upgrade", nil, cookie).Body.String(); !strings.Contains(body, `<option value="26.11"`) {
t.Errorf("26.11 is not offered:\n%s", body)
}
}
func TestSetChannelKeepsTheRest(t *testing.T) {
a, sys := newTestApp(t)
os.WriteFile(sys.confirmedPath(), []byte(sample), 0o600)