refactor: extract volume and image matching logic from rm_build.rs#124
Merged
jamiesunderland merged 1 commit intocoast-guard:mainfrom Mar 23, 2026
Conversation
Extract pure matching logic from async Docker-dependent functions into testable helpers: - volume_belongs_to_project: checks shared, compose, shared-services, and isolated volume naming patterns with label verification - image_matches_project: checks repo tags for coast-image and coasts compose prefixes Adds 13 unit tests covering all matching cases listed in the ticket. Parent functions (remove_project_volumes, remove_project_images) now delegate to the helpers. Existing #[allow] annotations on handle functions are kept as-is per ticket scope. Closes coast-guard#121
jamiesunderland
approved these changes
Mar 23, 2026
Contributor
jamiesunderland
left a comment
There was a problem hiding this comment.
Perfect! Thanks @mukeshblackhat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
coast-daemon/src/handlers/rm_build.rs:volume_belongs_to_project(name, project, labels)— checks shared, compose, shared-services, and isolated volume naming patterns with label verificationimage_matches_project(repo_tags, project)— checks repo tags forcoast-image/{project}:and{project}-coastsprefixesremove_project_volumesandremove_project_imagesto delegate to the new helpers#[allow(clippy::...)]annotations on thehandlefunctions are kept as-is per ticket scopeWhat was there before
remove_project_volumesandremove_project_imageshad matching logic inlined inside async Docker-dependent loops. This made it impossible to unit test the matching rules without a real Docker daemon.What changed
Single file:
coast-daemon/src/handlers/rm_build.rsExtracted functions (both private, pure, no async):
volume_belongs_to_projectcoast-shared--{project}--), compose volumes ({project}-coasts), shared-services volumes ({project}-shared-services), isolated volumes (coast--+ label match)image_matches_projectcoast-image/{project}:or{project}-coastsParent functions updated:
remove_project_volumes— replaced inline matching withvolume_belongs_to_projectcallremove_project_images— replaced inline matching withimage_matches_projectcall13 unit tests added:
volume_belongs_to_project(8 tests):image_matches_project(5 tests):Test plan
Verify the extraction
Run lint and full tests
Verify behavior is unchanged
Closes #121