What changed: Settings → Privacy → Subscription accounts (On/Off), `magpie accounts discovery [on|off]` and MAGPIE_NO_ACCOUNTS=1 turn off account discovery. It stays on by default. While it is off, magpie reads none of the agents' sign-ins: ~/.claude/.credentials.json, .claude.json's account, ~/.codex/auth.json, Copilot's, Cursor's, Devin's, Kiro's, Gemini's, ZCode's, Command Code's and OpenCode's files. It runs no `security` / `secret-tool` for the Keychain or Secret Service, and asks no agent CLI who is signed in. It serves no subscription. API-key providers, middleware plugins and Pi extensions work as before. Why: the reporter runs magpie on machines where reading other tools' credentials isn't wanted. The owner delegated the call. How: settings.NoAccountDiscovery (kept per computer by KeepOwn) and settings.AccountDiscoveryOff(). The variable only ever turns discovery off. The gates sit at every reader (readAccountFile, discoveryOff) and at every route that reads or writes a sign-in, so a route that skips Accounts still reads nothing: - Accounts, All, Logins, usage, renewal, warm-up, session identities, check-ins; - switching, forgetting, SetLoginOn, StartSignIn, the imports; - moves onto plugins. The ones that write refuse with an error that names how to turn it back on. On the agent side, Agent.Source and OpenCode's auth.json are gated, and Codex wiring goes by magpie's stash instead of auth.json, so a toggle never rewires Codex. logins.json and plugin-auth.json are left untouched and serve again when discovery is turned back on. A change applies at once (ForgetAccounts). Docs: providers-accounts.md, README (en, zh-CN), and the site's CLI table (en, zh, ja). Run: - TestAccountDiscoveryOffReadsNoSignIn (provider) and TestAccountDiscoveryOffAgentsReadNoSignIn (agent). Every credential path is a FIFO that records each open, and security, secret-tool, claude, codex, cursor-agent, devin, kiro-cli, copilot and grok are fakes on PATH. Both fail with the gate removed: they show the opens and `security find-generic-password -s Claude Code-credentials`, among others. Both pass with the gate in place. - TestAccountDiscoverySetting and TestAccountsDiscoveryCmd. - account-discovery.test.cjs: chromium and webkit, 900 and 360 wide, en/zh/zh-TW/ja/de, 32/32. The neighbouring privacy, redact, settings-sections and i18n-keys GUI tests: 49/49. - The full `go test -tags nogui ./...`, gofmt -l, and go vet for darwin, linux and windows on the touched packages. Not tried: a real machine under fs_usage, and Linux and Windows at runtime. The FIFO tests are !windows.
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// discoveryOut runs `magpie accounts discovery` with args and returns what
|
|
// it printed.
|
|
func discoveryOut(t *testing.T, args ...string) string {
|
|
t.Helper()
|
|
r, w, err := os.Pipe()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
old := os.Stdout
|
|
os.Stdout = w
|
|
done := make(chan string)
|
|
go func() { b, _ := io.ReadAll(r); done <- string(b) }()
|
|
err = run(append([]string{"accounts", "discovery"}, args...))
|
|
w.Close()
|
|
os.Stdout = old
|
|
out := <-done
|
|
r.Close()
|
|
if err != nil {
|
|
t.Fatalf("accounts discovery %v: %v", args, err)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// `magpie accounts discovery off` saves the opt-out (#1535), `on` takes it
|
|
// back, and with no argument it says which is in effect; it leaves every
|
|
// other setting as it was.
|
|
func TestAccountsDiscoveryCmd(t *testing.T) {
|
|
t.Setenv("MAGPIE_NO_ACCOUNTS", "")
|
|
if err := settings.Save(settings.Settings{Currency: "cny"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if out := discoveryOut(t); !strings.Contains(out, "is on") {
|
|
t.Errorf("default: %q", out)
|
|
}
|
|
if out := discoveryOut(t, "off"); !strings.Contains(out, "is off:") {
|
|
t.Errorf("off: %q", out)
|
|
}
|
|
if s := settings.Load(); !s.NoAccountDiscovery || s.Currency != "cny" {
|
|
t.Errorf("saved %+v", s)
|
|
}
|
|
discoveryOut(t, "on")
|
|
if settings.Load().NoAccountDiscovery {
|
|
t.Error("on left it off")
|
|
}
|
|
t.Setenv("MAGPIE_NO_ACCOUNTS", "1")
|
|
if out := discoveryOut(t); !strings.Contains(out, "MAGPIE_NO_ACCOUNTS") {
|
|
t.Errorf("under the variable: %q", out)
|
|
}
|
|
if err := run([]string{"accounts", "discovery", "maybe"}); err == nil {
|
|
t.Error("a word other than on or off taken")
|
|
}
|
|
}
|