charliepu on Discord (Windows), after v0.1.2385: the account that read no
allowance couldn't be removed. Remove answered "<email> is signed in to
Codex in C:\Users\charl\.codex-db-backup-20260803: sign it out there
(CODEX_HOME=... codex logout) to remove it". That folder is a backup no
Codex runs in. appdir.CodexHomes finds it by name (".codex*" holding an
auth.json), and rememberLogins read its account back at every look, so
forgetLogin refused rather than have it come back.
Now Remove forgets the account and sets that folder's sign-in aside in a
record of magpie's own (codex-homes-removed.json: the folder to a sha256
of its refresh token, or of its access token when it has none).
codexHomeLogins passes over a folder while it holds that sign-in. The
folder's files are left as they are: nothing in it is written, moved or
deleted. A sign-in made
in that folder again (Codex run there, a new token) isn't named by the
record, and is listed again with no step of the user's. With the record
unreadable, which sign-ins were removed is unknown, and no other folder's
account is read that time (accounts saved already stay listed).
Not done: treating ".codex-db-backup-*" folders as not Codex homes by
name. They are found by the same rule as ~/.codex-work, and their
sessions/ are still read for Sessions and usage as before; a name rule
would guess at what a user's folder is for. Removing is the user's own
answer, and works for any such folder.
Run at this head (origin/main 70d50254c plus this change; the doc line
added after):
- mote: go test -timeout 45m -count=1 ./internal/provider ./internal/appdir: ok (provider 142s;
135s at the earlier base e90a635a9)
- mote: GOOS=windows and GOOS=linux go vet ./internal/provider: ok
- xiaomi-gpu (Windows 11, win-run): go test ./internal/provider -run
'TestCodexHeldFolderAccountRemoved|TestCodexOtherHome|TestCodexHeldInOtherFolder':
all four pass
- gofmt -l internal/provider: empty
Broken by hand, each red:
- logins.go as on main: TestCodexHeldFolderAccountRemoved fails with the
"codex logout) to remove it" refusal, and so does
TestCodexOtherHomeAccountReadsQuota (its last check pinned the refusal;
it now expects the removal to go through).
- codexHomeLogins ignoring the record: "removed, then read back from the
backup folder".
- an unreadable record read as empty: "with the record unreadable, the
removed account came back".
docs/subsystems/providers-accounts.md's "Codex's other folders" row
said such an account couldn't be removed; it now says what Remove and
v0.1.2385's Sign in again do.
Not tried: the real app on Windows with a real backup folder (the test
runs on Windows with a sandbox HOME); a real account. No GUI change: the
row's Remove posts login/forget as before, which now goes through.
75 lines
2.6 KiB
Go
75 lines
2.6 KiB
Go
package provider
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// charliepu on Discord (Windows, 10-31): an account Codex was signed in to
|
|
// in C:\Users\charl\.codex-db-backup-20260803, a backup no Codex runs in,
|
|
// couldn't be removed: "sign it out there (CODEX_HOME=… codex logout) to
|
|
// remove it". Now Remove takes it out of magpie, the folder's files left
|
|
// as they are, and it isn't read back from there at the next look. A
|
|
// sign-in made in that folder again is listed again.
|
|
func TestCodexHeldFolderAccountRemoved(t *testing.T) {
|
|
home := signIn(t)
|
|
t.Setenv("CODEX_HOME", "")
|
|
backup := filepath.Join(home, ".codex-db-backup-20260803")
|
|
auth := func(refresh string) map[string]any {
|
|
idTok := fakeJWT(map[string]any{"email": "pro@example.com",
|
|
"https://api.openai.com/auth": map[string]any{"chatgpt_plan_type": "pro", "chatgpt_account_id": "acct-pro"}})
|
|
return map[string]any{"auth_mode": "chatgpt", "OPENAI_API_KEY": nil, "last_refresh": "2026-08-03T00:00:00Z",
|
|
"tokens": map[string]any{"id_token": idTok, "access_token": fakeJWT(map[string]any{"exp": 1.0}),
|
|
"refresh_token": refresh, "account_id": "acct-pro"}}
|
|
}
|
|
writeFile(t, filepath.Join(backup, "auth.json"), auth("r-old"))
|
|
before, _ := os.ReadFile(filepath.Join(backup, "auth.json"))
|
|
listed := func() bool {
|
|
ForgetAccounts()
|
|
rememberLogins(true)
|
|
for _, l := range Logins("codex") {
|
|
if l.User == "pro@example.com" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
if !listed() {
|
|
t.Fatalf("the backup folder's account isn't listed: %+v", Logins("codex"))
|
|
}
|
|
|
|
if err := ForgetLogin("codex", "pro@example.com"); err != nil {
|
|
t.Fatalf("remove the account held in the backup folder: %v", err)
|
|
}
|
|
if after, _ := os.ReadFile(filepath.Join(backup, "auth.json")); string(after) != string(before) {
|
|
t.Errorf("the backup folder's auth.json was changed: %s", after)
|
|
}
|
|
if listed() {
|
|
t.Fatalf("removed, then read back from the backup folder: %+v", Logins("codex"))
|
|
}
|
|
for _, l := range Logins("codex") {
|
|
if l.User != "me@example.com" {
|
|
t.Errorf("left after the removal: %+v", l)
|
|
}
|
|
}
|
|
|
|
// unreadable, the record says nothing: the removed account isn't
|
|
// listed again on a guess
|
|
if err := os.WriteFile(codexAsidePath(), []byte("{"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if listed() {
|
|
t.Fatalf("with the record unreadable, the removed account came back")
|
|
}
|
|
if err := setCodexAside(backup, before); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Codex signed in in that folder again: another sign-in, listed
|
|
writeFile(t, filepath.Join(backup, "auth.json"), auth("r-new"))
|
|
if !listed() {
|
|
t.Fatalf("a new sign-in in the folder isn't listed: %+v", Logins("codex"))
|
|
}
|
|
}
|