Repository navigation
test(invariant): finish dual-prefix support for core DB cutover (#3969) - #4436
Conversation
There was a problem hiding this comment.
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Warning Review limit reachedYou'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. View limit details
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. |
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 bothcrove_*(main) andludy_*(#3970 / #3971) PostgreSQL databases:apps/kernel/test/invariant/fixtures/db-identifiers.ts:auth_reader_select(the RLS policy name onauth.*, not apg_rolesrole) as transitioned wheneverludy_kernelis active, unblockinginvites.db.test.ts,mfa-required.db.test.ts, andsessions.db.test.ts.!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.apps/kernel/test/invariant/db-identifiers.test.ts: Add unit tests coveringauth_reader_selectpolicy transitions, reverse pre-cutoverludy_*->crove_*rewriting, and mixed intermediate transitions.apps/kernel/test/invariant/no-idempotency.test.ts: Match(?:crove|ludy)_kernel.enter_(?:user_)?context(in thefakeDbtest stub.apps/kernel/test/invariant/context.db.test.ts: QuerydbIds?.lockNamespace ?? NAMESPACEfor advisory lock classid checks and probes.apps/kernel/test/invariant/ddl-watch.db.test.ts: Normalize returnedobject_identitythroughdbIds.toCanonicalCatalogTextinsiderecords().apps/kernel/test/invariant/member-vy-background.db.test.ts: Expect activedbIds ? dbIds.table(table) : tableonAGENT_FORBIDDENdetail.apps/kernel/test/invariant/purge-append-only.db.test.ts: Rewrite the$2dynamic statement parameter viadbIds.rewriteSql, widen the static/dynamic deleter scan patterns to match(?:crove|ludy)_(?:kernel|social), and sort canonicalized deleter names deterministically.Acceptance
apps/kernel/test/invariant/; no user-facing or runtime behavior changes.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 oxlinton all 7 touched files: 0 warnings, 0 errors.node tools/ci/spdx-header.mjs: passed.5e2c74e5): PASS with 0 blocking findings (confirmed self-contained, zero rule loosening, not touching shared-core files).main, intermediate#3970, and full-cutover#3971states in unit tests and real PG 17 runs.a00_member_vy_forbid, andorg_purgescans keep full strictness (purge-append-onlyscans bothcrove_*andludy_*).org_idand pre-cutover -> upgradedlegal_entity_idscoping invariants unchanged.member-vy-background.db.test.tsandtask-legal-entity.db.test.tswill 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_*andludy_*prefixes) and correctly transitions theauth_reader_selectRLS 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
🔍 Changes Walkthrough
apps/kernel/test/invariant/fixtures/db-identifiers.tsludy_*identifiers back tocrove_*(outbound rewriting). Fixesauth_reader_selectto transition with the kernel schema even if not present inpg_roles. UpdatesrewriteCatalogParamto handle both prefixes.apps/kernel/test/invariant/db-identifiers.test.tsauth_reader_selectduring intermediate migration states.apps/kernel/test/invariant/context.db.test.tslockNamespacehelper instead of a hardcodedNAMESPACEconstant, ensuring advisory lock tests respect the active identifier context.apps/kernel/test/invariant/ddl-watch.db.test.tsobject_identitystrings usingdbIds.toCanonicalCatalogText, ensuring consistent reporting regardless of the active schema prefix.apps/kernel/test/invariant/member-vy-background.db.test.tsdbIds.table()for dynamic table name resolution, ensuring tests pass in bothcroveandludycontexts.apps/kernel/test/invariant/no-idempotency.test.tscrove_kernelandludy_kernelcontext entry functions.apps/kernel/test/invariant/purge-append-only.db.test.tscroveandludyprefixes. UsesdbIds.rewriteSqlfor 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