Skip to content

improvement(codebase): migrate tests to dbChainMock, extract react-query hooks#4234

Closed
waleedlatif1 wants to merge 3 commits intostagingfrom
waleedlatif1/codebase-quality-audit
Closed

improvement(codebase): migrate tests to dbChainMock, extract react-query hooks#4234
waleedlatif1 wants to merge 3 commits intostagingfrom
waleedlatif1/codebase-quality-audit

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • migrate 97 test files to centralized dbChainMock/dbChainMockFns — remove hoisted chain-wiring boilerplate
  • extend dbChainMock helper in @sim/testing to cover insert/update/delete/transaction/execute patterns
  • extract useGitHubStars and useVoiceSettings react-query hooks from inline fetches
  • centralize additional mocks (authMockFns, hybridAuthMockFns) and update sim-testing docs

Type of Change

  • Improvement

Testing

Tested manually — full test suite (300 files, 5310 tests) passes; type-check and lint pass across all 8 packages

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)

…ery hooks

Migrate 97 test files to centralized dbChainMock/dbChainMockFns helpers from
@sim/testing — removes hoisted chain-wiring boilerplate.

Extend dbChainMock to cover insert/update/delete/transaction/execute patterns.
Extract useGitHubStars and useVoiceSettings react-query hooks from inline fetches.
Centralize additional mocks (authMockFns, hybridAuthMockFns) and update docs.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 19, 2026

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 19, 2026 5:36pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 19, 2026

PR Summary

Medium Risk
Medium risk because several API routes adjust response shapes (notably chat auth/OTP returning full chat config) and many tests are refactored to new centralized mocks, which could mask behavioral regressions if mock chains diverge from real DB usage.

Overview
Centralizes common utilities and test mocking. Updates guidelines and code to use @sim/utils (generateId, generateShortId, sleep, toError) instead of legacy helpers, and expands docs to prefer @sim/testing centralized module mocks.

Refactors a large set of Vitest files to use dbChainMock/dbChainMockFns and shared mocks. Tests drop local vi.hoisted() chain wiring/logger/auth stubs in favor of @sim/testing mocks (auth, hybrid auth, audit, encryption, request utils, copilot http, workflow utils/orchestration, etc.), with resetDbChainMock() used where permanent overrides occur.

Makes a couple of targeted runtime changes. The landing GitHubStars component now uses a React Query hook (useGitHubStars) and removes the old action helper; chat authentication endpoints (/api/chat/[identifier] and OTP verify) now include full chat deployment config fields (title/description/customizations/output configs) in the success response instead of a boolean authenticated flag.

Reviewed by Cursor Bugbot for commit 96a0a83. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 96a0a83. Configure here.

throw new Error('Failed to fetch GitHub stars')
}
const data = await response.json()
return (data?.stars as string) ?? ''
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Falsy stars value displays empty string instead of fallback

Low Severity

fetchGitHubStars returns (data?.stars as string) ?? '', and the component uses stars ?? INITIAL_STARS. Both use nullish coalescing (??), which doesn't catch empty strings. If the API ever returns a falsy-but-not-nullish stars value (e.g. ""), the component renders an empty string. The old code used data.stars || DEFAULT_STARS, which correctly fell back on any falsy value.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 96a0a83. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

Superseded by #4235 (rebased cleanly onto latest staging).

@waleedlatif1 waleedlatif1 deleted the waleedlatif1/codebase-quality-audit branch April 21, 2026 18:21
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