From 71d8c6a1e2eaad5fe3578c114613b8fabcbcf690 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Tue, 15 Sep 2026 23:21:08 -0400 Subject: [PATCH] test(mobile): narrow the incompatible-reply error by instanceof, not by cast The two new tests in f741b2ea82 read the error through `as` casts, which the changed-code casting gate rejects. An `instanceof` guard narrows the same value and checks the class at the same time. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb --- mobile/src/transport/rpc-operation.test.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mobile/src/transport/rpc-operation.test.ts b/mobile/src/transport/rpc-operation.test.ts index a05170cb2a8..aaa0815bb87 100644 --- a/mobile/src/transport/rpc-operation.test.ts +++ b/mobile/src/transport/rpc-operation.test.ts @@ -330,12 +330,13 @@ describe('an incompatible reply', () => { {} ).catch((thrown: unknown) => thrown) - expect((caught as Error).message).toBe( - 'The host sent a reply this app could not read (worktree.ps)' - ) - expect((caught as Error).message).not.toContain('incompatible_reply') - expect((caught as RpcIncompatibleReplyError).code).toBe(RPC_INCOMPATIBLE_REPLY_CODE) - expect((caught as Error).name).toBe('RpcIncompatibleReplyError') + if (!(caught instanceof RpcIncompatibleReplyError)) { + throw new Error('expected an incompatible-reply error') + } + expect(caught.message).toBe('The host sent a reply this app could not read (worktree.ps)') + expect(caught.message).not.toContain('incompatible_reply') + expect(caught.code).toBe(RPC_INCOMPATIBLE_REPLY_CODE) + expect(caught.name).toBe('RpcIncompatibleReplyError') }) // A second bundle copy of this module fails `instanceof`, so the name is the fallback.