Skip to content

improvement(tests): db-mock migration tranche 2 — copilot, mothership, workspaces, connectors, mcp#5863

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

improvement(tests): db-mock migration tranche 2 — copilot, mothership, workspaces, connectors, mcp#5863
waleedlatif1 merged 2 commits into
stagingfrom
test/db-mock-migration-2

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Type of Change

  • Improvement

Testing

Full apps/sim suite green locally (13704/13705; sole failure is the known local ripgrep dependency, green in CI). Every migrated file verified standalone, per-cluster in shared-worker runs, and with neighbor sweeps (copilot 1029 tests, knowledge/mcp 615, mothership/workspaces 119). 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)

@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 10:13pm

Request Review

@cursor

cursor Bot commented Jul 22, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Test-only refactor and shared mock hardening; no production API or runtime behavior changes.

Overview
Second tranche of the DB mock migration: ~26 Vitest suites drop local vi.mock('@sim/db') chain factories and duplicate drizzle-orm stubs in favor of @sim/testing’s dbChainMock, dbChainMockFns, queueTableRows, and resetDbChainMock.

Tests now seed reads with queueTableRows(schemaMock.<table>, …), assert mutations via dbChainMockFns, and call resetDbChainMock() in beforeEach / afterAll so queued rows and …Once spy overrides do not leak across cases. Coverage spans copilot API routes and tool handlers, mothership chat routes, workspace API keys/BYOK/fork/invitations, knowledge connector routes, and MCP service/route tests.

In @sim/testing, resetDbChainMock resets all chain spies (including draining unconsumed mockResolvedValueOnce queues), adds notLike / notIlike to the drizzle mock, extends schemaMock.copilotChats with pinned and deletedAt, and adds a regression test for leftover …Once overrides.

Reviewed by Cursor Bugbot for commit 3f189f5. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR moves 26 test suites to the shared database mock infrastructure. The main changes are:

  • Replaces private database factories with dbChainMock and table-aware row queues.
  • Resets shared mock state between tests and drains one-shot overrides.
  • Adds missing Copilot chat fields to the shared schema mock.
  • Preserves route and service coverage across Copilot, Mothership, workspaces, connectors, and MCP.

Confidence Score: 5/5

This looks safe to merge.

  • The updated reset clears queued rows and one-shot mock behavior.
  • The migrated tests preserve their main success, error, authorization, and cleanup paths.
  • No blocking issue tied to an eligible earlier review finding remains.

Important Files Changed

Filename Overview
packages/testing/src/mocks/database.mock.ts Resets all shared chain spies and adds the missing SQL operator mocks.
packages/testing/src/mocks/database.mock.test.ts Adds a test proving reset removes unconsumed one-shot overrides.
packages/testing/src/mocks/schema.mock.ts Adds pinned and deletedAt to the Copilot chat schema mock.
apps/sim/lib/mcp/service.test.ts Migrates MCP service database behavior and status assertions to the shared mock.
apps/sim/app/api/mothership/chats/[chatId]/fork/route.test.ts Migrates fork transaction, cleanup, and resource-rewrite coverage to the shared mock.
apps/sim/app/api/copilot/checkpoints/revert/route.test.ts Uses table-aware queues for checkpoint and workflow lookups while retaining error coverage.

Reviews (2): Last reviewed commit: "fix(testing): drain unconsumed ...Once o..." | Re-trigger Greptile

Comment thread apps/sim/app/api/mcp/servers/[id]/refresh/route.test.ts
vi.clearAllMocks clears call history only — a ...Once override queued by a
previous test but never consumed survived into the next test. resetDbChainMock
now mockReset()s every shared spy and stable wrapper, which restores the
original implementation AND drains once-queues.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3f189f5. Configure here.

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