improvement(codebase): migrate tests to dbChainMock, extract react-query hooks#4235
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Runtime behavior changes: the chat auth endpoints now return full deployed chat config (id/title/description/customizations/authType/outputConfigs) on successful password/email OTP authentication, and the chat client is refactored to use new React Query hooks ( Reviewed by Cursor Bugbot for commit 3220eea. Configure here. |
Greptile SummaryThis PR migrates 97 test files to the new centralized Confidence Score: 5/5Safe to merge — all prior P0/P1 findings are resolved, remaining items are P2 style and docs suggestions Both critical bugs flagged in prior threads (wrong
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
subgraph dbChainMock["dbChainMock (centralized)"]
select["select / selectDistinct / selectDistinctOn"]
from["from()"]
joins["innerJoin / leftJoin"]
where["where()"]
terminals["limit / orderBy / returning / groupBy"]
insert["insert()"]
values["values()"]
ins_returns["returning / onConflictDoUpdate / onConflictDoNothing"]
update["update()"]
set["set()"]
del["delete()"]
execute["execute()"]
transaction["transaction(cb)"]
end
select --> from
from --> joins --> where
from --> where
where --> terminals
insert --> values --> ins_returns
update --> set --> where
del --> where
execute -.->|"resolves []"| done(["Promise.resolve([])"])
transaction -.->|"calls cb(dbChainMock.db)"| dbChainMock
subgraph hooks["New React Query Hooks"]
gh["useGitHubStars\n(staleTime: 1h, initialData: '27.8k')"]
vs["useVoiceSettings\n(staleTime: 5m, returns sttAvailable:false on error)"]
end
gh -->|"/api/stars"| server["Server"]
vs -->|"/api/settings/voice"| server
Reviews (5): Last reviewed commit: "fix(chat): reset chat state on identifie..." | Re-trigger Greptile |
…constants Move the placeholder star count into useGitHubStars as initialData with initialDataUpdatedAt: 0 so `data` is always a narrowed string while still refetching on mount. Fixes two Bugbot issues: stale '25.8k' in chat.tsx (vs '27.8k' in navbar) and empty-string return in fetchGitHubStars that bypassed `??` fallbacks in consumers. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
dbChainMock.db.transaction was an inline vi.fn() separate from the exported dbChainMockFns.transaction, so dbChainMockFns.transaction.mockResolvedValueOnce and assertions silently targeted the wrong instance. dbChainMock.db also omitted execute, so tests for any module that calls db.execute (logging-session, table service, billing balance) would throw TypeError. Both mocks now reference the module-level constants so overrides and resetDbChainMock affect the same fn. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
@greptile |
|
@cursor review |
…dbChainMock.db Why: - Welcome ChatMessage was rebuilt inline each render, producing a fresh timestamp and new array identity — cascading to ChatMessageContainer and VoiceInterface props on every tick. - dbChainMockFns exports selectDistinct/selectDistinctOn but the dbChainMock.db object omitted them, so tests that stub those builders hit undefined on the mocked module. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
@greptile |
|
@cursor review |
The scroll effect's empty dep array meant it ran only on the first render, when `chatConfig` is still loading and the component returns `<ChatLoadingState />` — so `messagesContainerRef.current` was null and the listener was never attached. Depend on the gating conditions that control which tree renders, so the effect re-runs once the real container is in the DOM (and re-attaches when toggling in/out of voice mode). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
@greptile |
|
@cursor review |
Keying `<ChatClient>` on `identifier` guarantees a full remount on route transitions between chats, so `conversationId`, `messages`, and every other piece of local state start fresh — no reset effect required. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ 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 3220eea. Configure here.
Summary
dbChainMock/dbChainMockFns— remove hoisted chain-wiring boilerplatedbChainMockhelper in@sim/testingto cover insert/update/delete/transaction/execute patternsuseGitHubStarsanduseVoiceSettingsreact-query hooks from inline fetchesauthMockFns,hybridAuthMockFns) and update sim-testing docsType of Change
Testing
Tested manually — full test suite (300 files, 5310 tests) passes; type-check and lint pass across all 8 packages
Checklist