Skip to content

fix(settings): clamp number settings to their field's range before saving - #634

Merged
LargeModGames merged 1 commit into
LargeModGames:mainfrom
kapok-4o:fix/settings-number-clamp
Sep 27, 2026
Merged

LargeModGames merged 1 commit into
LargeModGames:mainfrom
kapok-4o:fix/settings-number-clamp

Conversation

@kapok-4o

@kapok-4o kapok-4o commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #594. The five arms in apply_settings_changes now clamp to their target type before the cast, as the issue lists:

  • seek_milliseconds: clamp(0, u32::MAX)
  • like_animation_frames: clamp(1, u8::MAX)
  • table_scroll_padding: clamp(0, u16::MAX)
  • small_terminal_width / small_terminal_height: clamp(1, u16::MAX)

The clamp lives in settings_apply.rs, so the GUI's Action::SaveSettings path gets it too. The fatal check in user_config.rs is untouched.

Tests: like_animation_frames_above_255_saves_as_255_not_zero, negative_seek_duration_saves_as_zero, and the optional u16_settings_above_their_range_save_as_the_maximum (65536 for width and padding).

Testing

  • cargo fmt --all -- --check: clean
  • cargo clippy --no-default-features --features telemetry,tui -- -D warnings: clean
  • cargo test --no-default-features --features telemetry,tui: 1284 passed, 0 failed
  • cargo test --no-default-features --features telemetry,tui settings_apply: 4 passed
  • With the old max(1) as u8 and as u32 arms, the two required tests fail.

Additional notes

I checked this through apply_settings_changes only. I didn't do the manual "type 256 in Settings, save, restart" run from the issue.

This is one of five small PRs I opened together (#602, #603, #594, #595, #599). Each changelog entry sits at a different spot in [Unreleased] so they merge without conflicts in any order.

Written with AI coding assistants: the fix was drafted by Codex, then extracted onto its own branch, checked against the issue and re-tested by Claude Code.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Numeric settings now stay within their supported ranges when saved instead of wrapping to unexpected values. Negative seek durations and table scroll padding save as 0; like-animation frames and small-terminal dimensions are kept at or above 1.
    • Values above the supported maximum are capped, such as 256 like-animation frames saving as 255.
  • Documentation

    • Updated the unreleased changelog with examples of how out-of-range settings are handled.

…ving

apply_settings_changes cast Seek Duration, Like Animation Frames, Table
Scroll Padding and the small-terminal sizes with a bare `as`, so 256
frames wrapped to 0 and blocked the next launch, and -1 ms saved as
u32::MAX. Clamp each value to the range of its target type first, the
way the volume increment arm already does.

Fixes LargeModGames#594

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 131627a4-320e-4981-a45f-2b7a3f71df94

📥 Commits

Reviewing files that changed from the base of the PR and between 7c21df0 and f09091a.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/core/app/settings_apply.rs

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


📝 Walkthrough

Walkthrough

Settings application now clamps five numeric values to their supported ranges before conversion. Tests cover values below and above those ranges. The Unreleased changelog documents the fix.

Changes

Settings value clamping

Layer / File(s) Summary
Clamp settings values and verify bounds
src/core/app/settings_apply.rs, CHANGELOG.md
App::apply_settings_changes clamps seek duration, table scroll padding, like-animation frames, and small-terminal width and height before conversion. Tests verify representative lower and upper bounds. The changelog documents the affected settings.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to f0909

The settings values are bounded before saving, and no merge-blocking issue is identified. Normal checks remain appropriate.

Security Architecture Review

Security architecture risk: 🔵 Low · up to f0909

The change makes saved numeric settings respect their field ranges without adding a new settings entrypoint or changing the stored field types. No security concern was identified in the affected path. Restart behavior was not manually verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed inputs affect the application's own persisted behavior settings. The traced GUI save route uses the existing application-owned save method, rather than a new independently reachable write path.

Trust Boundaries and Controls

  • observed — Each modified assignment remains behind its existing setting-ID match and numeric-value check before updating the corresponding configuration field.

Resilience and Maintainability Implications

  • inferred — Bounding before conversion prevents these out-of-range inputs from wrapping into different stored values. An error after in-memory application but before a successful save remains possible under the pre-existing apply-then-save order; this PR does not introduce that order.
🚥 Pre-merge checks | ✅ 4
✅ 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 uses the valid conventional-commit prefix fix(settings):, clearly describes the main change, and uses a concise imperative subject.
Linked Issues check ✅ Passed Issue #594 requires clamping all five settings before casting in apply_settings_changes, plus automated tests for out-of-range values. The diff clamps seek duration to 0..=u32::MAX, like animation…
Out of Scope Changes check ✅ Passed The pull request changes only the five required casts, adds tests for Issue #594, and updates CHANGELOG.md with the same behavior. These changes support the linked issue and do not demonstrate unrel…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
✨ Simplify code
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Sep 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LargeModGames
LargeModGames merged commit 2878ad4 into LargeModGames:main Sep 27, 2026
31 checks passed
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.

Settings: Like Animation Frames 256 saves 0 and blocks launch

2 participants