Skip to content

Serialize CaskStructs in the internal API#21502

Open
Rylan12 wants to merge 3 commits intomainfrom
serialize-cask-structs
Open

Serialize CaskStructs in the internal API#21502
Rylan12 wants to merge 3 commits intomainfrom
serialize-cask-structs

Conversation

@Rylan12
Copy link
Member

@Rylan12 Rylan12 commented Feb 2, 2026

Follow-up to #21456

This PR updates the /api/internal/cask.TAG.json API to contain serialized cask structs, like we did with formulae.

Copilot AI review requested due to automatic review settings February 2, 2026 16:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates the internal cask API to serialize CaskStruct instances, following the same pattern established for formulae in PR #21456. The changes extract utility methods from FormulaStruct to the Utils module so they can be shared with CaskStruct, move the cask struct generation logic into a dedicated module, and implement serialization/deserialization methods for CaskStruct.

Changes:

  • Refactored deep symbol stringify/unstringify and compact_blank methods from FormulaStruct to Utils module
  • Added serialize/deserialize methods to CaskStruct with artifact handling
  • Extracted generate_cask_struct_hash from API::Cask into new CaskStructGenerator module
  • Updated internal cask API generation to serialize cask structs before writing to JSON

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Library/Homebrew/utils.rb Adds deep_stringify_symbols, deep_unstringify_symbols, and deep_compact_blank utility methods moved from FormulaStruct
Library/Homebrew/test/utils_spec.rb Moves tests for the utility methods from formula_struct_spec.rb to utils_spec.rb
Library/Homebrew/api/formula_struct.rb Removes utility methods that were moved to Utils and updates references to use Utils module
Library/Homebrew/test/api/formula_struct_spec.rb Removes tests that were moved to utils_spec.rb
Library/Homebrew/api/cask_struct.rb Adds serialize, deserialize, and deserialize_artifact_args methods for CaskStruct serialization
Library/Homebrew/api/cask/cask_struct_generator.rb New module containing generate_cask_struct_hash method moved from API::Cask
Library/Homebrew/api/cask.rb Removes generate_cask_struct_hash method and adds require for CaskStructGenerator
Library/Homebrew/cask/cask_loader.rb Updates reference to use CaskStructGenerator module
Library/Homebrew/dev-cmd/generate-cask-api.rb Updates to serialize CaskStruct instances and adds tap_git_head to JSON output

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far!

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added stale No recent activity and removed stale No recent activity labels Feb 24, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Rylan12 Rylan12 force-pushed the serialize-cask-structs branch from 9021f49 to a68725a Compare March 2, 2026 04:20
@Rylan12
Copy link
Member Author

Rylan12 commented Mar 2, 2026

Okay, finally had the time to overhaul this. It's split up into three commits, and a68725a is really where the interesting changes happen. The other two are just moving code around.

I've tested this by running the following:

Cask::Cask.all.reject do |cask|
  original_struct = Homebrew::API::Cask::CaskStructGenerator.generate_cask_struct_hash(cask.to_hash_with_variations)
  original_json = original_struct.serialize
  new_struct = Homebrew::API::CaskStruct.deserialize(original_json)
  new_json = new_struct.serialize
  new_struct == original_struct && new_json == original_json
end.count

This returns 0, indicating that the serialization/deserialization seems to work as expected.

I think this is ready to go, but it may be best to wait until after 5.1 is released, not sure what the timeline for that is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants