test(engine): add a fake engine adapter behind the RPC seam - #29612
Draft
chrisnojima wants to merge 1 commit into
Draft
test(engine): add a fake engine adapter behind the RPC seam#29612chrisnojima wants to merge 1 commit into
chrisnojima wants to merge 1 commit into
Conversation
This was referenced Sep 9, 2026
chrisnojima
added this pull request to stack #29617
September 9, 2026 19:40
Every generated *RpcPromise and every engine listener already funnels through getEngine()._rpcOutgoing, but the seam had exactly one adapter, so tests reached past it and spied on whichever generated symbol the implementation happened to call. installFakeEngine answers at that chokepoint by wire-method string, counting calls, so a test says what the service returns rather than which function the module calls. The adapter resolves, rejects, drives incremental/streaming incoming callbacks through the real listener, holds and releases waitingKeys, and fails loudly (console.error, which test/fail-on-console turns into a failure, plus a rejection) on a method the test never stubbed, so an unstubbed RPC can never look like a load that simply never finished. Handlers are typed off the generated MessageTypes, so a misspelled wire method or a wrong return shape is a compile error. The seam type narrows from Engine to the four members it actually uses; no production behaviour changes. Converted six test files off jest.spyOn of generated RPC symbols. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rccpV5nLxxC5opF5xzrz7
chrisnojima
force-pushed
the
nojima/HOTPOT-arch-10-fake-engine
branch
from
September 11, 2026 01:47
5606d8f to
7b85df2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The RPC seam is well placed — every generated
*RpcPromiseroutes through one chokepoint,createRpc→engine()._rpcOutgoing— but it had exactly one adapter, so it was hypothetical and every data test reached past it.~45 test files
jest.spyOngenerated RPC symbols;thread-context.test.tsxalone spies 20. Tests therefore encoded which RPC the implementation happens to call, not what the module promises: swappingteamsGetAnnotatedTeamfor a different RPC breaks tests whose contract is unchanged.Change
A test-only adapter at the existing chokepoint:
Plus
calls/setHandlers/unhandledMethods/uninstall.Handler maps are typed off the generated
MessageTypes, so a misspelled wire method or a wrong return shape is a compile error — it immediately caught one that an existingas neverspy had hidden.Covers resolve, reject, streaming through the real listener,
waitingKeyaccounting into the real waiting store, and cancel. Unhandled methods bothconsole.error(whichfail-on-consoleturns into a failure even if the caller swallows the rejection) and reject, so a test calling an RPC it didn't stub fails loudly rather than hanging.The only production change:
initEngine/getEnginenarrow toEngineSeam = Pick<Engine, '_rpcOutgoing' | 'cancelSession' | 'createSession' | 'dispatchWaitingAction'>, plus aresetEngine().Converted
6 test files off
jest.spyOnof generated symbols:use-loaded-team,chat/inbox/refresh-participants(10 spies),chat/conversation/team-hooks,info-panel/add-to-channel,status-actions,messages/reset-user.Not converted:
thread-context.test.tsx(2097 lines, 20 spies). Its spies replace the RPC listener wholesale and driveincomingCallMapsynchronously, so routing them through the real listener's macrotask deferral means rewriting all 20 tests' flush strategy. Deserves its own PR.Validation
lint:allclean —0 bailed out, 0 whole-props deps, tsc clean both projects.jest --runInBand— 231 suites / 2247 tests (baseline 230 / 2236).