Validate layer indexes during command parsing - #331
Merged
Conversation
Reject negative layer indexes before registry access, improve manifest range diagnostics, and cover parser and boundary behavior across supported cultures. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve the save-layers option conflict by preserving both layer index validation and the new force option. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes are cohesive, well-covered by tests, and improve both early validation and user-facing diagnostics without introducing risky behavioral changes.
Pull request overview
This PR improves the CLI UX and efficiency around layer-index options by validating negative layer indexes during command parsing (before any registry/manifest work), and by producing clearer, range-specific errors once manifest-dependent bounds are known.
Changes:
- Centralized construction of layer-index options to consistently describe zero-based indexing and reject negative values during parsing.
- Improved
ImageHelperupper-bound validation messages (explicit range, and a dedicated “no layers” message). - Updated comparison commands and tests to share full option names consistently and to cover boundary/invalid/culture-specific inputs.
File summaries
| File | Description |
|---|---|
| src/Valleysoft.Dredge/ImageHelper.cs | Improves out-of-range diagnostics (explicit valid range; special case for images with zero layers). |
| src/Valleysoft.Dredge/Commands/Image/SaveLayersOptions.cs | Switches --layer-index option creation to the centralized factory for consistent parsing/description/validation. |
| src/Valleysoft.Dredge/Commands/Image/LayerIndexOption.cs | Adds shared layer-index option factory with zero-based description and negative-value parsing validation. |
| src/Valleysoft.Dredge/Commands/Image/CompareFilesOptions.cs | Uses the shared layer-index option factory and exposes full option names as constants. |
| src/Valleysoft.Dredge/Commands/Image/CompareFilesCommand.cs | Passes full option names through to runtime diagnostics for consistency with registration. |
| src/Valleysoft.Dredge.Tests/ImageHelperTests.cs | Adds boundary and empty-manifest tests for improved range/“no layers” errors and correct layer fetching behavior. |
| src/Valleysoft.Dredge.Tests/CommandStructureTests.cs | Adds parser/structure tests for zero-based descriptions and negative/invalid/culture-specific input handling. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Negative layer indexes were accepted until after the image manifest had been fetched, causing avoidable registry work and producing vague range errors.
This change centralizes layer-index option construction so all affected options advertise zero-based indexing and reject negative values during parsing. Manifest-dependent upper-bound validation remains in
ImageHelper, with explicit valid ranges and a dedicated message for images with no layers. The comparison commands now share their full option names between registration and runtime diagnostics.Tests cover negative, malformed, overflowing, culture-specific, boundary, and empty-manifest inputs across .NET 9 and .NET 10. The complete Docker-backed suite passes with 501 tests per target framework.
Fixes: #316