Skip to content

Reject fractional and out-of-range ratings in photo.rate - #2755

Merged
echelon merged 2 commits into
storytold:mainfrom
Silvertree2010:fix/h1859-photo-rate-accepts-fractional-an
Oct 24, 2026
Merged

echelon merged 2 commits into
storytold:mainfrom
Silvertree2010:fix/h1859-photo-rate-accepts-fractional-an

Conversation

@Silvertree2010

@Silvertree2010 Silvertree2010 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Found while testing crates/engine/src/cmd/library.rs:736 (no existing issue): photo.rate accepts fractional and out-of-range ratings by truncating them.

Cause

photo.rate read rating as f64 and cast it with as i64, which truncates toward zero, before the 0..=5 range check. A value like 5.9 was stored as 5 and -0.9 as 0, where the command should have returned an error.

Fix

photo.rate now reads rating with index_req, which rejects non-integral and negative numbers, and then checks that the result is at most 5. Fractional or out-of-range values now return a BadParams error. Whole numbers, including 5.0, are still accepted.

Verified

  • Regression test tests::rating_rejects_fractional_values: fails on main without the fix and passes with it (cargo test -p lightcraft-engine --lib rating_rejects_fractional_values).
  • cargo xtask ci passes.

Not changed

I did not change index_req or f64_req. A missing rating key now reports 'rating must be a whole number 0..5' instead of 'missing number rating'.

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

Summary by CodeRabbit

  • Bug Fixes
    • Photo ratings now accept only whole-number values from 0 to 5. Fractional ratings are rejected without changing the existing rating.

Found while testing crates/engine/src/cmd/library.rs:736

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 24, 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 22762e3 and 50874ad.

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

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

Walkthrough

photo.rate now accepts only whole-number ratings from 0 through 5. Tests cover fractional inputs, valid whole-number inputs, and unchanged rating state after rejected inputs.

Changes: Photo rating validation

Layer / File(s) Summary
Validate ratings and test accepted values
crates/engine/src/cmd/library.rs, crates/engine/src/tests.rs
photo.rate rejects fractional ratings and values outside 0–5. Tests verify rejected values do not change the rating and that 5.0 and 3 are accepted.

Priority: Low

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: aiongg

Merge Risk: Minimal · up to 50874

No actionable merge-blocking risk remains; the rating validation change is ready for normal checks.

Architecture risk: Low · up to 50874

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; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/engine/src/tests.rs: Adds coverage asserting fractional photo.rate values are rejected without changing the rating, while 5.0 and integer 3 are accepted.
  • observed — Modified behavior in crates/engine/src/cmd/library.rs: photo.rate replaces floating-point parsing and integer truncation with integer parsing, accepting only values from 0 through 5 and returning a whole-number validation error otherwise.
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 4 functions across 2 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 "Reject fractional and out-of-range ratings in photo.rate" matches the main change. The raw summary and PR objectives both say photo.rate now rejects non-integer values (such as 5.9 and -0.9…
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 "Reject fractional and out-of-range ratings in photo.rate" matches the main change. The raw summary and PR objectives both say photo.rate now rejects non-integer values (such as 5.9 and -0.9) and values outside 0 through 5, where it previously truncated them and accepted them. The title names the command, the affected inputs, and the behavior change. It is specific and concise, and it does not use vague terms.

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.

# Conflicts:
#	crates/engine/src/cmd/library.rs
@echelon
echelon merged commit bb82525 into storytold:main Oct 24, 2026
3 checks passed
@echelon

echelon commented Oct 24, 2026

Copy link
Copy Markdown
Member

Landed in #2814. Thank you for the contribution, @Silvertree2010! Main had since wrapped photo.rate in a cull(...) call, so I merged main into your branch and kept your validation inside it.

If you haven't already, come and 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.

2 participants