-
Notifications
You must be signed in to change notification settings - Fork 584
Fix stop kill missing containers #979
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
base: main
Are you sure you want to change the base?
Conversation
|
@dcantah |
| let allContainers = try await ClientContainer.list() | ||
| let containers = try self.all | ||
| ? allContainers | ||
| : Self.containers(matching: containerIds, in: allContainers) |
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 handle ambiguous prefix matches here.
Currently, allContainers.first(where:) will silently pick the first matching container. If I have containers abc and abd, running stop ab might stop abc just because it appears first in the list.
It would be safer to filter all matches and throw an error if matches.count > 1 (unless there's an exact match). This aligns with how Docker handles ambiguous prefixes.
|
|
||
| @testable import ContainerCommands | ||
|
|
||
| struct ContainerStopValidationTests { |
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.
Could we add a test case for ambiguous prefixes?
We should verify that stop ab throws an error if both abc and abd exist. It's an important edge case to prevent accidental stops.
| import ContainerizationOS | ||
| import Foundation | ||
|
|
||
| package protocol ContainerIdentifiable { |
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.
Refactoring this resolution logic into a shared helper is a great move. It keeps Stop and Kill consistent and makes testing way easier.
Type of Change
Motivation and Context
The
stopandkillcommands currently do not gracefully handle cases where container IDs are missing or not found. This PR adds proper error handling for missing containers and ensures validation tests run correctly.Fixes #878
Testing