Skip to content
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

Shared layer logic for consistent output and unit testing #327

Merged
merged 19 commits into from
Oct 2, 2024

Conversation

schneems
Copy link
Contributor

PR #326 pointed out inconsistencies in the style of output for different layers and asked for additional tests. This refactor makes that request easier by introducing shared logic for invalid metadata and cache invalidation.

It's a ducktyping approach based on two traits:

  • magic_migrate::TryMigrate provides an interface to (possibly) migrate invalid metadata or display errors
  • MetadataDiff provides an interface to allow standardize cache invalidation and restoration logic

These allow me to remove the bulk of cache invalidation logic into a central shared location. They also expose a clean interface for unit testing cache invalidation logic, which can then be used on other layers.

I described some of the background desires in #325, comment: #325 (comment).

@schneems schneems requested a review from a team as a code owner September 25, 2024 01:28
@schneems schneems force-pushed the schneems/ruby-install-layer-refactor2 branch from d429dba to b4f8850 Compare September 25, 2024 15:06
@schneems schneems marked this pull request as draft September 30, 2024 17:15
@schneems schneems force-pushed the schneems/ruby-install-layer-refactor2 branch from fa3b1d6 to ada317a Compare September 30, 2024 20:46
@schneems schneems marked this pull request as ready for review September 30, 2024 20:49
There was a newline preventing rust-analyzer from ordering the `use` statements. I removed it, and saved and this is the outcome.
It might be safe to `expect` in the specific case, but not in the general one. We can return a nicely formatted string with information if it ever happens.
Instead of asserting implementation (that diffing a metadata object returns a vec entry), assert the behavior we want (that it clears the cache).
To fully exercise all caching logic in the shared folder, I'm introducing a helper to create a temporary `BuildContext` that can be used for exercising caching logic in test.

This also introduces tests for both `restored_layer_action` states as called through `cached_layer_write_metadata`. Which should address this comment #327 (comment).
In the ruby_install_layer we're exercising `cached_layer_write_metadata` but we were testing `restored_layer_action` which is called currently but might not be in the future via refactoring. This change asserts the behavior we want while using the exact same interface we are currently using.
@schneems schneems force-pushed the schneems/ruby-install-layer-refactor2 branch from ada317a to b556b9a Compare October 1, 2024 13:29
Copy link
Contributor

@colincasey colincasey left a comment

Choose a reason for hiding this comment

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

@schneems I'm good with most of this code but the inability to choose between build: true and launch: true in the cached_layer_write_metadata function seems like it should either be re-evaluated or explained.

buildpacks/ruby/src/layers/ruby_install_layer.rs Outdated Show resolved Hide resolved
buildpacks/ruby/src/layers/ruby_install_layer.rs Outdated Show resolved Hide resolved
buildpacks/ruby/src/layers/ruby_install_layer.rs Outdated Show resolved Hide resolved
buildpacks/ruby/src/layers/shared.rs Show resolved Hide resolved
- Ensures each of these cases where the vec is not empty will clear the cache.
- Makes it easier for reviewers to see the output as a user would see it.
@schneems schneems merged commit ec57995 into main Oct 2, 2024
7 checks passed
@schneems schneems deleted the schneems/ruby-install-layer-refactor2 branch October 2, 2024 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants