JonahFu on X: GitHub is unreachable without a proxy, while API requests may go direct, so plugin downloads' proxy should be set apart from the one model requests take. Before: plugin downloads already followed the global proxy (fetches through http.DefaultClient and netproxy.Func, bun add and git through netproxy.Env), so nothing ignored it; there was only no way to give them a different one. Now Settings › Network has a Plugin downloads row under Proxy: Same as above (the default, unset: downloads follow the global proxy as before), Direct, or Custom with its login, remembered as pluginProxyCustom as Proxy's Custom is. The CLI takes it as `magpie settings set pluginProxy <url|direct|"">`. It covers the plugins list and Discover's lists (fetchJSONFrom), a user's own npm registry (fetchRegistry), Bun's download (getURLFrom), bun add/update/remove and the git commands of GitHub-installed plugins (dlEnv). The plugin host (bun run) keeps the global proxy: its requests are the vendors'. Both fields belong to this computer (KeepOwn) and are left out of auto-backups, since a proxy URL may hold a password. Settings' Proxy row and the new one are drawn by one helper (proxyRow); the core's script budget is met by cutting the proxy rows' comments, no raise. Run (mote, through mote-run): gofmt -l clean; go vet of the touched packages (darwin), GOOS=linux -tags nogui ./..., GOOS=windows of the touched packages; go test -count=1 internal/settings, settingsapi, backup, netproxy, plugin, gui, cli all ok (gui after the comment cut; its first run had TestCoreScriptBudget 1,352 bytes over). GUI, chromium and webkit: settings-plugin-proxy (new, 5 languages x 2 widths), settings-proxy-remember, settings-proxy-auth, proxy-test, settings-sections, proxy-login-fields and the i18n files: 102 pass, 0 fail. plugin-proxy-page, proxy-own-wording, account-proxy, provider-proxy, routing-proxy, provider-many-keys-proxy and signin-proxy: 104 pass, 2 fail, both signin-proxy's "a subscription with no proxy offers the global one" at 380px in Chromium, red the same way on origin/mainb596da773(filed #5866). Again at this commit, rebased onb596da773: gofmt, the three go vets, the seven packages' go test (all ok, TestCoreScriptBudget included) and settings-plugin-proxy, -remember and -auth (50 pass, 0 fail). Broken by hand: fetchJSONFrom without netproxy.Downloads -> TestPluginDownloadsTakeTheirOwnProxy red (the list went direct and hit testenv's offline guard); bunCommand always taking env() -> red (bun add's HTTPS_PROXY ""); the GUI row saving key "proxy" -> settings-plugin-proxy 10 of 10 red in chromium. Not tried: a real install behind a real proxy with GitHub blocked; the Library's (skills, MCP) downloads and plugin icons (loaded by the webview through usemagpie.ai) still follow the global proxy; Windows.
117 lines
7.1 KiB
JavaScript
117 lines
7.1 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||
// Plugin downloads' proxy (JonahFu on X: GitHub needs a proxy, the vendors
|
||
// don't): Settings › Network has a row of its own under Proxy. Direct,
|
||
// Custom with a login, and Same as above each save pluginProxy alone, the
|
||
// global proxy as it was; Custom again brings back the last address, which
|
||
// the server remembers as pluginProxyCustom.
|
||
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 server(lang, posts) {
|
||
let cur = {
|
||
theme: "light", lang, tray: "panel", currency: "usd", textSize: 100,
|
||
proxy: "direct", proxyNow: "", proxySource: "off", pluginProxy: "",
|
||
trayUsageEvery: 3, version: "test", dir: "/test", lanURLs: [],
|
||
visionModels: [], imageGenModels: [], workbuddyCheckins: [],
|
||
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
|
||
};
|
||
return async (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 = ${JSON.stringify({ 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({ agents: [], profiles: [], settings: { lang, theme: "light" }, fx: cur.fx });
|
||
if (url.pathname === "/api/settings") {
|
||
if (req.method() === "POST") {
|
||
const body = req.postDataJSON();
|
||
posts.push(body);
|
||
// as settings.Save: the custom copy is the server's, set from the value
|
||
const own = body.pluginProxy && body.pluginProxy !== "direct";
|
||
cur = { ...cur, ...body, pluginProxyCustom: own ? body.pluginProxy : cur.pluginProxyCustom };
|
||
}
|
||
return json(cur);
|
||
}
|
||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||
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)];
|
||
return route.fulfill({ body: await fs.readFile(file), contentType });
|
||
};
|
||
}
|
||
|
||
const labels = {
|
||
en: { row: "Plugin downloads", same: "Same as above", direct: "Direct", custom: "Custom", user: "Username (optional)", pass: "Password (optional)", saved: "Saved" },
|
||
zh: { row: "插件下载", same: "同上", direct: "直连", custom: "自定义", user: "用户名(可选)", pass: "密码(可选)", saved: "已保存" },
|
||
"zh-TW": { row: "外掛下載", same: "同上", direct: "直連", custom: "自定義", user: "使用者名稱(選填)", pass: "密碼(選填)", saved: "已儲存" },
|
||
ja: { row: "プラグインのダウンロード", same: "上と同じ", direct: "直接接続", custom: "カスタム", user: "ユーザー名(任意)", pass: "パスワード(任意)", saved: "保存しました" },
|
||
de: { row: "Plugin-Downloads", same: "Wie oben", direct: "Direkt", custom: "Benutzerdefiniert", user: "Benutzername (optional)", pass: "Passwort (optional)", saved: "Gespeichert" },
|
||
};
|
||
|
||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||
for (const lang of Object.keys(labels)) {
|
||
const l = labels[lang];
|
||
for (const width of [1100, 420]) {
|
||
test(`${engine} ${lang} ${width}px: plugin downloads take a proxy of their own`, async (t) => {
|
||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||
t.after(() => browser.close());
|
||
const context = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" });
|
||
const page = await context.newPage();
|
||
page.setDefaultTimeout(4000);
|
||
page.setDefaultNavigationTimeout(60000);
|
||
const posts = [], errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
await page.route("**/*", server(lang, posts));
|
||
await page.goto("http://magpie.test/?view=settings&tab=network");
|
||
const row = page.locator("#pluginProxyRow");
|
||
await row.getByText(l.row, { exact: true }).waitFor();
|
||
const box = page.locator("#pluginProxySegs");
|
||
const mode = (name) => box.getByRole("button", { name, exact: true });
|
||
const saved = async (action, want) => {
|
||
const count = posts.length;
|
||
const response = page.waitForResponse((r) => r.url().endsWith("/api/settings") && r.request().method() === "POST");
|
||
await action();
|
||
await response;
|
||
await page.waitForFunction((word) => document.querySelector("#status")?.textContent.includes(word), l.saved);
|
||
assert.equal(posts.length, count + 1, "save once");
|
||
assert.equal(posts.at(-1).pluginProxy, want);
|
||
assert.equal(posts.at(-1).proxy, "direct", "the global proxy stays as it was");
|
||
assert(!("pluginProxyCustom" in posts.at(-1)), "the page sends the remembered proxy");
|
||
};
|
||
// its row starts on Same as above, Proxy's own on Off
|
||
assert.equal(await mode(l.same).getAttribute("aria-pressed"), "true");
|
||
assert.equal(await box.locator("input.proxy").count(), 0, "no address until Custom");
|
||
|
||
await mode(l.custom).click();
|
||
const address = box.locator("input.proxy");
|
||
await address.fill("http://127.0.0.1:7890");
|
||
await box.getByRole("textbox", { name: l.user, exact: true }).fill("me");
|
||
await box.getByLabel(l.pass, { exact: true }).fill("p@ss");
|
||
await saved(() => box.getByLabel(l.pass, { exact: true }).press("Enter"), "http://me:p%40ss@127.0.0.1:7890");
|
||
// the line under the name shows the address without the login
|
||
const sub = await page.locator("#pluginProxySub").textContent();
|
||
assert(sub.includes("127.0.0.1:7890") && !sub.includes("p%40ss"), sub);
|
||
|
||
await saved(() => mode(l.direct).click(), "direct");
|
||
await mode(l.custom).click();
|
||
assert.equal(await address.inputValue(), "http://127.0.0.1:7890", "Custom brings back the last address");
|
||
await address.press("Escape");
|
||
await saved(() => mode(l.same).click(), "");
|
||
|
||
// the global proxy row is drawn as before, its Test with it
|
||
assert.equal(await page.locator("#proxySegs button.proxy-test").count(), 1);
|
||
assert.equal(await page.locator("#pluginProxySegs button.proxy-test").count(), 0);
|
||
// nothing is wider than the page
|
||
const over = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
|
||
assert(over <= 0, `the page scrolls sideways by ${over}px`);
|
||
assert.deepEqual(errors, []);
|
||
});
|
||
}
|
||
}
|
||
}
|