Files
magpie/internal/gui/tests/agent-here.test.cjs
T
yetone 6b81344301 library: the keep-here switch says sync, and is on while it syncs (bin.90)
bin.90 on Discord read the Library editor's 「只在这台电脑」 switch as a
LAN-sharing switch: "this computer only" says nothing about what it keeps
from where. It is about sync, so it now says so.

- Library editor (MCP servers, skills): the switch is "Sync to your other
  computers" (同步到其他电脑 / 同步到其他電腦 / ほかのコンピュータと同期 /
  Mit deinen anderen Computern synchronisieren), on while the server or
  skill syncs. Its note says off keeps it here, and a sync from the
  others neither removes it nor replaces it.
- The stored value keeps its meaning: `local` true is still kept here.
  The switch shows !local and saves !on, so every saved library.json,
  sync payload and CLI flag (`magpie library mcp local NAME on|off`)
  means what it meant.
- Row tag: "Not synced" (不同步 / 同步しない / Nicht synchronisiert) where
  it said "This computer only", in the Library, the TUI ("not synced ·")
  and `magpie library` output.
- Agents page sibling (the same words for an agent's picks): its menu
  item is "Don't sync picks to your other computers", its tag "Not
  synced". The agentsHere setting is unchanged.
- docs/subsystems/library.md and sync-backup.md name the new labels.

app.js stays in its budget: origin/main 8af751987 was already 31 bytes
over coreScriptBudget (1,533,833 > 1,533,802), so a comment in
setAgentHidden was cut to one line (core 1,533,756 now), no raise.

Run on mote, rebased on 8af751987, budget again at 2cfeda3d3:
- GUI: mcp-local-server, agent-here, i18n-keys, skill-off-here: 78/78
  before the rebase, in Chromium and WebKit, every language, at 390, 640
  and 1100 wide and in the panel; after it agent-here, i18n-keys and
  mcp-local-server 56/56, agent-here again 30/30 after the trim.
- go test ./internal/tui ./internal/cli ok; ./internal/gui ok except
  TestMainWindowCorners/macOS_26_SDK, mote's macOS 27 (#3949, open,
  the same without this change); TestCoreScriptBudget ok after the trim.
- go vet ./internal/tui ./internal/cli ./internal/gui; GOOS=linux go vet
  -tags nogui and GOOS=windows go vet of tui and cli; gofmt -l clean.

Broken by hand: saving `d.local = on` (no negation) turns
mcp-local-server red (expected 'false', got 'true').

Not tried: a real sync between two computers with the switch flipped;
the stored value's meaning is checked through the saved request only.
2026-11-03 12:21:49 +08:00

116 lines
6.2 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// An agent's picks can be kept to this computer, as an MCP server can
// (chenxiang0010 on Discord: 「agent当前选择的模型可不可以像mcp那样 只对当前设备生效」).
// The row's menu has "Don't sync picks to your other computers" (said as
// sync, not "This computer only", which read as sharing: bin.90 on
// Discord): it posts agents/here, is ticked once on, and the window's row
// says "Not synced" beside the version, in every
// language, in Chromium and WebKit, in the window and the tray panel.
// Off again, the tick and the words go. No backend: faked here.
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 CHECK = "m3.5 8.5 3 3 6-7";
function fixture(lang, posts) {
let here = [];
const settings = () => ({ lang, theme: "light", agentsHere: here });
const state = () => ({
agents: [{
id: "codex", name: "Codex", path: "~/.codex/config.toml", icon: "codex", wired: true,
fields: [{ key: "model", label: "model", value: "glm-5.3-flash", options: [{ value: "glm-5.3-flash", label: "GLM-5.3-Flash", icon: "generic" }] }],
}],
profiles: [], settings: settings(),
});
async function serve(route) {
const req = route.request(), url = new URL(req.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/agents/here") {
const b = req.postDataJSON();
posts.push(b);
here = here.filter((x) => x !== b.agent);
if (b.on) here.push(b.agent);
return json(settings());
}
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/agents/cli") return json({ agents: { codex: { version: "0.166.0" } }, pending: false });
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true } });
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)];
const body = await fs.readFile(file).catch(() => null);
await route.fulfill(body ? { body, contentType } : { status: 404, body: "" });
}
return { serve };
}
const row = '.row.agent[data-id="codex"]';
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const where of ["window", "narrow", "panel"]) {
test(`${engine} ${lang} ${where}: an agent's picks kept to this computer`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const size = { window: { width: 1100, height: 700 }, narrow: { width: 640, height: 700 }, panel: { width: 360, height: 640 } }[where];
const page = await browser.newPage({ viewport: size });
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [], posts = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", fixture(lang, posts).serve);
await page.goto("http://magpie.test/" + (where === "panel" ? "?mode=panel" : ""));
await page.locator(row).waitFor();
const name = await page.evaluate(() => t("Don't sync picks to your other computers"));
const word = await page.evaluate(() => t("Not synced"));
if (lang !== "en") assert.notEqual(name, "Don't sync picks to your other computers", "not translated");
if (lang !== "en") assert.notEqual(word, "Not synced", "not translated");
const item = () => page.locator(".row-menu .rm-item", { hasText: name });
const open = async () => {
await page.locator(row).click({ button: "right" });
await item().waitFor();
};
const ticked = () => item().locator("path").getAttribute("d").then((d) => d === CHECK);
await open();
assert.equal(await ticked(), false, "ticked before it was turned on");
await item().click();
await page.waitForFunction(() => !document.querySelector(".row-menu"));
assert.deepEqual(posts, [{ agent: "codex", on: true }]);
const tag = page.locator(`${row} .ag-here`);
if (where === "panel") assert.equal(await tag.count(), 0, "the panel's row has no room for it");
else {
await tag.waitFor();
assert.equal(await tag.textContent(), word);
// the row keeps its width and the name stays whole
const fit = await page.locator(row).evaluate((r) => {
const n = r.querySelector(".who .name");
return { over: r.scrollWidth - r.clientWidth, cut: n.scrollWidth - n.clientWidth };
});
assert.ok(fit.over <= 0 && fit.cut <= 0, `the row overflows: ${JSON.stringify(fit)}`);
}
await open();
assert.equal(await ticked(), true, "not ticked once on");
// off again: the tick and the words go
await item().click();
await page.waitForFunction(() => !document.querySelector(".row-menu"));
assert.deepEqual(posts.at(-1), { agent: "codex", on: false });
await page.waitForFunction((sel) => !document.querySelector(sel), `${row} .ag-here`);
await open();
assert.equal(await ticked(), false, "still ticked once off");
assert.deepEqual(errors, []);
});
}
}
}