Skip to content

Validate layer indexes during command parsing - #331

Merged
mthalman merged 2 commits into
mainfrom
mthalman-validate-layer-indexes
Sep 6, 2026
Merged

Validate layer indexes during command parsing#331
mthalman merged 2 commits into
mainfrom
mthalman-validate-layer-indexes

Conversation

@mthalman

@mthalman mthalman commented Sep 6, 2026

Copy link
Copy Markdown
Owner

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

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>
Copilot AI lite review requested due to automatic review settings September 6, 2026 20:52
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 ImageHelper upper-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.

Comment thread src/Valleysoft.Dredge/Commands/Image/LayerIndexOption.cs
@mthalman
mthalman merged commit 81ddd04 into main Sep 6, 2026
3 checks passed
@mthalman
mthalman deleted the mthalman-validate-layer-indexes branch September 6, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate layer indexes during command parsing

2 participants