fix: preserve active account on add with OAuth command regression tests - #153
Open
Jeakcey wants to merge 2 commits into
Open
fix: preserve active account on add with OAuth command regression tests#153Jeakcey wants to merge 2 commits into
Jeakcey wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and behavior
With account A active, completing Add Account → ChatGPT Login for account B immediately activates B and overwrites the Codex
auth.json. Users who only want to save another account unexpectedly lose their current selection.OAuth completion now saves the account and preserves the existing active account, live authentication file, and usage timestamps. A first account also remains inactive until the user explicitly selects Switch. This keeps the existing guarded switch flow responsible for activation.
Fixes #140.
Relationship to #141 and attribution
This is an enhanced alternative to #141, based on current
main(25816fe). It includes @legibet's original fix fromec371e1691fe3b5188db336294e80495cc0fbb6b, cherry-picked with the original author attribution preserved. The follow-up commit adds command-level regression coverage beyond the storage-level test in #141.If maintainers prefer to merge #141, the follow-up test commit can be taken separately; the original fix is credited to @legibet.
Added regression coverage
Four async tests feed synthetic OAuth results into the real
complete_logincommand and exercise real account persistence:auth.jsoncontents (including newer session tokens), A's saved record, and B's inactive/never-used state.auth.json.Test-only, thread-local temporary homes isolate both
.codex-switcherand.codex. Filesystem access without a fixture fails in unit-test builds instead of falling back to real user files. Tests use a current-thread runtime and serialize access to the pending OAuth slot. Production path resolution is unchanged. No new dependencies are needed.The functional change covers OAuth completion and the shared single-account add path. Bulk import behavior is outside this change.
Validation
On Windows:
cargo test --manifest-path src-tauri/Cargo.toml --offline: 54 passed.cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets --offline: completed with existing warnings in unrelated code.pnpm build: passed.pnpm test:reset-credits: 3 passed.pnpm test:desktop-reopen: 7 passed.git diff --check: passed.OAuth results are synthetic; these tests do not perform a browser login, contact OAuth services, or stop running applications.