From 2a8a9aecfa4bd0bf563ec8201d651628be5c4c4f Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 12 Oct 2026 03:07:08 +0800 Subject: [PATCH] provider: signing out of ChatGPT and Devin's CLI checks go through the account's own proxy, as its sign-in does (#1663, demystify0137) What changed: two siblings of 3a53d06d9 still left through the global proxy, so an account's sign-out or its CLI checks came from a different exit than its sign-in and requests. - chatgpt_api.go forgetSIWCLogin: the refresh-token revoke (discovery and revocation endpoint) goes through ViaLogin for that account, read before the account is forgotten. - devin_accounts.go devinCommand: `devin auth status` and `devin models list` run with the proxy ctx names (a sign-in's), else the account's own (devinProxy: the logins.json entry for that home, the CLI's own for "", ProxyOfLogin; the subscription's for a home not kept yet), via netproxy.EnvWith, where it was netproxy.Env (global). - devin.go: askDevinStatusAt/askDevinIdentityAt/addDevinLogin take the sign-in's ctx, so the probe naming a just-signed-in account uses the proxy the sign-in goes through. askDevinIdentity had no caller left and is removed. - docs/subsystems/providers-accounts.md says so. What was run: - go test -tags nogui ./... (sandbox HOME) ok; gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on the touched packages. - New TestChatGPTSignOutGoesThroughItsProxy and TestDevinCLIGoesThroughItsProxy (internal/provider/signin_proxy_test.go). Red by hand: the revoke with context.Background() (it dials openai.invalid directly); devinCommand without devinProxy (models and status run with no proxy); askDevinStatusAt ignoring the sign-in's ctx (the new account's probe runs with the subscription's proxy, not the picked one). Not tried: a real ChatGPT or Devin account through a real proxy. Left out on purpose: a `--proxy` flag for `magpie accounts add`, and the installer's downloads (global proxy). --- docs/subsystems/providers-accounts.md | 2 +- internal/provider/chatgpt_api.go | 7 +- internal/provider/devin.go | 31 +++--- internal/provider/devin_accounts.go | 34 ++++-- internal/provider/signin_proxy_test.go | 144 +++++++++++++++++++++++++ 5 files changed, 191 insertions(+), 27 deletions(-) diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md index f50797fd9..5d5be190a 100644 --- a/docs/subsystems/providers-accounts.md +++ b/docs/subsystems/providers-accounts.md @@ -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`. 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) | +| 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. Signing out leaves through the same exit: a ChatGPT account's refresh token is revoked through its own proxy, read before the account is forgotten (`forgetSIWCLogin`), and Devin's CLI, asked who is signed in or for its models, runs with the account's proxy (`devinCommand`, `devinProxy`), or with the sign-in's while one asks it. | [`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/`); `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) | diff --git a/internal/provider/chatgpt_api.go b/internal/provider/chatgpt_api.go index 13502f9d3..ec540dd1f 100644 --- a/internal/provider/chatgpt_api.go +++ b/internal/provider/chatgpt_api.go @@ -114,12 +114,15 @@ func setSIWCLoginOn(user string, on bool) error { } // forgetSIWCLogin removes an account, and has OpenAI revoke its refresh -// token: signed out, it is gone there too. +// token: signed out, it is gone there too. The revoke leaves through the +// account's own proxy, as its sign-in and requests did (#1663), read +// before the account is forgotten. func forgetSIWCLogin(user string) error { + via := ViaLogin(context.Background(), ChatGPTAPIID, user) return forgetSideLogin(ChatGPTAPIID, user, siwcSide(), func(l savedLogin) { if c, ok := siwcSaved(l); ok { go func() { - ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + ctx, cancel := context.WithTimeout(via, 15*time.Second) defer cancel() _ = siwcRevoke(ctx, c) }() diff --git a/internal/provider/devin.go b/internal/provider/devin.go index 2d363a3be..6f309f21c 100644 --- a/internal/provider/devin.go +++ b/internal/provider/devin.go @@ -88,24 +88,21 @@ const devinIdentityTimeout = 30 * time.Second // and the account stays as it was (#154): only a CLI that says nobody is, // whose account's token was refused, or that keeps no credentials.toml, is // sure of nobody. -func askDevinStatus() (user, plan string, ok bool, err error) { return askDevinStatusAt("") } +func askDevinStatus() (user, plan string, ok bool, err error) { + return askDevinStatusAt(context.Background(), "") +} -// askDevinIdentity is who the CLI says is signed in, sure or not: the -// sign-in has just written the credentials and has to name the account. -func askDevinIdentity() (user, plan string, ok bool) { - u, p, ok, _ := askDevinStatusAt("") +// askDevinIdentityAt is who the CLI says is signed in in home ("" for its +// own), sure or not: a sign-in has just written the credentials and has to +// name the account. +func askDevinIdentityAt(ctx context.Context, home string) (user, plan string, ok bool) { + u, p, ok, _ := askDevinStatusAt(ctx, home) return u, p, ok } -// askDevinIdentityAt is askDevinIdentity for the account signed in in home -// ("" for the CLI's own). -func askDevinIdentityAt(home string) (user, plan string, ok bool) { - u, p, ok, _ := askDevinStatusAt(home) - return u, p, ok -} - -// askDevinStatusAt asks the CLI who is signed in in home ("" for its own). -func askDevinStatusAt(home string) (user, plan string, ok bool, err error) { +// askDevinStatusAt asks the CLI who is signed in in home ("" for its own), +// through the proxy ctx names, else the account's (devinCommand). +func askDevinStatusAt(ctx context.Context, home string) (user, plan string, ok bool, err error) { if settings.AccountDiscoveryOff() { return "", "", false, nil } @@ -113,7 +110,7 @@ func askDevinStatusAt(home string) (user, plan string, ok bool, err error) { if path == "" { return "", "", false, nil } - ctx, cancel := context.WithTimeout(context.Background(), devinIdentityTimeout) + ctx, cancel := context.WithTimeout(ctx, devinIdentityTimeout) defer cancel() out, err := devinCommand(ctx, home, path, "auth", "status").Output() user, plan, _ = parseDevinStatus(string(out)) @@ -664,7 +661,7 @@ func devinExchange(ctx context.Context, code, verifier, redirect string) (savedL removeDevinHome(home) return savedLogin{}, err } - user, plan, err := addDevinLogin(home) + user, plan, err := addDevinLogin(ctx, home) if err != nil { removeDevinHome(home) return savedLogin{}, err @@ -679,7 +676,7 @@ func devinExchange(ctx context.Context, code, verifier, redirect string) (savedL } forgetDevinStatus() forgetAccountCaches() - user, plan, ok := askDevinIdentity() + user, plan, ok := askDevinIdentityAt(ctx, "") if !ok { // the account is only ever seen through the CLI: without it // answering, magpie has nothing to show and nothing to run diff --git a/internal/provider/devin_accounts.go b/internal/provider/devin_accounts.go index 5f678182c..3f73a4647 100644 --- a/internal/provider/devin_accounts.go +++ b/internal/provider/devin_accounts.go @@ -43,12 +43,19 @@ func devinCredentialsAt(home string) string { } // devinCommand runs the devin CLI for an account: the CLI's own for home -// "", else with magpie's home as its data folder. +// "", else with magpie's home as its data folder. It goes through the +// proxy ctx names (a sign-in's), else the account's own (devinProxy), as +// the account's requests do, never always the global one (#1663). func devinCommand(ctx context.Context, home, path string, args ...string) *exec.Cmd { - if home == "" { - return agentCommand(ctx, path, args...) - } cmd := proc.CommandContext(ctx, path, args...) + proxy := netproxy.Choice(ctx) + if proxy == "" { + proxy = devinProxy(home) + } + if home == "" { + cmd.Env = netproxy.EnvWith(proxy, nil) + return cmd + } var env []string for _, e := range os.Environ() { k, _, _ := strings.Cut(e, "=") @@ -58,10 +65,23 @@ func devinCommand(ctx context.Context, home, path string, args ...string) *exec. } env = append(env, e) } - cmd.Env = netproxy.Env(append(env, "XDG_DATA_HOME="+home, "APPDATA="+home)) + cmd.Env = netproxy.EnvWith(proxy, append(env, "XDG_DATA_HOME="+home, "APPDATA="+home)) return cmd } +// devinProxy is the proxy of the account signed in in home (the CLI's own +// for ""), as logins.json names it: that account's (ProxyOfLogin), or the +// subscription's for a home no account is kept for yet. It reads +// logins.json without loginsMu, which a caller may hold. +func devinProxy(home string) string { + for _, l := range readLogins() { + if l.Agent == "devin" && l.Home == home && (home != "" || l.own()) { + return ProxyOfLogin("devin", l.User) + } + } + return ProxyOf("devin") +} + // devinLogin is a Devin account and the home it is signed in in, "" for // the CLI's own. type devinLogin struct { @@ -131,8 +151,8 @@ func removeDevinHome(home string) { // addDevinLogin keeps the account just signed in in home, in use beside // the others, once the CLI says whose it is. Signed in again, an account // keeps the newer home. -func addDevinLogin(home string) (user, plan string, err error) { - user, plan, ok := askDevinIdentityAt(home) +func addDevinLogin(ctx context.Context, home string) (user, plan string, err error) { + user, plan, ok := askDevinIdentityAt(ctx, home) if !ok || user == "" { return "", "", errors.New("signed in, but `devin auth status` doesn't show the account; run it in a terminal to see why") } diff --git a/internal/provider/signin_proxy_test.go b/internal/provider/signin_proxy_test.go index a2623285e..d763d8c1b 100644 --- a/internal/provider/signin_proxy_test.go +++ b/internal/provider/signin_proxy_test.go @@ -265,3 +265,147 @@ func TestClaudeSignInGoesThroughItsProxy(t *testing.T) { t.Fatalf("claude auth login ran with HTTPS_PROXY=%q", b) } } + +// Signing out of a ChatGPT account, OpenAI revokes its refresh token +// through the account's own proxy, the exit its sign-in and requests left +// through, not the global one (#1663). +func TestChatGPTSignOutGoesThroughItsProxy(t *testing.T) { + claudeHome(t) + f := newFakeOpenAI(t) + if done := signInVia(t, f, "oaiapp_123", same); done.State != "done" || done.User != "me@example.com" { + t.Fatalf("sign-in ended %+v", done) + } + dialed := dialsOut(t) + var mu sync.Mutex + var seen []string + record := func(who string) *httptest.Server { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mu.Lock() + seen = append(seen, who+" "+r.URL.String()) + mu.Unlock() + if r.URL.Path == "/.well-known/openid-configuration" { + json.NewEncoder(w).Encode(map[string]any{"revocation_endpoint": "http://openai.invalid/oauth/revoke"}) + } + })) + t.Cleanup(srv.Close) + return srv + } + sub, own := record("sub"), record("own") + setProxies(t, ChatGPTAPIID, sub.URL, map[string]string{"me@example.com": own.URL}) + oldI := siwcIssuer + siwcIssuer = "http://openai.invalid" + t.Cleanup(func() { siwcIssuer = oldI }) + + if err := ForgetLogin(ChatGPTAPIID, "me@example.com"); err != nil { + t.Fatal(err) + } + want := []string{"own http://openai.invalid/.well-known/openid-configuration", "own http://openai.invalid/oauth/revoke"} + for deadline := time.Now().Add(10 * time.Second); ; time.Sleep(20 * time.Millisecond) { + mu.Lock() + got := slices.Clone(seen) + mu.Unlock() + if slices.Equal(got, want) { + break + } + if time.Now().After(deadline) { + t.Fatalf("the sign-out went through %q, dialed %v", got, dialed()) + } + } + if d := dialed(); len(d) != 0 { + t.Fatalf("dialed %v past the proxy", d) + } +} + +// Devin's CLI, asked who is signed in and for its models, runs with the +// account's own proxy, and while a sign-in asks it, with the proxy the +// sign-in goes through, where it always had the global one (#1663). +func TestDevinCLIGoesThroughItsProxy(t *testing.T) { + shellFakes(t) + home := claudeHome(t) + data := filepath.Join(home, "data") + t.Setenv("XDG_DATA_HOME", data) + os.MkdirAll(filepath.Join(data, "devin"), 0o700) + own := string(devinCredentials("devin-session-token$own", "", "", "")) + os.WriteFile(filepath.Join(data, "devin", "credentials.toml"), []byte(own), 0o600) + // a CLI that notes the proxy it was run with, and says whose key is in + // the credentials.toml of its data folder + exe := filepath.Join(home, "devin") + runs := filepath.Join(home, "runs") + testenv.Program(t, exe, `#!/bin/sh +f="$XDG_DATA_HOME/devin/credentials.toml" +if grep -q own "$f" 2>/dev/null; then who=dev@example.com; else who=two@example.com; fi +echo "$who $1 $HTTPS_PROXY" >> `+runs+` +case "$1" in +models) echo '[]'; exit 0;; +esac +printf 'Logged in (via Devin). + +User: + Email: %s + +Account: + Tier: Devin Pro +' "$who" +`) + fakeDevin(t, exe) + exchange := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(map[string]any{"sessionToken": "devin-session-token$two"}) + })) + t.Cleanup(exchange.Close) + oldTok := devinExchangeURL + devinExchangeURL = exchange.URL + t.Cleanup(func() { devinExchangeURL = oldTok }) + const sub, mine, picked = "http://127.0.0.1:7001", "http://127.0.0.1:7002", "http://127.0.0.1:7003" + setProxies(t, "devin", sub, map[string]string{"dev@example.com": mine}) + ran := func() []string { + b, _ := os.ReadFile(runs) + os.Remove(runs) + var out []string + for _, l := range strings.Split(strings.TrimSpace(string(b)), "\n") { + if l != "" { + out = append(out, strings.TrimRight(l, "/")) + } + } + return out + } + forgetDevinStatus() + ran() + + // a second account, signed in through a proxy picked for it: the CLI + // asked whose it is runs with that proxy + p := picked + st, err := StartSignInWith("devin", SignInOptions{Proxy: &p}) + if err != nil { + t.Fatal(err) + } + finishInBrowser(t, st, "dv-code") + if st = waitDone(t, st.ID); st.State != "done" || st.User != "two@example.com" { + t.Fatalf("state %+v", st) + } + if got := ran(); !slices.Contains(got, "two@example.com auth "+picked) || + slices.ContainsFunc(got, func(l string) bool { return strings.HasPrefix(l, "two@") && !strings.HasSuffix(l, " "+picked) }) { + t.Fatalf("the sign-in ran the CLI as %q", got) + } + + // later, each account's CLI runs with that account's own proxy + var homeOf = map[string]string{} + for _, l := range devinLogins() { + homeOf[l.User] = l.Home + } + two, ok := homeOf["two@example.com"] + if !ok || two == "" { + t.Fatalf("logins %v", homeOf) + } + ran() + if _, err := askDevinFamiliesAt(context.Background(), two); err != nil && !strings.Contains(err.Error(), "no models") { + t.Logf("models: %v", err) + } + askDevinStatusAt(context.Background(), two) + askDevinStatusAt(context.Background(), "") + got := ran() + for _, want := range []string{"two@example.com models " + picked, "two@example.com auth " + picked, "dev@example.com auth " + mine} { + if !slices.Contains(got, want) { + t.Fatalf("ran %q, no %q", got, want) + } + } +}