Skip to content

Conversation

@Azorlogh
Copy link

@Azorlogh Azorlogh commented Dec 8, 2025

Summary by cubic

Fixes save-all so negative balances are not reset to zero. This prevents incorrect fund availability and correctly triggers missingFunds for overdrawn accounts.

  • Bug Fixes
    • Only zero out balance on save-all when the balance is positive.
    • Added a script test for a negative USD balance that expects missingFunds.

Written for commit 23909b2. Summary will update automatically on new commits.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Walkthrough

The runSaveStatement function in the interpreter is optimized to reset balance to zero only when the current balance is positive, avoiding unnecessary writes for zero or negative balances. A new test scenario for saving from an account with overdraft handling is added.

Changes

Cohort / File(s) Summary
Core logic optimization
internal/interpreter/interpreter.go
Conditionalizes balance reset to zero—now only when current balance is positive, preventing unnecessary writes for already-zero or negative balances
Overdraft test scenario
internal/interpreter/testdata/script-tests/save/save-from-account__save-all-negative-balance.num
Adds new test data for saving all funds from an account with overdraft allowance enabled

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Logic change: Straightforward conditional optimization with clear intent; verify impact on existing balance semantics and test coverage
  • Test data file: Confirm script syntax and overdraft scenario configuration align with expected behavior

Poem

🐰 A balance once positive, now set to rest,
Zero-writes avoided—efficiency's best!
Overdrafts tested, edge cases found,
With rabbit-quick logic, we're code-safe and sound! 💫

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately summarizes the main change: fixing save-all behavior when balance is negative.
Description check ✅ Passed The PR description is directly related to the changeset, explaining the bug fix and test additions for negative balance handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/save-all-negative-balance

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
internal/interpreter/interpreter.go (1)

398-400: LGTM! Consider adding a clarifying comment.

The optimization is correct: when saving "all", there's no need to reset the balance if it's already zero or negative (overdraft). This avoids unnecessary state mutations and is semantically accurate—you can't save funds from an overdrawn account.

Consider adding a brief inline comment to explain this behavior for future maintainers.

Apply this diff to add documentation:

 if amt == nil {
+	// Only reset balance if positive; zero/negative balances are already "saved out"
 	if balance.Sign() > 0 {
 		balance.Set(big.NewInt(0))
 	}
 }
internal/interpreter/testdata/script-tests/save/save-from-account__save-all-negative-balance.num (1)

1-6: Consider adding comments to clarify the test scenario.

The test filename suggests it validates saving from an account with a negative balance, but the initial account state isn't explicit in the test file. Adding comments would help future maintainers understand:

  • What is @alice's initial balance (positive, zero, or negative)?
  • What behavior is being validated by this test?
  • What are the expected outcomes after each operation?

For example:

+# Test: Save-all should be a no-op when balance is negative (overdraft)
+# Initial: @alice has negative or zero balance
+# Expected: save-all doesn't error, subsequent overdraft works
 save [USD *] from @alice
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 06a7199 and 23909b2.

⛔ Files ignored due to path filters (1)
  • internal/interpreter/testdata/script-tests/save/save-from-account__save-all-negative-balance.num.specs.json is excluded by !**/*.json
📒 Files selected for processing (2)
  • internal/interpreter/interpreter.go (1 hunks)
  • internal/interpreter/testdata/script-tests/save/save-from-account__save-all-negative-balance.num (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Tests
  • GitHub Check: Dirty

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.11%. Comparing base (06a7199) to head (23909b2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #106      +/-   ##
==========================================
- Coverage   68.13%   68.11%   -0.02%     
==========================================
  Files          45       45              
  Lines        4290     4291       +1     
==========================================
  Hits         2923     2923              
  Misses       1209     1209              
- Partials      158      159       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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