nnlrl_75403 on Discord: a magpie used as another's Remote magpie stayed on
its old version after the local one updated, and had to be updated by
hand on the other computer. Now nothing needs setting up:
- provider.KeepRemotesUpdated (started by the app's updater and by
magpie serve) runs UpdateRemotes 30 s after start and hourly. A
released build with automatic updates on reads each Remote magpie's
version (GET /v1) and, when it is older, asks it through
POST /v1/magpie/update?version=<v> with the provider's key, at most
once in six hours per version. Off here, or a dev build: nothing asked.
- The remote updates as its own automatic update would: the app
downloads and restarts once idle (updater.updateAsked → download,
waitIdle); magpie serve puts the latest in where it runs from, one at
a time, never elevated, and serveFollow restarts into it. Automatic
updates or downloads off there: it answers "off" and stays.
- A copy that can't replace itself says why: a container (docker pull
ghcr.io/yetone/magpie:latest), a package manager's (its command), a
folder it can't write, a build from source. A magpie from before the
route answers 404 ("too old"), a read-only or held key is "refused".
The provider's row on the Providers page adds a short status to its
line ("updating to v…" for 30 min, or "can't update itself" etc.),
with the reason and the command in its tooltip. en/zh/zh-TW/ja/de.
- The route replaces the program, so it takes the Codex reset's
admission: another machine only while shared, never a browser page,
an enabled key with full access from loopback too (401 without one),
read-only 403 gateway_key_read_only, held 403 gateway_key_held. It is
in readOnlyRefused and the CORS route list.
App.js stays under TestCoreScriptBudget by cutting two comments; the
budget is not raised.
Run (on mote, at the tree committed here):
- gofmt -l internal/: clean. go vet of gateway, gui, cli, provider for
darwin, GOOS=linux and GOOS=windows: ok.
- go test -count=1 ./internal/gui ./internal/cli ./internal/provider
./internal/gateway: gui and cli ok but for #5644's two settings tests
(red on main since 6b7ee4a98, owned); provider and gateway were
still running at the push, and go in the full run after it.
- Rebased on origin/main c7c05dcf2, again: gofmt, vet, the new tests,
ReadOnlyKeyEveryRoute, CORS, TestCoreScriptBudget (not raised) and
both GUI files 32 of 32: ok.
- New: TestRemoteUpdateNeedsAFullKey (no key from loopback, Origin null,
an app scheme, *.localhost, a rebound Host, a foreign page with and
without the full key, another machine with none or a wrong key,
read-only and held keys, then not shared; the updater is never
called until a full key asks, from LAN and loopback),
TestRemoteMagpieAskedToFollow (UpdateRemotes against a real gateway:
dev build, same and newer remote, NoAutoUpdate here, asked once per
version, container answer kept, read-only key refused, a 404 magpie
"old"), TestUpdateAskedByAnotherMagpie, TestRemoteUpdateNote,
TestServeUpdateAsked.
- GUI: remote-update.test.cjs (new) and remote-self.test.cjs, Chromium
and WebKit, 1100 and 420 wide, en/zh/ja/de: 32 of 32 ok, with every
key checked in zh, zh-TW, ja and de. i18n-en-no-cjk ok. i18n-keys'
"a plugin's words are its own" is red, the same on origin/main
f8525323d (#5327/#5332, #5426, #5482); its other cases ok.
Broken by hand, each red, then put back: the handler's key check
(loopback without a key got 200 updating), its held-key check, the
route itself (404 = the old code), asking a remote that is current,
ignoring NoAutoUpdate here, asking again for the same version, the
app ignoring automatic updates off, the app never waiting to restart,
serve's single flight (2 downloads), serve's container answer.
The handler's own Origin and not-shared checks stay green when removed:
corsGuard and lanGuard refuse those first; they are kept as the Codex
reset keeps them.
Not tried: a real update of a real remote (a Docker magpie and an app
on another Mac) end to end; Windows and Linux runs of the new tests
(vet only); the full suite (run after the push).
Reported-by: nnlrl_75403
111 lines
7.1 KiB
JavaScript
111 lines
7.1 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// nnlrl_75403 on Discord: once magpie updates, the Remote magpies it uses
|
|
// are asked to update too. A Remote magpie's row says what came of it:
|
|
// updating to the version, or, where it can't, why, with what to run
|
|
// there over it (a container's image, a package manager's command). A row
|
|
// with nothing to say says nothing. In English, Chinese, Japanese and
|
|
// German, Chromium and WebKit, at 1100 and 420 wide.
|
|
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 remote = (id, name, more = {}) => ({
|
|
id, name, preset: "remote-magpie", icon: "magpie", host: "192.168.1.20:3425", chat: "http://192.168.1.20:3425/v1", responses: "", anthropic: "", catalog: "", routing: "",
|
|
models: [{ id: "own/m1", name: "m1", on: true }], agents: [], fallback: [], headers: {}, keyList: [], key: { set: true, masked: "mg-…a1b2" }, ready: true, ...more,
|
|
});
|
|
|
|
function serve(lang, list) {
|
|
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
|
return async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/providers") return json({ providers: list, presets: [], excluded: [], gateway: { running: true, window: true } });
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
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" }[path.extname(file)];
|
|
await route.fulfill({ body: await fs.readFile(file), contentType });
|
|
};
|
|
}
|
|
|
|
const said = {
|
|
en: { updating: "updating to v0.1.200", cant: "can't update itself", off: "automatic updates off", there: "update it there" },
|
|
zh: { updating: "正在更新到 v0.1.200", cant: "无法自行更新", off: "已关闭自动更新", there: "请在那台电脑上更新" },
|
|
ja: { updating: "v0.1.200 に更新中", cant: "自動で更新できません", off: "自動更新はオフ", there: "あちらで更新してください" },
|
|
de: { updating: "wird auf v0.1.200 aktualisiert", cant: "kann sich nicht selbst aktualisieren", off: "automatische Updates aus", there: "dort aktualisieren" },
|
|
};
|
|
// the keys internal/gui/update_remote.go sends
|
|
const strings = [
|
|
"can't update itself",
|
|
"updating to {v}",
|
|
"This magpie updated, so that one was asked to update to {v} too. It restarts into it once nothing is in flight.",
|
|
"automatic updates off",
|
|
"Automatic updates are turned off on that computer, so it stays on its version.",
|
|
"update it there",
|
|
"That magpie is too old to be updated from here: update it on that computer once.",
|
|
"Updating it from here takes a gateway key with full access there; this provider's key is read-only or held.",
|
|
"It runs in a container: pull the new image (docker pull ghcr.io/yetone/magpie:latest) and recreate the container.",
|
|
"{manager} installed it there: update it with {manager}.",
|
|
"{manager} installed it there: update it with {cmd}",
|
|
"It was built from source: update it the way it was built.",
|
|
"magpie can't replace itself where it runs on that computer: update it there.",
|
|
];
|
|
|
|
const rows = [
|
|
remote("home", "Home", { remoteUpdate: { say: "updating to {v}", tip: strings[2], v: "v0.1.200" } }),
|
|
remote("nas", "NAS", { remoteUpdate: { say: "can't update itself", tip: strings[8] } }),
|
|
remote("arch", "Arch", { remoteUpdate: { say: "can't update itself", tip: strings[10], manager: "pacman", cmd: "yay -S magpie-bin" } }),
|
|
remote("lab", "Lab", { remoteUpdate: { say: "automatic updates off", tip: strings[4] } }),
|
|
remote("old", "Old", { remoteUpdate: { say: "update it there", tip: strings[6] } }),
|
|
remote("office", "Office"),
|
|
];
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const width of [1100, 420]) {
|
|
for (const lang of Object.keys(said)) {
|
|
test(`${engine} ${width} ${lang}: a Remote magpie's row says what came of asking it to update`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, rows));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
await page.locator(".row.provider").first().waitFor();
|
|
const rup = (name) => page.locator(".row.provider", { hasText: name }).first().locator(".sub .rup");
|
|
const s = said[lang];
|
|
for (const [name, text] of [["Home", s.updating], ["NAS", s.cant], ["Arch", s.cant], ["Lab", s.off], ["Old", s.there]]) {
|
|
assert.equal(await rup(name).count(), 1, `${name} says something`);
|
|
assert.equal((await rup(name).textContent()).trim(), text, name);
|
|
const tip = await rup(name).getAttribute("title");
|
|
assert.ok(tip.length > 20, `${name}'s tip says why: ${tip}`);
|
|
}
|
|
assert.match(await rup("NAS").getAttribute("title"), /docker pull ghcr\.io\/yetone\/magpie:latest/);
|
|
assert.match(await rup("Arch").getAttribute("title"), /yay -S magpie-bin/);
|
|
assert.match(await rup("Arch").getAttribute("title"), /pacman/);
|
|
assert.match(await rup("Home").getAttribute("title"), /v0\.1\.200/);
|
|
assert.doesNotMatch(await rup("Arch").getAttribute("title"), /\{(manager|cmd)\}/);
|
|
assert.equal(await rup("Office").count(), 0, "a row with nothing to say says nothing");
|
|
// the line keeps within the row
|
|
const row = await page.locator(".row.provider", { hasText: "NAS" }).first().boundingBox();
|
|
const sub = await page.locator(".row.provider", { hasText: "NAS" }).first().locator(".sub").boundingBox();
|
|
assert.ok(sub.x >= row.x && sub.x + sub.width <= row.x + row.width + 1, `the line fits the row at ${width}`);
|
|
if (lang === "en") {
|
|
const missing = await page.evaluate((ks) => ["zh", "zh-TW", "ja", "de"].flatMap((l) => ks.filter((k) => !I18N[l][k]).map((k) => `${l}: ${k}`)), strings);
|
|
assert.deepEqual(missing, [], "every string has its translations");
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
}
|