settings: app updates get their own proxy choice (moonlityu on X)
Settings > Network has a new "App updates" row under the plugin proxy row:
Same as above (default, today's behaviour), Direct, Custom or a saved proxy.
It is Settings.UpdateProxy / UpdateProxyCustom, kept per computer
(KeepOwn), left out of auto-backups with the other proxies, and listed in
the saved proxies' "in use" check, so a saved proxy used by updates can't be
deleted. update.proxied() wraps its transport: a request that names no
proxy of its own (magpie update --proxy does) takes the setting; unset, it
follows the global proxy as before. A value a user already set is never
changed.
Per-model proxy inside one provider is not added: a proxy belongs to a
provider, an account or a key, so a provider can't split by model without a
second provider on the same URL (noted in providers-accounts.md).
app.js stays within TestCoreScriptBudget by cutting five long comments, no
raise.
Run (Linux via wsl-run, rebased on origin/main 961427f12): go test of
internal/update, settings, settingsapi, backup and internal/gui (-tags
nogui) incl. TestCoreScriptBudget and the settings-keep guards; new
settings-update-proxy.test.cjs in chromium and webkit, 5 languages, 1100
and 420px; gofmt; go vet for darwin, windows and linux (nogui) on the
touched packages.
Broken by hand: removing the updateProxy wrapper turns
TestUpdateTakesItsOwnProxy red.
GUI reds named: settings-proxy-auth "optional proxy credentials" webkit
(expected 'name', actual ''; red on origin/main too, #5562, seen again);
saved-proxies "webkit de 420px" stopped passing with the third row because
the add form's Save button sat 1px below a 760px window and WebKit's
scrollTop stuck at 214 (#6130); that test's window is now 900px high.
Not tried: a real update behind a real proxy, the Windows/macOS apps,
WebKitGTK.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -406,6 +406,7 @@ func autoCollect(app string) (Bundle, error) {
|
||||
s := *b.Settings
|
||||
s.Proxy, s.ProxyCustom = "", ""
|
||||
s.PluginProxy, s.PluginProxyCustom = "", ""
|
||||
s.UpdateProxy, s.UpdateProxyCustom = "", ""
|
||||
s.Proxies = nil
|
||||
b.Settings = &s
|
||||
}
|
||||
|
||||
@@ -186,6 +186,7 @@ func TestAutoBackupHoldsNoSecrets(t *testing.T) {
|
||||
s := settings.Load()
|
||||
s.GitHubToken, s.LANKey, s.Proxy = "ghp_SYNTHETIC_PRIVATE_TOKEN", "lan-SYNTHETIC-KEY", "http://user:proxy-SYNTHETIC-pass@10.0.0.1:8080"
|
||||
s.PluginProxy = "socks5://user:plugin-SYNTHETIC-pass@10.0.0.2:1080"
|
||||
s.UpdateProxy = "socks5://user:update-SYNTHETIC-pass@10.0.0.3:1080"
|
||||
if err := settings.Save(s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -218,6 +219,7 @@ func TestAutoBackupHoldsNoSecrets(t *testing.T) {
|
||||
ws := *want.Settings
|
||||
ws.Proxy, ws.ProxyCustom = "", ""
|
||||
ws.PluginProxy, ws.PluginProxyCustom = "", ""
|
||||
ws.UpdateProxy, ws.UpdateProxyCustom = "", ""
|
||||
want.Settings, want.Created, want.App = &ws, time.Time{}, ""
|
||||
raw, _ := json.Marshal(want)
|
||||
var wantBack Bundle
|
||||
|
||||
+15
-18
@@ -2089,7 +2089,6 @@ function appRestart(a) {
|
||||
return go;
|
||||
}
|
||||
|
||||
// Air's own Codex and Claude Agent: the IDE plugin's run this computer's codex and claude, the app's never go through magpie (jumy_18634)
|
||||
const AIR_KINDS = new Set(["air", "air-ide"]);
|
||||
function airSaid(a, line) {
|
||||
const warn = (s) => { const w = line(el("span", "ag-dot"), el("span", "", s)); w.classList.add("ag-warn", "ag-air-own"); return w; };
|
||||
@@ -6138,7 +6137,6 @@ function renderProviders(quiet) {
|
||||
key = el("span", "key " + (p.key.set ? (keyPill(p) === p.key.masked ? "on" : "on acct") : p.ready ? "free" : "none"), p.key.set ? keyPill(p) : p.ready ? t("no key") : t("needs a key"));
|
||||
key.title = p.key.set ? t("API key {masked}", { masked: p.key.masked }) : p.ready ? t("Local servers need no key") : t("Open the row and paste an API key");
|
||||
}
|
||||
// every pill is one width so the dots line up down the list; a label too long for it ends in "…" and is said whole on hover
|
||||
const label = key.textContent;
|
||||
key.textContent = "";
|
||||
key.append(el("span", "", label));
|
||||
@@ -8512,7 +8510,6 @@ function iconPicker(ed) {
|
||||
// spring, and closing folds it back into that (still there, re-rendered or
|
||||
// not); with nothing pressed it rises from a little below.
|
||||
const SPRING = CSS.supports?.("animation-timing-function", "linear(0, 1)")
|
||||
// a damped spring (damping .8): 1.5% over, settled by the end of the duration it runs for (460 ms)
|
||||
? "linear(0, 0.0203, 0.0723, 0.1448, 0.2292, 0.3188, 0.4086, 0.4951, 0.576, 0.6498, 0.7157, 0.7735, 0.8232, 0.8654, 0.9005, 0.9293, 0.9525, 0.9708, 0.9849, 0.9956, 1.0033, 1.0087, 1.0122, 1.0142, 1.015, 1.0151, 1.0146, 1.0136, 1.0124, 1.0111, 1.0097, 1.0084, 1.0071, 1.0059, 1.0049, 1.0039, 1.0031, 1.0024, 1.0018, 1.0013, 1)"
|
||||
: "cubic-bezier(.2, .9, .25, 1.02)";
|
||||
const IOS_EASE = "cubic-bezier(.32, .72, 0, 1)";
|
||||
@@ -9195,7 +9192,6 @@ function vertexRoot(u) {
|
||||
if (!u.includes("://")) u = "https://" + u;
|
||||
return u.replace(/\/v1(?:beta1)?$/, "");
|
||||
}
|
||||
// with a key (keyed) the project is optional: express mode asks at the global endpoint, and a base URL stands in for Google's host
|
||||
function vertexBase(v, keyed) {
|
||||
const project = (v?.project || "").trim().toLowerCase(), loc = (v?.location || "").trim().toLowerCase() || "global";
|
||||
const root = keyed ? vertexRoot(v?.baseUrl) : "";
|
||||
@@ -9908,7 +9904,6 @@ function drawEditor(p, presetID) {
|
||||
advIn.append(...field(t("Images"), itk, t("Off: an agent's images are sent inline on every turn.")));
|
||||
}
|
||||
|
||||
// a balance token of the vendor's own (AiHubMix), or a custom one's (balanceFix), its URL above (balSlot)
|
||||
let balFix = null, balSlot = null;
|
||||
if (custom) {
|
||||
balSlot = el("div", "bal-slot");
|
||||
@@ -14438,7 +14433,6 @@ function to100(v) { return Math.max(0, Math.min(100, v)); }
|
||||
// quotaNoShare: no share was said (0 is one, absent is not, #3650), or the
|
||||
// window is a wallet's balance (#3950): its text or figure is all there is
|
||||
function quotaNoShare(w) { return !!w.text || w.used == null || w.balance != null; }
|
||||
// spanBtn: a span as a button: a <button> in a wrapping line keeps WebKit's row one line high till the next layout
|
||||
function spanBtn(b) {
|
||||
b.tabIndex = 0;
|
||||
b.setAttribute("role", "button");
|
||||
@@ -20774,17 +20768,21 @@ function renderProxy(s, keep) {
|
||||
}
|
||||
const proxyState = { custom: false };
|
||||
// plugin downloads' proxy (JonahFu on X); plugins' vendor requests follow the one above
|
||||
const pluginProxyState = { custom: false };
|
||||
const pluginProxyState = { custom: false }, updateProxyState = { custom: false };
|
||||
function renderPluginProxy(s, keep) {
|
||||
const v = (s.pluginProxy || "").trim();
|
||||
const cur = !v ? "auto" : v === "direct" ? "off" : v.startsWith("@") ? "saved" : "custom";
|
||||
$("#pluginProxySub").textContent = cur === "auto" ? t("Plugins, npm and GitHub go through the proxy above")
|
||||
: cur === "off" ? t("Plugins, npm and GitHub go direct") : t("Plugins, npm and GitHub go through {proxy}", { proxy: v.startsWith("@") ? savedProxyName(v) : proxyDisplay(v) });
|
||||
proxyRow(s, keep, {
|
||||
key: "pluginProxy", box: $("#pluginProxySegs"), cur, state: pluginProxyState,
|
||||
modes: withSavedMode([["auto", t("Same as above")], ["off", t("Direct")], ["custom", t("Custom")]], cur === "saved"),
|
||||
again: () => renderPluginProxy(s, keep),
|
||||
});
|
||||
for (const [key, state, sub] of [
|
||||
["pluginProxy", pluginProxyState, (p) => [t("Plugins, npm and GitHub go through the proxy above"), t("Plugins, npm and GitHub go direct"), t("Plugins, npm and GitHub go through {proxy}", p)]],
|
||||
["updateProxy", updateProxyState, (p) => [t("Updates go through the proxy above"), t("Updates go direct"), t("Updates go through {proxy}", p)]], // moonlityu on X
|
||||
]) {
|
||||
const v = (s[key] || "").trim();
|
||||
const cur = !v ? "auto" : v === "direct" ? "off" : v.startsWith("@") ? "saved" : "custom";
|
||||
$("#" + key + "Sub").textContent = sub({ proxy: v.startsWith("@") ? savedProxyName(v) : proxyDisplay(v) })[cur === "auto" ? 0 : cur === "off" ? 1 : 2];
|
||||
proxyRow(s, keep, {
|
||||
key, box: $("#" + key + "Segs"), cur, state,
|
||||
modes: withSavedMode([["auto", t("Same as above")], ["off", t("Direct")], ["custom", t("Custom")]], cur === "saved"),
|
||||
again: () => renderPluginProxy(s, keep),
|
||||
});
|
||||
}
|
||||
}
|
||||
// proxyRow: o.key's modes, and Custom's address and login; o.state.custom is Custom not saved yet.
|
||||
function proxyRow(s, keep, o) {
|
||||
@@ -20860,7 +20858,6 @@ function proxyRow(s, keep, o) {
|
||||
return row;
|
||||
}
|
||||
|
||||
// renderProxyCheck: Test (#2076), the exits through the proxy and direct; one both ways fails only if it didn't connect (#2369).
|
||||
let proxyCheck = null; // { key, busy, out, err }
|
||||
function renderProxyCheck(s, row) {
|
||||
const key = (s.proxySource || "") + "|" + (s.proxyNow || "");
|
||||
@@ -22749,7 +22746,7 @@ function dockChoice(s) {
|
||||
|
||||
// prefsKeep is what the settings page sends of s, all of it each time.
|
||||
function prefsKeep(s) {
|
||||
return { theme: s.theme, colorblind: !!s.colorblind, reduceMotion: !!s.reduceMotion, noBird: !!s.noBird, lang: s.lang, tray: s.tray, dock: !!s.dock, dockWindow: !!s.dockWindow, dockNever: !!s.dockNever, lightweight: s.lightweight, keepAwake: !!s.keepAwake, keepAwakeDisplay: !!s.keepAwakeDisplay, noWSLAgents: !!s.noWSLAgents, quitNoAsk: !!s.quitNoAsk, proxy: s.proxy || "", pluginProxy: s.pluginProxy || "",
|
||||
return { theme: s.theme, colorblind: !!s.colorblind, reduceMotion: !!s.reduceMotion, noBird: !!s.noBird, lang: s.lang, tray: s.tray, dock: !!s.dock, dockWindow: !!s.dockWindow, dockNever: !!s.dockNever, lightweight: s.lightweight, keepAwake: !!s.keepAwake, keepAwakeDisplay: !!s.keepAwakeDisplay, noWSLAgents: !!s.noWSLAgents, quitNoAsk: !!s.quitNoAsk, proxy: s.proxy || "", pluginProxy: s.pluginProxy || "", updateProxy: s.updateProxy || "",
|
||||
sessionTerminal: s.sessionTerminal || "",
|
||||
uiFont: s.uiFont || null, codeFont: s.codeFont || null,
|
||||
otel: s.otel || {},
|
||||
|
||||
@@ -1206,6 +1206,10 @@ const I18N = {
|
||||
"Same as above": "同上",
|
||||
"Plugins, npm and GitHub go through the proxy above": "插件、npm 和 GitHub 走上面的代理",
|
||||
"Plugins, npm and GitHub go direct": "插件、npm 和 GitHub 直连",
|
||||
"App updates": "应用更新",
|
||||
"Updates go through the proxy above": "更新走上面的代理",
|
||||
"Updates go direct": "更新直连",
|
||||
"Updates go through {proxy}": "更新走 {proxy}",
|
||||
"Plugins, npm and GitHub go through {proxy}": "插件、npm 和 GitHub 走 {proxy}",
|
||||
"Following HTTPS_PROXY, {proxy}": "跟随 HTTPS_PROXY:{proxy}",
|
||||
"Ask Cloudflare through the proxy and direct, and compare the addresses the two leave from": "通过代理和直连各请求一次 Cloudflare,比较两者的出口地址",
|
||||
@@ -6270,6 +6274,10 @@ const I18N = {
|
||||
"Same as above": "同上",
|
||||
"Plugins, npm and GitHub go through the proxy above": "外掛、npm 和 GitHub 走上面的代理",
|
||||
"Plugins, npm and GitHub go direct": "外掛、npm 和 GitHub 直連",
|
||||
"App updates": "應用程式更新",
|
||||
"Updates go through the proxy above": "更新走上面的代理",
|
||||
"Updates go direct": "更新直連",
|
||||
"Updates go through {proxy}": "更新走 {proxy}",
|
||||
"Plugins, npm and GitHub go through {proxy}": "外掛、npm 和 GitHub 走 {proxy}",
|
||||
"Following HTTPS_PROXY, {proxy}": "跟隨 HTTPS_PROXY:{proxy}",
|
||||
"Ask Cloudflare through the proxy and direct, and compare the addresses the two leave from": "透過代理和直連各請求一次 Cloudflare,比較兩者的出口位址",
|
||||
@@ -11305,6 +11313,10 @@ const I18N = {
|
||||
"Same as above": "上と同じ",
|
||||
"Plugins, npm and GitHub go through the proxy above": "プラグイン、npm、GitHub は上のプロキシを使います",
|
||||
"Plugins, npm and GitHub go direct": "プラグイン、npm、GitHub は直接接続します",
|
||||
"App updates": "アプリのアップデート",
|
||||
"Updates go through the proxy above": "アップデートは上のプロキシを使います",
|
||||
"Updates go direct": "アップデートは直接接続します",
|
||||
"Updates go through {proxy}": "アップデートは {proxy} を使います",
|
||||
"Plugins, npm and GitHub go through {proxy}": "プラグイン、npm、GitHub は {proxy} を使います",
|
||||
"Following HTTPS_PROXY, {proxy}": "HTTPS_PROXY に従う:{proxy}",
|
||||
"Ask Cloudflare through the proxy and direct, and compare the addresses the two leave from": "プロキシ経由と直接で Cloudflare に 1 回ずつ問い合わせ、出口のアドレスを比べます",
|
||||
@@ -16355,6 +16367,10 @@ const I18N = {
|
||||
"Same as above": "Wie oben",
|
||||
"Plugins, npm and GitHub go through the proxy above": "Plugins, npm und GitHub gehen über den Proxy oben",
|
||||
"Plugins, npm and GitHub go direct": "Plugins, npm und GitHub gehen direkt",
|
||||
"App updates": "App-Updates",
|
||||
"Updates go through the proxy above": "Updates gehen über den Proxy oben",
|
||||
"Updates go direct": "Updates gehen direkt",
|
||||
"Updates go through {proxy}": "Updates gehen über {proxy}",
|
||||
"Plugins, npm and GitHub go through {proxy}": "Plugins, npm und GitHub gehen über {proxy}",
|
||||
"Following HTTPS_PROXY, {proxy}": "Folgt HTTPS_PROXY, {proxy}",
|
||||
"Ask Cloudflare through the proxy and direct, and compare the addresses the two leave from": "Fragt Cloudflare einmal über den Proxy und einmal direkt und vergleicht die Adressen, von denen beide ausgehen",
|
||||
|
||||
@@ -355,6 +355,10 @@
|
||||
<div class="who"><div class="name" data-t>Plugin downloads</div><div class="sub" id="pluginProxySub"></div></div>
|
||||
<div id="pluginProxySegs" class="proxy-segs"></div>
|
||||
</div>
|
||||
<div class="row pref" id="updateProxyRow">
|
||||
<div class="who"><div class="name" data-t>App updates</div><div class="sub" id="updateProxySub"></div></div>
|
||||
<div id="updateProxySegs" class="proxy-segs"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-head"><span class="label" data-t>Proxies</span></div>
|
||||
<div class="list prefs" id="proxiesList"></div>
|
||||
|
||||
@@ -33,7 +33,7 @@ type savedProxyJSON struct {
|
||||
}
|
||||
|
||||
type proxyUseJSON struct {
|
||||
Where string `json:"where,omitempty"` // "global" or "plugins"; else a provider
|
||||
Where string `json:"where,omitempty"` // "global", "plugins" or "updates"; else a provider
|
||||
Provider string `json:"provider,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
}
|
||||
@@ -71,6 +71,9 @@ func savedProxies() []savedProxyJSON {
|
||||
if strings.TrimSpace(cur.PluginProxy) == ref {
|
||||
row.Uses = append(row.Uses, proxyUseJSON{Where: "plugins"})
|
||||
}
|
||||
if strings.TrimSpace(cur.UpdateProxy) == ref {
|
||||
row.Uses = append(row.Uses, proxyUseJSON{Where: "updates"})
|
||||
}
|
||||
for _, u := range provider.ProxyUses(p.ID) {
|
||||
row.Uses = append(row.Uses, proxyUseJSON{Provider: u.Provider, Account: u.Account})
|
||||
}
|
||||
|
||||
@@ -212,6 +212,7 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) {
|
||||
was.RequestArchiveLocal, was.RequestArchiveLocalMB = true, 256
|
||||
was.ProxyCustom = "http://me:secret@proxy.example:8080"
|
||||
was.PluginProxyCustom = "http://me:secret@plugins.example:8080"
|
||||
was.UpdateProxyCustom = "http://me:secret@updates.example:8080"
|
||||
was.PanelShortcut = "Ctrl+Alt+K"
|
||||
was.Proxies = []settings.NamedProxy{{ID: "p1", Name: "Office", URL: "http://proxy.example:8080"}} // their own routes, /api/proxies/*
|
||||
was.ProxyNames = map[string]string{"p1": "Office"}
|
||||
|
||||
@@ -63,7 +63,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
test(`${engine} ${lang} ${width}px: saved proxies are listed, tested and chosen`, 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 context = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(4000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// App updates' 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 updateProxy alone, the
|
||||
// global proxy as it was; Custom again brings back the last address, which
|
||||
// the server remembers as updateProxyCustom.
|
||||
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: "", updateProxy: "",
|
||||
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.updateProxy && body.updateProxy !== "direct";
|
||||
cur = { ...cur, ...body, updateProxyCustom: own ? body.updateProxy : cur.updateProxyCustom };
|
||||
}
|
||||
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: "App updates", 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: "App-Updates", 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: app updates 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("#updateProxyRow");
|
||||
await row.getByText(l.row, { exact: true }).waitFor();
|
||||
const box = page.locator("#updateProxySegs");
|
||||
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).updateProxy, want);
|
||||
assert.equal(posts.at(-1).proxy, "direct", "the global proxy stays as it was");
|
||||
assert.equal(posts.at(-1).pluginProxy, "", "plugin downloads stay as they were");
|
||||
assert(!("updateProxyCustom" 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("#updateProxySub").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("#updateProxySegs button.proxy-test").count(), 0);
|
||||
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, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,3 +54,30 @@ func TestPluginProxySaved(t *testing.T) {
|
||||
t.Fatal("a refused value overwrote the saved one")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateProxyOwn(t *testing.T) {
|
||||
from := Settings{Theme: "dark", UpdateProxy: "socks5://a:b@there:1080", UpdateProxyCustom: "socks5://a:b@there:1080"}
|
||||
from.KeepOwn(Settings{UpdateProxy: "direct", UpdateProxyCustom: "http://c:d@here:8080"})
|
||||
if from.UpdateProxy != "direct" || from.UpdateProxyCustom != "http://c:d@here:8080" || from.Theme != "dark" {
|
||||
t.Fatalf("a sync changed this computer's update proxy: %+v", from)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateProxySaved(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
if err := Save(Settings{UpdateProxy: " socks5://u:p@127.0.0.1:1080 "}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s := Load(); s.UpdateProxy != "socks5://u:p@127.0.0.1:1080" || s.UpdateProxyCustom != s.UpdateProxy || s.Proxy != "" || s.PluginProxy != "" {
|
||||
t.Fatalf("saved %+v", s)
|
||||
}
|
||||
if err := Save(Settings{UpdateProxy: "direct", UpdateProxyCustom: Load().UpdateProxyCustom}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s := Load(); s.UpdateProxy != "direct" || s.UpdateProxyCustom != "socks5://u:p@127.0.0.1:1080" {
|
||||
t.Fatalf("direct lost the remembered address: %+v", s)
|
||||
}
|
||||
if Save(Settings{UpdateProxy: "ftp://x:21"}) == nil {
|
||||
t.Fatal("ftp:// taken as a proxy")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,15 @@ type Settings struct {
|
||||
PluginProxy string `json:"pluginProxy,omitempty"`
|
||||
// PluginProxyCustom is PluginProxy's ProxyCustom.
|
||||
PluginProxyCustom string `json:"pluginProxyCustom,omitempty"`
|
||||
// UpdateProxy is the proxy magpie's own update goes through: the
|
||||
// update feed, the release notes and the release's file (moonlityu on
|
||||
// X: models direct, updates through a proxy). "" follows Proxy, as
|
||||
// updates always did; "direct" uses none; anything else is the proxy,
|
||||
// as Proxy takes it. A proxy given to one `magpie update --proxy` run
|
||||
// comes first. This computer's own (KeepOwn), as Proxy is.
|
||||
UpdateProxy string `json:"updateProxy,omitempty"`
|
||||
// UpdateProxyCustom is UpdateProxy's ProxyCustom.
|
||||
UpdateProxyCustom string `json:"updateProxyCustom,omitempty"`
|
||||
// Proxies are the proxies kept by name (NamedProxy); a proxy choice
|
||||
// "@"+id anywhere (Proxy, PluginProxy, a provider's, a key's, an
|
||||
// account's) uses one. This computer's own (KeepOwn).
|
||||
@@ -1580,6 +1589,7 @@ func (s *Settings) KeepOwn(cur Settings) {
|
||||
s.DockNever, s.DockSettled = cur.DockNever, cur.DockSettled
|
||||
s.ProxyCustom, s.Proxies, s.ProxyNames = cur.ProxyCustom, cur.Proxies, cur.ProxyNames
|
||||
s.PluginProxy, s.PluginProxyCustom = cur.PluginProxy, cur.PluginProxyCustom
|
||||
s.UpdateProxy, s.UpdateProxyCustom = cur.UpdateProxy, cur.UpdateProxyCustom
|
||||
s.WindowMaximised, s.KeepAwake, s.KeepAwakeDisplay = cur.WindowMaximised, cur.KeepAwake, cur.KeepAwakeDisplay
|
||||
s.WindowAt = cur.WindowAt
|
||||
s.TrayUsages, s.TrayUsage, s.TrayUsageEvery, s.TrayNoLogos, s.TrayNoBird, s.TrayPace, s.TrayNoCost = cur.TrayUsages, cur.TrayUsage, cur.TrayUsageEvery, cur.TrayNoLogos, cur.TrayNoBird, cur.TrayPace, cur.TrayNoCost
|
||||
@@ -2440,6 +2450,13 @@ func saveOwn(s Settings, recording, reads bool) error {
|
||||
if s.PluginProxy != "" && s.PluginProxy != "direct" && !IsProxyRef(s.PluginProxy) {
|
||||
s.PluginProxyCustom = s.PluginProxy
|
||||
}
|
||||
s.UpdateProxy = strings.TrimSpace(s.UpdateProxy)
|
||||
if err := CheckProxyIn(s.UpdateProxy, s.Proxies); err != nil {
|
||||
return fmt.Errorf("updates: %w", err)
|
||||
}
|
||||
if s.UpdateProxy != "" && s.UpdateProxy != "direct" && !IsProxyRef(s.UpdateProxy) {
|
||||
s.UpdateProxyCustom = s.UpdateProxy
|
||||
}
|
||||
s.Vision = strings.TrimSpace(s.Vision)
|
||||
if s.Vision != "" && s.Vision != "off" && !strings.Contains(s.Vision, "/") {
|
||||
return fmt.Errorf("the vision model must be a model's id such as openai/gpt-5-mini, or off, not %q", s.Vision)
|
||||
|
||||
@@ -37,7 +37,7 @@ var Keys = []string{
|
||||
// usage and alerts
|
||||
"currency", "chineseUnits", "usageAlert", "balanceAlert", "resetReminder", "turnDoneAlert", "maskAlert",
|
||||
// network
|
||||
"proxy", "pluginProxy",
|
||||
"proxy", "pluginProxy", "updateProxy",
|
||||
// privacy
|
||||
"redact", "redactPersonal", "redactKinds", "redactWords", "redactWordsAnyCase", "redactWordsWhole", "redactShape",
|
||||
"noStats", "noUsageStats", "otel",
|
||||
@@ -297,6 +297,7 @@ func Merge(body []byte, cur settings.Settings, web bool) (settings.Settings, err
|
||||
in.GitHubToken = cur.GitHubToken // set on its own (github-token), never sent to the page
|
||||
in.ProxyCustom = cur.ProxyCustom // set by settings.Save from the proxy, never by the page
|
||||
in.PluginProxyCustom = cur.PluginProxyCustom // and plugin downloads' from theirs
|
||||
in.UpdateProxyCustom = cur.UpdateProxyCustom // and updates'
|
||||
in.ProxyNames = cur.ProxyNames
|
||||
in.Proxies = cur.Proxies // set on its own (proxies), the password never sent to the page
|
||||
in.RequestArchive = cur.RequestArchive // the Gateway page's, set on its own
|
||||
|
||||
@@ -66,3 +66,69 @@ func TestUpdateGoesThroughTheProxy(t *testing.T) {
|
||||
t.Fatalf("through the proxy: %v, want %v", seen, want)
|
||||
}
|
||||
}
|
||||
|
||||
// Updates take a proxy of their own (moonlityu on X: models direct, updates
|
||||
// through a proxy): UpdateProxy is used while the global proxy is direct,
|
||||
// a proxy given to the run comes first, and unset follows the global one.
|
||||
func TestUpdateTakesItsOwnProxy(t *testing.T) {
|
||||
h := t.TempDir()
|
||||
t.Setenv("HOME", h)
|
||||
t.Setenv("USERPROFILE", h)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
||||
for _, k := range []string{"HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy", "NO_PROXY", "no_proxy"} {
|
||||
t.Setenv(k, "")
|
||||
}
|
||||
var mu sync.Mutex
|
||||
hits := map[string]int{}
|
||||
serve := func(name string) *httptest.Server {
|
||||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
mu.Lock()
|
||||
hits[name]++
|
||||
mu.Unlock()
|
||||
json.NewEncoder(w).Encode(Release{Version: "9.9.9"})
|
||||
}))
|
||||
}
|
||||
own, global, run := serve("own"), serve("global"), serve("run")
|
||||
defer own.Close()
|
||||
defer global.Close()
|
||||
defer run.Close()
|
||||
t.Setenv("MAGPIE_UPDATE_FEED", "http://feed.magpie.invalid/api/latest")
|
||||
ask := func(ctx context.Context, s settings.Settings) {
|
||||
t.Helper()
|
||||
if err := settings.Save(s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := Latest(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
want := func(own_, global_, run_ int) {
|
||||
t.Helper()
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if hits["own"] != own_ || hits["global"] != global_ || hits["run"] != run_ {
|
||||
t.Fatalf("hits own/global/run = %d/%d/%d, want %d/%d/%d", hits["own"], hits["global"], hits["run"], own_, global_, run_)
|
||||
}
|
||||
}
|
||||
// global direct, updates through their own proxy
|
||||
ask(context.Background(), settings.Settings{Proxy: "direct", UpdateProxy: own.URL})
|
||||
want(1, 0, 0)
|
||||
// the global proxy elsewhere: the update's own still wins
|
||||
ask(context.Background(), settings.Settings{Proxy: global.URL, UpdateProxy: own.URL})
|
||||
want(2, 0, 0)
|
||||
// a proxy given to this run (magpie update --proxy) comes first
|
||||
ask(WithProxy(context.Background(), run.URL), settings.Settings{Proxy: global.URL, UpdateProxy: own.URL})
|
||||
want(2, 0, 1)
|
||||
// unset: the global proxy, as before
|
||||
ask(context.Background(), settings.Settings{Proxy: global.URL})
|
||||
want(2, 1, 1)
|
||||
// direct for updates while the global proxy is set: neither proxy is asked
|
||||
// (the feed host resolves nowhere, so the request fails)
|
||||
if err := settings.Save(settings.Settings{Proxy: global.URL, UpdateProxy: "direct"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := Latest(context.Background()); err == nil {
|
||||
t.Fatal("a direct update reached a host that resolves nowhere")
|
||||
}
|
||||
want(2, 1, 1)
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/rosetta"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/source"
|
||||
)
|
||||
|
||||
@@ -98,7 +99,27 @@ func proxied() http.RoundTripper {
|
||||
// trusted beside the system's; the file is still checked against the
|
||||
// feed's SHA-256 and, on macOS, the signer
|
||||
netproxy.TrustEnvRoots(t)
|
||||
return netproxy.Dispatch(t)
|
||||
return updateProxy{netproxy.Dispatch(t)}
|
||||
}
|
||||
|
||||
// updateProxy has a request that names no proxy of its own (WithProxy,
|
||||
// magpie update --proxy) go through Settings' UpdateProxy when it is set
|
||||
// (moonlityu on X: models direct, updates through a proxy); unset, it
|
||||
// follows the global proxy as updates always did.
|
||||
type updateProxy struct{ http.RoundTripper }
|
||||
|
||||
func (u updateProxy) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if c := strings.TrimSpace(settings.Load().UpdateProxy); c != "" && netproxy.Choice(req.Context()) == "" {
|
||||
req = req.WithContext(netproxy.With(req.Context(), c))
|
||||
}
|
||||
return u.RoundTripper.RoundTrip(req)
|
||||
}
|
||||
|
||||
// CloseIdleConnections passes on to the transport underneath.
|
||||
func (u updateProxy) CloseIdleConnections() {
|
||||
if c, ok := u.RoundTripper.(interface{ CloseIdleConnections() }); ok {
|
||||
c.CloseIdleConnections()
|
||||
}
|
||||
}
|
||||
|
||||
// Latest asks the feed for the newest release, its notes in English.
|
||||
|
||||
Reference in New Issue
Block a user