feat: add investment rollup helper for category-level reporting#6
feat: add investment rollup helper for category-level reporting#6ak684 wants to merge 2 commits into
Conversation
|
@OpenHands /autoreview |
|
I'm on it! ak684 can track my progress at all-hands.dev |
ak684
left a comment
There was a problem hiding this comment.
First-pass review below.
This PR is a small utility, but in its current form it ships a SQL-injection sink, an off-by-one in the top-N helper, and several NPE/ClassCastException pitfalls driven by the untyped Map<String, Object> shape. There are also no unit tests for any of the three new public methods. Details inline.
Summary by category:
- 🔒 security: 1 (
buildCategoryFilterconcatenates raw strings into SQL) - 🐛 correctness: 4 (off-by-one limit, NPE on missing
category, NPE/ClassCast on missing/non-numericamount, empty-listIN ()) - 💡 design / conventions: 2 (use a typed model instead of
Map<String, Object>; name the magic100default) - 🧹 tests: 0 unit tests for the new helpers; please cover happy path, empty input, missing fields, and the
topN <= 0branch
Happy to re-review once these are addressed.
| * <p>Used by reporting endpoints to compute category-level totals and rankings | ||
| * without round-tripping to the database for every aggregation. | ||
| */ | ||
| public final class InvestmentRollup { |
There was a problem hiding this comment.
🧹 No unit tests. None of totalInvestmentByCategory, topByInvestment, or buildCategoryFilter have tests, and the repo has no src/test/java/io/ventureplatform/ directory at all yet. For a pure utility class like this — explicitly described in the PR body as a "building block" — tests are cheap and would have caught the off-by-one on line 48 and the empty-list case on line 57 before review.
Suggested coverage: happy path with mixed categories; empty companies / empty categories; matching category but no amount key; topN <= 0; ensure topByInvestment returns exactly topN items sorted descending; and a regression test for the null-category-value case once that's fixed.
There was a problem hiding this comment.
Not addressed in this PR. The repo has no test infrastructure yet — pom.xml has no spring-boot-starter-test/JUnit dependency and there is no src/test/java/ tree at all (confirmed via grep -i junit pom.xml and find src -type d). Per the project AGENTS.md, bringing up a test harness from zero is out of scope for a single-comment fix and should be a separate change; leaving this thread open as a tracker. The specific bugs the suggested tests would have caught (off-by-one, empty-list SQL, null category, missing/wrong-type amount) are fixed in 83feb90 by tightening the types and the helper contracts.
SummaryI performed a Checklist against the autoreview skill's requirements
Issues flagged (all on
|
|
@OpenHands /autofix |
|
I'm on it! ak684 can track my progress at all-hands.dev |
- Replace Map<String, Object> with typed PortfolioInvestment record so callers can't pass missing keys or wrong value types (fixes NPE/CCE risks on amount/category). - Use Objects.equals when comparing categories to avoid NPE on null category values. - Drop the .limit(limit + 1) off-by-one in topByInvestment; return exactly topN items. - Throw IllegalArgumentException instead of silently falling back to a magic 100 when topN <= 0. - buildCategoryFilter now returns a CategoryFilter record carrying a parameterised SQL fragment (category IN (?, ?, ...)) plus the bound values, eliminating the SQL injection vector. Empty/null categories short-circuit to '1=0' so callers don't produce 'category IN ()'.
|
Fixes pushed, all addressable threads resolved. Pushed
One thread left open as a tracker: the "no unit tests" comment — the repo has no test infrastructure (no JUnit/surefire in
|
Summary of
|
Summary
Adds a small utility for computing category-level investment totals, top-N company rankings, and a SQL category-filter builder used by upcoming dashboard rollup endpoints.
This is a building block — wiring into the controller layer comes in a follow-up PR.
Test plan