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:
@@ -190,10 +190,11 @@ let
|
||||
builds=$(grep -cE '^ +/nix/store/[^ ]*\.drv$' <<<"$dry" || true)
|
||||
echo " to fetch: ''${download:-nothing, or no cache reachable}; to build here: $builds"
|
||||
|
||||
jq -n --arg channel "$channel" --arg rev "$newest" --arg ref "$pin" --arg version "$new_version" \
|
||||
release_version=$(jq -r '.version // ""' /etc/router-release 2>/dev/null || true)
|
||||
jq -n --arg channel "$channel" --arg release "$release_version" --arg rev "$newest" --arg ref "$pin" --arg version "$new_version" \
|
||||
--arg time "$(date -u +%FT%TZ)" --arg download "$download" --argjson builds "$builds" \
|
||||
--argjson reboot "$reboot" --slurpfile changes ${dir}/changes.json \
|
||||
'{channel: $channel, rev: $rev, ref: $ref, version: $version, time: $time, download: $download,
|
||||
'{channel: $channel, release: $release, rev: $rev, ref: $ref, version: $version, time: $time, download: $download,
|
||||
builds: $builds, rebootNeeded: $reboot, changes: $changes[0]}' > ${dir}/preview.json
|
||||
echo "$new_version$([ "$reboot" = false ] || echo ' (a new kernel runs after a reboot)'): router-upgrade apply activates it"
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ type UpgradeChange struct {
|
||||
// UpgradePreview is preview.json.
|
||||
type UpgradePreview struct {
|
||||
Channel string `json:"channel"`
|
||||
Release string `json:"release"` // the nixos-router that made it
|
||||
Rev string `json:"rev"`
|
||||
Version string `json:"version"`
|
||||
Time string `json:"time"`
|
||||
@@ -179,12 +180,13 @@ func (a *app) upgradeData() upgradeData {
|
||||
}
|
||||
var c UpgradeCheck
|
||||
// What was checked before another channel was chosen or before the last
|
||||
// upgrade says nothing about now.
|
||||
// upgrade says nothing about now; nor does a preview that another
|
||||
// nixos-router made (it may list packages differently).
|
||||
if readUpgradeFile(filepath.Join(a.sys.upgradeDir(), "check.json"), &c) && c.Channel == d.Channel && c.Running.Version == d.Version {
|
||||
d.Check = &c
|
||||
}
|
||||
var p UpgradePreview
|
||||
if readUpgradeFile(filepath.Join(a.sys.upgradeDir(), "preview.json"), &p) && p.Channel == d.Channel {
|
||||
if readUpgradeFile(filepath.Join(a.sys.upgradeDir(), "preview.json"), &p) && p.Channel == d.Channel && p.Release != "" && p.Release == a.sys.installedRelease().Version {
|
||||
d.Preview = &p
|
||||
}
|
||||
return d
|
||||
|
||||
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user