Skip to content

Fix four AccountService bugs found in bug hunt (each with a failing test) - #383

Open
devin-ai-integration[bot] wants to merge 1 commit into
bug-hunt-demofrom
devin/1795058965-bug-hunt-fixes
Open

devin-ai-integration[bot] wants to merge 1 commit into
bug-hunt-demofrom
devin/1795058965-bug-hunt-fixes

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Summary

Bug hunt on bug-hunt-demo. Each bug is proven by a test in the new AccountServiceTest (Mockito unit tests). All 9 tests fail on the base branch and pass with this change. ./mvnw clean test passes: 10 tests, 0 failures.

Bug Test(s) Fix
hasSufficientFunds used compareTo(amount) > 0, but its doc says "at least". Withdrawing or transferring the exact balance failed with "Insufficient funds". hasSufficientFundsIsTrueWhenBalanceEqualsAmount, withdrawingTheFullBalanceSucceeds, transferringTheFullBalanceSucceeds > 0 → >= 0
getTransactionHistory(account, from, to) used end = to.atStartOfDay() with an exclusive bound, but the doc says "both days inclusive". The to day was dropped, so a single-day range always returned []. dateRangeHistoryIncludesTransactionsOnTheEndDay, singleDayRangeReturnsThatDaysTransactions end = to.plusDays(1).atStartOfDay()
Negative amounts were accepted. withdraw(-50) increased the balance, transferAmount(..., -200) took money from the recipient, and deposit(-50) reduced the balance. negativeWithdrawalIsRejectedAndDoesNotIncreaseBalance, negativeTransferIsRejectedAndDoesNotTakeRecipientFunds, negativeDepositIsRejectedAndDoesNotDecreaseBalance New requireNonNegative(amount) guard in all three methods. /deposit now catches the error and shows it on the dashboard, the same way /withdraw and /transfer already do (before, it would have returned a 500).
loadUserByUsername threw a plain RuntimeException for unknown users, but the UserDetailsService contract requires UsernameNotFoundException. The account == null check never ran. loadUserByUsernameThrowsUsernameNotFoundForUnknownUser findByUsername(...).orElseThrow(() -> new UsernameNotFoundException(...))

Dropped suspect: a self-transfer creating money. With Spring's open-in-view on, both sides of the transfer are the same entity during a web request, so I could not show it as a real bug.

Note: zero amounts are still allowed. No test covered them, so their behavior is unchanged.

Devin-Org: engineering

Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/76f92a851e5b4ac1b58b539be0350cf5
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/76f92a851e5b4ac1b58b539be0350cf5?variant=devin
Requested by: @gracejuan-star


Note

Devin errored when opening this Pull Request as gracejuan-star.
As a fallback, Devin opened this PR as itself.


Devin Review

…n-user exception in AccountService

Co-Authored-By: Grace Juan <grace.juan@cognition.ai>
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Custom reviewers

  • ✨ Blast Radius Reviewer: no findings · View
  • 🛡️ API Security Reviewer: no findings · View

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Author

Browser verification: dashboard fixes

Tested locally on Java 17 and MySQL 8, with two newly registered users.

  • Withdrawing and transferring an exact $100 balance both worked. Alice ended at $0 and Bob received $100.
  • A negative deposit, withdrawal and transfer each showed "Amount must not be negative". Neither user's balance or history changed.
  • Regression checks passed: the insufficient-funds error, a normal deposit, withdrawal and transfer, an unknown-user login (goes to /login?error), and a valid login afterwards.
  • Not browser-tested: the date-range history method. No page calls it, so only the unit tests cover it.
Negative deposit rejected No extra history rows after negative operations
Dashboard validation Unchanged transaction history
Exact transfer: Alice $0 Exact transfer: Bob $100
Alice after exact transfer Bob credited

Recording (sped up 4x):

Test recording

Written by Devin

This branch has not been deployed

No deployments
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.

0 participants