Skip to content

Reject invalid layout index in master.deleteLayout and renameLayout - #1358

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h2442-master-deletelayout-with-an-inva
Oct 25, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h2442-master-deletelayout-with-an-inva

Conversation

@Silvertree2010

@Silvertree2010 Silvertree2010 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Found while testing crates/engine/src/cmd/design.rs:1353 (layout_target), used by delete_layout at :1368 and rename_layout at :1356 (no existing issue): master.deleteLayout with an invalid (negative or non-integer) layout index deletes the selected layout.

Cause

layout_target read master and layout with usize_param, which turns a negative or non-integer value into None. It then fell back to the selected layout, so a bad index silently acted on a layout the caller did not name.

Fix

layout_target now uses opt_usize_param, so an absent index still falls back to the selection, but a present invalid index returns BadParams. The document is left unchanged in that case. The command name is passed in so the error names the right command.

Verified

  • Regression test cmd::design::tests::layout_commands_reject_invalid_index: fails on main without the fix and passes with it (cargo test -p deckcraft-engine --lib layout_commands_reject_invalid_index).
  • cargo xtask ci passes except tests::east_asian_vertical_text_stands_ideographs_upright, which also fails on main without this change.

Not changed

Other commands that use usize_param were not changed.

🤖 Generated with AI by ApolloOffice, see the Co-Authored-By trailers for the models

Summary by CodeRabbit

  • Bug Fixes
    • Layout rename and deletion commands now report errors for negative or fractional indices instead of using default indices. Omitting indices continues to work for deletion.

Found while testing crates/engine/src/cmd/design.rs:1353 (layout_target), used by delete_layout at :1368 and rename_layout at :1356

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between a0eeb34 and 6523a49.

Files selected for processing: 1
  • crates/engine/src/cmd/design.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Master layout rename and delete commands now reject supplied negative or fractional indices instead of falling back to selected or default layouts. Tests verify that invalid indices do not change layouts and that deletion still works when indices are omitted.

Changes: Master Layout Index Validation

Layer / File(s) Summary
Command validation and regression coverage
crates/engine/src/cmd/design.rs
layout_target validates supplied indices using command-specific validation. Rename and delete commands provide their command names. Tests cover invalid indices, unchanged layouts, and deletion with omitted indices.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: echelon

Merge Risk: Minimal · up to 6523a

Invalid numeric indices are rejected, while null retains the existing optional-index behavior. This change is ready to merge after normal checks.

Architecture risk: Low · up to 6523a

The change affects 1 system.

Changed systems: crates

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/engine/src/cmd/design.rs: layout_target now accepts a command name and validates supplied master and layout indices with opt_usize_param. rename_layout supplies its command name; invalid supplied values now error instead of being treated as absent and defaulting to the selected or first layout.
  • observed — Modified behavior in crates/engine/src/cmd/design.rs: delete_layout now supplies its command name to layout_target, so invalid supplied indices are rejected instead of falling back to defaults.
  • observed — Modified behavior in crates/engine/src/cmd/design.rs: Adds a test asserting that negative and fractional master or layout indices cause rename and delete commands to fail without changing layout counts or names; deletion with omitted indices still succeeds.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: master.deleteLayout and master.renameLayout now reject invalid layout indices instead of falling back to the selection. The raw summary and objectives both describe th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: master.deleteLayout and master.renameLayout now reject invalid layout indices instead of falling back to the selection. The raw summary and objectives both describe this change, which matches the title. The title is specific and short enough to scan in history.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 24905e7 into storytold:main Oct 25, 2026
3 checks passed
@echelon

echelon commented Oct 25, 2026

Copy link
Copy Markdown
Member

Landed on main — thank you for the contribution! Main switched to explicit imports today (#1270), so a follow-up commit adds the opt_usize_param import. If you haven't already, come join us on Discord: https://discord.gg/artcraft

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.

3 participants