Merge upstream/main into main (weekly sync, 2026-09-29)

Merged
JA
2mo ago
+17678-1360

Summary

The weekly upstream sync that #118 ("Staying in sync", duty 1) requires. It brings fork main level with we-promise/sure a11d671fe: 47 upstream commits since #238. Upstream main has moved 13 commits past that point since the branch was cut. They go in the next sync, so this PR's resolutions stay reviewable as they are.

Merge it with a merge commit, not a squash, per #118 duty 4.

Commits on the branch:

  • 6f8db65e1: the merge of upstream a11d671fe (22 conflicting files, resolved as below).
  • 604fdb698: keeps the fork's loan engine in every file upstream we-promise/sure#3474 touched.
  • 35957f9ca: moves the retirement plan migration off upstream's version number.
  • df958ee5e: merges main at 7086ebd3a, which brings in #259.

Scope and dependencies

  • Issue: #118 (weekly sync duty). The reminder that should stop syncs slipping is #263.
  • Parent PR/branch, if stacked: none. Base is main at 7086ebd3a.
  • Intentionally out of scope:
    • The 13 upstream commits after a11d671fe.
    • Moving the fork's loan schedule table onto upstream's new DS::Table (we-promise/sure#3805). See below.

Conflicts and resolutions

Shared files, merged on their merits (6f8db65e1):

  • Upstream's :uncategorized activity filter (we-promise/sure#3797) is kept beside the fork's extra-payment params.
  • The fork's PERMISSION_LEVELS table is kept. It already gives :annotate the meaning upstream adds.
  • Both sides' tests are kept in the account, transaction and market-data importer tests.

Upstream we-promise/sure#3474 (loan payoff projection and chart): the fork's side, everywhere (6f8db65e1 and 604fdb698). This follows #184's decision that the fork keeps its own loan engine.

  • The first merge resolved only the conflicting hunks that way. we-promise/sure#3474's files that merged without conflict came in whole, including upstream's Loan::PayoffChart and its tests. They call methods only upstream's engine has (Loan#origination_date, a projection local on the schedule tab), so 45 tests errored.

  • 604fdb698 puts every file we-promise/sure#3474 touched back to the fork's version. It removes app/models/loan/payoff_chart.rb and test/models/loan/payoff_chart_test.rb, which exist only upstream.

  • It then replays the other upstream commits in this sync that touched the same files, so none of them is lost:

    Upstream commitFile(s)
    261350a7c (we-promise/sure#3797, uncategorized filter)accounts_controller.rb and its test
    a9d82a97d (tag preload)accounts_controller.rb
    f2785fe5a (period picker)period_picker.html.erb, its test, accounts_controller_test.rb
    a83321c1ctest/i18n_test.rb
  • Not replayed: b6ba9c57e (we-promise/sure#3805), which moves four hand-built tables onto DS::Table. One of them is the loan schedule table. The fork's schedule table carries rate-change markers that upstream's lacks, so its hunk doesn't apply. Moving that table onto DS::Table is fork UI work, not a sync resolution. The other three tables are unaffected.

  • After 604fdb698, we-promise/sure#3474's 29 files differ from fork main only by the replayed changes above.

The migration version collision (35957f9ca):

  • The problem. Upstream's 20260928090000_normalize_trade_republic_activity_labels and the fork's 20260928090000_create_retirement_plans share a version, so the merged tree couldn't load (DuplicateMigrationVersionError).
  • The renumber. The fork's migration becomes 20260928090100, still before the two fork migrations that alter retirement_plans. Its create_table and three check constraints use if_not_exists.
  • The re-run. A database that already ran the fork's migration has 20260928090000 recorded, so it would treat upstream's normalisation as done and skip it for good. The new fork-only 20260930090000_rerun_trade_republic_activity_label_normalization runs it once more. It is idempotent: the translated labels it maps are gone after one run, and the labels it clears are already NULL.

Schema regeneration (duty 2)

The committed db/schema.rb is the merged schema with the version stamp moved to 2026_09_30_090000. It was checked, not taken on trust:

  • I loaded fork main's schema into a scratch database and seeded it, then ran db:migrate with this branch.
  • The resulting dump differs from the committed file in three check constraints only (financekit_lineage_account_origin, chk_retirement_plan_streams_kind/_source, chk_retirement_plans_mode). There, this local PostgreSQL prints ARRAY['a'::character varying::text, …] in place of ARRAY[…]::text[]. The constraints are the same, and the committed file keeps the parents' form, as #238 did.

New upstream migrations in this sync:

  • 20260927160000_add_brokerage_account_id_to_trade_republic_items
  • 20260927161700_backfill_brokerage_account_id_on_trade_republic_items
  • 20260928090000_normalize_trade_republic_activity_labels
  • 20260928180000_add_otp_last_used_at_to_users

Evidence checklist

  • Each issue in this PR has its own acceptance criteria and no unrelated issue work is included. This is a sync, plus the two resolutions it needed.
  • Contract rows touched by this change name existing tests. (Not applicable: the fork's loan engine and its contract are unchanged.)
  • Any gate test has an observed failing mutation transcript attached. (See the migration mutations under Validation.)
  • Fixtures used as evidence assert internal consistency. (Not applicable.)
  • Financial calculations use BigDecimal and documented rounding points. (Not applicable.)
  • De-identification uses token-shape allowlists; no personal data is included.
  • Files changed, decisions, tests/runtime, risks, and next unblocked issue are documented below.

Validation

Local runs used Ruby 3.3.6 with the 3.4.9 pin overridden locally, because 3.4.9 can't be installed here, and PostgreSQL 16. CI is authoritative.

Full bin/rails test, before and after the fixes:

  • At 6f8db65e1 (the first merge, now loadable with the migration fix applied): 11,263 runs, 8 failures, 48 errors. Of those, 7 were environmental, 4 were the month-end loan tests that #259 fixes, and about 45 were the we-promise/sure#3474 breakage above.
  • At df958ee5e: 11,228 runs, 48,633 assertions, 4 failures, 3 errors, 33 skips. All 7 are this environment's known failures, the same 7 as on unmerged main here:
    • Provider::RegistryTest (Anthropic env)
    • Provider::OpenaiTest (Ruby 3.3 Hash#inspect)
    • three Settings::HostingsControllerTest Anthropic base-URL tests
    • ActiveStorageAuthorizationTest and Admin::UsersControllerTest (no image processor)

Migration simulation. I built a scratch database from fork main's schema, which has 20260928090000 recorded as the retirement migration. I seeded it with a retirement plan and two Trade Republic transactions labelled Storting, one on a cash account and one on an investment account. Then I ran db:migrate with this branch:

  • Before 35957f9ca: it fails with ActiveRecord::DuplicateMigrationVersionError.
  • After: it runs the five pending migrations: 20260927160000, 20260927161700, 20260928090100, 20260928180000 and 20260930090000. The retirement plan row and all nine constraints survive. The labels become nil on the cash account and Contribution on the investment account, which are upstream's intended values.
  • Mutation, without the re-run migration: the migration completes with nothing pending, but both labels stay Storting. That is the silent failure 20260930090000 exists to prevent.
  • Mutation, without if_not_exists: the migration aborts, because the table already exists.
  • Same process: with 20260928090000 unrecorded, the normalisation and the re-run both execute in one migrate. There's no double-load warning, and the second pass changes nothing.

Linting and security:

  • bin/rubocop: 2,945 files, no offenses.
  • bin/brakeman --no-pager -q: 0 warnings.
  • erb_lint --lint-all: 2 autocomplete offenses in app/views/loans/_form.html.erb (lines 104 and 108). That file is identical on main, which reports the same offenses. This PR doesn't touch the file, so it is left out of scope.

Risks, blockers, and follow-up

  • we-promise/sure#3474 may carry fixes the fork's engine lacks. Upstream's payoff projection went through its own review. Comparing it with the fork's engine for anything worth adopting belongs with #184, not this sync.
  • The fork's schedule table isn't on DS::Table (we-promise/sure#3805). That's fork UI work, if wanted.
  • Deployments: on a database that ran the fork's retirement migration, 20260930090000 normalises Trade Republic labels once when this deploys. It changes only trade_republic entries whose label isn't locked, user-edited or set by an enrichment, which is upstream's own rule.
  • Next: the remaining 13 upstream commits; then reconcile #258's pending-SQL files with the pre-flight on this base, per #262.