Move Lunch Flow's models onto the provider kit base classes

Merged
JA
2d ago
+175-318

Summary

Provider kit Track B, B7a: Lunch Flow's connection and account models move onto the provider kit's base classes, and Lunch Flow drops its own syncer body and unlinking concern for the kit's. A pure move: no behaviour changes, and every existing Lunch Flow test passes unedited. The Lunch Flow convergence slices (C1a–C1c) made Lunch Flow's syncer identical to the kit's, which is what lets this be a move.

Part of #5003 (Track B, step 7: the Lunch Flow conversion, models layer, as B1 did for Brex).

Stacked on #5241. Fork pre-flight: jaysbeekay/sure#731 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).

What changed

  • LunchflowItem < ProviderItem (it gets Syncable and Unlinking from the base) and LunchflowAccount < ProviderAccount (it gets account_provider, account and current_account from the base; linked_account stays).
  • LunchflowItem::Syncer < ProviderItem::Syncer, a thin subclass, as BrexItem::Syncer is. It keeps the constant and SafeSyncError, names Lunch Flow's credential errors, and keeps Lunch Flow's investment data-quality warning through a new kit hook, collect_processing_warnings (a no-op by default, called right after processing, where Lunch Flow called its warning).
  • app/models/lunchflow_item/unlinking.rb deleted; ProviderItem::Unlinking does the same work.
  • EnableBankingItem::Unlinking said it mirrored the deleted Lunch Flow concern; that line goes (it does not mirror the kit's either).
  • Tests: the model half of the kit's contract (connection on its own table, sync, provider error text, unlink, dry run, destroy) moves into ProviderItemModelLifecycleTests, which ProviderItemLifecycleTests includes, so Brex runs exactly the same tests; Lunch Flow includes the model half now and the rest when its account flow moves.

Demo data

No demo data needed.

Migration notes

No migration. Sync and AccountProvider rows keep recording LunchflowItem and LunchflowAccount.

Verification

  • Existing tests unedited: git diff of test/ touches no existing Lunch Flow test. The Lunch Flow model, syncer, importer, processor, controller and cache tests, with Brex's and ProviderItemTest: 207 runs, 0 failures.
  • Contract (fail-first): new LunchflowItem::LifecycleTest includes ProviderItemModelLifecycleTests and adds "a sync warns when a linked account is an investment account". The warning test checks both sides: no warning for a linked depository account, the warning once it is an investment account. On the old models all 7 fail (to be a kind of ProviderItem, not LunchflowItem, undefined method 'provider_accounts' / 'provider_key').
  • Mutations, each caught: the kit never calling the warnings hook; Lunch Flow's hook not overriding it; the hook warning for every account type (all three by the warning test); Lunch Flow's credential errors not named (LunchflowItem::SyncerTest, rejected key).
  • bin/rails test (full, at the B7a commit): 16,337 runs, 0 failures; the same 8 ReleaseNotesWorkflowTest errors (no node in the test image).
  • bin/rubocop on changed files: no offenses. bin/brakeman: no warnings.
  • Size: non-test +10 / -215 (205 lines removed net).
  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • Family::Syncer.syncable_item_associations still finds lunchflow_items (asserted in the contract).
  • Family::FinancialDataReset, DestroyJob / DestroyableLater and ProviderDisconnectable reach LunchflowItem through its own class, unchanged.
  • unlink_all! results now key each entry provider_account_id instead of lfa_id; nothing reads that key (LunchflowItemsController#destroy ignores the result). The lfa_id in LunchflowAccount::Investments::HoldingsProcessor is a separate log payload.
  • Siblings: ProviderItem::Syncer's new hook is a no-op for Brex.

Review notes

A code review of the diff before commit raised eight points. Taken: the warning test now asserts both sides (and stubs schedule_account_syncs), and the inaccurate "Mirrors" comment in Enable Banking's unlinking is dropped rather than repointed. Declined, each the kit's existing behaviour that this move adopts as Brex's B1 did:

  • the lfa_id → provider_account_id result key (no reader; see Blast radius);
  • the kit's unlinker looks up links inside its per-account rescue, so a DB error there is recorded in result[:error] instead of raising to destroy, which rescued and logged it anyway;
  • the warning hook gets an unloaded relation and Lunch Flow calls current_account per row: the same queries Lunch Flow's syncer ran before;
  • a shared investment-warning helper for CoinStats and SimpleFIN: their own provider moves.

Unrelated dead code noticed: LunchflowAccount has_one :linked_account has no caller; left alone.


Summary by cubic

Moves Lunch Flow's connection and account models onto the provider kit's base classes so the provider uses the kit's shared syncer and unlinking logic instead of its own copies. No behavior changes; all existing Lunch Flow tests pass unedited. The stack history reconciliation brings no new code changes to this PR.

  • LunchflowItem and LunchflowAccount now inherit ProviderItem and ProviderAccount, getting Syncable, shared unlinking, and the account associations from the base.
  • LunchflowItem::Syncer becomes a thin subclass of ProviderItem::Syncer, keeping Lunch Flow's credential error naming and its limited-investment-data warning via a new collect_processing_warnings hook, a no-op for Brex. The warning covers linked Investment and Crypto accounts and its count is pinned by tests.
  • The shared syncer's failure path now records the same provider_sync_error debug log entry Lunch Flow's old syncer wrote.
  • LunchflowItem::Unlinking is deleted; the kit's unlinker does the same work. Unlink results are keyed by provider_account_id instead of lfa_id; nothing reads that key.
  • The model part of the lifecycle contract moves into ProviderItemModelLifecycleTests, which both Brex's and Lunch Flow's suites include. The EnableBankingItem::Unlinking comment that said it mirrored the deleted Lunch Flow concern is removed.