Skip to content

feat: decouple SM-2 algorithm, add timezone handling, and unit tests … - #1527

Open
Dev1822 wants to merge 1 commit into
Canopus-Labs:mainfrom
Dev1822:feature/issue-1524
Open

feat: decouple SM-2 algorithm, add timezone handling, and unit tests …#1527
Dev1822 wants to merge 1 commit into
Canopus-Labs:mainfrom
Dev1822:feature/issue-1524

Conversation

@Dev1822

@Dev1822 Dev1822 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

📝 Pull Request Description

Related Issue

Closes #1524

Summary

Extracted the calculateSM2 spaced repetition logic out of the flashcard controller and into a dedicated utility service (utils/srsAlgorithm.js). Introduced an optional timezone parameter to the algorithm so nextDueDate can accurately align with the start of the day (midnight) in the user's local timezone, rather than relying strictly on absolute server time. Finally, added a comprehensive Vitest unit testing suite to validate all repetition edge cases and timezone offsets.


Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature
  • ♻️ Refactoring
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • 🔥 Other(please describe) ______

How Has This Been Tested?

  • Wrote 10 rigorous unit tests validating again/hard/medium/easy rating boundaries, ease factor minimums, and timezone parsing (America/New_York, Australia/Sydney, etc.).
  • Ran the full backend test suite (npm run test / vitest) confirming 100% pass rate for the new algorithm logic.

Screenshots (if applicable)

N/A - Backend logic and unit test refactor only.


Checklist

  • My code follows the project's guidelines
  • I have tested my changes
  • I have updated documentation where necessary
  • I have linked the related issue
  • My changes do not introduce new warnings or errors

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Dev1822, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 3 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: aae480a6-79d5-435b-aede-98000d746060

📥 Commits

Reviewing files that changed from the base of the PR and between 8ba0a98 and f231eca.

⛔ Files ignored due to path filters (1)
  • backend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • backend/controllers/flashcardController.js
  • backend/tests/srsAlgorithm.test.js
  • backend/utils/srsAlgorithm.js

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

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.

[Feature]: Decouple and Unit Test the SM-2 Space Repetition Algorithm

1 participant