zelong77 asked for two things once Devin 0.1.30's cache keep-alive
worked: its pings were invisible in magpie, and the interval and ping
count could only be edited in plugins.json. The owner decided pings are
shown as counted usage and the two numbers are edited in the GUI.
- host.js gives plugins input.magpie.usage(provider, call) and
input.magpie.account(provider). usage validates the call (kind
[a-z0-9_-]{1,40}, a model id, whole-number tokens from 0, status at
most 999, error clipped to 500) and sends an unasked "usage" event;
host.go hands it to plugin.OnUsage in the background.
- internal/usage/plugin_calls.go writes each one as a row of agent
magpie on the plugin's provider (provider.PluginID) and account
(provider.PluginAccountUser), with its kind. It is counted, priced
and in every total, not a probe. Kind cache_keepalive is in the
purpose catalog as "Cache keep-alive" (five languages), so the
request log names and filters it. The ping itself still goes straight
to Devin, never through the gateway, which would break the cache.
- /api/plugins reads every plugin's package options example, not only a
middleware's or request hook's, and the Installed row offers the same
Options JSON editor for a provider or agent plugin that suggests or
has options (not while it is off). Clear's confirm no longer calls
them a middleware's options.
- The Devin mover's min is 0.1.31, which reports each ping and gives
its two settings' defaults (285 s, 6) to the editor. npm has 0.1.31
(published 10:03Z); the plugins publish run is red only for
think-tags' known E404 (plugins#180).
- docs: provider-plugins.md (the API, the options editor),
gateway-sessions.md (the counted row beside probes).
Run at this tree (rebased on origin/main 85e37162e):
- mote (mote-run): go test -count=1 -timeout 45m ./internal/plugin
./internal/usage ./internal/gui ./internal/provider: plugin, usage,
provider ok; gui red only in TestMainWindowCorners/macOS_26_SDK, the
macOS 27 red already filed as #3949 (not this change's code).
- mote: GOOS=linux and GOOS=windows go vet of plugin, usage, provider ok;
gofmt -l clean.
- mote: plugin-provider-options.test.cjs (new, 5 languages, 980/420px,
Chromium + WebKit), plugin-gateway.test.cjs and i18n-keys.test.cjs:
28 of 28 pass.
- The whole GUI suite (make test-ui) on WSL magpie-desktop (mote was at
load ~100 with other sessions' suites, #4125), at the 8f804396f base:
cut off after 498 test entries, when the session's background jobs
were killed; 495 ok, 3 red, none on a page this change touches. Run
again alone at origin/main 85e37162e, the same files are red there
too: account-eye webkit (#4244), agent-expand-steady webkit 980px
(#2935), add-button zh's 3000ms waitForFunction (filed #4792). The
rest of the suite was not run.
Broken by hand (each red, then put back):
- host.go dropping the "usage" event: TestPluginReportsOwnUsage fails.
- plugins.go reading optionsExample for middleware/hooks only:
TestProviderPluginOptionsExample fails.
- purpose.go without the Cache keep-alive kind:
TestPluginKeepaliveIsCounted fails (purpose {}).
- plugins.js without ownOpts: plugin-provider-options.test.cjs times
out waiting for the Options button in every language.
Not tried: a real Devin account's keep-alive ping reported into a real
magpie (needs a live Devin conversation idle for 285 s); a plugin can
report a row for any provider id, as magpie.load can.
111 lines
7.9 KiB
JavaScript
111 lines
7.9 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A provider plugin's own options on the Installed tab (plugins#592): one
|
|
// whose package suggests options (Devin's cacheKeepaliveInterval and
|
|
// cacheKeepaliveMaxPings) or that has some set gets the same Options
|
|
// editor a middleware has, starting from its package's example; one with
|
|
// neither, or switched off, gets none. Clearing them asks first, in words
|
|
// that don't call them a middleware's. Every language; 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 DEVIN = "npm:@magpie-community/opencode-devin-auth", PLAIN = "npm:@magpie-community/opencode-plain-auth", OFF = "npm:@magpie-community/opencode-off-auth";
|
|
const example = { cacheKeepaliveInterval: 285, cacheKeepaliveMaxPings: 6 };
|
|
const state = { bun: true, bunVersion: "1.3.0", plugins: [
|
|
{ spec: DEVIN, ownName: "Devin Auth", providers: ["Devin"], moved: ["devin"], named: true, optionsExample: example },
|
|
{ spec: PLAIN, ownName: "Plain Auth", providers: ["Plain"], moved: [], named: true },
|
|
{ spec: OFF, ownName: "Offco Auth", off: true, providers: ["Offco"], moved: [], named: true, optionsExample: example },
|
|
] };
|
|
|
|
function server(lang, pluginState) {
|
|
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: [], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
|
|
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
|
if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
|
|
if (url.pathname === "/api/plugins/market" || url.pathname === "/api/plugins" || url.pathname === "/api/plugins/listings") return json(url.pathname === "/api/plugins" ? pluginState : url.pathname === "/api/plugins/listings" ? { listings: [] } : { listings: [], state: pluginState });
|
|
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 W = {
|
|
en: { installed: "Installed", options: "Options", save: "Save", clear: "Clear", cancel: "Cancel", gone: /^Saved options will be removed\. The plugin will run with no options\.$/ },
|
|
zh: { installed: "已安装", options: "选项", save: "保存", clear: "清空", cancel: "取消", gone: /^已保存的选项将被移除。插件将不带选项运行。$/ },
|
|
"zh-TW": { installed: "已安裝", options: "選項", save: "儲存", clear: "清空", cancel: "取消", gone: /^已儲存的選項將被移除。外掛將不帶選項執行。$/ },
|
|
ja: { installed: "インストール済み", options: "オプション", save: "保存", clear: "クリア", cancel: "キャンセル", gone: /^保存したオプションが削除されます。プラグインはオプションなしで実行されます。$/ },
|
|
de: { installed: "Installiert", options: "Optionen", save: "Speichern", clear: "Leeren", cancel: "Abbrechen", gone: /^Die gespeicherten Optionen werden entfernt\. Das Plugin läuft ohne Optionen\.$/ },
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": a provider plugin's options in its row", async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const [lang, w] of Object.entries(W)) {
|
|
await t.test(lang, async () => {
|
|
for (const width of [980, 420]) {
|
|
const page = await (await browser.newContext({ viewport: { width, height: 820 } })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [], posted = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
const pluginState = structuredClone(state);
|
|
await page.route("**/*", server(lang, pluginState));
|
|
await page.route("**/api/plugins/options", (r) => {
|
|
const body = r.request().postDataJSON();
|
|
posted.push(body);
|
|
pluginState.plugins[0].options = body.options ?? undefined;
|
|
return r.fulfill({ json: pluginState });
|
|
});
|
|
await page.goto("http://magpie.test/?view=plugins");
|
|
const view = page.locator("#view-plugins");
|
|
await page.locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
|
|
const names = { [DEVIN]: "Devin Auth", [PLAIN]: "Plain Auth", [OFF]: "Offco Auth" };
|
|
const row = (spec) => view.locator(".pm-row").filter({ has: page.locator(".name", { hasText: names[spec] }) });
|
|
await row(DEVIN).waitFor();
|
|
await row(PLAIN).waitFor();
|
|
assert.equal(await row(PLAIN).getByRole("button", { name: w.options, exact: true }).count(), 0, "no Options on a plugin that has none");
|
|
assert.equal(await row(OFF).getByRole("button", { name: w.options, exact: true }).count(), 0, "no Options on one switched off");
|
|
const devin = row(DEVIN);
|
|
await devin.getByRole("button", { name: w.options, exact: true }).click();
|
|
const ta = devin.locator(".pm-opts textarea");
|
|
await ta.waitFor();
|
|
assert.deepEqual(JSON.parse(await ta.inputValue()), example);
|
|
const box = await ta.boundingBox();
|
|
assert.ok(box && box.x >= 0 && box.x + box.width <= width, `the editor fits at ${width}px: ${JSON.stringify(box)}`);
|
|
assert.equal(await page.evaluate(() => document.scrollingElement.scrollWidth <= innerWidth), true, "no sideways scroll");
|
|
await ta.fill('{"cacheKeepaliveInterval": 240, "cacheKeepaliveMaxPings": 10}');
|
|
await devin.locator(".pm-opts").getByRole("button", { name: w.save, exact: true }).click();
|
|
await devin.locator(".pm-opts").waitFor({ state: "detached" });
|
|
assert.deepEqual(posted, [{ spec: DEVIN, options: { cacheKeepaliveInterval: 240, cacheKeepaliveMaxPings: 10 } }]);
|
|
await devin.getByRole("button", { name: w.options, exact: true }).click();
|
|
assert.deepEqual(JSON.parse(await ta.inputValue()), { cacheKeepaliveInterval: 240, cacheKeepaliveMaxPings: 10 });
|
|
await devin.getByRole("button", { name: w.clear, exact: true }).click();
|
|
const confirm = page.getByRole("alertdialog");
|
|
await confirm.waitFor();
|
|
assert.match((await confirm.locator("#actionConfirmMessage").textContent()).trim(), w.gone);
|
|
await confirm.getByRole("button", { name: w.cancel, exact: true }).click();
|
|
assert.equal(posted.length, 1, "Cancel keeps the saved options");
|
|
await devin.getByRole("button", { name: w.clear, exact: true }).click();
|
|
await confirm.locator("button").last().click();
|
|
await devin.locator(".pm-opts").waitFor({ state: "detached" });
|
|
assert.deepEqual(posted[1], { spec: DEVIN, options: null });
|
|
assert.equal(await view.locator("select").count(), 0);
|
|
assert.deepEqual(errors, []);
|
|
await page.context().close();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|