-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix: update brew auto update version check #6238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e493207 to
2fa833e
Compare
| BrewUpgrade, | ||
| } | ||
|
|
||
| #[cfg(any(not(debug_assertions), test))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the usage of this is guarded - without removing this I have string #[cfg(any(not(debug_assertions), test))] through get_upgrade_version which triggers a lot more changes. Alternatively I can create another get_update_action which returns None for debug_assertions cfg only but that is not super clean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is here so that we don't get the message all the time in dev mode. I think it's important to make this work.
| match self { | ||
| UpdateAction::NpmGlobalLatest => ("npm", &["install", "-g", "@openai/codex@latest"]), | ||
| UpdateAction::BunGlobalLatest => ("bun", &["install", "-g", "@openai/codex@latest"]), | ||
| UpdateAction::BrewUpgrade => ("brew", &["upgrade", "--cask", "codex"]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove --cask flag because it is not necessary.
|
|
||
| use crate::version::CODEX_CLI_VERSION; | ||
|
|
||
| pub fn get_upgrade_version(config: &Config) -> Option<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both the history cell (displaying upgrade message) and update_prompt (auto update) use this value for showing and calculating the correct update message.
codex-rs/tui/src/updates.rs
Outdated
| #[serde(default)] | ||
| latest_brew_version: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional because the existing version.json does not contain this and parsing it would error (hidden but still).
4a198c4 to
a7ba34c
Compare
codex-rs/tui/src/updates.rs
Outdated
| } else { | ||
| None | ||
| } | ||
| latest_version_for_action(&info, update_action).and_then(|latest_version| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get the latest version based on installation method.
codex-rs/tui/src/updates.rs
Outdated
| Some(UpdateAction::BrewUpgrade) if !info.latest_brew_version.is_empty() => { | ||
| Some(&info.latest_brew_version) | ||
| } | ||
| Some(UpdateAction::BrewUpgrade) => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The case which you have a version.json but it is not updated (i.e. not outside the window for updating) and therefore brew version is missing. Instead of using the latest version number from github we will wait until we can get the value from brew.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
codex-rs/tui/src/updates.rs
Outdated
| match self { | ||
| UpdateAction::NpmGlobalLatest => ("npm", &["install", "-g", "@openai/codex@latest"]), | ||
| UpdateAction::BunGlobalLatest => ("bun", &["install", "-g", "@openai/codex@latest"]), | ||
| UpdateAction::BrewUpgrade => ("brew", &["upgrade", "--cask", "codex"]), | ||
| UpdateAction::BrewUpgrade => ("brew", &["upgrade", "codex"]), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore
--cask flag for Brew upgrades
The update action now invokes brew upgrade codex, but Codex is published as a Homebrew cask, not a formula. Our own FAQ (docs/faq.md lines 46‑55) explicitly tells users to run brew upgrade --cask codex after the migration from a formula, because omitting --cask causes Homebrew to look for a formula named codex and fail with “No available formula with the name ‘codex’”. With this change the automatic update the CLI runs (and the command string shown to the user) will always fail for Brew installs, preventing updates for that channel. The UpdateAction::BrewUpgrade branch should continue to pass the --cask flag.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upgrade is actually fine and --cask is not necessary.
c7bf6cc to
76c5897
Compare
76c5897 to
7ea7f34
Compare
| mod text_formatting; | ||
| mod tui; | ||
| mod ui_consts; | ||
| pub mod update_action; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be pub?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - this is used in the the cli crate for typing https://github.com/openai/codex/blob/main/codex-rs/cli/src/main.rs#L23.
codex-rs/tui/src/update_action.rs
Outdated
| /// Returns string representation of the command-line arguments for invoking the update. | ||
| pub fn command_str(self) -> String { | ||
| let (command, args) = self.command_args(); | ||
| let args_str = args.join(" "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use shlex.join
codex-rs/tui/src/update_action.rs
Outdated
| let prev = std::env::var_os("CODEX_MANAGED_BY_NPM"); | ||
|
|
||
| // First: no npm var -> expect None (we do not run from brew in CI) | ||
| unsafe { std::env::remove_var("CODEX_MANAGED_BY_NPM") }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to test using dependency injection/pass from above for the env: setvar can cause undefined behavior, which is why it is marked unsafe.
0883d10 to
99a6734
Compare
codex-rs/tui/src/update_action.rs
Outdated
| detect_update_action( | ||
| cfg!(target_os = "macos"), | ||
| &exe, | ||
| managed_by_npm, | ||
| managed_by_bun, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bolinfest let me know your thoughts on this - it is pretty scalable and we can moved away from setting env variables in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, yes, this is what I meant by "pass from above."
codex-rs/tui/src/update_action.rs
Outdated
| detect_update_action( | ||
| cfg!(target_os = "macos"), | ||
| &exe, | ||
| managed_by_npm, | ||
| managed_by_bun, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, yes, this is what I meant by "pass from above."
codex-rs/tui/src/update_action.rs
Outdated
| /// Returns the list of command-line arguments for invoking the update. | ||
| pub fn command_args(self) -> (&'static str, &'static [&'static str]) { | ||
| match self { | ||
| UpdateAction::NpmGlobalLatest => ("npm", &["install", "-g", "@openai/codex@latest"]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would drop the @latest for now. At least, I wasn't aware that maintaining that tag was part of our contract with the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped latest tag for bun install too.
| /// Returns string representation of the command-line arguments for invoking the update. | ||
| pub fn command_str(self) -> String { | ||
| let (command, args) = self.command_args(); | ||
| shlex::try_join(std::iter::once(command).chain(args.iter().copied())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That copied() seems a bit suspicious to me. try_join() takes by reference: https://docs.rs/shlex/latest/shlex/fn.try_join.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha this statement has a bit too much of a nesting - .copied() is applied on the args.iter() and not the overall iter object. .chain expects an iterator and not an itr which is why we need to use copied.
codex-rs/tui/src/update_action.rs
Outdated
| if managed_by_npm { | ||
| return Some(UpdateAction::NpmGlobalLatest); | ||
| } | ||
| if managed_by_bun { | ||
| return Some(UpdateAction::BunGlobalLatest); | ||
| } | ||
| if is_macos | ||
| && (current_exe.starts_with("/opt/homebrew") || current_exe.starts_with("/usr/local")) | ||
| { | ||
| return Some(UpdateAction::BrewUpgrade); | ||
| } | ||
| None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary use of return is not canonical Rust. Prefer:
| if managed_by_npm { | |
| return Some(UpdateAction::NpmGlobalLatest); | |
| } | |
| if managed_by_bun { | |
| return Some(UpdateAction::BunGlobalLatest); | |
| } | |
| if is_macos | |
| && (current_exe.starts_with("/opt/homebrew") || current_exe.starts_with("/usr/local")) | |
| { | |
| return Some(UpdateAction::BrewUpgrade); | |
| } | |
| None | |
| if managed_by_npm { | |
| Some(UpdateAction::NpmGlobalLatest); | |
| } else if managed_by_bun { | |
| Some(UpdateAction::BunGlobalLatest); | |
| } else if is_macos | |
| && (current_exe.starts_with("/opt/homebrew") || current_exe.starts_with("/usr/local")) | |
| { | |
| Some(UpdateAction::BrewUpgrade); | |
| } else { | |
| None | |
| } |
| } | ||
| } | ||
|
|
||
| #[cfg(any(not(debug_assertions), test))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't pub, so I don't think you need this cfg line, do you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep it - removing it leads to a dead_code warning for dev build. We can add #[allow(dead_code)] but a strongly defined cfg makes it feel more intentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| impl UpdateAction { | ||
| /// Returns the list of command-line arguments for invoking the update. | ||
| pub fn command_args(self) -> (&'static str, &'static [&'static str]) { | ||
| match self { | ||
| UpdateAction::NpmGlobalLatest => ("npm", &["install", "-g", "@openai/codex@latest"]), | ||
| UpdateAction::BunGlobalLatest => ("bun", &["install", "-g", "@openai/codex@latest"]), | ||
| UpdateAction::BrewUpgrade => ("brew", &["upgrade", "codex"]), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore
--cask in brew upgrade command
The new UpdateAction::BrewUpgrade now emits brew upgrade codex. Homebrew upgrades formulae by default and requires --cask to upgrade casks, so this command fails with “No available formula with the name ‘codex’” when the user confirms the update prompt or when the CLI auto‑runs the update after exit. The previous implementation correctly used brew upgrade --cask codex. Please reintroduce the flag so Brew installations actually update.
Useful? React with 👍 / 👎.
Summary
https://github.com/Homebrew/homebrew-cask/blob/main/Casks/c/codex.rbto get the latest available version for brew usage.