Don't compact service_args in FormulaStruct#serialize#22002
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts FormulaStruct#serialize to preserve falsy values inside service_args when generating the formula API hash, preventing invalid service DSL reconstruction (e.g., keep_alive successful_exit: false being compacted into keep_alive nil and triggering Sorbet runtime type errors during brew info/API formula loading).
Changes:
- Preserve
service_argsacrossUtils.deep_compact_blanksofalse(and other “blank” values per ActiveSupport) are not dropped from service DSL arguments. - Return the compacted hash explicitly after restoring
service_args. - Remove now-unneeded
service_argsarg-pair formatting inFormulaStruct.deserialize.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Note: technically this isn't backward compatible, and in between when this is merged and formulae.brew.sh is regenerated, there is a very small number of formulae1 that will not be installable. Since I think only me and Mike have this set, I'll just avoid this by merging when you're asleep 😅 (or you can merge it while I'm asleep). As long as it merges with or after Homebrew/formulae.brew.sh#2173, the broken period will be a max of 15 minutes. Footnotes
|
Fixes the following issue:
Since
service_argsare defined by theserviceDSL and only include methods explicitly called, we shouldn't compact away falsey values. For example:Internally, this sets
@keep_alive = { successful_exit: false }which has a different effect from@keep_alive = nilwhich is what you get if you don't callkeep_aliveat all.However, the current
FormulaStructserialization filters away all falsey values, reducing this tokeep_alive nilwhich causes a type error. In reality, we need the falsey DSL values to be preserved.The values passed to
service_argsare computed byHomebrew::Service.from_hashwhich only includes DSLs that were explicitly used, so this doesn't add any unnecessary information to the serialized files.Please merge at the same time or after Homebrew/formulae.brew.sh#2173
brew lgtm(style, typechecking and tests) with your changes locally?