Skip to content

test(invariant): finish dual-prefix support for core DB cutover (#3969) - #4436

Merged
JOY (JOY) merged 1 commit into
mainfrom
agy/3969-invariant-dual-prefix-2
Nov 22, 2026
Merged

JOY (JOY) merged 1 commit into
mainfrom
agy/3969-invariant-dual-prefix-2

Conversation

@JOY

@JOY JOY (JOY) commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Refs #3969
Refs #3970

Summary

Follow-up to #3969 updating 7 self-contained files in apps/kernel/test/invariant/ (zero production code changes, zero rules loosened) so the base invariant suite works cleanly against both crove_* (main) and ludy_* (#3970 / #3971) PostgreSQL databases:

  1. apps/kernel/test/invariant/fixtures/db-identifiers.ts:
    • Treat auth_reader_select (the RLS policy name on auth.*, not a pg_roles role) as transitioned whenever ludy_kernel is active, unblocking invites.db.test.ts, mfa-required.db.test.ts, and sessions.db.test.ts.
    • Support reverse-direction outbound SQL and catalog-parameter rewriting on pre-cutover (!isKernelLudy) and partially transitioned databases so upgrade invariant tests (proposal-legal-entity.db.test.ts, task-legal-entity.db.test.ts) can seed pre-cutover snapshots through post-cutover runtime code without colliding with active domains or Category B / test identifiers.
  2. apps/kernel/test/invariant/db-identifiers.test.ts: Add unit tests covering auth_reader_select policy transitions, reverse pre-cutover ludy_* -> crove_* rewriting, and mixed intermediate transitions.
  3. apps/kernel/test/invariant/no-idempotency.test.ts: Match (?:crove|ludy)_kernel.enter_(?:user_)?context( in the fakeDb test stub.
  4. apps/kernel/test/invariant/context.db.test.ts: Query dbIds?.lockNamespace ?? NAMESPACE for advisory lock classid checks and probes.
  5. apps/kernel/test/invariant/ddl-watch.db.test.ts: Normalize returned object_identity through dbIds.toCanonicalCatalogText inside records().
  6. apps/kernel/test/invariant/member-vy-background.db.test.ts: Expect active dbIds ? dbIds.table(table) : table on AGENT_FORBIDDEN detail.
  7. apps/kernel/test/invariant/purge-append-only.db.test.ts: Rewrite the $2 dynamic statement parameter via dbIds.rewriteSql, widen the static/dynamic deleter scan patterns to match (?:crove|ludy)_(?:kernel|social), and sort canonicalized deleter names deterministically.

Acceptance

  • User-visible change: Test-only change in apps/kernel/test/invariant/; no user-facing or runtime behavior changes.
  • Evidence (local, pre-push, head a3b4f620e):
    • pnpm vitest run apps/kernel/test/invariant/db-identifiers.test.ts apps/kernel/test/invariant/no-idempotency.test.ts: 2 files, 12 tests passed (0 skipped).
    • CROVE_TEST_ADMIN_URL=... pnpm vitest run apps/kernel/test/invariant/context.db.test.ts apps/kernel/test/invariant/ddl-watch.db.test.ts apps/kernel/test/invariant/purge-append-only.db.test.ts apps/kernel/test/invariant/sessions.db.test.ts apps/kernel/test/invariant/proposal-legal-entity.db.test.ts: 5 files, 39 tests passed (0 skipped).
    • pnpm --filter @ludy/kernel-server typecheck: passed.
    • pnpm exec oxlint on all 7 touched files: 0 warnings, 0 errors. node tools/ci/spdx-header.mjs: passed.
  • Review results:
    • Independent flagship security & pre-PR review (5e2c74e5): PASS with 0 blocking findings (confirmed self-contained, zero rule loosening, not touching shared-core files).
    • Codex CLI review: unavailable due to quota exhaustion until Nov 25, 2026.
  • Correctness: Logic verified across main, intermediate #3970, and full-cutover #3971 states in unit tests and real PG 17 runs.
  • Security and authorization: Fail-closed checks, privilege audits, RLS policy drop probes, a00_member_vy_forbid, and org_purge scans keep full strictness (purge-append-only scans both crove_* and ludy_*).
  • Tenancy: org_id and pre-cutover -> upgraded legal_entity_id scoping invariants unchanged.
  • Money: Not applicable (test-only invariant dual-prefix updates).
  • Performance: Not applicable (pre-compiled regexes in test fixture only).
  • Accessibility: Not applicable (backend test files only).
  • Risk left: Wait for green CI on all workflows before squash-merging; member-vy-background.db.test.ts and task-legal-entity.db.test.ts will be verified end-to-end by CI and against PR feat(db,kernel): cut over core schemas, roles, GUCs and runtime to ludy_* (#3970) #4433 after merge.

📌 TL;DR

This PR enhances the database identifier abstraction layer to support bidirectional SQL rewriting (handling both crove_* and ludy_* prefixes) and correctly transitions the auth_reader_select RLS policy alongside the kernel schema. It updates invariant tests to utilize these new capabilities, ensuring robustness during schema migrations and cutover scenarios.

🎯 Type of Change

  • 🚀 New feature
  • 🐛 Bugfix
  • 🧹 Refactor
  • ⚡ Performance
  • 📚 Documentation
  • ⚙️ CI / Configuration

🔍 Changes Walkthrough

File Summary of Changes
apps/kernel/test/invariant/fixtures/db-identifiers.ts Core logic update. Adds support for rewriting ludy_* identifiers back to crove_* (outbound rewriting). Fixes auth_reader_select to transition with the kernel schema even if not present in pg_roles. Updates rewriteCatalogParam to handle both prefixes.
apps/kernel/test/invariant/db-identifiers.test.ts Adds tests verifying the new bidirectional rewriting logic and the specific handling of auth_reader_select during intermediate migration states.
apps/kernel/test/invariant/context.db.test.ts Updates tests to use a dynamic lockNamespace helper instead of a hardcoded NAMESPACE constant, ensuring advisory lock tests respect the active identifier context.
apps/kernel/test/invariant/ddl-watch.db.test.ts Updates DDL event retrieval to canonicalize object_identity strings using dbIds.toCanonicalCatalogText, ensuring consistent reporting regardless of the active schema prefix.
apps/kernel/test/invariant/member-vy-background.db.test.ts Updates error detail assertions to use dbIds.table() for dynamic table name resolution, ensuring tests pass in both crove and ludy contexts.
apps/kernel/test/invariant/no-idempotency.test.ts Updates the regex in the fake DB mock to match both crove_kernel and ludy_kernel context entry functions.
apps/kernel/test/invariant/purge-append-only.db.test.ts Updates SQL patterns and query arguments to handle both crove and ludy prefixes. Uses dbIds.rewriteSql for dynamic statement injection and sorts results for stable assertions.

📊 Architectural Flow

flowchart TD
    A[Test Suite] -->|Uses| B[db-identifiers.ts]
    B -->|Builds| C[DbIdentifiers Object]
    C -->|Contains| D[rewriteSql]
    C -->|Contains| E[rewriteCatalogParam]
    C -->|Contains| F[toCanonicalCatalogText]
    
    D -->|Input: SQL| G{Check Prefix}
    G -->|crove_*| H[Replace with ludy_*]
    G -->|ludy_*| I[Replace with crove_*]
    H --> J[Output: Rewritten SQL]
    I --> J
    
    E -->|Input: Param| K{Check Type}
    K -->|Schema/Role| L[Map to Active ID]
    K -->|GUC| M[Map to Active GUC]
    L --> N[Output: Canonical Param]
    M --> N
    
    F -->|Input: Catalog Text| O[Normalize to crove_*]
    O --> P[Output: Canonical Text]
    
    J --> Q[Invariant Tests]
    N --> Q
    P --> Q
Loading

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@vercel

vercel Bot commented Nov 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated
ludy Skipped Skipped Nov 22, 2026 11:35am UTC
ludy-app Skipped Skipped Nov 22, 2026 11:35am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 25 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eebafc35-d945-4b9b-8f96-430ed3f0ca5a
Commits

Reviewing files that changed from the base of the PR and between 096a31b and a3b4f62.

Files selected for processing: 7

  • apps/kernel/test/invariant/context.db.test.ts
  • apps/kernel/test/invariant/db-identifiers.test.ts
  • apps/kernel/test/invariant/ddl-watch.db.test.ts
  • apps/kernel/test/invariant/fixtures/db-identifiers.ts
  • apps/kernel/test/invariant/member-vy-background.db.test.ts
  • apps/kernel/test/invariant/no-idempotency.test.ts
  • apps/kernel/test/invariant/purge-append-only.db.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

dos[bot]
dos Bot approved these changes Nov 22, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Code Review completed (7 eligible files · 18,154 chars · 1 model call(s) · 1 PR unit(s))

Whole diff with bounded context at base 096a31b / head a3b4f62.

✅ CLEAN_PASS: Complete diff reviewed

@JOY
JOY (JOY) merged commit 0ec6825 into main Nov 22, 2026
35 checks passed
@JOY
JOY (JOY) deleted the agy/3969-invariant-dual-prefix-2 branch November 22, 2026 12:01

This branch was previously deployed

1 inactive deployment
Preview – ludy — a3b4f620 Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant