feat: refactor CodexAuth so invalid state cannot be represented #10208
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.
Previously,
CodexAuthwas defined as follows:codex/codex-rs/core/src/auth.rs
Lines 39 to 46 in d550fbf
But if you looked at its constructors, we had creation for
AuthMode::ApiKeywherestoragewas built using a nonsensical path (PathBuf::new()) andauth_dot_jsonwasNone:codex/codex-rs/core/src/auth.rs
Lines 212 to 220 in d550fbf
By comparison, when
AuthMode::ChatGPTwas used,api_keywas alwaysNone:codex/codex-rs/core/src/auth.rs
Lines 665 to 671 in d550fbf
#10012 took things further because it introduced a new
ChatgptAuthTokensvariant toAuthMode, which is important in when invokingaccount/login/startvia the app server, but most logic internal to the app server should just reason about twoAuthModevariants:ApiKeyandChatGPT.This PR tries to clean things up as follows:
LoginAccountParamsandAuthModeincodex-rs/app-server-protocol/both continue to have theChatgptAuthTokensvariant, though it is used exclusively for the on-the-wire messaging.codex-rs/core/src/auth.rsnow has its ownAuthModeenum, which only has two variants:ApiKeyandChatGPT.CodexAuthhas been changed from a struct to an enum. It is a disjoint union where each variant (ApiKey,ChatGpt, andChatGptAuthTokens) have only the associated fields that make sense for that variant.Stack created with Sapling. Best reviewed with ReviewStack.