Files
magpie/internal/gui/tests/proxy-down.test.cjs
T
yetone a4bf1a039e netproxy: Auto goes direct while the system's loopback proxy isn't running (@bitssly on X)
@bitssly (X, magpie 0.1.4519, Windows 11 amd64): with the proxy on Auto,
every model failed with 502 "proxy not reachable" once their VPN app was
off, a restart of magpie too, until they set the proxy Off. A VPN or
proxy app that quits without clearing Internet Options leaves
ProxyEnable=1 and ProxyServer=127.0.0.1:port in HKCU, and Auto took the
system proxy as it was: every request went to a port nothing listens on.

Auto now takes a system proxy on loopback only while its port accepts a
connection (liveSystem, through the same listening check the login
shell's proxy already had: 300ms dial, kept 15s while up, 2s while down,
so the VPN coming back is followed within 2 seconds). Every route that
asks Auto goes through it: For (netproxy.Func for the gateway and every
transport, and http.DefaultClient through Install), EnvWith (the CLIs
magpie starts, Bun, and the plugin host, whose proxy check every 15s/2s
restarts it on a change) and Describe. Settings › Network says it:
source "down" reads "Nothing answers at the proxy found, {proxy};
requests go direct until it runs again", in every language.

Not changed, on purpose:
- A proxy set in magpie is never gone around: a dead one still fails.
- The environment's *_PROXY, set for this process by whoever started
  it, is taken as it is, dead or not.
- A system proxy elsewhere than loopback isn't probed: a proxy that is
  down can't be told from a network that drops a probe.
- internal/agent/codex_proxy.go reads the raw System(): it predicts what
  Codex itself does.
- Going direct while the VPN is off means vendors see the computer's own
  address. A user who needs to fail closed sets the proxy in magpie.

Run:
- win-run (xiaomi-gpu, Windows 11) go test ./internal/netproxy: ok.
  TestWindowsDeadSystemProxyGoesDirect writes ProxyEnable/ProxyServer to
  a scratch key that RegOverridePredefKey puts in place of HKCU, so the
  box's own Internet Options are untouched. It reads them through the
  real system() and the real 300ms dial: direct while nothing listens,
  the proxy again once a listener runs.
- win-run go test ./internal/plugin: TestPiPackage,
  TestCachedReadsSavedProvidersOnce (#7197), TestDistReadFailedIsntMissing
  (#6075) and TestPluginLeavesTheUserNetworkDirect (#4115) are red on
  Windows at origin/main 239da9991 too; the last two pass 3 of 3 here.
- wsl-run (magpie-desktop) go test -timeout 45m ./... at ac4da60cb
  (these two commits on origin/main 9bf5848c1): ok except
  TestRequestStateKeptAcrossACatalogFetchedAgain (#6572, red at
  origin/main too), TestSearchQueueKeepsCodexAlive/cancel (#7090) and
  the root, cli and gui packages, which need gtk4 there.
- At the pushed head (rebased on e4e9eb092), mote-run go test
  -timeout 45m of netproxy, gui, plugin, gateway, usage, provider and
  agent: ok except TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes
  (#7117, red 3 of 3 at origin/main e4e9eb092 too) and two TempDir
  cleanup reds, TestSetPortServesWhenTheOldOneWasTaken (#7112) and
  TestRequestChunksFromDisk (#4390; 3 of 3 alone).
- go vet ./... and GOOS=windows go vet ./... on mote: ok; vet natively
  on Windows: ok; Linux vet of netproxy, plugin, gateway, agent and
  provider in WSL: ok. gofmt -l clean.
- GUI, wsl-run: proxy-down.test.cjs (5 languages, 1100 and 420px,
  chromium and webkit), i18n-keys and every *proxy* and settings-* file
  at ac4da60cb. Reds: settings-proxy-auth / settings-proxy-remember 4s
  clicks beside a Go suite (#7192, #5562; 30 of 30 alone),
  provider-proxy (#7100) and settings-update-source webkit, red the same
  at origin/main 9bf5848c1. At the pushed head proxy-down, i18n-keys,
  settings-search, settings-proxy-remember, proxy-gaps and
  proxy-own-wording: 94 of 94.

Broken by hand: liveSystem returning the system proxy as it is turns
TestDeadLoopbackSystemProxyGoesDirect red (WSL) and the Windows
registry test red (xiaomi-gpu).

Not tried: magpie.exe against the box's real Internet Options (shared
machine), which source the reporter's proxy was in (registry or env), and
whether a connection dialled direct is kept after the VPN comes back
(#4523 is that class for a changed proxy).
2026-11-19 18:04:19 +08:00

67 lines
3.9 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// @bitssly on X (Windows, proxy Auto): a VPN app turned off left the
// system's proxy at its loopback port, and every model failed with 502
// "proxy not reachable" until Off. Auto now goes direct while nothing
// listens there (netproxy.liveSystem), and Settings says so: the proxy
// found, by its address without its login, and that requests go direct.
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) {
const cur = {
theme: "light", lang, tray: "panel", currency: "usd", textSize: 100,
proxy: "", proxyNow: "http://127.0.0.1:7897", proxySource: "down",
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") 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 want = {
en: "Nothing answers at the proxy found, http://127.0.0.1:7897; requests go direct until it runs again",
zh: "找到的代理 http://127.0.0.1:7897 没有在运行,请求先直连,等它恢复后再走代理",
"zh-TW": "找到的代理 http://127.0.0.1:7897 沒有在執行,請求先直連,等它恢復後再走代理",
ja: "見つかったプロキシ http://127.0.0.1:7897 が応答しないため、再び動くまで直接接続します",
de: "Der gefundene Proxy http://127.0.0.1:7897 antwortet nicht; Anfragen laufen direkt, bis er wieder läuft",
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(want)) {
for (const width of [1100, 420]) {
test(`${engine} ${lang} ${width}px: Auto with a dead system proxy says it goes direct`, 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 errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang));
await page.goto("http://magpie.test/?view=settings&tab=network");
await page.waitForFunction((s) => document.querySelector("#proxySub")?.textContent === s, want[lang]);
assert.deepEqual(errors, []);
});
}
}
}