update: the app and magpie web follow each other's update (visamzh on X)

visamzh on X: with the desktop app and magpie web both open, an update
from either side left the other still offering it ("↑ 更新") until it was
quit by hand.

Cause: the app and magpie web are two processes over one program, each
with its own updater (state, download, latest) in memory. One restarting
to update puts the new binary in; the other is told nothing. Its
replaced() (the binary on disk is no longer the one it started from) was
read only on a click of its own Update or on magpie update's gateway ask
(restartBeside), which reaches only the process serving the gateway. And
a browser's page reloaded (backAsNew) only after a restart it asked for
itself, so magpie web's tab kept the old page and its pill even once
the process under it was new.

Fix:
- followReplaced (update_beside.go): every updater stats its binary each
  5 s and, once another magpie replaced it, restarts into it through
  restartBeside, once: at once when idle, else after the gateway's
  requests (waitIdle), as for magpie update's ask. Not for what this
  process put in itself (installed, set by install, cleared by
  wontStart), not twice (followed), not for a build that isn't a release
  (make dev, go build rebuild in place). It stops with backendCtx, so a
  copy left draining after a handover doesn't look.
- waitFor (update_wait.go): a wait for the gateway restarts into what
  another magpie put in whatever the feed says now; before, a feed out
  of reach or a "latest" answer ended the wait with nothing restarted.
- boot.js names the version that served the page (bootPrefs.version);
  app.js's servedAnew reloads a browser's page (web) when /api/update's
  current names another, on the reads it already made (load, focus, back
  into view) and once a minute while shown. The app's own windows come
  back with their new process and are left alone.
- docs/subsystems/gui-shell.md describes it.

Run (mote, through mote-run, at 1e1068c86 + this change unless said):
- gofmt -l internal/gui: nothing.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build, GOOS=linux go build -tags nogui, GOOS=windows go
  build: all ok.
- go test -tags nogui -race -count=5 -run
  'Follow|AnotherMagpies|OwnUpdate|OwnBuild|UpdateClicked|Wait|Beside|
  Restart|Install|WhatsNew|Quiet' ./internal/gui/: ok (102.9s).
- go test -tags nogui -timeout 45m ./internal/gui/... ./internal/cli/...
  ./internal/update/... . : gui, update, update/launcher and magpie ok;
  internal/cli red in TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red the same on origin/main
  51fa4b7eb alone, filed as #5026 (from 0872bc2a0).
- node --test internal/gui/tests/update-served-anew.test.cjs: 34/34
  (Chromium and WebKit; en, zh, zh-TW, ja, de; 1100 and 420 wide; the
  minute poll under page.clock; the app's window not reloaded).

Broken by hand, each red, then put back:
- followReplaced never restarting: TestAnotherMagpiesUpdateRestartsThisOne
  and TestAnotherMagpiesUpdateWaitsForTheGatewayThenRestarts red.
- the installed guard dropped: TestOwnUpdateIsNotFollowedAgain and
  TestUpdateClickedOverAnothersIsNotFollowedAgain red (a second restart).
- waitFor's "in" case off: TestAnotherMagpiesUpdateWaitsForTheGateway
  ThenRestarts red (the wait ends with nothing restarted).
- boot.js without the version: TestBootNamesTheVersionThatServedThePage
  red.
- servedAnew not reloading: 15 of 16 subtests red in Chromium.
- the minute poll removed: the 5 "left on screen" subtests red in WebKit.

A first cut also refused a second install() once one was in; that made
TestRestartBySelfComesBackQuietly and TestWhatsNewQuietAfterRestartTo
Update red (they restart one updater several times), so the flag only
keeps followReplaced off.

Not tried: a real pair of the app and magpie web on two release builds
with one replacing the binary (only temp files and fakes); Windows
(InstallBinaryAside starts the staged file there, so the own-install
test is skipped and the click test covers the flag) and Linux runs;
the whole GUI suite: mote was never free (two other sessions' full GUI suites, load ~400), so it runs on the Linux box after this lands.
This commit is contained in:
yetone
2026-11-04 06:59:29 +08:00
parent 452c28a78c
commit 6673171595
8 changed files with 411 additions and 5 deletions
+26
View File
@@ -836,6 +836,32 @@ while the new version starts (#4521). See `TestUpdateInATerminalRestartsTheAppWi
[`restart_test.go`](../../internal/gateway/restart_test.go) and
`TestUpdateAsksTheRunningMagpieToRestart`.
The app and `magpie web` open together each have an updater of their own
over the same program, and the gateway's ask reaches only the one serving
the gateway (visamzh on X: one restarted to update, and the other ran on
as the old version, its Update pill still offering the version already
in). So every updater also looks at its binary every 5 s
(`followReplaced` in [`update_beside.go`](../../internal/gui/update_beside.go),
`replacedTick`) and, once another magpie replaced it, restarts into it
through `restartBeside` once, whatever Settings' automatic restart says:
an old version left running is what the user asked to leave behind. A
gateway busy has it wait as above (`waitFor` restarts into what is on
disk without asking the feed again), a process restarting into its own
install (`installed`) or already following one (`followed`) doesn't, and
a build that isn't a release (`update.Released`; `make dev`, `go build`)
is never followed. A browser's page (`magpie web`, the app's page) learns
the version that served it from boot.js (`bootPrefs.version`) and reloads
when `/api/update`'s `current` names another (`servedAnew` in app.js), on
the reads it already makes (load, focus, coming back into view) and once a
minute while it is shown; the app's own windows come back with their new
process. See `TestAnotherMagpiesUpdateRestartsThisOne`,
`TestOwnUpdateIsNotFollowedAgain`, `TestOwnBuildRebuiltIsNotFollowed`,
`TestAnotherMagpiesUpdateWaitsForTheGatewayThenRestarts`,
`TestUpdateClickedOverAnothersIsNotFollowedAgain` and
`TestBootNamesTheVersionThatServedThePage` in
[`update_follow_test.go`](../../internal/gui/update_follow_test.go), and
`update-served-anew.test.cjs`.
See `TestRestartHandsTheGatewayOver` (the new version a second process,
a stream across the restart finishing whole, requests during it answered,
and the old one quitting only after its stream) and
+4
View File
@@ -992,6 +992,10 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
// and the text size, which the Mac's header measures against the
// traffic lights
boot := map[string]any{"lang": s.Lang, "theme": s.Theme, "textSize": s.TextSize, "web": isWeb(w)}
// and the version that served the page: a browser's page reloads
// once another answers in its place (visamzh on X), as after its
// own restart to update (backAsNew)
boot["version"] = Version
if s.Colorblind {
boot["colorblind"] = true
}
+22
View File
@@ -31,6 +31,9 @@ if (mode === "panel" && !document.body.classList.contains("linux")) $("header.to
// `magpie web`: the page in a browser tab, with no window of the app's
// around it — it opens links itself, and what is the desktop's is left out
const web = !!window.bootPrefs?.web;
// the version that served this page, which servedAnew compares the one
// answering now with
const pageVersion = window.bootPrefs?.version || "";
// magpie web seen from another computer: localhost is the viewer's (curtinp118)
const remotePage = web && !/^(localhost|127(\.\d+){3}|\[::1\]|::1)$/i.test(location.hostname);
// layout.js applies the mode and platform before the header can paint.
@@ -4405,6 +4408,7 @@ function updatePath(p) {
async function renderUpdateBadge() {
const b = $("#update"), label = b.querySelector("span");
const u = await api(updatePath("update")).catch(() => null);
if (servedAnew(u)) return;
if (u) updateLast = u, u.at = Date.now();
// pulling: a click is downloading it again, and restarts once it's in
const pulling = !!u && !!b.dataset.pulling && ["checking", "downloading", "ready"].includes(u.state);
@@ -4535,6 +4539,19 @@ async function backAsNew(was) {
}
}
// servedAnew reloads a browser's page (magpie web, or the app's page)
// that another version of magpie now answers for, and says whether it did.
// The page restarted to update itself reloads in backAsNew; one whose
// magpie restarted for another's update (the app's window put it in, and
// magpie web followed, or the app restarted under its own page) ran on as
// the old page, its Update pill still offering the version already in
// (visamzh on X).
function servedAnew(u) {
if (!web || !pageVersion || !u?.current || u.current === pageVersion) return false;
location.reload();
return true;
}
// updateStuck says why this magpie can't replace itself where it is: off
// the Mac, a folder it may not write to, such as C:\ (#1277), or a
// container, whose image is what gets updated.
@@ -22300,6 +22317,7 @@ async function renderUpdate(r, u) {
if (early) renderUpdate(r, updateLast);
else if (bare) r.querySelector(".who").append(el("div", "sub say", "\u00a0"));
u = await api(updatePath("update?fresh=1")).catch(() => null);
if (servedAnew(u)) return;
if (!u || !r.isConnected || seqOf(r) !== seq) return;
if (early) updateSeq.set(r, seq + 1); // stops timers
} else if (!r.isConnected) return;
@@ -24112,6 +24130,10 @@ setInterval(async () => {
}
window.addEventListener("focus", () => loadBack());
setInterval(renderUpdateBadge, 15 * 60 * 1000); // a window left open still hears of a new version
// a browser's page on screen hears within a minute that its magpie
// restarted into an update put in elsewhere (servedAnew), without a click
// into it first
if (web) setInterval(() => { if (!document.hidden) renderUpdateBadge(); }, 60e3);
// renderPluginDot puts a dot on Plugins while a plugin's update waits for
// the reader (someone else's plugin, or one pinned; the community's update
// by themselves)
@@ -0,0 +1,117 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// visamzh on X: the app's window and magpie web open together. One restarted
// to update; the other's page ran on as the old one, its Update pill still
// offering the version already in. A browser's page (magpie web, the app's
// page) now reloads once another version of magpie answers in its place:
// when it is clicked back into, and, left on screen, within a minute. The
// app's own window doesn't, its process making a new one. Every language,
// both engines, wide and narrow; no backend, the API is faked.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const langs = ["en", "zh", "zh-TW", "ja", "de"];
function settingsPayload(lang) {
return {
theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd",
dock: false, dockWindow: false, proxy: "", redact: false, redactPersonal: false, redactWords: [],
codexWarmup: "", claudeWarmup: "", codexWarmAt: "", claudeWarmAt: "", workbuddyCheckin: false, noStats: false,
trayUsage: "", trayUsageEvery: 3, vision: "", imageGen: "",
version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425",
proxyNow: "none", proxySource: "none", login: false,
visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [],
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
};
}
// ctl.version is the magpie answering: 0.1.400 with 0.1.401 downloaded,
// until the other side's update has it restart as 0.1.401
function server(lang, web, ctl) {
return async (route) => {
const req = route.request(), url = new URL(req.url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/") ctl.pages++;
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${web},version:"${ctl.version}"};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: settingsPayload(lang), fx: settingsPayload(lang).fx });
if (url.pathname === "/api/settings") return json(settingsPayload(lang));
if (url.pathname === "/api/update") {
return json(ctl.version === "0.1.400"
? { state: "ready", current: "0.1.400", latest: "0.1.401" }
: { state: "latest", current: "0.1.401", latest: "0.1.401" });
}
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png", ".json": "application/json" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const pill = (page) => page.locator("#update");
async function open(browser, width, lang, web, ctl, clock) {
const errors = [];
const page = await (await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
page.on("pageerror", (e) => { if (!/^ResizeObserver loop completed with undelivered notifications/.test(e.message)) errors.push(e.message); });
if (clock) await page.clock.install();
await page.route("**/*", server(lang, web, ctl));
await page.goto("http://magpie.test/?view=settings");
await pill(page).waitFor({ state: "visible" });
await page.evaluate(() => { window.oldPage = true; });
return { page, errors };
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": a page whose magpie restarted into another's update reloads", async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const width of [1100, 420]) for (const lang of langs) {
await t.test(`${lang} at ${width}: clicked back into`, async () => {
const ctl = { version: "0.1.400", pages: 0 };
const { page, errors } = await open(browser, width, lang, true, ctl);
// the app's window put 0.1.401 in, and magpie web restarted into it
ctl.version = "0.1.401";
await page.evaluate(() => window.dispatchEvent(new Event("focus")));
await page.waitForFunction(() => !window.oldPage && document.readyState === "complete");
assert.equal(ctl.pages, 2, "loaded again once");
await page.waitForTimeout(400);
assert.equal(await pill(page).isHidden(), true, "the reloaded page offers no update");
assert.equal(ctl.pages, 2, "no reload after the first");
assert.deepEqual(errors, []);
await page.context().close();
});
}
for (const lang of langs) {
await t.test(`${lang}: left on screen, within a minute`, async () => {
const ctl = { version: "0.1.400", pages: 0 };
const { page, errors } = await open(browser, 1100, lang, true, ctl, true);
ctl.version = "0.1.401";
await page.clock.runFor(61e3);
await page.waitForFunction(() => !window.oldPage, null, { polling: 50 });
assert.equal(ctl.pages, 2);
assert.deepEqual(errors, []);
await page.context().close();
});
}
await t.test("the app's own window doesn't reload", async () => {
const ctl = { version: "0.1.400", pages: 0 };
const { page, errors } = await open(browser, 1100, "en", false, ctl);
ctl.version = "0.1.401";
await page.evaluate(() => window.dispatchEvent(new Event("focus")));
await page.waitForTimeout(600);
assert.equal(await page.evaluate(() => window.oldPage), true);
assert.equal(ctl.pages, 1);
assert.deepEqual(errors, []);
await page.context().close();
});
});
}
+10 -2
View File
@@ -84,6 +84,12 @@ type updater struct {
autoRestart func() bool
autoSkip string
waitAsked bool // the restart waiting was a click's
// installed: this process put an update in (install), and is leaving
// for it; followed: it is restarting into one another magpie put in
// (restartBeside). Either way what is on disk is no longer another's
// for followReplaced to restart into.
installed bool
followed bool
}
type updateJSON struct {
@@ -139,6 +145,7 @@ func updateDue(s settings.Settings, last, now time.Time) bool {
func (u *updater) start() {
u.place(runtime.GOOS, update.GUI)
gateway.SetRestarter(u.restartBeside) // magpie update in a terminal
go u.followReplaced(backendCtx) // the app's or magpie web's update (visamzh on X)
if u.bundle != "" {
go update.ForgetOldStaging(u.bundle) // #3965
}
@@ -504,7 +511,7 @@ func (u *updater) install(ask bool) bool {
// another magpie updated the binary after this one started: it is
// in, and swapping this one's download in would move it aside (the
// download is left: it may be the other's, staged at the same name)
u.staged = ""
u.staged, u.installed = "", true
return true
}
if u.staged == "" {
@@ -535,7 +542,7 @@ func (u *updater) install(ask bool) bool {
}
return false
}
u.staged = ""
u.staged, u.installed = "", true
return true
}
@@ -550,6 +557,7 @@ func (u *updater) wontStart(err error) {
}
b := update.NoteBlocked(v, err)
u.blocked, u.state, u.aside = &b, "blocked", ""
u.installed = false // this one runs on, back in its place
u.err = err.Error()
}
+41
View File
@@ -1,6 +1,9 @@
package gui
import (
"context"
"time"
"github.com/yetone/magpie/internal/gateway"
"github.com/yetone/magpie/internal/update"
)
@@ -19,6 +22,7 @@ func (u *updater) restartBeside(version string) gateway.RestartReply {
restart := u.autoRestart
in := u.replaced()
if in {
u.followed = true
// what the terminal put in is the version restarted into, as if
// this one had downloaded it: the feed isn't asked first
if version != "" && (u.latest == nil || update.Newer(version, u.latest.Version)) {
@@ -46,3 +50,40 @@ func (u *updater) restartBeside(version string) gateway.RestartReply {
reply.State, reply.Busy = "waiting", &b
return reply
}
// replacedTick is how often followReplaced looks at what is on disk; tests
// shorten it.
var replacedTick = 5 * time.Second
// followReplaced restarts this magpie into an update another magpie put in
// where it runs from, as restartBeside does for magpie update's ask
// (visamzh on X). The app and magpie web run from the same program (the
// terminal's magpie is the app's, linked), and each had its own updater:
// one restarting to update put the new version in, and the other ran on
// as the old one, its Update still offering the version already in, its
// page never reloaded. Neither tells the other, and the other may serve
// no gateway to be asked on, so each looks for itself, a stat every
// replacedTick, until ctx ends (the copy an update left draining looks no
// more, #4938). Only once for a change, so a wait the user called off
// isn't started again; never for what this one put in itself (installed),
// nor in a build of its own, which a rebuild in place would restart.
func (u *updater) followReplaced(ctx context.Context) {
t := time.NewTicker(replacedTick)
defer t.Stop()
for {
select {
case <-ctx.Done():
return
case <-t.C:
}
if !update.Released(Version) {
continue
}
u.mu.Lock()
due := u.autoRestart != nil && !u.installed && !u.followed && u.replaced()
u.mu.Unlock()
if due {
u.restartBeside("")
}
}
}
+182
View File
@@ -0,0 +1,182 @@
package gui
import (
"context"
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/yetone/magpie/internal/gateway"
"github.com/yetone/magpie/internal/update"
)
// following runs u.followReplaced on short ticks as a magpie of version v,
// ended with the test.
func following(t *testing.T, u *updater, v string) {
t.Helper()
oldTick, oldVersion := replacedTick, Version
replacedTick, Version = 5*time.Millisecond, v
ctx, cancel := context.WithCancel(context.Background())
var done sync.WaitGroup
done.Add(1)
go func() {
defer done.Done()
u.followReplaced(ctx)
}()
t.Cleanup(func() {
cancel()
done.Wait()
replacedTick, Version = oldTick, oldVersion
})
}
// startedFrom is an updater for the binary at a new path, as this process
// started from it, whose restart counts.
func startedFrom(t *testing.T, restarts *atomic.Int32) (*updater, string) {
t.Helper()
exe := filepath.Join(t.TempDir(), "magpie")
if err := os.WriteFile(exe, []byte("v0.1.1"), 0o755); err != nil {
t.Fatal(err)
}
u := &updater{state: "ready", exe: exe, latest: &update.Release{Version: "v0.1.2"}}
u.self, _ = os.Stat(exe)
u.autoRestart = func() bool { restarts.Add(1); return true }
return u, exe
}
// stays waits most for a count that must stay what it is.
func stays(most time.Duration, n *atomic.Int32, want int32) bool {
for end := time.Now().Add(most); time.Now().Before(end); time.Sleep(5 * time.Millisecond) {
if n.Load() != want {
return false
}
}
return true
}
// visamzh on X: the app and magpie web open together, each with its own
// updater over the same program. One restarted to update and put the new
// version in; the other ran on as the old one, its Update pill still
// offering the version already in. Now the other sees what is on disk
// change and restarts into it, as for magpie update's ask, once. On the
// old code nothing looks, and nothing restarts.
func TestAnotherMagpiesUpdateRestartsThisOne(t *testing.T) {
var restarts atomic.Int32
u, exe := startedFrom(t, &restarts)
following(t, u, "v0.1.1")
if !stays(100*time.Millisecond, &restarts, 0) {
t.Fatal("restarted with nothing put in")
}
// the window's restart to update puts the new version in
if err := os.WriteFile(exe, []byte("v0.1.2 is longer"), 0o755); err != nil {
t.Fatal(err)
}
eventually(t, "magpie web never restarted into the version the app put in", func() bool { return restarts.Load() == 1 })
if !stays(100*time.Millisecond, &restarts, 1) {
t.Fatalf("restarted %d times for one update", restarts.Load())
}
}
// What this process put in itself is the restart it is making already: a
// second, from looking at the disk, would start the new version twice.
func TestOwnUpdateIsNotFollowedAgain(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("InstallBinaryAside starts the download to check it there; the click below covers the flag")
}
var restarts atomic.Int32
u, exe := startedFrom(t, &restarts)
staged := filepath.Join(filepath.Dir(exe), "magpie.new")
if err := os.WriteFile(staged, []byte("v0.1.2 is longer"), 0o755); err != nil {
t.Fatal(err)
}
u.staged = staged
following(t, u, "v0.1.1")
if !u.install(true) {
t.Fatalf("the install failed: %s", u.err)
}
if !u.replaced() {
t.Fatal("the install left the binary as it was")
}
if !stays(150*time.Millisecond, &restarts, 0) {
t.Fatal("restarted again for its own update")
}
}
// A build of its own (make dev, go build) is rebuilt in place, which isn't
// an update to restart into.
func TestOwnBuildRebuiltIsNotFollowed(t *testing.T) {
var restarts atomic.Int32
u, exe := startedFrom(t, &restarts)
following(t, u, "dev")
if err := os.WriteFile(exe, []byte("rebuilt, and longer"), 0o755); err != nil {
t.Fatal(err)
}
if !stays(150*time.Millisecond, &restarts, 0) {
t.Fatal("a dev build restarted for its rebuild")
}
}
// With the gateway busy the restart waits for it, and then goes into what
// the other put in whatever the feed says: here it can't be reached, with
// nothing downloaded by this one. On the old code the wait ended with
// nothing to restart into.
func TestAnotherMagpiesUpdateWaitsForTheGatewayThenRestarts(t *testing.T) {
var restarts atomic.Int32
u, exe := startedFrom(t, &restarts)
busy := &fakeBusy{}
busy.set(gateway.Busy{Requests: 1, Last: time.Now()})
quick(t, busy, u)
waitRecheck = (*updater).recheck // the feed asked, and out of reach
following(t, u, "v0.1.1")
if err := os.WriteFile(exe, []byte("v0.1.2 is longer"), 0o755); err != nil {
t.Fatal(err)
}
eventually(t, "never waited for the gateway", func() bool { w, _ := u.waitingFor(); return w })
if restarts.Load() != 0 {
t.Fatal("restarted with a request in flight")
}
busy.set(gateway.Busy{})
eventually(t, "never restarted once the gateway was idle", func() bool { return restarts.Load() == 1 })
}
// A click on the old one's Update, the other's version in already, is its
// restart: looking at the disk doesn't make a second.
func TestUpdateClickedOverAnothersIsNotFollowedAgain(t *testing.T) {
var restarts atomic.Int32
u, exe := startedFrom(t, &restarts)
if err := os.WriteFile(exe, []byte("v0.1.2 is longer"), 0o755); err != nil {
t.Fatal(err)
}
if !u.install(true) {
t.Fatal("the other's version wasn't taken as put in")
}
following(t, u, "v0.1.1")
if !stays(150*time.Millisecond, &restarts, 0) {
t.Fatal("restarted again beside the click's restart")
}
}
// boot.js names the version that served the page, which a browser's page
// compares with /api/update's current to reload once another magpie, here
// magpie web restarted into the app's update, answers in its place.
func TestBootNamesTheVersionThatServedThePage(t *testing.T) {
h := t.TempDir()
t.Setenv("HOME", h)
t.Setenv("USERPROFILE", h)
t.Setenv("XDG_CONFIG_HOME", h+"/.config")
t.Setenv("XDG_CACHE_HOME", h+"/.cache")
oldVersion := Version
Version = "0.1.777"
defer func() { Version = oldVersion }()
rec := httptest.NewRecorder()
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("GET", "/boot.js", nil))
if !strings.Contains(rec.Body.String(), `"version":"0.1.777"`) {
t.Fatalf("boot.js doesn't name the version: %s", rec.Body)
}
}
+9 -3
View File
@@ -126,8 +126,14 @@ func (u *updater) waitFor(gen int) {
if !idleAt(b, time.Now()) {
continue
}
switch u.json().State {
case "ready":
u.mu.Lock()
// another magpie put the update in (restartBeside): that is what
// the restart goes into, whatever the feed answers now
in := u.replaced()
u.mu.Unlock()
switch st := u.json().State; {
case in:
case st == "ready":
// a newer version out since is downloaded first, and waited for
u.mu.Lock()
asked := u.waitAsked
@@ -136,7 +142,7 @@ func (u *updater) waitFor(gen int) {
if u.asking() || u.json().State != "ready" {
continue
}
case "checking", "downloading":
case st == "checking", st == "downloading":
continue
default:
// nothing left to restart into (a newer one failed to download)