Start a Lunch Flow import at the sync's window when it has one

Merged
JA
2d ago
+102-7

Summary

Lunch Flow convergence, C1b: a Lunch Flow sync now honours its sync window, as Brex's does. When a sync has an explicit window_start_date, every account's transaction fetch starts there. Without one, nothing changes.

Part of #5003 (Track B, Lunch Flow convergence).

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

Behaviour delta (Lunch Flow)

SyncBeforeAfter
no window (scheduled and manual syncs)the start date from the account's history and the chosen start dateunchanged
with window_start_datethe window was ignoredeach fetch starts at the window's start, overriding the incremental start, as Brex's importer does
a windowed fetch of an account that still needs historyrecorded history_synced_fromno history marker is recorded, because the fetch didn't start at the chosen start date, so the next unwindowed sync still fetches the history

transactions_synced_through is still recorded after every successful fetch: a windowed fetch runs from the window start to now.

What changed

  • LunchflowItem::Syncer passes sync.window_start_date to import_latest_lunchflow_data(sync_start_date:), which passes it to LunchflowItem::Importer.
  • LunchflowItem::Importer#determine_sync_start_date returns the window's start when given. fetch_and_store_transactions records the history marker only for an unwindowed fetch.

Demo data

No demo data needed.

Migration notes

No migration.

Verification

  • Tests (fail-first):

    • New LunchflowItem::ImporterSyncWindowTest:
      • a window sets where a later fetch starts, over the incremental start;
      • a window sets where a first fetch starts, over the chosen start date, and records no history marker;
      • the connection hands its import the window.
    • LunchflowItem::SyncerTest: "the import starts from the sync's window".

    Before the change they fail: unknown keyword: :sync_start_date, and the import was called without the window.

  • Existing tests unchanged: LunchflowItem::ImporterStartDateTest (the unwindowed start-date rules) passes unedited.

  • Mutations, each caught: the window ignored by the importer; a windowed fetch recording history; the connection dropping the window; the syncer dropping the window.

  • bin/rails test (full, at the C1b commit): 16,313 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 +15 / -7.

  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • import_latest_lunchflow_data has one caller, the syncer, and its keyword is optional.
  • LunchflowItem::Importer.new has one app caller.

Summary by cubic

A Lunch Flow sync now honors its sync window: when a sync has a window_start_date, every account's transaction fetch starts there, overriding the chosen or incremental start, as Brex's importer does. Unwindowed syncs are unchanged.

  • The syncer passes sync.window_start_date to the import, which the importer's start-date logic returns when given.
  • A windowed first fetch that still needs history records the window start as history_synced_from, so the next unwindowed sync fetches the earlier history from the chosen start.
  • When a window starts after the last successful fetch, the fetch leaves transactions_synced_through in place, so the next sync resumes from the last fetch and covers the gap.

Summary by CodeRabbit

  • New Features
    • Transaction imports now honor the selected sync window, starting from its beginning when appropriate.
    • Existing transaction history is preserved when a sync window starts later than the account’s recorded sync position. Earlier history can also be retrieved when the import returns data.
  • Tests
    • Added coverage for sync-window transaction fetching, history boundaries, and resuming from a previously recorded sync position.