Files
magpie/internal/gui/tests/plugin-gateway.test.cjs
T
JoeyWu-tech 7a1bfaf2f0 plugins: kindChip says the word it is given, so a request hook's chip is one call (#3821)
The Installed tab's row of a gateway request hook made its chip as
middleware's and then wrote "Request hook" over the chip's word, in
five lines. kindChip now takes a word to say in place of its kind's,
and the row asks for its chip in one line. Behaviour is unchanged: the
same chip, class, glyph and tooltip, its word translated as before.
This makes room under TestCoreScriptBudget for the next commit without
raising the budget: the core's scripts go from 1,527,972 to 1,527,897
of 1,528,076.

plugin-gateway.test.cjs, which opens such a row, now checks its chip
says Request hook in each of its five languages; nothing checked it.

What was run (tree 0b0ba0c9, on origin/main 56602426, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, the Go tests at umask 077:
- plugin-gateway.test.cjs, Chromium and WebKit: 12 of 12 pass. With
  56602426's plugins.js under it: 12 of 12, so the chip said the same
  before this change.
- kindChip ignoring the word given (t(word) for t(name || word)): 0 of
  12, the chip saying Middleware, translated, in every language.
- TestCoreScriptBudget: ok.
- The GUI files near the change, vet and the full suite ran at the next
  commit's tree, which holds this one.

Not tried: the real app's window (no display here, the page in
Playwright's browsers only).

Landed by yetone in a batch of Coffemon's patches from the issues.
What was run, go1.26.8, on origin/main cc81ad4ea, then again at
70a0c387c (gofmt, the three vets, the changed tests, umask 077):
- mote (macOS 27): gofmt -l clean; go vet, GOOS=linux go vet -tags
  nogui and GOOS=windows go vet ./...: ok. edit and testenv at umask
  077; agent, provider, library and gateway with an empty .git above
  TMPDIR; davsync, imagemcp, plugin, library, edit, testenv whole; the
  changed tests in agent, provider, gateway and gui; the timing tests
  -count=10 (gateway, davsync, imagemcp) and -count=5 (agent): all ok.
  TestCoreScriptBudget ok: core 1,536,751 of 1,537,034, app.js
  1,312,975 of 1,315,316, no budget raised.
- Red on the old code: on origin/main, TestWriteAtomicReadOnlyHardLink
  at umask 077 and two Reasonix tests under an empty .git; on Linux
  (wsl-run) TestProgram at umask 077 with the old program.go. With
  each fix's code taken back to main's, the Gemini imageConfig tests,
  TestPluginToldWhereTheAgentWorks, TestSkillRepoTraced,
  TestTaggedHooksAlone, TestMainURL/TestMainView and update-auto,
  plugin-github-hooks, plugins-more-discover, plugin-namesake were
  red. Broken by hand: claudeKeyed always true (both
  OwnEndpointNeverAsked tests red), claudeAsk a no-op
  (TestClaudeFirstWriteAsksTheProxy red), GitAt taking any .git folder
  (the three TestGitOnDisk tests red).
- GUI: 123 files (plugins*, update-*, panel/tray/start/context, i18n,
  gui-zh-tw/ja/de and every file that evals app.js parts) in WebKit on
  Linux (wsl-run). 11 files had reds (click-scroll, panel-fold,
  plugin-card-update, plugin-github, plugin-move*, segs-glide,
  tray-totals, update-*), and run again side by side they fail the
  same on origin/main d80d75f30 (79 pass, 26 fail here; 78 and 27
  there). They are click-scroll guards ("the click must not scroll
  the page"), varying by language from run to run (#4385).
  copilot-ghe's route-after-close red is #1949, seen on main 244d80e23
  too. In Chromium on mote, Chromium segfaulted partway through files
  (#4125): context-map, context-scroll-end and context-tune fail the
  same on origin/main 0911a65e7, so the batch's own files
  (plugin-namesake, update-auto, plugins-more-discover,
  plugin-github-hooks) ran in Chromium on Linux: 62 of 62.
- Full suite (go test -tags nogui -count=1 -timeout 45m ./..., mote)
  at 472a0608f (on 70a0c387c): every package ok but internal/gateway,
  whose five reds were #4362's (Antigravity turned-away and
  TestCodexSpentGrokFailingIsTold), fixed on main in d80d75f30. After
  the rebase on 244d80e23 the five pass, and gofmt, the three vets
  and the targeted runs above were run again: ok. In Linux the
  sign-in, copilot, plugin-github*, plugins-more-discover,
  plugin-namesake, plugin-gateway, update-auto, quota-refresh-order
  and i18n files ran in both engines: 475 pass, 4 fail (copilot-ghe
  #1949, plugin-github's click scroll, both red on main too).
- Rebased again on c7171a256, over its budget fix e94bf7a08: gofmt, vet of
  gui, gateway, provider and plugin, TestCoreScriptBudget (core
  1,536,265 of 1,536,586 with the batch's last commit, statusTErr and settingsErr), the Gemini,
  GitOnDisk and plugin tests, and in Linux both engines i18n-keys,
  update-mirror, plugin-namesake, plugins-more-discover,
  plugin-github-hooks and update-auto (138 of 138): ok.
Not tried: the whole GUI suite (mote's WebKit wouldn't launch and its
Chromium segfaulted, #4125); macOS WebKit; the real app's window.
2026-10-30 15:53:22 +08:00

76 lines
4.9 KiB
JavaScript

// Gateway-only plugins have options and private-data-free diagnostics. APIs are fixtures.
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 = process.env.MAGPIE_GATEWAY_ASSETS || path.resolve(__dirname, "../assets");
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 SPEC = "/fixtures/context-plugin";
for (const engine of ["chromium", "webkit"]) {
test(engine + ": gateway configuration and diagnostics", async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({channel:"chromium"}));
t.after(() => browser.close());
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
await t.test(lang, async () => {
const page = await browser.newPage({viewport:{width:980,height:820}});
page.setDefaultTimeout(5000);
const posted = [], errors = [];
const state = {bun:true, bunVersion:"1.4.3", plugins:[{
spec:SPEC, providers:[], moved:[], isGateway:true, gatewayOnly:true,
optionsExample:{serverUrl:"http://127.0.0.1:8000",gatewayTimeoutMs:5000},
gateway:{calls:3,failures:1,avgMillis:5.5,lastOutcome:"ready",lastBytes:120},
}]};
page.on("pageerror", e=>errors.push(e.message));
await page.route("**/*",server(lang,state));
await page.route("**/api/plugins/options", r=>{
const data=r.request().postDataJSON(); posted.push(data);
state.plugins[0].options=data.options;
return r.fulfill({json:state});
});
await page.goto("http://magpie.test/?view=plugins");
const installed = {en:"Installed",zh:"已安装","zh-TW":"已安裝",ja:"インストール済み",de:"Installiert"}[lang];
await page.locator(":is(.lib-tabs .opt, .nav-s):visible",{hasText:installed}).click();
const row=page.locator("#view-plugins .pm-row");
assert.equal(await row.locator(".pm-chip.kind.pv").count(),0);
const hook={en:"Request hook",zh:"请求 Hook","zh-TW":"請求 Hook",ja:"リクエストフック",de:"Anfrage-Hook"}[lang];
assert.equal((await row.locator(".pm-chip.kind.mw").innerText()).trim(),hook);
const line=row.locator(".pm-gateway");
await line.waitFor();
assert.match(await line.innerText(), /120/);
if(lang!=="en") assert.doesNotMatch(await line.innerText(),/Context injected|calls,|bytes injected/);
const options={en:"Options",zh:"选项","zh-TW":"選項",ja:"オプション",de:"Optionen"}[lang];
await row.getByRole("button",{name:options,exact:true}).click();
const textarea=row.locator(".pm-opts textarea");
assert.deepEqual(JSON.parse(await textarea.inputValue()),state.plugins[0].optionsExample);
await textarea.fill('{"serverUrl":"http://127.0.0.1:9000","gatewayTimeoutMs":6000}');
const save={en:"Save",zh:"保存","zh-TW":"儲存",ja:"保存",de:"Speichern"}[lang];
await row.locator(".pm-opts").getByRole("button",{name:save,exact:true}).click();
await textarea.waitFor({state:"detached"});
assert.deepEqual(posted,[{spec:SPEC,options:{serverUrl:"http://127.0.0.1:9000",gatewayTimeoutMs:6000}}]);
assert.deepEqual(errors,[]);
await page.close();
});
}
});
}