Ignore a package preview made by another nixos-router

A preview is kept until the next one; after an update it could still show
the list the older version made.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV9dZrK6nipHkPfyM4F
This commit is contained in:
2026-11-18 09:00:44 +01:00
co-authored by Claude Sonnet 5.5
parent 6e097b7473
commit 163df5966d
3 changed files with 26 additions and 5 deletions
+19 -1
View File
@@ -67,6 +67,8 @@ func TestUpgradePage(t *testing.T) {
a, sys := newTestApp(t)
a.sys.VersionFile = filepath.Join(t.TempDir(), "nixos-version")
os.WriteFile(a.sys.VersionFile, []byte("26.11.20261027.31ecbac\n"), 0o600)
a.sys.ReleaseFile = filepath.Join(t.TempDir(), "router-release")
os.WriteFile(a.sys.ReleaseFile, []byte(`{"version":"0.12.11"}`), 0o600)
var started int
orig := startUnit
startUnit = func(unit string) error {
@@ -159,7 +161,7 @@ func TestUpgradePage(t *testing.T) {
t.Fatal("the unit was started without a preview")
}
os.MkdirAll(a.sys.upgradeDir(), 0o700)
os.WriteFile(filepath.Join(a.sys.upgradeDir(), "preview.json"), []byte(`{"channel":"26.05","rev":"0123456789abcdef0123456789abcdef01234567","version":"26.11.20261110.0123456","time":"2026-11-10T10:00:00Z","download":"(350.5 MiB download, 1.2 GiB unpacked)","builds":3,"rebootNeeded":true,"changes":[{"name":"frr","from":"10.1","to":"10.2"},{"name":"linux","from":"6.12.5","to":"6.12.8"}]}`), 0o600)
os.WriteFile(filepath.Join(a.sys.upgradeDir(), "preview.json"), []byte(`{"channel":"26.05","release":"0.12.11","rev":"0123456789abcdef0123456789abcdef01234567","version":"26.11.20261110.0123456","time":"2026-11-10T10:00:00Z","download":"(350.5 MiB download, 1.2 GiB unpacked)","builds":3,"rebootNeeded":true,"changes":[{"name":"frr","from":"10.1","to":"10.2"},{"name":"linux","from":"6.12.5","to":"6.12.8"}]}`), 0o600)
body := page()
for _, want := range []string{"frr", "10.1", "10.2", "linux", "350.5 MiB", "3 derivations", "after the next reboot", "Upgrade to 26.11.20261110.0123456"} {
if !strings.Contains(body, want) {
@@ -182,6 +184,22 @@ func TestUpgradePage(t *testing.T) {
}
})
t.Run("a preview made by another nixos-router is not shown", func(t *testing.T) {
path := filepath.Join(a.sys.upgradeDir(), "preview.json")
data, _ := os.ReadFile(path)
for _, release := range []string{`"release":"0.12.10",`, ``} {
old := strings.Replace(string(data), `"release":"0.12.11",`, release, 1)
os.WriteFile(path, []byte(old), 0o600)
if strings.Contains(page(), "linux") {
t.Fatalf("a preview with %q is shown", release)
}
}
os.WriteFile(path, data, 0o600)
if !strings.Contains(page(), "linux") {
t.Fatal("the preview of this release is not shown")
}
})
t.Run("a preview of another channel is not shown", func(t *testing.T) {
post("/upgrade/channel", url.Values{"channel": {"unstable"}})
if strings.Contains(page(), "linux") {