Skip to content

improvement(tests): db-mock migration tranche 1 — knowledge, billing/org, workflows/background#5861

Merged
waleedlatif1 merged 2 commits into
stagingfrom
test/db-mock-migration-1
Jul 22, 2026
Merged

improvement(tests): db-mock migration tranche 1 — knowledge, billing/org, workflows/background#5861
waleedlatif1 merged 2 commits into
stagingfrom
test/db-mock-migration-1

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Migrate 19 test suites off private vi.mock('@sim/db', <factory>) implementations onto the shared dbChainMock + queueTableRows API from improvement(testing): consolidate @sim/db mocks into one table-aware chain mock #5856 — net ~−1,260 lines of bespoke chain plumbing
  • Resolves the known shared-worker rival pairs: knowledge processing-queueapi/knowledge/utils, the billing polluters (lock-order, dashboard-credit-grant, subscription), and workflows/persistence/utilsschedules/deploy
  • Add .for() to the mock's limit builder so drizzle's .limit(1).for('update') row-lock form chains (found by the migration; contract test added)
  • Document the join-table queue fallback footgun on queueTableRows
  • Tranche 1 of ~6; ~100 private factories remain, next tranches follow the same mechanical pattern

Type of Change

  • Improvement

Testing

Full apps/sim suite green locally (13704/13705; sole failure is the known local ripgrep dependency, green in CI). Each migrated file verified standalone, per-cluster in shared-worker runs, and with neighbor sweeps (lib/billing lib/admin 462 tests, lib/workflows background 1061 tests, knowledge cluster 231 tests). tsc + biome clean.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…kground suites off private @sim/db factories
…org, workflows/background

- migrate 19 suites off private vi.mock('@sim/db') factories onto the shared
  dbChainMock + queueTableRows API (net ~-1,260 lines of bespoke chain
  plumbing); resolves the known shared-worker rival pairs (knowledge
  processing-queue vs api utils; billing polluters; persistence/utils vs
  schedules/deploy)
- add .for() to the mock's limit builder (drizzle .limit(1).for('update'))
  with a contract test
- document the join-table queue fallback footgun on queueTableRows
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 22, 2026 9:44pm

Request Review

@cursor

cursor Bot commented Jul 22, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Test-only refactor of mocks and assertions; production code is untouched aside from shared testing utilities.

Overview
Tranche 1 moves ~19 API, lib, and background Vitest suites off hand-rolled @sim/db mocks onto the shared dbChainMock stack (queueTableRows, resetDbChainMock, dbChainMockFns, schemaMock). That deletes a large amount of per-file select-chain factories and FIFO selectResults arrays in favor of table-keyed row queues and shared spies.

The shared mock gains .limit(n).for('update') support (plus a contract test), and queueTableRows docs call out the join-table queue fallback footgun. Migrated tests follow the same shape: vi.mock('@sim/db', () => dbChainMock), reset queues each run, queue rows per schema table (often with small helpers like queueFolderLookup / queueOwnerAndOrg), and assert via dbChainMockFns instead of local DB stubs. Several org/roster/invitation tests now import real @sim/db/schema tables for queue keys instead of duplicating schema mocks.

No production routes or services change—only packages/testing mock behavior and test wiring, aimed at fixing shared-worker pollution between rival suites (knowledge, billing/org, workflows/background).

Reviewed by Cursor Bugbot for commit 00a06cb. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR moves the first group of database tests onto the shared mock infrastructure. The main changes are:

  • Migrates 19 suites to dbChainMock and table-specific row queues.
  • Adds .limit(...).for(...) row-lock chaining to the shared mock.
  • Adds contract coverage for the new builder path.
  • Documents join-table queue fallback behavior.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The new row-lock builder keeps one lazy row supplier across the chain.
  • The migrated suites reset shared queue and spy state between tests.

Important Files Changed

Filename Overview
packages/testing/src/mocks/database.mock.ts Extends the awaitable limit builder with .for() while preserving the shared lazy row supplier.
packages/testing/src/mocks/database.mock.test.ts Adds coverage for queued rows through .limit(1).for('update').
apps/sim/app/api/knowledge/utils.test.ts Replaces custom database datasets with table queues and shared invocation-order assertions.
apps/sim/app/api/organizations/[id]/invitations/route.test.ts Moves sequential query results to table-aware queues and guards relevant join fallbacks with explicit empty rows.
apps/sim/lib/workflows/persistence/utils.test.ts Migrates persistence tests to the shared database mock and its row-lock builder support.

Reviews (1): Last reviewed commit: "improvement(tests): db-mock migration tr..." | Re-trigger Greptile

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