Repository navigation
Reject invalid layout index in master.deleteLayout and renameLayout - #1358
Conversation
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>
|
No actionable comments were generated in the recent review.
|
| 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:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related PRs
- storytold/deckcraft#1304: Applies the same invalid-index rejection rule to animation commands.
- storytold/deckcraft#1189: Applies the same rule to table row and column commands.
- storytold/deckcraft#1254: Applies the same rule to
slide.hideandslide.layout.
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:
cratesArchitecture 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_targetnow accepts a command name and validates suppliedmasterandlayoutindices withopt_usize_param.rename_layoutsupplies 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_layoutnow supplies its command name tolayout_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
masterorlayoutindices cause rename and delete commands to fail without changing layout counts or names; deletion with omitted indices still succeeds.
-
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
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.
|
Landed on main — thank you for the contribution! Main switched to explicit imports today (#1270), so a follow-up commit adds the |
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
masterandlayoutwith 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
cmd::design::tests::layout_commands_reject_invalid_index: fails onmainwithout the fix and passes with it (cargo test -p deckcraft-engine --lib layout_commands_reject_invalid_index).cargo xtask cipasses excepttests::east_asian_vertical_text_stands_ideographs_upright, which also fails onmainwithout 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