Generate provider models on the provider kit

Merged
JA
2d ago
+275-244

Summary

Provider kit Track B, B6a: the provider:family generator emits a provider's models on the provider kit. The generated connection model inherits ProviderItem and the account model ProviderAccount, so a new provider syncs through ProviderItem::Syncer and unlinks through ProviderItem::Unlinking. The syncer and unlinking templates are deleted outright, with no flag (decided 2026-11-15).

Part of #5003 (Track B, step 6: the generator onto the kit, sliced by layer: B6a models, B6b account flow, then controller and routes, then views).

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

Before / after (what rails g provider:family writes)

BeforeAfter
app/models/<key>_item.rb< ApplicationRecord, including Syncable and Unlinking, with its own #syncer< ProviderItem (which supplies Syncable, ProviderItem::Unlinking and, by constant lookup, ProviderItem::Syncer)
import_latest_<key>_data(sync: nil), passing the sync to the importer(sync_start_date: nil), as ProviderItem::Syncer calls it; the importer is built without the sync, with a TODO to pass the start date on
with_credentials scopenoneevery secret field set (all when the provider declares no secret); ProviderItem::AccountFlow lists connections through it
app/models/<key>_account.rb< ApplicationRecord with its own account_provider / account associations and #current_account< ProviderAccount, which defines all three
app/models/<key>_item/syncer.rb92-line templatenot written; syncer.rb.tt deleted
app/models/<key>_item/unlinking.rb74-line templatenot written; unlinking_concern.rb.tt deleted
Locale: sync messagessync.status.* (read only by the deleted syncer)syncer.*: the keys, plural forms and interpolations ProviderItem::Syncer reads, as Brex's

Existing providers are untouched: this changes only what the generator writes.

What the generated provider gives up, stated

  • Investment stats. The old syncer also collected trade and holding counts for --type=investment; ProviderItem::Syncer collects transaction stats only. A provider that needs more overrides collect_processing_warnings or subclasses the syncer, as Brex and Mercury do for credential errors.
  • The auth-error status flip. The old syncer set status: :requires_update on Provider::<Key>::AuthenticationError. The kit's syncer stores a translated credentials_invalid message when a subclass's credentials_error? says so, and leaves status alone.
  • The disposition: argument on unlink_all!. The deleted unlinking concern accepted disposition: and refused anything but retain. ProviderItem::Unlinking#unlink_all! always retains and takes no disposition. The generated model still includes ProviderDisconnectable with supports_discard = false, so it still advertises retain only; no caller in the app passes a disposition to a family provider's unlink_all! (checked by grep; only FinanceKit's API takes one).

Screenshots

None: no UI change.

Demo data

No demo data needed.

Migration notes

No migration. The generator's migration template is unchanged.

Verification

  • Tests, fail-first. In Provider::FamilyGeneratorTest, five new tests failed on the old templates, each for the right reason (the model still < ApplicationRecord; no with_credentials; syncer.rb still written; no gocardless_items.syncer in the locale) and pass after:
    • the generated item model is a provider kit connection (banking and investment);
    • it counts every connection as credentialed when it has no secret field;
    • the generated account model is a provider kit account;
    • the generator writes no syncer or unlinking concern (and both templates are gone);
    • the generated locale has every syncer message the provider kit reads: the same keys, plural forms and interpolations as brex_items.syncer.
  • Test removed: "the unlinking scaffold renders to valid Ruby and carries the disposition seam" tested the deleted template.
  • Mutations, each caught (7): the item model left < ApplicationRecord; with_credentials ignoring the secret; import_latest_* keeping sync:; the account model left < ApplicationRecord; a syncer key missing from the locale; a plural form dropped; an interpolation dropped.
  • bin/rails test (full, at this commit): 16,527 runs, 0 failures; the same 8 ReleaseNotesWorkflowTest errors (no node in the test image).
  • bin/rubocop on the changed Ruby, bin/brakeman: no offenses or warnings.
  • Size (git diff -C): non-test +46 / -214.
  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

Who else hits these lines, and what do they pass?

  • Only rails g provider:family; nothing in the app loads the templates. The generator's other steps (adapter, migration, importer, processors, jobs) are unchanged; the processors and jobs call current_account, which ProviderAccount defines.
  • Siblings: the generated controller, routes and views still use the old scaffolds and the old panel.* / sync.success keys; the next slices move them onto the kit. docs/api/rails_provider_generator.md already describes the pre-kit models and is updated with the last slice.

Summary by cubic

The provider:family generator now emits models that inherit the provider kit's ProviderItem and ProviderAccount, so a new provider syncs through ProviderItem::Syncer and unlinks through ProviderItem::Unlinking. The syncer and unlinking templates are deleted; the generator no longer writes either file. Existing providers are unaffected.

Behavior changes for generated providers

  • import_latest_<key>_data takes sync_start_date: instead of sync:; the importer is built without a sync, with a TODO to pass the start date on.
  • The importer returns a { success:, accounts_failed:, transactions_failed: } hash the kit's syncer reads; partial fetch failures are counted.
  • The account table stores the provider id in account_id with a unique index on [<key>_item_id, account_id] (previously <key>_account_id with a table-wide unique index); the explicit index name is written only when it fits the 63-character limit.
  • The locale replaces sync.status.* messages with the syncer.* keys ProviderItem::Syncer reads, matching Brex's set.
  • The connectable concern defaults a blank connection name to the provider name.
  • Item models get a with_credentials scope checking every secret field (or all when there are none), which the kit's account flow uses.
  • The old syncer's investment stats, auth-error status flip, and disposition: argument on unlink_all! are gone; ProviderItem::Unlinking always retains.