gui: the sign-in box shows the proxy it goes through, and another can be picked and kept as the account's (#1663, demystify0137)
What changed: while a sign-in waits (or after it failed), the box shows "Proxy: …" beside Open again. It opens the app menu (openProtoMenu, no native select) with Global (only when it could be kept), Direct, the subscription's proxy, each account's proxy and Custom…, which asks for an http://, https:// or socks5:// address. Picking one starts the sign-in again through it and cancels the open one; when it ends, the backend keeps the pick as the account's (keepSignInProxy). Userinfo in a proxy URL is never shown. "Sign in again" on an account now names that account (user), so it goes through the account's own proxy. The user and the pick are carried through the risk, site and plugin-method steps. Strings in zh, zh-TW, ja and de. docs/subsystems/providers-accounts.md describes the sign-in proxy. Why: the reporter asked that a sign-in use the subscription's or the account's proxy and be able to choose one; the default now does, and this lets the user choose and see it. What was run: - signin-proxy.test.cjs (new): Chromium and WebKit, en/zh/zh-TW/ja/de, at 900 and 380 wide, 40/40. It fails against HEAD's app.js (no link). - The sign-in, add-sheet, plugin-signin, click-scroll, i18n-keys and gui-<lang> files: 203/203; signin-close.test.cjs updated (the acts row now also holds the proxy link). - go test -tags nogui ./... ok; gofmt; linux/windows vet. Not tried: a real vendor sign-in through a real proxy from the window.
This commit is contained in:
@@ -28,7 +28,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi
|
||||
| Subscription accounts | `Accounts` reads the credentials each agent keeps on disk or in the macOS Keychain; nothing is stored twice. With account discovery off (#1535, below) none of them is read. A built-in that has moved to its plugin is dropped (`Moved`), and plugin accounts are placed in its slot (`placeMoved`). `Sign` adds the account's own auth, then the user's `Headers`. | [`account.go`](../../internal/provider/account.go) |
|
||||
| Token refresh | Each account refreshes through its vendor. For example, `codexToken` refreshes within 5 minutes of expiry and writes the rotated tokens back into `~/.codex/auth.json` for Codex CLI. A 400 or 401 from the vendor's refresh endpoint means it was refused (`refreshFailed`). | [`account.go`](../../internal/provider/account.go) |
|
||||
| Saved accounts | `logins.json` remembers every Codex and Claude Code account seen signed in. A switch moves the credentials into the agent's own store and saves the ones it replaces. A saved account that is on (`SetLoginOn`) stands behind the agent's own. Its tokens stay in `logins.json`. | [`logins.go`](../../internal/provider/logins.go), [`logins_on.go`](../../internal/provider/logins_on.go) |
|
||||
| Sign-in in magpie | `StartSignIn` runs the vendor's own browser OAuth with its client and takes the tokens at a callback on this machine. A browser that can't reach that callback (magpie on a server or in Docker) ends on a page that won't load; its address, pasted (`SubmitSignInCallback`), goes through the same callback handler (`pastedCallback`). A plugin's browser sign-in (`auto`) whose page names a port on this machine to come back to takes its pasted address too: magpie opens it there on 127.0.0.1, for the plugin's own listener (`pluginCallback`, `loopbackPorts`); Command Code's page posts its key from script, so it offers the API key way instead. A Claude account is signed in by Claude Code itself. Signing in brings back an account removed from magpie (`ShowAccount`). A sign-in started in magpie (`StartSignIn`, `StartPluginSignIn`) reads as done (`SignInStatus`, `WaitSignIn`) only after `finish` has run `ShowAccount` for its account, so the window, which opens the account as soon as it sees done, finds it listed. If providers.json can't be written then, the account stays hidden and the sign-in still ends done. Signing in to a plugin's provider from the command line (`pluginLogin`, with a key or the browser) brings it back too. It also takes off the mark a sign-in its vendor turned away left on the account (`Lapsed`) and shows again the agent's own account removed in magpie (`clearPluginLapse`). The window's plugin sign-in does the same with the browser (`pluginDone`, then `finish`) or with a key (`PluginAPIKey`); a key and the command line share these steps in `PluginSignedIn`. | [`signin.go`](../../internal/provider/signin.go), [`claude_signin.go`](../../internal/provider/claude_signin.go), [`pluginsignin.go`](../../internal/provider/pluginsignin.go), [`pluginsignin_paste.go`](../../internal/provider/pluginsignin_paste.go), [`plugins_cli.go`](../../plugins_cli.go) |
|
||||
| Sign-in in magpie | `StartSignIn` runs the vendor's own browser OAuth with its client and takes the tokens at a callback on this machine. A browser that can't reach that callback (magpie on a server or in Docker) ends on a page that won't load; its address, pasted (`SubmitSignInCallback`), goes through the same callback handler (`pastedCallback`). A plugin's browser sign-in (`auto`) whose page names a port on this machine to come back to takes its pasted address too: magpie opens it there on 127.0.0.1, for the plugin's own listener (`pluginCallback`, `loopbackPorts`); Command Code's page posts its key from script, so it offers the API key way instead. A Claude account is signed in by Claude Code itself. Signing in brings back an account removed from magpie (`ShowAccount`). A sign-in started in magpie (`StartSignIn`, `StartPluginSignIn`) reads as done (`SignInStatus`, `WaitSignIn`) only after `finish` has run `ShowAccount` for its account, so the window, which opens the account as soon as it sees done, finds it listed. If providers.json can't be written then, the account stays hidden and the sign-in still ends done. Signing in to a plugin's provider from the command line (`pluginLogin`, with a key or the browser) brings it back too. It also takes off the mark a sign-in its vendor turned away left on the account (`Lapsed`) and shows again the agent's own account removed in magpie (`clearPluginLapse`). The window's plugin sign-in does the same with the browser (`pluginDone`, then `finish`) or with a key (`PluginAPIKey`); a key and the command line share these steps in `PluginSignedIn`. A sign-in leaves through the proxy the account's own requests will use (#1663): `ProxyOfLogin` (the account's, else the subscription's, else the global one) for the account being signed in again, the subscription's for a new one. Every request of the flow goes through `signInFlow.via`, Claude Code's own login gets it as *_PROXY (`netproxy.EnvWith`), and a plugin's sign-in runs its fetch under that proxy (`via` in `host.js`; `plugins_cli.go` for the command line). The window's sign-in box shows it as a "Proxy: …" link (`signInProxyLink`, the app menu, no userinfo shown) with Global, Direct, the subscription's and each account's proxy, or a typed one; picking one starts the sign-in again through it (`SignInOptions.Proxy`), and when it ends the pick is kept as the account's (`keepSignInProxy`: the subscription's own when it is its only account, else the account's entry). Global isn't offered while the subscription has a proxy and other accounts, since nothing could keep it. The browser's own leg goes through the browser's network, not magpie's. | [`signin.go`](../../internal/provider/signin.go), [`claude_signin.go`](../../internal/provider/claude_signin.go), [`pluginsignin.go`](../../internal/provider/pluginsignin.go), [`pluginsignin_paste.go`](../../internal/provider/pluginsignin_paste.go), [`proxy.go`](../../internal/provider/proxy.go), [`plugins_cli.go`](../../plugins_cli.go) |
|
||||
| Import from files | `ImportLogins` (ChatGPT, Claude), `ImportGoogleAccounts` (Antigravity) and `ImportFactoryKeys` take other tools' files, from the window (`signin/import`) or `magpie accounts import` (#1453). ChatGPT reads Codex's `auth.json`, CLIProxyAPI's and Cockpit Tools' files, Sub2API's export (`sub2apiEntry`) and codexbar's `~/.codexbar/config.json` (`codexbarEntries`: the `openai_oauth` provider's accounts and `openAI.remoteConnectionAccounts`, the workspace from `openAIAccountId`). Each ChatGPT and Google sign-in is refreshed before it is added, so the tool the file came from is signed out of it; both surfaces say so first, and the command imports nothing without `--yes` or a yes. Claude's are kept as the file has them. A refresh token magpie holds already is `exists`, never refreshed; accounts are matched by email and workspace (`sameLogin`). An entry with an access token and no refresh token is refused (`accessOnly`). One file of several that holds no account is a failed row with its place (`ImportedAccount.File`), never skipped. The files are only read. | [`login_import.go`](../../internal/provider/login_import.go), [`google_import.go`](../../internal/provider/google_import.go), [`factory_key.go`](../../internal/provider/factory_key.go), [`accounts_cli.go`](../../accounts_cli.go) |
|
||||
| Used-up switch | When the account Codex or Claude Code is signed in to has used its allowance, the agent is signed in to the next account that is on and has room (#208). | [`codex_switch.go`](../../internal/provider/codex_switch.go) |
|
||||
| Routing groups | User-made groups from the Routing view, and auto-found groups of the same model across providers (derived, never stored). Members are `provider/model[:effort]`. A group can nest another (`group/<id>`); `SaveGroup` refuses loops. `Match` takes a glob or `re:` pattern (#766). A found group follows its providers: one switched off or removed leaves it, and one on again is back. A found group the user changed (an `auto-…` id stored) is read without the members of providers magpie no longer has (`withoutRemoved`, not written back, so a provider back under its id is back in it), except a manual group's pick, a rule's model, or all of them when none would be left. A switched-off provider's members stay in it, skipped by `membersIn`, and the Routing page says them as switched off (`memberJSON.providerOff`). The user's own groups keep their members. Three templates make a group in one click from the models the user has (`provider.Templates`, `AddTemplate`; the Routing page's cards before a first group and its Templates menu after, `magpie group template [kind] [name]`): `smart` sends a hard turn to the strongest model and an easy one or a compaction to a cheap one, asked by a classifier (the decision API when there is one, else the cheapest priced model that doesn't reason); `thrifty` starts on two cheap models of different providers and sends high reasoning to the strongest; `steady` fails over between the strongest model of up to three providers. A model is weighed by its maker's list price when known, else what its provider charges, else by its id's size words (`sizeOf`); one over `tooDear` (USD 100 a million output tokens) is never picked. A template that can't be made says what is missing (`Need`). It is saved under a name and id no group has (`freeGroupName`, shared with `CopyGroup`), never over one. A group is shared as text (`ShareGroup`, a group row's Copy to share): JSON marked `"magpie": "routing-group"` with a format `version` (`ShareVersion`), holding the group's members as it names them, patterns, routing, rules, classifier and settings. A group holds only `provider/model` ids, never a key, account or address, and the derived matches, found/hidden/off flags and the rules that hold by a folder (a path on the sharer's machine, `Rule.Folders`) stay behind; a pasted one is left out too. `ImportGroup` (the Routing page's Import, `POST /api/groups/import`) reads it with words or a code fence around it, refuses another text, a newer format or none (`ShareError`, said in the reader's language). A member whose provider the importer has is kept; else the same model (`AutoGroupOf`) under the first provider of theirs that serves it (`Instead`); else it is left out and named (`Missing`), with the rules that send to it, its place among the off and fast members, and a classifier gone takes the intent rules and auto effort with it. Nothing is added when no member is left; what is added gets a free name, never replacing a group. A group of patterns only that match nothing now (a plugin's models not listed) has no members: `/api/groups` says them, and an unmakeable template's, as `[]`, never `null`; the Routing page reads the response through `groupsFrom` and draws a group it still can't draw as one row saying so, so one bad group never hides the rest (#1585). | [`group.go`](../../internal/provider/group.go), [`grouptemplate.go`](../../internal/provider/grouptemplate.go), [`group_share.go`](../../internal/provider/group_share.go) |
|
||||
@@ -137,6 +137,9 @@ Account discovery can be turned off (#1535): Settings → Privacy → *Subscript
|
||||
## Verification
|
||||
|
||||
```sh
|
||||
go test -tags nogui ./internal/provider -run 'GoesThroughItsProxy'
|
||||
go test -tags nogui ./internal/plugin -run TestPluginSignInProxy
|
||||
node --test internal/gui/tests/signin-proxy.test.cjs internal/gui/tests/signin-close.test.cjs
|
||||
go test -tags nogui ./internal/provider -run 'TestAccount|TestImport|TestCodex|TestGroup|TestQuota|TestLogin|TestSignIn|TestSeveralKeys|TestKeyProtocol|TestSetKeyWeight|TestReadSub2APIKeyLimits|TestSub2APIKeyLimitsOnItsCard|TestKeyAllowance|TestPlanKeyAllowance|TestPayAsYouGoKeyAskedSeldom|TestClaudeAccountToldRenewed|TestPluginAccountToldRenewed|TestAllowancesReadOnlyWhenAsked|TestAllowancesReadByThemselvesByDefault|TestKeyReadsOnlyWhenAsked'
|
||||
go test -tags nogui ./internal/provider -run 'TestCapHeld|TestCapReached|TestWindowCapHeld|TestSetWindowCap'
|
||||
go test -tags nogui ./internal/provider -run 'TestSeat|TestPlanOfASignedInAccountShownOnce|TestGLMPlanMatchesZCodePlugin|TestAccountName'
|
||||
|
||||
@@ -2410,8 +2410,11 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
.signing .n { font-weight: 500; }
|
||||
.signing .s { color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }
|
||||
.signing > .text { margin: -3px 0; }
|
||||
.signing .acts { display: flex; gap: 2px; margin: 2px 0 0 -4px; }
|
||||
.signing .acts { display: flex; flex-wrap: wrap; gap: 2px; margin: 2px 0 0 -4px; min-width: 0; }
|
||||
.signing .acts .link { color: var(--fg-2); }
|
||||
/* the proxy the sign-in goes through (#1663): a long address ends in an
|
||||
ellipsis inside the sheet */
|
||||
.signing .acts .via { max-width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.signing .devcode { display: flex; align-items: center; gap: 6px; margin: 6px 0 2px; }
|
||||
.signing .devcode code { font: var(--code-style, normal) 600 17px/1.2 var(--code-font, var(--code)); font-stretch: var(--code-stretch, 100%); letter-spacing: .12em; padding: 4px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); user-select: all; }
|
||||
/* the sign-in link, one line, selected whole with a click */
|
||||
|
||||
+160
-28
@@ -11046,31 +11046,38 @@ let signing = null; // the sign-in under way: { id, agent, url, state, installin
|
||||
const signingOpen = () => signing?.state === "waiting" || signing?.state === "installing";
|
||||
let justAdded = ""; // the account that just came in, to greet it
|
||||
|
||||
async function startSignIn(agent, risky, site) {
|
||||
// o: { user } signing that account in again, { proxy } the one picked to
|
||||
// sign in through (#1663): none picked, the one the account's requests go
|
||||
// through
|
||||
async function startSignIn(agent, risky, site, o = {}) {
|
||||
if (signingOpen()) api("signin/" + signing.id + "/cancel", {}).catch(() => {});
|
||||
// an account Google may suspend is added only once that is said
|
||||
if (subOf(agent)?.risk && !risky) {
|
||||
signing = { agent, state: "risk" };
|
||||
signing = { agent, state: "risk", forUser: o.user, picked: o.proxy };
|
||||
renderProviders();
|
||||
return;
|
||||
}
|
||||
// one on more than one site says which first
|
||||
if (subOf(agent)?.sites && !site) {
|
||||
signing = { agent, state: "site" };
|
||||
signing = { agent, state: "site", forUser: o.user, picked: o.proxy };
|
||||
renderProviders();
|
||||
return;
|
||||
}
|
||||
if (subOf(agent)?.plugin) return startPluginSignIn(subOf(agent), pluginMethod(subOf(agent), site));
|
||||
signing = { agent, site, state: "starting" };
|
||||
if (subOf(agent)?.plugin) return startPluginSignIn(subOf(agent), pluginMethod(subOf(agent), site), {}, o);
|
||||
const keep = { site, forUser: o.user, picked: o.proxy };
|
||||
signing = { agent, ...keep, proxy: o.proxy ?? signInProxyOf(agent, o.user), state: "starting" };
|
||||
renderProviders();
|
||||
try {
|
||||
signing = await api("signin", site ? { agent, site } : { agent });
|
||||
signing.site = site;
|
||||
const body = { agent };
|
||||
if (site) body.site = site;
|
||||
if (o.user) body.user = o.user;
|
||||
if (o.proxy != null) body.proxy = o.proxy;
|
||||
signing = { ...(await api("signin", body)), ...keep };
|
||||
if (web && signing.url) api("open", { url: signing.url });
|
||||
renderProviders();
|
||||
followSignIn(signing.id);
|
||||
} catch (e) {
|
||||
signing = { agent, site, state: "failed", error: e.message };
|
||||
signing = { agent, ...keep, proxy: o.proxy ?? signInProxyOf(agent, o.user), state: "failed", error: e.message };
|
||||
renderProviders();
|
||||
}
|
||||
}
|
||||
@@ -11084,16 +11091,32 @@ async function followSignIn(id) {
|
||||
if (st.state === "waiting" || st.state === "installing") {
|
||||
// the CLI it needed is in: now the vendor's page can open
|
||||
if (signing.state === "installing" && st.state === "waiting" && st.url) api("open", { url: st.url }).catch(() => {});
|
||||
if (signing.state !== st.state || signing.url !== st.url || signing.code !== st.code) { signing = { ...st, site: signing.site, method: signing.method }; renderProviders(); }
|
||||
if (signing.state !== st.state || signing.url !== st.url || signing.code !== st.code) { signing = { ...st, ...signingKept() }; renderProviders(); }
|
||||
continue;
|
||||
}
|
||||
if (st.state === "done") return signedIn(st);
|
||||
// a failed one keeps its site and way, for Try again
|
||||
signing = st.state === "canceled" ? null : { ...st, site: signing.site, method: signing.method };
|
||||
signing = st.state === "canceled" ? null : { ...st, ...signingKept() };
|
||||
renderProviders();
|
||||
}
|
||||
}
|
||||
|
||||
// signingKept: what a sign-in under way keeps across its updates, for Try
|
||||
// again and a proxy picked for it — its site and way, the account signed
|
||||
// in to again, the proxy picked
|
||||
function signingKept() {
|
||||
return { site: signing.site, method: signing.method, inputs: signing.inputs, forUser: signing.forUser, picked: signing.picked, askProxy: signing.askProxy, customProxy: signing.customProxy };
|
||||
}
|
||||
|
||||
// signInProxyOf: the proxy an account's sign-in goes through when none is
|
||||
// picked, as the server picks it (#1663): the account's own, else its
|
||||
// subscription's, else the global one ("")
|
||||
function signInProxyOf(agent, user) {
|
||||
const p = providers?.providers?.find((x) => x.account?.agent === agent);
|
||||
const own = user && p?.accountProxies?.[String(user).trim().toLowerCase()];
|
||||
return own || (p?.proxy || "").trim();
|
||||
}
|
||||
|
||||
// signedIn: a sign-in done — the account opened in the editor.
|
||||
async function signedIn(st) {
|
||||
signing = null;
|
||||
@@ -11117,7 +11140,7 @@ async function signedIn(st) {
|
||||
// startPluginSignIn: a plugin's provider signed in to as OpenCode's
|
||||
// `auth login` does — the way to sign in, the questions that way asks,
|
||||
// then the browser (and the code its page shows, pasted back) or a key.
|
||||
async function startPluginSignIn(sub, method, inputs = {}) {
|
||||
async function startPluginSignIn(sub, method, inputs = {}, o = {}) {
|
||||
const ms = sub.plugin.methods || [];
|
||||
if (!ms.length) {
|
||||
signing = { agent: sub.agent, state: "failed", error: t("The plugin has no way to sign in to {name}", { name: sub.name }) };
|
||||
@@ -11125,32 +11148,35 @@ async function startPluginSignIn(sub, method, inputs = {}) {
|
||||
}
|
||||
if (method == null) {
|
||||
if (ms.length > 1) {
|
||||
signing = { agent: sub.agent, state: "method" };
|
||||
signing = { agent: sub.agent, state: "method", forUser: o.user, picked: o.proxy };
|
||||
return renderProviders();
|
||||
}
|
||||
method = 0;
|
||||
}
|
||||
signing = { agent: sub.agent, method, inputs, state: "starting" };
|
||||
const keep = { method, inputs, forUser: o.user, picked: o.proxy };
|
||||
signing = { agent: sub.agent, ...keep, proxy: o.proxy ?? signInProxyOf(sub.agent, o.user), state: "starting" };
|
||||
renderProviders();
|
||||
try {
|
||||
const r = await api("plugin-signin/prompt", { provider: sub.pid, method, inputs });
|
||||
if (signing?.agent !== sub.agent) return;
|
||||
if (r.prompt) {
|
||||
signing = { agent: sub.agent, method, inputs, prompt: r.prompt, state: "prompt" };
|
||||
signing = { agent: sub.agent, ...keep, prompt: r.prompt, state: "prompt" };
|
||||
return renderProviders();
|
||||
}
|
||||
if (ms[method].type === "api") {
|
||||
signing = { agent: sub.agent, method, inputs, state: "key" };
|
||||
signing = { agent: sub.agent, ...keep, state: "key" };
|
||||
return renderProviders();
|
||||
}
|
||||
signing = await api("plugin-signin", { provider: sub.pid, method, inputs });
|
||||
signing.method = method;
|
||||
const body = { provider: sub.pid, method, inputs };
|
||||
if (o.user) body.user = o.user;
|
||||
if (o.proxy != null) body.proxy = o.proxy;
|
||||
signing = { ...(await api("plugin-signin", body)), ...keep };
|
||||
if (web && signing.url) api("open", { url: signing.url });
|
||||
renderProviders();
|
||||
followSignIn(signing.id);
|
||||
} catch (e) {
|
||||
if (signing?.agent !== sub.agent) return;
|
||||
signing = { agent: sub.agent, method, state: "failed", error: e.message };
|
||||
signing = { agent: sub.agent, ...keep, proxy: o.proxy ?? signInProxyOf(sub.agent, o.user), state: "failed", error: e.message };
|
||||
renderProviders();
|
||||
}
|
||||
}
|
||||
@@ -11166,7 +11192,7 @@ async function pluginAnswer(sub, value) {
|
||||
signing = { ...flow, error: r.error, value };
|
||||
return renderProviders();
|
||||
}
|
||||
startPluginSignIn(sub, flow.method, r.inputs);
|
||||
startPluginSignIn(sub, flow.method, r.inputs, { user: flow.forUser, proxy: flow.picked });
|
||||
} catch (e) {
|
||||
if (signing === flow) { signing = { ...flow, error: e.message, value }; renderProviders(); }
|
||||
}
|
||||
@@ -11191,6 +11217,7 @@ function renderPluginAsk(sub) {
|
||||
const box = el("div", "signing plugin-ask");
|
||||
const tt = el("span", "tt");
|
||||
box.append(tt);
|
||||
const flow = signing;
|
||||
const close = el("button", "text", t("Cancel"));
|
||||
close.onclick = cancelSignIn;
|
||||
if (signing.state === "method") {
|
||||
@@ -11201,13 +11228,12 @@ function renderPluginAsk(sub) {
|
||||
sub.plugin.methods.forEach((m, i) => {
|
||||
const b = el("button", "text primary", m.label || t(m.type === "api" ? "API key" : "Browser"));
|
||||
b.dataset.method = String(i);
|
||||
b.onclick = () => startPluginSignIn(sub, i);
|
||||
b.onclick = () => startPluginSignIn(sub, i, {}, { user: flow.forUser, proxy: flow.picked });
|
||||
ch.append(b);
|
||||
});
|
||||
return box;
|
||||
}
|
||||
const q = signing.prompt;
|
||||
const flow = signing;
|
||||
const form = el("form", "callback-form");
|
||||
const why = el("span", "s why", flow.error || "");
|
||||
if (flow.state === "prompt" && q.type === "select") {
|
||||
@@ -11316,6 +11342,99 @@ function cancelSignIn() {
|
||||
renderProviders();
|
||||
}
|
||||
|
||||
// A sign-in goes through the proxy its account's requests will go through,
|
||||
// so the vendor sees the account come from one place (#1663,
|
||||
// demystify0137): the sheet says which, and another can be picked, which
|
||||
// starts it again through that one and is kept as the account's proxy.
|
||||
// proxyShown is a proxy's address without the name and password in it.
|
||||
function proxyShown(u) {
|
||||
return String(u || "").replace(/^([a-z][a-z0-9+.-]*:\/\/)[^@/]*@/i, "$1");
|
||||
}
|
||||
function proxyName(v) {
|
||||
return !v ? t("Global proxy") : v === "direct" ? t("Direct") : proxyShown(v);
|
||||
}
|
||||
|
||||
// signInThrough: the sign-in under way started again through proxy v.
|
||||
function signInThrough(sub, v) {
|
||||
const f = signing;
|
||||
const o = { user: f?.forUser, proxy: v };
|
||||
if (!sub.plugin) return startSignIn(sub.agent, true, f?.site, o); // which ends this one
|
||||
if (f?.id && signingOpen()) api("signin/" + f.id + "/cancel", {}).catch(() => {});
|
||||
startPluginSignIn(sub, f?.method, f?.inputs || {}, o);
|
||||
}
|
||||
|
||||
// signInProxyChoices: the proxies a sign-in can go through — the global
|
||||
// one, none, the subscription's, the ones its other accounts go through,
|
||||
// or one typed in. The global one is left out while the subscription has
|
||||
// a proxy of its own and other accounts: an account can't be kept on the
|
||||
// global proxy then.
|
||||
function signInProxyChoices(sub) {
|
||||
const p = providers?.providers?.find((x) => x.account?.agent === sub.agent);
|
||||
const own = (p?.proxy || "").trim();
|
||||
const me = String(signing.forUser || "").trim().toLowerCase();
|
||||
const others = (p?.account?.logins || []).some((l) => String(l.user || "").trim().toLowerCase() !== me);
|
||||
const opts = [];
|
||||
const seen = new Set(["", "direct"]);
|
||||
const add = (v, note) => {
|
||||
if (seen.has(v)) return;
|
||||
seen.add(v);
|
||||
opts.push({ v, name: proxyShown(v), literalName: true, note });
|
||||
};
|
||||
if (!own || own === "direct" || !others) opts.push({ v: "", name: "Global proxy", note: "Follows the proxy in Settings" });
|
||||
opts.push({ v: "direct", name: "Direct", note: "Through no proxy" });
|
||||
if (own) add(own, t("{name}'s proxy", { name: sub.name }));
|
||||
for (const [u, v] of Object.entries(p?.accountProxies || {})) add((v || "").trim(), t("{user}'s proxy", { user: u }));
|
||||
if (signing.proxy) add(signing.proxy, "");
|
||||
opts.push({ v: "\x01", name: "Custom…", note: "http://, https:// or socks5://" });
|
||||
return opts;
|
||||
}
|
||||
|
||||
// signInProxyLink: the proxy the sign-in goes through, a link that picks
|
||||
// another.
|
||||
function signInProxyLink(sub) {
|
||||
const b = el("button", "link via", t("Proxy: {proxy}", { proxy: proxyName(signing.proxy) }));
|
||||
// the whole address too, which a narrow sheet cuts short
|
||||
b.title = proxyName(signing.proxy) + "\n" + t("The sign-in goes through this proxy, as the account's requests will. One picked here is kept as the account's.");
|
||||
b.setAttribute("aria-haspopup", "menu");
|
||||
b.setAttribute("aria-expanded", "false");
|
||||
b.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
const flow = signing;
|
||||
openProtoMenu(b, signInProxyChoices(sub), flow.askProxy ? "\x01" : flow.proxy || "", (v) => {
|
||||
if (signing !== flow) return;
|
||||
if (v === "\x01") { flow.askProxy = true; return renderProviders(); }
|
||||
if (v === (flow.proxy || "") && !flow.askProxy) return;
|
||||
signInThrough(sub, v);
|
||||
}, "Sign in through");
|
||||
};
|
||||
return b;
|
||||
}
|
||||
|
||||
// signInProxyForm: a proxy typed in to sign in through.
|
||||
function signInProxyForm(sub) {
|
||||
const flow = signing;
|
||||
const form = el("form", "callback-form proxy-ask");
|
||||
const label = t("Proxy");
|
||||
const inp = input(flow.customProxy || "", "http://127.0.0.1:7890");
|
||||
inp.setAttribute("aria-label", label);
|
||||
inp.autocomplete = "off";
|
||||
inp.onkeydown = (e) => e.stopPropagation();
|
||||
const go = el("button", "text primary", t("Sign in through it"));
|
||||
go.type = "submit";
|
||||
go.disabled = !inp.value.trim();
|
||||
inp.oninput = () => { flow.customProxy = inp.value; go.disabled = !inp.value.trim(); };
|
||||
const submit = (e) => {
|
||||
e.preventDefault();
|
||||
if (signing !== flow || !inp.value.trim()) return;
|
||||
signInThrough(sub, inp.value.trim());
|
||||
};
|
||||
form.onsubmit = submit;
|
||||
go.onclick = submit;
|
||||
form.append(inp, go);
|
||||
setTimeout(() => { if (inp.isConnected) inp.focus({ preventScroll: true }); });
|
||||
return form;
|
||||
}
|
||||
|
||||
// A Copilot account on GitHub Enterprise Cloud with data residency signs in
|
||||
// at its enterprise's <name>.ghe.com, not github.com (#723): the device
|
||||
// code's panel offers that, and the host is asked in place of the code.
|
||||
@@ -11399,7 +11518,8 @@ function renderSigning(sub) {
|
||||
tt.append(el("span", "s", t(sub.riskNote || "Google may suspend an Antigravity account it sees used outside Antigravity. Use one you can afford to lose.")));
|
||||
box.append(tt);
|
||||
const go = el("button", "text primary", t("Sign in anyway"));
|
||||
go.onclick = () => startSignIn(sub.agent, true);
|
||||
const o = { user: signing.forUser, proxy: signing.picked };
|
||||
go.onclick = () => startSignIn(sub.agent, true, undefined, o);
|
||||
const close = el("button", "text", t("Cancel"));
|
||||
close.onclick = cancelSignIn;
|
||||
if (sub.importable) {
|
||||
@@ -11424,11 +11544,12 @@ function renderSigning(sub) {
|
||||
close.onclick = cancelSignIn;
|
||||
box.append(close);
|
||||
const sites = el("div", "sites");
|
||||
const flow = signing;
|
||||
for (const [id, label, host] of sub.sites) {
|
||||
const b = el("button", "text primary", t(label));
|
||||
b.dataset.site = id;
|
||||
b.title = host;
|
||||
b.onclick = () => startSignIn(sub.agent, true, id);
|
||||
b.onclick = () => startSignIn(sub.agent, true, id, { user: flow.forUser, proxy: flow.picked });
|
||||
sites.append(b);
|
||||
}
|
||||
box.append(sites);
|
||||
@@ -11441,7 +11562,7 @@ function renderSigning(sub) {
|
||||
if (labels.some((l) => (m.label || "").includes(l))) return;
|
||||
const b = el("button", "link", t(m.label || (m.type === "api" ? "API key" : "Browser")));
|
||||
b.dataset.method = String(i);
|
||||
b.onclick = () => startPluginSignIn(sub, i);
|
||||
b.onclick = () => startPluginSignIn(sub, i, {}, { user: flow.forUser, proxy: flow.picked });
|
||||
ways.append(b);
|
||||
});
|
||||
if (ways.childElementCount) box.append(ways);
|
||||
@@ -11456,11 +11577,16 @@ function renderSigning(sub) {
|
||||
tt.append(el("span", "n", t("Sign-in didn't finish")), el("span", "s", signing.error || ""));
|
||||
box.append(tt);
|
||||
const again = el("button", "text primary", t("Try again"));
|
||||
again.onclick = () => sub.plugin ? startPluginSignIn(sub, signing.method) : startSignIn(sub.agent, true, signing.site);
|
||||
const o = { user: signing.forUser, proxy: signing.picked };
|
||||
again.onclick = () => sub.plugin ? startPluginSignIn(sub, signing.method, signing.inputs || {}, o) : startSignIn(sub.agent, true, signing.site, o);
|
||||
const close = el("button", "text", t("Cancel"));
|
||||
close.onclick = cancelSignIn;
|
||||
const acts = el("span", "acts");
|
||||
const ghe = copilotHostSwitch(sub);
|
||||
if (ghe) tt.append(el("span", "acts", ghe));
|
||||
if (ghe) acts.append(ghe);
|
||||
acts.append(signInProxyLink(sub));
|
||||
tt.append(acts);
|
||||
if (signing.askProxy) tt.append(signInProxyForm(sub));
|
||||
box.append(close, again);
|
||||
return box;
|
||||
}
|
||||
@@ -11502,7 +11628,13 @@ function renderSigning(sub) {
|
||||
acts.append(open);
|
||||
const ghe = copilotHostSwitch(sub);
|
||||
if (ghe) acts.append(ghe);
|
||||
acts.append(signInProxyLink(sub));
|
||||
tt.append(acts);
|
||||
if (signing.askProxy) tt.append(signInProxyForm(sub));
|
||||
} else if (signing.state === "waiting") {
|
||||
// a sign-in run by the vendor's CLI, no page of magpie's to show
|
||||
tt.append(el("span", "acts", signInProxyLink(sub)));
|
||||
if (signing.askProxy) tt.append(signInProxyForm(sub));
|
||||
}
|
||||
if (signing.pasteCallback || signing.pasteCode || signing.pasteKey) {
|
||||
const flow = signing;
|
||||
@@ -11778,7 +11910,7 @@ function renderAccounts(a, p) {
|
||||
row.classList.add("signed-out");
|
||||
row.append(el("span", "using", t("Sign-in required")));
|
||||
const again = el("button", "text", t("Sign in again"));
|
||||
again.onclick = () => startSignIn(a.agent);
|
||||
again.onclick = () => startSignIn(a.agent, false, undefined, { user: l.user });
|
||||
row.append(again);
|
||||
// the one Claude Code is signed in to can't be forgotten (ForgetLogin)
|
||||
if (!l.active) {
|
||||
@@ -11790,7 +11922,7 @@ function renderAccounts(a, p) {
|
||||
row.classList.add("signed-out");
|
||||
row.append(el("span", "using", t("Sign-in required")));
|
||||
const again = el("button", "text", t("Sign in again"));
|
||||
again.onclick = () => startSignIn(a.agent);
|
||||
again.onclick = () => startSignIn(a.agent, false, undefined, { user: l.user });
|
||||
const forget = el("button", "text quiet", t("Remove"));
|
||||
forget.title = l.own ? forgetOwnTitle(a) : t("magpie forgets this account's sign-in; the account itself is untouched");
|
||||
forget.onclick = () => accountAction("login/forget", { agent: a.agent, user: l.user }, t("{user} removed", { user: l.user }));
|
||||
|
||||
@@ -1431,6 +1431,15 @@ const I18N = {
|
||||
"Stop waiting for this sign-in": "不再等待这次登录",
|
||||
"Copy link": "复制链接",
|
||||
"Sign-in link": "登录链接",
|
||||
"Proxy: {proxy}": "代理:{proxy}",
|
||||
"The sign-in goes through this proxy, as the account's requests will. One picked here is kept as the account's.": "登录经由这个代理,与这个账号之后的请求相同。在这里选的代理会保存为这个账号的代理。",
|
||||
"Sign in through": "登录经由",
|
||||
"Through no proxy": "不经过代理",
|
||||
"{name}'s proxy": "{name} 的代理",
|
||||
"{user}'s proxy": "{user} 的代理",
|
||||
"Custom…": "自定义…",
|
||||
"http://, https:// or socks5://": "http://、https:// 或 socks5://",
|
||||
"Sign in through it": "经由它登录",
|
||||
"Account in use": "正在使用的账号",
|
||||
"Open it in another browser or profile: copy it there": "要用其他浏览器或浏览器配置登录,复制此链接到那里打开",
|
||||
"If the page the browser ends on won't load (magpie runs on a server or in Docker), copy its whole address and paste it here.": "若浏览器最终停在打不开的页面(magpie 运行在服务器或 Docker 中),请复制其完整地址粘贴到这里。",
|
||||
@@ -5763,6 +5772,15 @@ const I18N = {
|
||||
"Stop waiting for this sign-in": "不再等待這次登入",
|
||||
"Copy link": "複製連結",
|
||||
"Sign-in link": "登入連結",
|
||||
"Proxy: {proxy}": "代理:{proxy}",
|
||||
"The sign-in goes through this proxy, as the account's requests will. One picked here is kept as the account's.": "登入經由這個代理,與這個帳號之後的請求相同。在這裡選的代理會儲存為這個帳號的代理。",
|
||||
"Sign in through": "登入經由",
|
||||
"Through no proxy": "不經過代理",
|
||||
"{name}'s proxy": "{name} 的代理",
|
||||
"{user}'s proxy": "{user} 的代理",
|
||||
"Custom…": "自訂…",
|
||||
"http://, https:// or socks5://": "http://、https:// 或 socks5://",
|
||||
"Sign in through it": "經由它登入",
|
||||
"Account in use": "正在使用的帳號",
|
||||
"Open it in another browser or profile: copy it there": "要用其他瀏覽器或瀏覽器設定登入,複製此連結到那裡開啟",
|
||||
"If the page the browser ends on won't load (magpie runs on a server or in Docker), copy its whole address and paste it here.": "若瀏覽器最終停在打不開的頁面(magpie 執行在伺服器或 Docker 中),請複製其完整位址貼上到這裡。",
|
||||
@@ -10071,6 +10089,15 @@ const I18N = {
|
||||
"Stop waiting for this sign-in": "このサインインの待機をやめる",
|
||||
"Copy link": "リンクをコピー",
|
||||
"Sign-in link": "サインインリンク",
|
||||
"Proxy: {proxy}": "プロキシ:{proxy}",
|
||||
"The sign-in goes through this proxy, as the account's requests will. One picked here is kept as the account's.": "サインインはこのプロキシを経由します。このアカウントのリクエストも同じです。ここで選んだプロキシはこのアカウントのものとして保存されます。",
|
||||
"Sign in through": "サインインの経路",
|
||||
"Through no proxy": "プロキシを使わない",
|
||||
"{name}'s proxy": "{name} のプロキシ",
|
||||
"{user}'s proxy": "{user} のプロキシ",
|
||||
"Custom…": "カスタム…",
|
||||
"http://, https:// or socks5://": "http://、https:// または socks5://",
|
||||
"Sign in through it": "これ経由でサインイン",
|
||||
"Account in use": "使用中のアカウント",
|
||||
"Open it in another browser or profile: copy it there": "別のブラウザやプロファイルで開く場合:そちらにコピーしてください",
|
||||
"If the page the browser ends on won't load (magpie runs on a server or in Docker), copy its whole address and paste it here.": "ブラウザの最後のページが読み込めない場合(magpie がサーバーや Docker で動いているとき)は、そのアドレス全体をコピーしてここに貼り付けてください。",
|
||||
@@ -14398,6 +14425,15 @@ const I18N = {
|
||||
"Stop waiting for this sign-in": "Nicht mehr auf diese Anmeldung warten",
|
||||
"Copy link": "Link kopieren",
|
||||
"Sign-in link": "Anmeldelink",
|
||||
"Proxy: {proxy}": "Proxy: {proxy}",
|
||||
"The sign-in goes through this proxy, as the account's requests will. One picked here is kept as the account's.": "Die Anmeldung läuft über diesen Proxy, wie später die Anfragen des Kontos. Ein hier gewählter wird als Proxy des Kontos gespeichert.",
|
||||
"Sign in through": "Anmelden über",
|
||||
"Through no proxy": "Über keinen Proxy",
|
||||
"{name}'s proxy": "Proxy von {name}",
|
||||
"{user}'s proxy": "Proxy von {user}",
|
||||
"Custom…": "Eigener…",
|
||||
"http://, https:// or socks5://": "http://, https:// oder socks5://",
|
||||
"Sign in through it": "Darüber anmelden",
|
||||
"Account in use": "Verwendetes Konto",
|
||||
"Open it in another browser or profile: copy it there": "In einem anderen Browser oder Profil öffnen: dorthin kopieren",
|
||||
"If the page the browser ends on won't load (magpie runs on a server or in Docker), copy its whole address and paste it here.": "Lädt die Seite, auf der der Browser landet, nicht (magpie läuft auf einem Server oder in Docker), kopieren Sie ihre vollständige Adresse und fügen Sie sie hier ein.",
|
||||
|
||||
@@ -115,9 +115,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
});
|
||||
});
|
||||
assert(fit.every((f) => f.inside), JSON.stringify(fit));
|
||||
// one button puts it away: Open again stands alone, no Close
|
||||
// one button puts it away: Open again stands alone, no Close (beside
|
||||
// it only the proxy the sign-in goes through, #1663)
|
||||
const acts = box.locator(".acts");
|
||||
assert.deepEqual(await acts.locator("button").allTextContents(), [w.again]);
|
||||
assert.deepEqual(await acts.locator("button:not(.via)").allTextContents(), [w.again]);
|
||||
assert.equal(await box.getByRole("button", { name: w.close, exact: true }).count(), 0, "no Close beside Cancel");
|
||||
const cancel = box.locator(":scope > button", { hasText: w.cancel });
|
||||
assert.equal(await cancel.count(), 1);
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A sign-in goes through the proxy its account's requests will go through
|
||||
// (#1663, demystify0137: a sign-in went through the global proxy, the
|
||||
// account's requests after it through the subscription's). The sign-in
|
||||
// sheet says which, as a link: Claude's account with a proxy of its own,
|
||||
// signed in to again past Claude's warning, says that one, and the request
|
||||
// names the account. The link's menu offers Direct, Claude's proxy (its
|
||||
// password left out), the account's own and Custom…, but not the global
|
||||
// proxy, which an account can't be kept on while Claude has a proxy and
|
||||
// other accounts; picking one starts the sign-in again through it, the one
|
||||
// before canceled; Custom… asks for the address in place. A subscription
|
||||
// with no proxy and one account offers the global proxy, ticked. Nothing
|
||||
// moves the page, the link stays inside the sheet at a phone's width. In
|
||||
// every language, Chromium and WebKit; no backend, the API is faked here.
|
||||
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 SUB = "http://u:secret@10.0.0.1:7890", SHOWN = "http://10.0.0.1:7890", BOB = "socks5://10.0.0.2:1080";
|
||||
const claude = {
|
||||
id: "claude", name: "Claude", icon: "claude-color", chat: "", responses: "", anthropic: "", catalog: "",
|
||||
models: [{ id: "claude-opus-5", name: "Claude Opus 5", on: true }], agents: [], fallback: [], headers: {}, keyList: [],
|
||||
account: { agent: "claude", agentName: "Claude Code", user: "alice@example.com", plan: "MAX", logins: [{ user: "alice@example.com", plan: "MAX", active: true, on: true }, { user: "bob@example.com", plan: "PRO", lapsed: true }] },
|
||||
proxy: SUB, accountProxies: { "bob@example.com": BOB },
|
||||
};
|
||||
const codex = {
|
||||
id: "codex", name: "Codex", icon: "codex-color", chat: "", responses: "", anthropic: "", catalog: "",
|
||||
models: [{ id: "gpt-6", name: "GPT-6", on: true }], agents: [], fallback: [], headers: {}, keyList: [],
|
||||
account: { agent: "codex", agentName: "Codex", user: "me@example.com", plan: "PLUS", logins: [{ user: "me@example.com", plan: "PLUS", active: true, on: true }] },
|
||||
proxy: "",
|
||||
};
|
||||
|
||||
function serve(lang, seen) {
|
||||
const providers = { providers: [claude, codex], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
const flows = {};
|
||||
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(state);
|
||||
if (url.pathname === "/api/providers") return json(providers);
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
||||
if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/signin") {
|
||||
const b = route.request().postDataJSON();
|
||||
seen.starts.push(b);
|
||||
const id = "s" + seen.starts.length;
|
||||
// the server's own pick when none is: the account's, else the
|
||||
// subscription's (provider.pickProxy)
|
||||
const proxy = b.proxy ?? (b.user === "bob@example.com" ? BOB : b.agent === "claude" ? SUB : "");
|
||||
flows[id] = { id, agent: b.agent, state: "waiting", url: "https://vendor.example/oauth?state=" + id, proxy };
|
||||
return json(flows[id]);
|
||||
}
|
||||
const m = url.pathname.match(/^\/api\/signin\/(s\d+)(\/cancel)?$/);
|
||||
if (m) {
|
||||
if (m[2]) { seen.canceled.push(m[1]); flows[m[1]].state = "canceled"; }
|
||||
return json(flows[m[1]]);
|
||||
}
|
||||
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: { anyway: "Sign in anyway", again: "Sign in again", via: "Proxy: {p}", global: "Global proxy", direct: "Direct", custom: "Custom…", go: "Sign in through it" },
|
||||
zh: { anyway: "仍然登录", again: "重新登录", via: "代理:{p}", global: "全局代理", direct: "直连", custom: "自定义…", go: "经由它登录" },
|
||||
"zh-TW": { anyway: "仍然登入", again: "重新登入", via: "代理:{p}", global: "全域代理", direct: "直連", custom: "自訂…", go: "經由它登入" },
|
||||
ja: { anyway: "それでもサインイン", again: "再度サインイン", via: "プロキシ:{p}", global: "グローバルプロキシ", direct: "直接接続", custom: "カスタム…", go: "これ経由でサインイン" },
|
||||
de: { anyway: "Trotzdem anmelden", again: "Erneut anmelden", via: "Proxy: {p}", global: "Globaler Proxy", direct: "Direkt", custom: "Eigener…", go: "Darüber anmelden" },
|
||||
};
|
||||
|
||||
const sizes = [{ width: 900, height: 800 }, { width: 380, height: 760 }];
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of Object.keys(W)) {
|
||||
for (const size of sizes) {
|
||||
test(`${engine} ${lang} ${size.width}: a sign-in says its proxy and another can be picked`, async (t) => {
|
||||
const w = W[lang];
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await (await browser.newContext({ viewport: size, reducedMotion: "reduce" })).newPage();
|
||||
t.after(async () => {
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${size.width}-signin-proxy.png`) });
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [], seen = { starts: [], canceled: [] };
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, seen));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
const scrolls = () => page.evaluate(() => [window.scrollX, window.scrollY, ...[...document.querySelectorAll("*")].filter((e) => e.scrollTop).map((e) => e.scrollTop)]);
|
||||
const wide = () => page.evaluate(() => document.documentElement.scrollWidth > innerWidth);
|
||||
|
||||
// Bob, signed in to again: through his own proxy, his name sent
|
||||
await page.locator(".row.provider", { hasText: "Claude" }).first().click();
|
||||
const bob = page.locator(".editor .accts .acc", { hasText: "bob@example.com" });
|
||||
await bob.locator("button", { hasText: w.again }).click();
|
||||
const box = page.locator(".editor .signing");
|
||||
// Claude's warning first: the account asked for kept past it
|
||||
await box.locator("button", { hasText: w.anyway }).click();
|
||||
const via = box.locator(".acts .via");
|
||||
await via.waitFor();
|
||||
assert.deepEqual(seen.starts, [{ agent: "claude", user: "bob@example.com" }]);
|
||||
assert.equal((await via.textContent()).trim(), w.via.replace("{p}", BOB));
|
||||
const fit = await via.evaluate((v) => { const r = v.getBoundingClientRect(), b = v.closest(".signing").getBoundingClientRect(); return r.left >= b.left - 0.5 && r.right <= b.right + 0.5; });
|
||||
assert(fit, "the link stays inside the sheet");
|
||||
assert.equal(await wide(), false, "nothing wider than the window");
|
||||
|
||||
// its menu: no global proxy, Claude's without its password, Bob's ticked
|
||||
// in sight first: Playwright scrolls to what it clicks
|
||||
await via.scrollIntoViewIfNeeded();
|
||||
const before = await scrolls();
|
||||
await via.click();
|
||||
const menu = page.locator(".proto-menu");
|
||||
await menu.waitFor();
|
||||
const names = await menu.locator(".pm-item .pm-name").allTextContents();
|
||||
assert.deepEqual(names, [w.direct, SHOWN, BOB, w.custom]);
|
||||
assert(!(await menu.textContent()).includes("secret"), "the proxy's password isn't shown");
|
||||
assert.equal(await menu.locator(".pm-item.on .pm-name").textContent(), BOB);
|
||||
assert.deepEqual(await scrolls(), before, "opening the menu moved nothing");
|
||||
|
||||
// Claude's proxy picked: the sign-in starts again through it
|
||||
await menu.locator(".pm-item", { hasText: SHOWN }).click();
|
||||
await page.waitForFunction(() => document.querySelector(".editor .signing .acts .via")?.textContent.includes("10.0.0.1"));
|
||||
assert.deepEqual(seen.starts[1], { agent: "claude", user: "bob@example.com", proxy: SUB });
|
||||
// the one before is canceled (a request of its own, not awaited)
|
||||
for (let i = 0; i < 40 && seen.canceled.length < 1; i++) await page.waitForTimeout(50);
|
||||
assert.deepEqual(seen.canceled, ["s1"]);
|
||||
assert.equal((await via.textContent()).trim(), w.via.replace("{p}", SHOWN));
|
||||
|
||||
// Custom…: its address asked in place, then signed in through
|
||||
await via.click();
|
||||
await menu.locator(".pm-item", { hasText: w.custom }).click();
|
||||
const form = box.locator("form.proxy-ask");
|
||||
await form.waitFor();
|
||||
const go = form.locator("button", { hasText: w.go });
|
||||
assert.equal(await go.isDisabled(), true, "nothing to sign in through yet");
|
||||
await form.locator("input").fill("http://127.0.0.1:8888");
|
||||
await go.click();
|
||||
await page.waitForFunction(() => document.querySelector(".editor .signing .acts .via")?.textContent.includes("8888"));
|
||||
assert.deepEqual(seen.starts[2], { agent: "claude", user: "bob@example.com", proxy: "http://127.0.0.1:8888" });
|
||||
for (let i = 0; i < 40 && seen.canceled.length < 2; i++) await page.waitForTimeout(50);
|
||||
assert.deepEqual(seen.canceled, ["s1", "s2"]);
|
||||
assert.equal(await box.locator("form.proxy-ask").count(), 0, "the address isn't asked again");
|
||||
assert.equal(await wide(), false, "nothing wider than the window");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${lang} ${size.width}: a subscription with no proxy offers the global one`, async (t) => {
|
||||
const w = W[lang];
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await (await browser.newContext({ viewport: size, reducedMotion: "reduce" })).newPage();
|
||||
t.after(() => browser.close());
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [], seen = { starts: [], canceled: [] };
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, seen));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator(".row.provider", { hasText: "Codex" }).first().click();
|
||||
await page.locator(".editor .accts .acc.add").first().click();
|
||||
const via = page.locator(".editor .signing .acts .via");
|
||||
await via.waitFor();
|
||||
assert.deepEqual(seen.starts, [{ agent: "codex" }]);
|
||||
assert.equal((await via.textContent()).trim(), w.via.replace("{p}", w.global));
|
||||
await via.click();
|
||||
const menu = page.locator(".proto-menu");
|
||||
assert.deepEqual(await menu.locator(".pm-item .pm-name").allTextContents(), [w.global, w.direct, w.custom]);
|
||||
assert.equal(await menu.locator(".pm-item.on .pm-name").textContent(), w.global);
|
||||
// Direct picked: started again with no proxy at all
|
||||
await menu.locator(".pm-item", { hasText: w.direct }).click();
|
||||
await page.waitForFunction((d) => document.querySelector(".editor .signing .acts .via")?.textContent.includes(d), w.direct);
|
||||
assert.deepEqual(seen.starts[1], { agent: "codex", proxy: "direct" });
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user