Add the overlaps section to Rule health

JA
14d ago
+393-1

Closes jaysbeekay/sure#702

Upstream issue: we-promise/sure#5175
Upstream PR: we-promise/sure#5527 (same branch, same commit), in native stack we-promise/sure#5529

Stacked on jaysbeekay/sure#796 (up/rule-health); the diff below is this branch's own commits. jaysbeekay/sure#797 (up/rule-similar-warning) now stacks on this branch, since its save-time check reuses the text comparison added here. Split out of #796 to keep that change near the ~300-line guide (owner decision, 2026-11-17); #796 is now "Part of" the issue and this slice closes it.

Summary

Adds the Overlaps section to the Rule health page: active rules below another that sets the same field on transactions both match ("1 of its 2 matches are also matched by the rule above"), or whose conditions name the same or contained text (a merchant condition read as the merchant's name) with otherwise the same conditions, so uber AND amount > 100 and uber AND amount < 10 are not listed. Pairs already listed as duplicates or conflicts, and shadowed rules, are left out.

What changed

  • Rule::Health#overlaps, with same_text?, texts, conditions_besides_text and merchant_names, exactly as reviewed on #796 at 88d98be0b (commit "Add the overlaps section to Rule health" is the revert of its removal there).
  • Review fix (Gatekeeper full review 6946839460, finding 4): same_text? folded every condition's text, so = Uber and = uber were listed as the same text although = matches case and the two rules match disjoint transactions. Text is now folded only when one side runs as ILIKE (like, starts_with, ends_with), the same rule condition_value uses.
  • rules/_health_report.html.erb overlaps section and its rules.health.overlaps.* strings.

Size: 97 non-test lines (health.rb 83).

Deliberately left out

  • Finding 5 (merchant_names reads Merchant unscoped): declined. The ids come from the family's own rule conditions, the name is only compared as text and never rendered, and family.merchants would drop the provider merchants a merchant condition legitimately names (TransactionMerchant#options lists available_merchants_for). Scoping through available_merchants adds a pluck of every transaction's merchant id per report for no exposure.
  • The shared count reads matches before any rule runs, like the rest of the report; it is advisory, and #796 now holds back the shadowed and match-nothing verdicts where a rule above changes what a rule reads.

Blast radius: who else hits this line, and what do they pass?

  • same_text? and texts are read by overlaps here and by Rule::Health#similar_to in #797, which passes the form's unsaved rule; both get the same case rule.
  • condition_value (duplicates, conflicts) is unchanged here.

Tests

test/models/rule/health_test.rb: the 8 overlap tests moved back from #796, plus 1 new; rules_controller_test.rb: the report test asserts the overlaps section again.

TestKind
shared transactions on the same field: overlap, 1 of 2positive
shared transactions, different fields: no overlapnegative
"contains uber" vs "= UBER EATS": overlap with 0 sharedpositive
= "Uber" vs = "uber": not the same text (new; failed before the fix: overlap listed with same_text=true)negative
contained text with contradicting amount conditions: no overlapnegative
contained text inside an OR group: still the same textpositive
merchant condition read by name: overlap; merchant renamed: nonedelta
contained text, different fields: no overlapnegative
same conditions, same value, plus another action: overlappositive
controller: report renders the conflicts, shadowed and overlaps sectionscontroller

Mutations (container copy only)

MutationCaught by
fold text for every operator= "Uber" vs = "uber"
never fold textmerchant condition read by name
overlaps ignore the shared field, merchant compared by id, skip every same-conditions paircarried from #796's table at 88d98be0b, code unchanged

Validation

  • health_test.rb, rules_controller_test.rb, runner_test.rb, runner/claims_test.rb at 102e4ff29: 129 runs, 0 failures, 0 errors. Full suite: CI on this branch.
  • rubocop and erb_lint on the changed files: no offenses.
  • Checked against upstream AGENTS.md: t() for every string, DS::Section as in #796, no new dependencies.

Refresh (2026-11-22)

  • Merged up/rule-health (with current upstream main) in; no conflicts. New commit 2d521e66d: the shared line pluralises on the shared count ("1 of its 2 matches is…", "2 of its 3 matches are…"); new controller test failed before on 1 of its 2 matches is.
  • Full bin/rails test at 2d521e66d: 18187 runs, 0 failures, 8 errors (environmental ReleaseNotesWorkflowTest, no node).

Screenshots

Before (up/rule-health, a53e59371): Duplicates and Shadowed only. After (2d521e66d): the Overlaps section, light, dark and mobile.

BeforeAfter
Light702-before-light-health702-after-light-health
Dark702-before-dark-health702-after-dark-health
Mobile702-before-light-mobile-health702-after-light-mobile-health