KoiLx0 runs one magpie as a client of another, through a gateway key, and had to switch every agent on by hand on the client before it took the remote's models. A Remote magpie's editor now has "Connect new agents to this remote" (自动接入新 agent) under Advanced, off by default. It is kept per computer in the stash (remote.<id>.connectAgents), not in providers.json, so a synced or shared providers list doesn't turn it on anywhere else. No server-side key permission. With it on, the follow loop (FollowRemotePicks, every 5 minutes, and at once when the switch is turned on) connects an agent installed here that the remote has connected, on the remote's pick (connectFromRemote), and records it as <agent>.remote.auto = on. An agent the user disconnected here is never connected again: - one with the Agents page's Disconnect mark, connected or not before; - one recorded on that is no longer connected (taken out by hand in its file, or by any other route) is recorded off. An agent magpie put back on quit (quit.restored) is left to RewireOnStart and not taken for a disconnect. Connecting it by hand records on again. The follow throttle's time is now under a mutex, since the save handler resets it from another goroutine. The switch shows in /api/providers as connectAgents and is saved as connectAgents (a save that leaves it out keeps it; a provider that isn't a Remote magpie is refused it). Advanced opens on its own while it is on. docs/subsystems/providers-accounts.md says all of this. app.js stays within its budget (TestCoreScriptBudget): the Remote magpie's three ticks (MCP servers, skills and prompts, agents) and their save are one loop, which the new switch costs less than it saves. Run: - mote, go test -tags nogui -count=1 -timeout 45m ./... with the first draft of app.js: every package ok but internal/gui, where only TestCoreScriptBudget failed (1087333 > 1086971). After the loop, rebased on origin/main187d06724(budget passes there alone), at this head: TestCoreScriptBudget, internal/gui, internal/agent and internal/cli ok. - mica: TestRemoteConnectsNewAgents, TestConnectFollowsTheRemoteMagpiesPicks, TestProviderSaveConnectAgents ok. - mote: go vet (darwin), GOOS=linux go vet -tags nogui, GOOS=windows go vet on internal/agent and internal/gui ok; gofmt -l clean. - GUI, mica, both engines, at f261f7ba6 (before the loop and the rebase): remote-connect-agents.test.cjs (new: under Advanced and closed while off, sent as ticked, Advanced opens on it ticked, unticked sent so; en, zh, zh-TW, ja, de at 420px, no sideways scroll) passes, with i18n-keys, i18n-en-no-cjk and every file that reaches the provider editor's Advanced or a Remote magpie (64 files): 1738 pass, 26 fail. The same files at origin/main19794cc10: 1728 pass, 24 fail, the same reds by name (editor-hints webkit #6156, account-arrange #6010, lan-join #6353, vertex-editor #4720, remote-magpie #5013, commented with this sha) except name-suffix-remote (#5147, red at base too on another language) and one count-free browser launch timeout; both files alone: 80 of 80 pass. At this head (rebased, with the loop): remote-connect-agents, library-mcp-on, provider-advanced-fold, i18n-keys, i18n-en-no-cjk pass; remote-magpie red as at base (#5013); editor-advanced-align red once in webkit, 1 of 4 alone (#6421, a Claude Code account's editor this change doesn't reach; it was red at base in the 64-file run). - Real use on mica, sandbox HOMEs, this branch's binary: remote R (`magpie serve`, Claude Code on gpt-5.4-mini) and a fresh client C with Claude Code installed, not connected. Switch off: C's settings.json stayed {}. Switch on, C restarted: "agent: Claude Code connected as the remote magpie's", ANTHROPIC_DEFAULT_SONNET_MODEL office/openai/gpt-5.4-mini, recorded on. `magpie claude default` (disconnect) and C restarted: settings back to the user's, recorded off, not connected again. Broken by hand, each red in TestRemoteConnectsNewAgents: - connectFromRemote returning at once (the old code): "not connected on the remote's group/fast"; - without the on-then-unconnected record: "an agent the user disconnected by hand in its file was connected again"; - without the Disconnect mark check: "an agent marked disconnected, never recorded, was connected"; - without the quit.restored exception: "a quit-restored agent: wired false, recorded off". Not tried: the switch turned on from the real app's window (the GUI test fakes the API; the save handler is covered by TestProviderSaveConnectAgents and real use wrote the stash key); agents other than Claude Code for real (the code is the same ConnectHow for every agent with fields); Windows and Linux runs.
104 lines
5.8 KiB
JavaScript
104 lines
5.8 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// KoiLx0 on X: a client magpie had each agent switched on by hand before
|
|
// it took the remote's models. A Remote magpie's editor has a switch for
|
|
// that, "Connect new agents to this remote", under Advanced: off, and the
|
|
// fold closed, while the backend says it is off; sent as ticked; and with
|
|
// it on, Advanced opens on it ticked. In every language, both engines, at
|
|
// a narrow width with no sideways scroll. 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 office = () => ({ id: "office", name: "Office", icon: "magpie", preset: "remote-magpie", chat: "http://office/v1", responses: "http://office/v1", anthropic: "http://office",
|
|
models: [{ id: "lib/m1", name: "Chat", on: true }], agents: [], key: { set: true, masked: "sk-…ab12" } });
|
|
const presets = [{ id: "remote-magpie", name: "Remote magpie", icon: "magpie", kind: "remote", added: true, endpoint: "http://192.168.1.20:3425" }];
|
|
|
|
function server(lang, state, saves) {
|
|
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:false};` });
|
|
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: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/providers") return json({ providers: [state.p], presets, excluded: [], gateway: { running: true, window: true } });
|
|
if (url.pathname === "/api/provider/save") {
|
|
const body = route.request().postDataJSON();
|
|
saves.push(body);
|
|
if (body.connectAgents != null) state.p = { ...state.p, connectAgents: body.connectAgents || undefined };
|
|
return json({ providers: [state.p], presets, excluded: [], gateway: { running: true, window: true } });
|
|
}
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
|
if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
|
|
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)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
const L = {
|
|
en: "Connect new agents to this remote",
|
|
zh: "自动接入新 agent",
|
|
"zh-TW": "自動接入新 agent",
|
|
ja: "新しいエージェントを自動で接続する",
|
|
de: "Neue Agenten automatisch verbinden",
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": a Remote magpie's switch to connect new agents, under Advanced", async (t) => {
|
|
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const [lang, words] of Object.entries(L)) {
|
|
await t.test(lang, async () => {
|
|
const saves = [], state = { p: office() };
|
|
const page = await (await browser.newContext({ viewport: { width: 420, height: 800 } })).newPage();
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", server(lang, state, saves));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
const ed = page.locator(".editor");
|
|
const open = async () => {
|
|
await page.locator('#providers .row[data-id="office"]').click();
|
|
await ed.locator(".ehead b", { hasText: "Office" }).waitFor();
|
|
};
|
|
const save = () => Promise.all([page.waitForResponse((r) => r.url().endsWith("/api/provider/save")), ed.locator(".bar button.primary").first().click()]);
|
|
|
|
// off: under Advanced, closed
|
|
await open();
|
|
const adv = ed.locator("details.advanced");
|
|
const sw = adv.locator(".connect-agents");
|
|
assert.equal(await sw.count(), 1, "the switch is under Advanced");
|
|
assert.equal(await sw.textContent(), words);
|
|
assert.equal(await adv.evaluate((d) => d.open), false, "Advanced closed while it is off");
|
|
assert.equal(await sw.locator("input").isChecked(), false);
|
|
assert.equal(await page.evaluate(() => document.scrollingElement.scrollWidth <= innerWidth), true, "no sideways scroll");
|
|
|
|
// ticked: sent so
|
|
await adv.locator("summary").click();
|
|
await sw.locator("input").check();
|
|
await save();
|
|
assert.equal(saves.at(-1).connectAgents, true);
|
|
await page.keyboard.press("Escape");
|
|
await ed.waitFor({ state: "detached" });
|
|
|
|
// on: Advanced opens on it ticked; unticked, sent so
|
|
await page.evaluate(() => { advanced = null; });
|
|
await open();
|
|
assert.equal(await adv.evaluate((d) => d.open), true, "Advanced opens while it is on");
|
|
assert.equal(await sw.locator("input").isChecked(), true);
|
|
await sw.locator("input").uncheck();
|
|
await save();
|
|
assert.equal(saves.at(-1).connectAgents, false);
|
|
assert.deepEqual(errors, []);
|
|
await page.context().close();
|
|
});
|
|
}
|
|
});
|
|
}
|