baranwang on X asked to keep Claude Desktop's own (1P, Anthropic) sign-in while using magpie. Turning on "Separate app" in Claude Desktop's row on the Agents page (or `magpie claude-desktop launcher add`) moves magpie's 3P wiring into ~/Library/Application Support/Claude-Magpie-3p and adds ~/Applications/Claude Magpie.app. That launcher opens Claude.app with --user-data-dir on that folder, so it runs side by side with the user's own Claude.app. Its icon is Claude's icon with a magpie badge. Off is the default, and turning it off (`launcher remove`) moves the wiring back and removes the app. It is macOS only: Desktop's packaged app strips CLAUDE_USER_DATA_DIR, and on Windows it hardcodes LOCALAPPDATA\Claude-3p. The folder ends in -3p because Desktop adds -3p to any other name. Restarting the isolated app ends only its own process (pkill on its --user-data-dir) and opens the launcher again. Run at 1b25cda26 (this change on origin/mainbe9dbce02); rebased ontofdabddeb4(catalog only), then go build ./..., vet and the budget and launcher tests again: ok. All on mote: - gofmt -l clean; go vet ./internal/...; GOOS=linux go vet -tags nogui and GOOS=windows go vet on agent, cli, desktopiso, desktopdir, gui. - go test (whole packages) desktopiso, desktopdir, settings, settingsapi, proc: ok. -run Isolated|TestDesktopInstance|TestAddStartsDesktopOnTheFolder| TestScript|TestAddLeavesTheirs|ClaudeDesktop|Restart in agent; TestClaudeDesktopLauncher|TestEveryRouteHasACommandOrIsNamed|Help in cli; TestCoreScriptBudget|TestSettingsSaveKeepsWhatItDoesNotSend|Budget|Desktop in gui and gateway: ok. - An earlier full `go test ./...` at fef23255f had four reds, all from this change and fixed here: the route without a command (now in notYet), settings_keep's DesktopIsolated, os/exec instead of proc, and the core script budget (paid by sharing the switch helper with the largest-window line and cutting comments; no raise). A second full run of the touched packages queued ~7h on mote's suite lock behind other sessions and was stopped; the targeted runs above replace it. - GUI on mote, both engines: desktop-isolated (new; en, zh, zh-TW, ja, de; 1100 and 640; aria-checked, posts, status text, no scroll, no select, absent without `isolated`), desktop-longest, click-scroll, plain-names, i18n-keys: ok. page-width-steady, panel-fold and zero-priced-free are red, the same 33 tests at origin/mainbe9dbce02(diffed): #4541/#5013, #5796, #5262. i18n-keys' "a plugin's words are its own" is red on main too (#5332). - Whole GUI suite on WSL at an older head: 400 of 22778 red across ~100 files of other pages, in line with #5559 (478 of 21666 on main there). Not rerun on mote. Real use, on mote in a sandbox HOME with Claude.app 4.23118 linked in: `claude-desktop magpie`, then `launcher add`, moved the wiring to Claude-Magpie-3p (deploymentMode 3p, mcpServers and locale carried). Opening Claude Magpie.app started Claude with --user-data-dir=.../Claude-Magpie-3p; it wrote configLibrary and model-catalog there (3P mode) and no -3p-3p folder. A second, 1P Claude ran beside it on its own sandbox folder. Opening the launcher again kept one instance; the pkill pattern matched only the isolated pid; both quit on SIGTERM. `launcher remove` put the wiring back and removed the app. Broken by hand: a folder without -3p (Desktop made -3p-3p), the CLAUDE_USER_DATA_DIR env route (ignored by the packaged app), os/exec in the quit (TestNoCommandBypassesProc red). Not tried: a screenshot of the running app (screencapture fails over ssh); a model request through a gateway from the isolated app; Windows and Linux (not offered there). Known: the Dock shows Claude's own icon for the running isolated app, and Chrome pairing is off in a moved userData folder.
122 lines
7.0 KiB
JavaScript
122 lines
7.0 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// Claude Desktop on magpie from an app of its own (#5671): on a Mac, Claude
|
|
// Desktop's opened row has a "Separate app" line with a Claude Magpie
|
|
// switch. Off as before; a click posts the new choice, the switch follows
|
|
// the state the reply carries, and no click scrolls the page. Where the
|
|
// state has no isolated (Windows, Linux) the line isn't there. Every
|
|
// language, wide and narrow. 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");
|
|
|
|
function fixture(lang, offered = true) {
|
|
const settings = { lang, theme: "light" };
|
|
const posts = [];
|
|
const iso = { on: false };
|
|
const state = () => ({
|
|
agents: [{
|
|
id: "claude-desktop", name: "Claude Desktop", path: "/test/claude_desktop_config.json", icon: "claude-color", wired: true,
|
|
fields: [{ key: "provider", label: "provider", value: "magpie", options: [{ value: "magpie", label: "magpie", icon: "magpie" }] }],
|
|
models: { shown: 2, listed: 2, by: [{ name: "OpenCode Go", icon: "opencode", n: 2 }], names: ["DeepSeek V4 Pro", "Exo Free"] },
|
|
...(offered ? { isolated: { ...iso } } : {}),
|
|
}],
|
|
profiles: [], 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/settings/desktop-isolated") {
|
|
const body = req.postDataJSON();
|
|
posts.push(body);
|
|
iso.on = body.on;
|
|
if (body.on) iso.launcher = "/test/Applications/Claude Magpie.app";
|
|
else delete iso.launcher;
|
|
return json(state());
|
|
}
|
|
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: {}, 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)];
|
|
await route.fulfill({ body: await fs.readFile(file), contentType });
|
|
}
|
|
return { serve, posts };
|
|
}
|
|
|
|
const W = {
|
|
en: { k: "Separate app", hint: "Your own Claude Desktop stays signed in with Anthropic. macOS only.", ok: "Open Claude Magpie from Applications", details: "Details" },
|
|
zh: { k: "独立应用", hint: "你自己的 Claude Desktop 保持 Anthropic 登录。仅限 macOS。", ok: "从「应用程序」打开 Claude Magpie", details: "详情" },
|
|
"zh-TW": { k: "獨立應用程式", hint: "你自己的 Claude Desktop 維持 Anthropic 登入。僅限 macOS。", ok: "從「應用程式」打開 Claude Magpie", details: "詳情" },
|
|
ja: { k: "独立アプリ", hint: "ご自身の Claude Desktop は Anthropic にサインインしたままです。macOS のみ。", ok: "「アプリケーション」から Claude Magpie を開いてください", details: "詳細" },
|
|
de: { k: "Eigene App", hint: "Dein eigenes Claude Desktop bleibt bei Anthropic angemeldet. Nur macOS.", ok: "Öffne Claude Magpie unter Programme", details: "Details" },
|
|
};
|
|
const cd = '.row.agent[data-id="claude-desktop"]';
|
|
const sw = `${cd} .ag-isolated .lib-switch`;
|
|
|
|
async function open(engine, lang, width, offered, t) {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
const page = await browser.newPage({ viewport: { width, height: 700 } });
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
const fx = fixture(lang, offered);
|
|
await page.route("**/*", fx.serve);
|
|
t.after(() => browser.close());
|
|
await page.goto("http://magpie.test/");
|
|
await page.locator(cd).waitFor();
|
|
await page.locator(`${cd} .ag-link`, { hasText: W[lang].details }).click();
|
|
await page.locator(`${cd} .ag-exp`).waitFor();
|
|
return { page, fx, errors };
|
|
}
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of Object.keys(W)) {
|
|
for (const width of [1100, 640]) {
|
|
test(`${engine} ${lang} ${width}px: Claude Desktop's row turns Claude Magpie on and off`, async (t) => {
|
|
const w = W[lang];
|
|
const { page, fx, errors } = await open(engine, lang, width, true, t);
|
|
const line = page.locator(`${cd} .ag-exp .ag-isolated`);
|
|
await line.waitFor();
|
|
const row = page.locator(`${cd} .ag-exp .ag-kv`, { has: page.locator(".ag-isolated") });
|
|
assert.equal(await row.locator(".ag-k").textContent(), w.k);
|
|
assert.equal(await line.locator(".ag-isolated-say").textContent(), "Claude Magpie");
|
|
assert.equal(await line.locator(".ag-hint").textContent(), w.hint);
|
|
assert.equal(await page.locator(sw).getAttribute("aria-checked"), "false", "on before it was switched");
|
|
const box = await line.boundingBox();
|
|
assert.ok(box.x + box.width <= width && box.height > 0, JSON.stringify(box));
|
|
|
|
const y = await page.evaluate(() => scrollY);
|
|
await page.locator(sw).click();
|
|
await page.waitForFunction((sel) => document.querySelector(sel)?.getAttribute("aria-checked") === "true", sw);
|
|
assert.deepEqual(fx.posts, [{ on: true }]);
|
|
assert.equal(await page.locator("#status").textContent(), w.ok);
|
|
// and off again, by its words
|
|
await page.locator(`${cd} .ag-isolated .ag-isolated-say`).click();
|
|
await page.waitForFunction((sel) => document.querySelector(sel)?.getAttribute("aria-checked") === "false", sw);
|
|
assert.deepEqual(fx.posts, [{ on: true }, { on: false }]);
|
|
|
|
assert.equal(await page.evaluate(() => scrollY), y, "a click scrolled the page");
|
|
assert.equal(await page.locator("select").count(), 0, "a native select");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
test(`${engine}: no Separate app line where Desktop can't run so`, async (t) => {
|
|
const { page, errors } = await open(engine, "en", 1100, false, t);
|
|
assert.equal(await page.locator(`${cd} .ag-isolated`).count(), 0);
|
|
assert.equal(await page.locator(`${cd} .ag-exp .ag-k`, { hasText: W.en.k }).count(), 0);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|