test(database,service): hold every live statement to the immutability Neon Realtime requires

Merged
CH
6d ago
+314-0

This PR changes no user-visible behaviour. It adds tests only. It's the first of three small Realtime plumbing PRs split out of #3232, so the plumbing can land without any feature attached. Every Realtime PR is on hold, so please don't merge it yet.

What it does

Neon Realtime refuses a statement that calls any function, operator, or aggregate that Postgres doesn't mark immutable ("scalar expression uses a mutable function"). Postgres and PGlite run the same statement without complaint, so the refusal only shows up in production.

  • mutableFunctionsOf (packages/database/src/testing/live-immutability.ts, exported from @luke/database/testing) turns a statement into a temporary view, reads what the view's rule calls from pg_rewrite, and names every call that isn't immutable. Casts through text are included.
  • live-immutability.test.ts covers the helper itself.
  • live-statements.test.ts runs every statement /api/live/inbox seals on main through the helper: the account inbox's parts and the failed runs. They all pass already.

Stack

  1. This PR (base main)
  2. Seal through drizzleAdapter() (base: this PR)
  3. Shared host follow, live-follow.ts (base: PR 2)
  4. #3232, the plan and agent scope inbox (base: PR 3)

Made with Luke