gui: a sync notice's Show says why the sync folder didn't open (#4066)

In Settings › Sync and backup, the notice a sync leaves (what it
replaced here or on the server) has Show, which opens the sync folder
in the file manager. When that failed, nothing was said (#4066):
renderSync named the sync row's text `status`, a local that hid the
status() function, so Show's `.catch((e) => status(e.message, "err"))`
called that string, threw a TypeError, and the status line stayed
empty. The local is named `line` now, so the catch reaches status(),
and Show says its error in red, as a failed call does elsewhere. It
fails, for example, when the sync folder is gone, or on a Linux
without xdg-open. No other function in internal/gui/assets declares a
status of its own (a git grep at 60561129). app.js is 10 bytes
smaller.

What was run (tree 2fb0c3db, on origin/main 60561129, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, the Go tests at umask 077:
- sync-note-show.test.cjs, new (Node 22.22.1, Playwright 1.62.1): with
  WebDAV sync on, a notice of providers replaced here, and
  davsync/reveal answering 400 with Wails' error for a Linux without
  xdg-open, Show asks for the folder once, the status line says that
  error in red (role alert), and nothing throws. In English and
  Chinese, Chromium and WebKit, 3 runs: 4 of 4 each run.
- 60561129's app.js put back, the new test kept: 0 of 4, each red at
  "the status line says why the folder didn't open" with the status
  line empty, after Show had asked for the folder.
- The 14 other GUI files a git grep finds #sync in (11 with #syncList,
  Settings' sync section; refresh-page, sync-spin and update-hide have
  only #sync, the header's refresh button), each alone in both
  engines: green, but for s3-sync in WebKit, en, red at "picking
  WebDAV must not scroll the page" in 4 runs of 4, and at 60561129 in
  3 runs of 3; #3413 has the same subtest red, at its S3 click.
- i18n-keys, which reads the strings with no browser: 3 of 4, the
  fourth red as at 60561129, "a plugin's words are its own", for
  plugins/routing/i18n.js's "masking…" (#4053); 4 of 4 at 174250b2,
  which fixed it.
- go test -tags nogui -count=1 -v ./internal/gui, Bun 1.4.2 first on
  PATH: 418 pass, 3 skip (TestCLIBehindIsLstatOnlyAndDismissible, Mac
  only; TestHandoverSuccessor, run by another test; TestUsageScale, opt
  in), and 2 red, its gateway tests TestGatewayHeldByAContainer and
  TestGatewayFixQuitsOnlyAMagpie (#3649). TestCoreScriptBudget passes.
- gofmt -l clean. go vet -tags nogui for linux, windows and darwin, go
  vet for windows, go build -tags nogui for linux and darwin and go
  build for windows: exit 0 each. go vet and go build without the tag
  on linux: exit 1 (no libsoup-3.0 or gio-unix-2.0 here).
- go test -tags nogui -count=1 -timeout 45m ./... (Bun 1.4.2, log
  kept; 8m22s, load 28 at its start): 71 packages ok, and 14 tests red
  in 6 packages, none of them this commit's tests or what they cover
  (internal/gui's are its gateway tests): agent TestInstalledVersion,
  TestHowInstalled, TestCursorFolderFromTheEditorIsNotTheCLI,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI and
  TestOmpDetectedWithPiDir (#3141);
  TestReasonixCLIRequiresSupportedNativeVersion and
  TestReasonixCLIRecoversAfterProbeTimeout (#3641); edit
  TestWriteAtomicReadOnlyHardLink and testenv TestProgram (umask
  077, #3640); gateway TestPluginToldWhereTheAgentWorks (the /tmp/.git
  of #3675); gui TestGatewayHeldByAContainer and
  TestGatewayFixQuitsOnlyAMagpie (#3649); sessions TestAgyTitleLater
  (#3708), which alone passes 30 of 30 here and at 60561129.

Not tried: the real app's Show, on any system (no file manager or
display here).

Reviewed and run again by the maintainer at the stack's tree 45994757c
(this commit and the six beside it, on origin/main 90518de26), go1.26.8:
- mote (macOS, arm64): gofmt -l clean; go vet and go build for darwin,
  GOOS=linux -tags nogui and GOOS=windows (library, plugin, gui): exit 0.
  go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  internal/proc TestNoCommandBypassesProc (#4491), both red on main
  from b09349d17 and c59c547c5, in files this stack doesn't touch.
  go test -race -run 'TestWSL|TestTagged|TestPinnedPiCache' for
  library and plugin: ok.
- magpie-desktop (Linux, wsl-run; WebKit hangs on mote), Chromium and
  WebKit: every library-*, sync-*, s3-sync, github-sync and i18n-keys
  file, 4 at a time: 1003 of 1020. The 17 reds are in 6 files no commit here
  touches: i18n-keys ("Unmarked", #4524), library-chip-fan, -items,
  -mcp-health, -mcp-hub (#4483) and -mcp-tools. Those 6 alone, one at a
  time, at load ~60: 74 of 92 here, 77 of 92 at 90518de26 itself. Red
  in both: i18n-keys, -chip-fan and -items in WebKit, -mcp-tools in
  Chromium ja 420; -mcp-health green in both; -mcp-hub's WebKit case
  red here only, the case #4483 has red on main. -chip-fan and -items
  are #3072's and #4501's kind, WebKit under load.
- Note: main has said Show's error since 40af66027 (#3685), whose
  .catch(statusErr) reaches the module's status() past the local; the
  "60561129's app.js put back" run above is from before it. So on main
  this commit is the rename, which keeps the next catch written there
  from hitting the string, and the test, which guards Show's error.
- Broken by hand on Linux: the local named status again and Show's
  catch back to `(e) => status(e.message, "err")`: sync-note-show red,
  0 of 4, in both engines.
This commit is contained in:
JoeyWu-tech
2026-10-31 17:00:14 +08:00
committed by yetone
parent 75d63a1545
commit 225b494bea
2 changed files with 91 additions and 5 deletions
+5 -5
View File
@@ -20204,7 +20204,7 @@ async function renderSync(v) {
if (v.agents !== false) goes.push("agents");
if (v.library !== false) goes.push("library");
if (v.usage) goes.push("usage");
let status = t("Keeps {parts} the same on every computer", {
let line = t("Keeps {parts} the same on every computer", {
parts: t(v.keys === false ? "providers without their API keys" : "providers with their API keys") + t(", ") + parts(goes) });
const s3 = v.on && v.kind === "s3";
const github = v.on && v.kind === "github";
@@ -20213,13 +20213,13 @@ async function renderSync(v) {
// a bucket is named by its address, and the server it is on unless AWS
const host = github ? [v.url, v.branch].filter(Boolean).join(" · ")
: s3 ? [v.url, v.endpoint && hostOf(v.endpoint.includes("://") ? v.endpoint : "https://" + v.endpoint)].filter(Boolean).join(" · ") : hostOf(v.url);
status = v.error ? t("Couldn't sync: {error}", { error: v.serverFile ? serverFileSaid(v.serverFile) : t(v.error) })
line = v.error ? t("Couldn't sync: {error}", { error: v.serverFile ? serverFileSaid(v.serverFile) : t(v.error) })
: v.last ? t("Synced {when} · {host}", { when: syncWhen(v.last), host }) : t("Not synced yet · {host}", { host });
// the other kind's server, kept from before sync moved here
for (const kind of Object.keys(syncServers(v))) status += " · " + t("{kind} settings kept", { kind: syncNames[kind] });
if (v.auto === 0) status += " · " + t("only when asked");
for (const kind of Object.keys(syncServers(v))) line += " · " + t("{kind} settings kept", { kind: syncNames[kind] });
if (v.auto === 0) line += " · " + t("only when asked");
}
const sub = row(t(github ? "GitHub sync" : s3 ? "S3 sync" : v.on ? "WebDAV sync" : "WebDAV, S3 or GitHub sync"), status, ...(v.on
const sub = row(t(github ? "GitHub sync" : s3 ? "S3 sync" : v.on ? "WebDAV sync" : "WebDAV, S3 or GitHub sync"), line, ...(v.on
? [btn(t("Sync now"), async (e) => { e.target.classList.add("busy"); renderSync(await api("davsync/now", {}).catch((x) => ({ ...v, error: x.message }))); }),
btn(t(syncOpen === "dav" ? "Close" : "Edit"), toggle("dav"))]
: [btn(t(syncOpen === "dav" ? "Close" : "Set up"), toggle("dav"))]));
@@ -0,0 +1,86 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// A sync's notice (what it replaced here or on the server) has Show, which
// opens the sync folder in the file manager. When that fails, Show says why
// on the status line, in red, as any failed call does, and nothing throws.
// renderSync named its row's text status, a local that hid status(), so
// Show's catch called that string, threw, and the status line stayed empty
// (#4066). In English and Chinese, Chromium and WebKit. The API is faked;
// nothing is synced or opened.
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 { openPart } = require("./reader.cjs");
const assets = path.resolve(__dirname, "../assets");
// Wails' words on a Linux with no xdg-open
const FAILED = 'failed to open the file explorer: exec: "xdg-open": executable file not found in $PATH';
function serve(lang, posts) {
const settings = {
theme: "light", lang, tray: "panel", version: "test", dir: "/tmp/magpie",
gateway: "http://127.0.0.1:3425", visionModels: [], imageGenModels: [],
fx: { rate: 7.2, stale: false },
};
const sync = { on: true, kind: "webdav", url: "https://dav.jianguoyun.com/dav/", user: "me", passwordSet: true, passphraseSet: true,
keys: true, agents: true, library: true, auto: 3, last: new Date().toISOString(),
notice: { at: new Date().toISOString(), here: ["providers"], saved: "/tmp/magpie/sync" } };
return async (route) => {
const request = route.request();
const pathname = new URL(request.url()).pathname;
const json = (data) => route.fulfill({ json: data });
if (pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
if (pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (pathname === "/api/state") return json({ agents: [], profiles: [], settings });
if (pathname === "/api/settings") return json(settings);
if (pathname === "/api/usage/quotas") return json([]);
if (pathname === "/api/groups") return json({ groups: [], models: [] });
if (pathname === "/api/plugins") return json({ plugins: [] });
if (pathname === "/api/davsync") return json(sync);
if (pathname === "/api/davsync/reveal") {
posts.push("reveal");
return route.fulfill({ status: 400, json: { error: FAILED } });
}
if (pathname.startsWith("/api/")) return json({});
const file = path.join(assets, pathname === "/" ? "index.html" : pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
return route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const show = { en: "Show", zh: "显示" };
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
test(`${engine} ${lang}: a sync notice's Show says why the folder didn't open`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await (await browser.newContext({ viewport: { width: 900, height: 700 }, reducedMotion: "reduce" })).newPage();
const errors = [], posts = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, posts));
t.after(async () => {
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-sync-note-show.png`), fullPage: true });
}
await browser.close();
});
page.setDefaultTimeout(5000);
await page.goto("http://magpie.test/");
await page.locator("#prefs").click();
await openPart(page, "sync");
const note = page.locator("#syncList .sync-note");
await note.waitFor({ state: "visible" });
await note.getByRole("button", { name: show[lang], exact: true }).click();
await page.waitForFunction(() => document.querySelector("#status").textContent !== "", null, { timeout: 3000 }).catch(() => {});
assert.deepEqual(posts, ["reveal"], "Show asked for the sync folder");
const status = page.locator("#status");
assert.equal(await status.textContent(), FAILED, "the status line says why the folder didn't open");
assert.ok(await status.evaluate((s) => s.classList.contains("err")), "in red");
assert.equal(await status.getAttribute("role"), "alert");
assert.deepEqual(errors, [], "nothing threw");
});
}
}