diff --git a/accounts_cli.go b/accounts_cli.go index c04d59873..18b16276a 100644 --- a/accounts_cli.go +++ b/accounts_cli.go @@ -166,6 +166,9 @@ func accountsCmd(args []string) error { fmt.Println(" ", "Codex's background service is still signed in as", was+"; restart it to use", args[3]+":", provider.CodexDaemonRestart) fmt.Println(" ", muted.Render("running Codex sessions will be interrupted")) } + if was := provider.CodexAppStale(); was != "" { + fmt.Println(" ", "The Codex app is still signed in as", was+", and shows its limits; quit it and open it again to use", args[3]) + } } return nil } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index cd36e5a20..66b855def 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -11219,6 +11219,7 @@ function renderAccounts(a, p) { list.append(box); } if (a.agent === "codex" && providers?.codexDaemon) list.append(renderCodexDaemon(providers.codexDaemon)); + if (a.agent === "codex" && providers?.codexApp) list.append(renderCodexApp(providers.codexApp)); if (signing?.agent === a.agent) list.append(renderSigning(sub)); else { const add = el("button", "acc add"); @@ -11261,6 +11262,23 @@ function renderCodexDaemon(user) { return box; } +// renderCodexApp: the Codex desktop app reads the sign-in only when it +// opens, so after a switch it stays on the account before (user): it shows +// that account's limits and, once they are spent, sends in no thread. Only +// quitting and opening it again moves it; magpie doesn't quit it unasked. +function renderCodexApp(user) { + const box = el("div", "signing daemon"); + box.append(el("span", "mark", "!")); + const tt = el("span", "tt"); + tt.append(el("span", "n", t("The Codex app is still signed in as {user}", { user })), + el("span", "s", t("It shows that account's usage limits until it is quit and opened again. Quit it and open it again to use the new account."))); + box.append(tt); + const ok = el("button", "text", t("Got it")); + ok.onclick = () => accountAction("codex/daemon/dismiss-app", {}); + box.append(ok); + return box; +} + // Accounts brought in from another tool's export instead of signing in // again: the files' text (or what is pasted) goes to magpie, which checks // each account with the vendor before keeping it, and says what became of diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 8db89c921..bd9813c45 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1375,6 +1375,8 @@ const I18N = { "Sign {agent} in to this account": "让 {agent} 登录到这个账号", "{agent} is now signed in as {user}": "{agent} 已切换为 {user}", "Codex's background service is still signed in as {user}": "Codex 的后台服务仍登录着 {user}", + "The Codex app is still signed in as {user}": "Codex 应用仍登录着 {user}", + "It shows that account's usage limits until it is quit and opened again. Quit it and open it again to use the new account.": "在退出并重新打开之前,它显示的一直是该账号的用量限额。退出后重新打开即可使用新账号。", "Restart it to use the new account. Running Codex sessions will be interrupted.": "重启后才会使用新账号,正在运行的 Codex 会话将中断。", "Restart Zed if it still asks for an API key: magpie has configured its gateway credential in the system credential store.": "若 Zed 仍要求输入 API 密钥,请重启 Zed:网关凭据已写入系统凭据存储。", "In Air, start a new task and pick Magpie in its agent menu: magpie's models and routing groups are in its model menu.": "在 Air 中新建任务并在智能体菜单选 Magpie:模型菜单中即有 magpie 的模型和路由组。", @@ -5302,6 +5304,8 @@ const I18N = { "Sign {agent} in to this account": "讓 {agent} 登入到這個帳號", "{agent} is now signed in as {user}": "{agent} 已切換為 {user}", "Codex's background service is still signed in as {user}": "Codex 的後臺服務仍登入著 {user}", + "The Codex app is still signed in as {user}": "Codex 應用仍登入著 {user}", + "It shows that account's usage limits until it is quit and opened again. Quit it and open it again to use the new account.": "在結束並重新開啟之前,它顯示的一直是該帳號的用量限額。結束後重新開啟即可使用新帳號。", "Restart it to use the new account. Running Codex sessions will be interrupted.": "重啟後才會使用新帳號,正在執行的 Codex 會話將中斷。", "Restart Zed if it still asks for an API key: magpie has configured its gateway credential in the system credential store.": "若 Zed 仍要求輸入 API 金鑰,請重啟 Zed:閘道憑據已寫入系統憑據儲存。", "In Air, start a new task and pick Magpie in its agent menu: magpie's models and routing groups are in its model menu.": "在 Air 中新增任務並在智慧體選單選 Magpie:模型選單中即有 magpie 的模型和路由組。", @@ -9205,6 +9209,8 @@ const I18N = { "Sign {agent} in to this account": "{agent} をこのアカウントにサインインさせる", "{agent} is now signed in as {user}": "{agent} は {user} としてサインインしました", "Codex's background service is still signed in as {user}": "Codex のバックグラウンドサービスはまだ {user} としてサインインしています", + "The Codex app is still signed in as {user}": "Codex アプリはまだ {user} としてサインインしています", + "It shows that account's usage limits until it is quit and opened again. Quit it and open it again to use the new account.": "終了して開き直すまで、そのアカウントの使用上限を表示し続けます。新しいアカウントを使うには、終了してもう一度開いてください。", "Restart it to use the new account. Running Codex sessions will be interrupted.": "新しいアカウントを使うには再起動してください。実行中の Codex セッションは中断されます。", "Restart Zed if it still asks for an API key: magpie has configured its gateway credential in the system credential store.": "Zed がまだ APIキーを求める場合は Zed を再起動してください。magpie はシステムの資格情報ストアにゲートウェイの資格情報を設定済みです。", "In Air, start a new task and pick Magpie in its agent menu: magpie's models and routing groups are in its model menu.": "Air で新しいタスクを開始し、エージェントメニューで Magpie を選んでください。magpie のモデルとルーティンググループはモデルメニューにあります。", @@ -13127,6 +13133,8 @@ const I18N = { "Sign {agent} in to this account": "{agent} bei diesem Konto anmelden", "{agent} is now signed in as {user}": "{agent} ist jetzt als {user} angemeldet", "Codex's background service is still signed in as {user}": "Der Hintergrunddienst von Codex ist noch als {user} angemeldet", + "The Codex app is still signed in as {user}": "Die Codex-App ist noch als {user} angemeldet", + "It shows that account's usage limits until it is quit and opened again. Quit it and open it again to use the new account.": "Sie zeigt die Nutzungslimits dieses Kontos, bis sie beendet und neu geöffnet wird. Beenden Sie sie und öffnen Sie sie erneut, um das neue Konto zu verwenden.", "Restart it to use the new account. Running Codex sessions will be interrupted.": "Starten Sie ihn neu, um das neue Konto zu verwenden. Laufende Codex-Sitzungen werden unterbrochen.", "Restart Zed if it still asks for an API key: magpie has configured its gateway credential in the system credential store.": "Starten Sie Zed neu, falls es weiterhin nach einem API-Schlüssel fragt: magpie hat die Anmeldedaten des Zugangspunkts im Anmeldeinformationsspeicher des Systems hinterlegt.", "In Air, start a new task and pick Magpie in its agent menu: magpie's models and routing groups are in its model menu.": "Starten Sie in Air eine neue Aufgabe und wählen Sie im Agentenmenü Magpie: Die Modelle und Weiterleitungsgruppen von magpie stehen im Modellmenü.", diff --git a/internal/gui/codex_daemon_test.go b/internal/gui/codex_daemon_test.go index 7a2b590d7..ef416e8a9 100644 --- a/internal/gui/codex_daemon_test.go +++ b/internal/gui/codex_daemon_test.go @@ -51,6 +51,9 @@ func TestCodexDaemonRestartRoute(t *testing.T) { if w := post("dismiss"); w.Code != 200 { t.Fatalf("dismiss: %d %s", w.Code, w.Body) } + if w := post("dismiss-app"); w.Code != 200 { + t.Fatalf("dismiss-app: %d %s", w.Code, w.Body) + } if w := post("nope"); w.Code != 404 { t.Fatalf("unknown action: %d", w.Code) } diff --git a/internal/gui/providers.go b/internal/gui/providers.go index 400ed7bbe..b3d21d84c 100644 --- a/internal/gui/providers.go +++ b/internal/gui/providers.go @@ -372,6 +372,10 @@ type providersJSON struct { // signed in to after Codex was switched to another; "" when none is // left behind (provider.CodexDaemonStale). CodexDaemon string `json:"codexDaemon,omitempty"` + // CodexApp is the account the Codex desktop app is still signed in to + // after Codex was switched to another, until it is quit and opened + // again (provider.CodexAppStale) + CodexApp string `json:"codexApp,omitempty"` // Plugins are the providers the plugins sign in to, for the add sheet Plugins []pluginSubJSON `json:"plugins"` // OnPlugins are the built-in subscriptions moved onto their plugins, @@ -724,6 +728,7 @@ func providersState() providersJSON { } s.Gateway.Archive = archiveState() s.CodexDaemon = provider.CodexDaemonStale() + s.CodexApp = provider.CodexAppStale() s.Plugins = pluginSubs() s.Fetching = provider.FetchingNew() return s @@ -1627,6 +1632,8 @@ func providerRoutes(mux *http.ServeMux, w Windows) { agent.CodexDaemonRestarted() case "dismiss": provider.DismissCodexDaemon() + case "dismiss-app": + provider.DismissCodexApp() default: http.NotFound(rw, r) return diff --git a/internal/gui/tests/codex-app-stale.test.cjs b/internal/gui/tests/codex-app-stale.test.cjs new file mode 100644 index 000000000..3769d52af --- /dev/null +++ b/internal/gui/tests/codex-app-stale.test.cjs @@ -0,0 +1,87 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// The Codex app reads the sign-in only when it opens. After magpie switches +// Codex to another account it stays on the one before, shows that account's +// limits and, once they are spent, sends in no thread (CavillZhang on X). +// Codex's accounts say so, with the account the app is on and what moves it +// (quit and open it again), until the app reopens or "Got it" is clicked. +// In every language, Chromium and WebKit, wide and narrow. +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 codex = { + id: "codex", name: "Codex", icon: "codex-color", chat: "", responses: "", anthropic: "", catalog: "", routing: "smart", + models: [{ id: "gpt-6", name: "GPT-6", on: true }], agents: [], fallback: [], headers: {}, keyList: [], + account: { + agent: "codex", agentName: "Codex", user: "spare@example.com", plan: "PLUS", + logins: [ + { user: "spare@example.com", plan: "PLUS", active: true, on: true }, + { user: "spent@example.com", plan: "PLUS", on: true }, + ], + }, +}; + +function serve(lang, posted) { + let app = "spent@example.com"; + const providers = () => ({ providers: [codex], presets: [], excluded: [], gateway: { running: true, window: true }, ...(app ? { codexApp: app } : {}) }); + const state = { agents: [], profiles: [], settings: { lang, theme: "light" } }; + 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:true};` }); + 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/codex/daemon/dismiss-app") { posted.push(url.pathname); app = ""; return json(providers()); } + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + 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)]; + await route.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +const keys = [ + "The Codex app is still signed in as {user}", + "It shows that account's usage limits until it is quit and opened again. Quit it and open it again to use the new account.", + "Got it", +]; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + for (const width of [900, 480]) { + test(`${engine} ${lang} ${width}px: Codex's accounts say the Codex app is still on the account before`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + const errors = [], posted = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, posted)); + await page.goto("http://magpie.test/?view=providers"); + await page.locator(".row.provider", { hasText: "Codex" }).first().click(); + const box = page.locator(".editor .signing.daemon"); + await box.waitFor(); + const text = await box.textContent(); + assert.match(text, /spent@example\.com/); + if (lang === "en") assert.match(text, /Quit it and open it again/); + else { + const missing = await page.evaluate(([l, ks]) => ks.filter((k) => !I18N[l][k]), [lang, keys]); + assert.deepEqual(missing, [], `every string has its ${lang}`); + assert.doesNotMatch(text, /Quit it and open it again/); + } + const fits = await box.evaluate((b) => [...b.querySelectorAll("*")].every((e) => e.getBoundingClientRect().right <= b.getBoundingClientRect().right + 0.5)); + assert.ok(fits, "nothing in the notice runs past it"); + assert.equal(await page.evaluate(() => document.scrollingElement.scrollWidth <= innerWidth), true, "no sideways scroll"); + await box.locator("button").click(); + await box.waitFor({ state: "detached" }); + assert.deepEqual(posted, ["/api/codex/daemon/dismiss-app"]); + assert.deepEqual(errors, []); + }); + } + } +} diff --git a/internal/provider/codex_daemon.go b/internal/provider/codex_daemon.go index 72d47b7db..45f469758 100644 --- a/internal/provider/codex_daemon.go +++ b/internal/provider/codex_daemon.go @@ -138,16 +138,6 @@ func findCodexDaemon(ps []proc.Process, home string) int { return ids[0] } -// codexDaemon is the process id of Codex's managed app-server, 0 when none -// runs; known is false when the processes couldn't be listed. -func codexDaemon(ctx context.Context) (pid int, known bool) { - ps, err := listProcesses(ctx) - if err != nil { - return 0, false - } - return findCodexDaemon(ps, codexHome()), true -} - // codexDaemonLeft is the app-server that was running when Codex's account // last changed, and the account it was started on: it stays on that one // until it restarts. @@ -160,6 +150,13 @@ var ( codexDaemonMu sync.Mutex codexDaemonLeft leftDaemon codexDaemonChecked time.Time + // codexAppLeft is the Codex desktop app's own app-server (ChatGPT.app's + // CodexCLI.app) that was running when Codex's account changed: it + // keeps the account it started on until the app is quit and opened + // again (codex-rs AuthManager reloads auth.json only for the same + // account), so the app goes on reading that account's limits, and + // stops sending in every thread once those are spent. + codexAppLeft leftDaemon ) // codexDaemonRecheck is how long CodexDaemonStale trusts what it last saw. @@ -170,21 +167,31 @@ const codexDaemonRecheck = 5 * time.Second func noteCodexSwitch(from, to string) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - pid, known := codexDaemon(ctx) + ps, err := listProcesses(ctx) + known := err == nil codexDaemonMu.Lock() defer codexDaemonMu.Unlock() codexDaemonChecked = time.Now() + if !known { + return + } + noteLeft(&codexDaemonLeft, findCodexDaemon(ps, codexHome()), from, to) + noteLeft(&codexAppLeft, findCodexApp(ps), from, to) +} + +// noteLeft updates what is known of the app-server pid, running as Codex's +// account changes from one to another. +func noteLeft(left *leftDaemon, pid int, from, to string) { switch { - case !known: case pid == 0: - codexDaemonLeft = leftDaemon{} - case pid == codexDaemonLeft.pid: - // the daemon is on the account it started with, whatever came between - if strings.EqualFold(to, codexDaemonLeft.user) { - codexDaemonLeft = leftDaemon{} + *left = leftDaemon{} + case pid == left.pid: + // it is on the account it started with, whatever came between + if strings.EqualFold(to, left.user) { + *left = leftDaemon{} } default: - codexDaemonLeft = leftDaemon{pid, from} + *left = leftDaemon{pid, from} } } @@ -194,22 +201,45 @@ func noteCodexSwitch(from, to string) { func CodexDaemonStale() string { codexDaemonMu.Lock() defer codexDaemonMu.Unlock() - if codexDaemonLeft.pid == 0 { - return "" - } - if time.Since(codexDaemonChecked) > codexDaemonRecheck { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - pid, known := codexDaemon(ctx) - cancel() - codexDaemonChecked = time.Now() - if known && pid != codexDaemonLeft.pid { - // restarted, or stopped, since: it reads the sign-in afresh - codexDaemonLeft = leftDaemon{} - } - } + recheckLeft() return codexDaemonLeft.user } +// CodexAppStale answers the account the Codex desktop app is still signed +// in to when Codex has been switched to another since the app opened, "" +// when it isn't open or is on the account Codex is. The app shows that +// account's limits, and once they are spent won't send in any thread, +// until it is quit and opened again. +func CodexAppStale() string { + codexDaemonMu.Lock() + defer codexDaemonMu.Unlock() + recheckLeft() + return codexAppLeft.user +} + +// recheckLeft forgets an app-server left on an account before that has +// restarted, or stopped, since: a new one reads the sign-in afresh. What +// was known stays when the processes can't be listed. codexDaemonMu is +// held. +func recheckLeft() { + if codexDaemonLeft.pid == 0 && codexAppLeft.pid == 0 || time.Since(codexDaemonChecked) <= codexDaemonRecheck { + return + } + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + ps, err := listProcesses(ctx) + cancel() + codexDaemonChecked = time.Now() + if err != nil { + return + } + if findCodexDaemon(ps, codexHome()) != codexDaemonLeft.pid { + codexDaemonLeft = leftDaemon{} + } + if findCodexApp(ps) != codexAppLeft.pid { + codexAppLeft = leftDaemon{} + } +} + // DismissCodexDaemon stops saying the app-server is on another account. func DismissCodexDaemon() { codexDaemonMu.Lock() @@ -217,6 +247,44 @@ func DismissCodexDaemon() { codexDaemonLeft = leftDaemon{} } +// DismissCodexApp stops saying the Codex app is on another account. +func DismissCodexApp() { + codexDaemonMu.Lock() + defer codexDaemonMu.Unlock() + codexAppLeft = leftDaemon{} +} + +// findCodexApp picks, among the running processes, the app-server the +// Codex desktop app runs for itself: 0 when it isn't open. On macOS that +// is ChatGPT.app's (or Codex.app's) bundled codex, `…/CodexCLI.app/ +// Contents/MacOS/codex [-c k=v…] app-server --analytics-default-enabled …`; +// on Windows the Store app's `…\WindowsApps\OpenAI.Codex_…\codex.exe +// app-server`. Not the managed daemon, nor an app-server's helpers or +// proxy, nor an editor's codex. +func findCodexApp(ps []proc.Process) int { + for _, p := range ps { + if isManagedDaemon(p.Args) { + continue + } + // the program's own path: ps leaves a path's spaces unquoted, so + // "…/Codex Computer Use.app/Contents/MacOS/…" reads as one named Codex + exe, rest := splitExe(p.Args) + if !strings.Contains(exe, ".app/Contents/") && !strings.Contains(exe, `\WindowsApps\OpenAI.`) { + continue + } + if base := strings.ToLower(exe[strings.LastIndexAny(exe, `/\`)+1:]); base != "codex" && base != "codex.exe" { + continue + } + f := strings.Fields(rest) + i := slices.Index(f, "app-server") + if i < 0 || i+1 < len(f) && !strings.HasPrefix(f[i+1], "-") { + continue + } + return p.PID + } + return 0 +} + // RestartCodexDaemon has Codex restart its app-server, which reads the // sign-in again: `codex app-server daemon restart`, run with the codex CLI // magpie finds and the Codex home it signs Codex in through. Codex 0.162's diff --git a/internal/provider/codex_daemon_test.go b/internal/provider/codex_daemon_test.go index 990417d19..cb05eb6d4 100644 --- a/internal/provider/codex_daemon_test.go +++ b/internal/provider/codex_daemon_test.go @@ -397,3 +397,90 @@ func TestKeepCodexDaemonCurrentFails(t *testing.T) { t.Fatalf("%+v", c) } } + +func TestFindCodexApp(t *testing.T) { + // the ChatGPT app's own app-server, as ps listed it on the owner's Mac + // (ChatGPT 26.1007), beside a terminal codex and the managed daemon + app := "/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex -c features.code_mode_host=true app-server --analytics-default-enabled -c plugins.codex-app-tools@openai-bundled.mcp_servers.codex_app.enabled=true" + for want, ps := range map[int][]proc.Process{ + 9: {{PID: 3, Args: "codex"}, {PID: 4, Args: "/Users/me/.codex/packages/app-server-daemon/releases/0.162.0-aarch64-apple-darwin/bin/codex app-server --listen unix:///x --managed-daemon"}, {PID: 9, Args: app}}, + 8: {{PID: 8, Args: `"C:\Program Files\WindowsApps\OpenAI.Codex_1.0\app\resources\codex.exe" app-server`}}, + 0: { + {PID: 3, Args: "codex app-server proxy"}, + {PID: 5, Args: "/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex exec-server --remote x"}, + {PID: 6, Args: "/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex app-server daemon restart"}, + {PID: 7, Args: "/Users/me/.vscode/extensions/openai.chatgpt-1.0/bin/darwin-aarch64/codex app-server"}, + {PID: 10, Args: "/Users/me/.codex/computer-use/Codex Computer Use.app/Contents/MacOS/SkyComputerUseService app-server"}, + }, + } { + if got := findCodexApp(ps); got != want { + t.Errorf("findCodexApp = %d, want %d (%v)", got, want, ps) + } + } +} + +// The Codex app reads the sign-in once, as it opens: switched while it +// runs, it stays on the account before, shows that account's limits and, +// once they are spent, sends in no thread (CavillZhang on X). magpie says +// so until the app is opened again. +func TestCodexAppStale(t *testing.T) { + t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", t.TempDir()) + app := new(int) + old := listProcesses + t.Cleanup(func() { + listProcesses = old + DismissCodexDaemon() + DismissCodexApp() + }) + listProcesses = func(context.Context) ([]proc.Process, error) { + if *app < 0 { + return nil, errors.New("no ps") + } + ps := []proc.Process{{PID: 7, Args: "codex"}} + if *app > 0 { + ps = append(ps, proc.Process{PID: *app, Args: "/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex -c features.code_mode_host=true app-server --analytics-default-enabled"}) + } + return ps, nil + } + recheck := func() { codexDaemonMu.Lock(); codexDaemonChecked = time.Time{}; codexDaemonMu.Unlock() } + DismissCodexApp() + + noteCodexSwitch("a@x", "b@x") + if got := CodexAppStale(); got != "" { + t.Fatalf("app not open: %q", got) + } + *app = 60 + noteCodexSwitch("a@x", "b@x") + if got := CodexAppStale(); got != "a@x" { + t.Fatalf("got %q, want a@x", got) + } + if got := CodexDaemonStale(); got != "" { + t.Fatalf("the app's app-server taken for the daemon: %q", got) + } + noteCodexSwitch("b@x", "c@x") + if got := CodexAppStale(); got != "a@x" { + t.Fatalf("after a third: got %q, want a@x", got) + } + noteCodexSwitch("c@x", "a@x") + if got := CodexAppStale(); got != "" { + t.Fatalf("back on its own: %q", got) + } + // quit and opened again: a new app-server, which read the new sign-in + noteCodexSwitch("a@x", "b@x") + *app = 61 + recheck() + if got := CodexAppStale(); got != "" { + t.Fatalf("reopened: %q", got) + } + noteCodexSwitch("b@x", "a@x") + *app = -1 + recheck() + if got := CodexAppStale(); got != "b@x" { + t.Fatalf("list failing: got %q, want b@x", got) + } + DismissCodexApp() + if got := CodexAppStale(); got != "" { + t.Fatalf("dismissed: %q", got) + } +} diff --git a/internal/provider/codex_switch.go b/internal/provider/codex_switch.go index 3599d6421..ada1d1a85 100644 --- a/internal/provider/codex_switch.go +++ b/internal/provider/codex_switch.go @@ -240,6 +240,11 @@ func SwitchWhenSpent(ctx context.Context, agent string) (string, error) { share, _ := loginSwitching(agent) log.Printf("%s: %s has used %g%% or more of its allowance; signed it in to %s", agent, from, share, to) } + if agent == "codex" { + if was := CodexAppStale(); was != "" { + log.Printf("codex: the Codex app is still signed in to %s, and shows its limits, until it is quit and opened again", was) + } + } // the models the agent is offered are the new account's plan's catalog.Touched() return to, nil