Group the allocation by tag, and see through funds on it
Part of #122. The two halves of IP3 that could not ship with their own slices.
Ready for review, based on main. #194 (the grouping registry), #198 (tags)
and #200 (constituents) have all merged; this branch has taken main and the
diff below is only the new work on top. The stacked-draft note that stood here,
and its warning that CodeRabbit would skip a non-default base, both describe a
state that ended when the three landed.
The asset-class drill-down renders flat while look-through is on, rather
than opening onto the fund's own sub-classes and contradicting the parent row
above it. Building the child level properly is a product decision about what
the bottom row means, raised as #217.
The problem
Two slices shipped a capability with nothing to do with it:
- 3.5 (#198) gave a household its own tagging scheme. The four classification
axes are the ones everyone gets; grouping by tag is the only reason to have
tagged anything, and that neededALLOCATION_GROUPINGS. - 3.7 (#200) stored what a fund actually holds but never showed it, so a
portfolio held through funds still charted as almost entirely Unclassified —
the exact problem that slice existed to solve.
Two rules decided here, not assumed
A multi-tagged holding is split evenly across its tags. A security can carry
several tags, unlike a taxonomy column. Counting it once per tag makes the
segments overrun the portfolio — and this section renders as a donut, so
segments summing to 140% draw a chart that is simply wrong. #194's own invariant
test ("every allocation grouping measures the same portfolio") is what caught it.
"Half in pension, half in tech bet" is an answer a reader can act on.
A constituent with no Security row is carried as unclassified, not dropped.
Constituents are stored as bare tickers, so classification comes from a Security
row when one exists. Dropping the rest would shrink the portfolio total by the
weight of every constituent the family does not separately hold — for a broad
index fund, nearly all of it.
The toggle is offered only on the classification axes and only when the
portfolio holds a fund with constituents. Account, currency and kind are
properties of the position, not the instrument, and a fund's constituents have
no account of their own; grouping by security with look-through is meaningless
because the security is the fund.
Evidence
Written before the implementation and watched to fail — the 16 model tests in
test/models/investment_statement/allocation_tags_and_look_through_test.rb failed
first, then the 8 in test/controllers/portfolios_look_through_test.rb.
The fix this section used to describe — #194's "a cash holding is liquidity"
precondition, broken by #192's apply_default_asset_class — is no longer in this
diff. It landed on main through #195 while this branch was still stacked.
A green baseline was taken on the merge of the three branches before any new
code, so nothing here is attributed to a merge conflict. The only conflict was
app/models/security.rb, where #198's has_many :taggings and #200's has_many :constituents were added at the same anchor; both are kept.
Thirteen mutations, all caught:
| Mutation | Caught by |
|---|---|
| tags not scoped to the family | another-family's-tag |
| untagged holdings dropped | an untagged holding is carried, not dropped |
| multi-tagged counted once per tag | the split test |
| account cash not carried into the grouping | 2 tests |
| unresolvable constituent dropped | total-is-preserved |
look_through_split returns {} for a non-fund | 2 tests |
look_through never reaches the statement | parameter-changes-segments |
| controller never reads the parameter | parameter-changes-segments |
| toggle offered on every axis | axis-it-does-not-apply-to |
| toggle offered with no funds held | not-offered-without-funds |
grouping links drop look_through | keeps-toggle-across-axes |
| the drill-down guard under look-through removed | asset-class rows do not open onto the fund's own columns |
the partial stops passing look_through to allocation_children | the same test |
Two of my own tests were vacuous and the mutation run found both:
- "a constituent with no security row is carried as unclassified" asserted an
unclassified segment existed — but another holding already produced one, so
it passed while the constituent was being dropped outright. Now asserts the
total is preserved, which is what dropping actually breaks. - The two new invariant tests first compared against
portfolio_value, which the
fixture family's balances exceed for reasons unrelated to grouping. They now
compare the tag grouping against another grouping — the invariant that matters,
and the one #194 enforces.
Three more vacuous tests, found by CodeRabbit's first pass on this branch.
"the toggle is not offered on an axis it does not apply to" and two others
asserted assert_select ... count: 0 without ever asserting the response, and a
redirect or an error page satisfies that just as well as a rendered one. All
three now assert assert_response :success first.
Checks: full suite 10029 runs, 42531 assertions, 0 failures, 0 errors, 33
skips, re-measured at the current head. bin/rubocop 2779 files, no offenses. erb_lint clean. brakeman 0
warnings. db/schema.rb untouched.
Summary by CodeRabbit
- New Features
- Added Tag as a portfolio allocation grouping. Holdings with multiple tags are split across them, while untagged holdings and cash remain included.
- Added an optional look-through control for supported allocation views. When enabled, fund allocations are grouped by their constituents’ classifications, with totals preserved. The control appears only when the portfolio holds funds with usable constituent weights.
- Tests
- Added coverage for tag grouping, look-through availability and behavior, and family-specific tags in the holdings picker.