From 9030600ccaffe32c1141675ab510d076e9949cb2 Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:44:50 +0800 Subject: [PATCH] Import packages/client-core/tests/history-fast-path.test.ts --- .../tests/history-fast-path.test.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 packages/client-core/tests/history-fast-path.test.ts diff --git a/packages/client-core/tests/history-fast-path.test.ts b/packages/client-core/tests/history-fast-path.test.ts new file mode 100644 index 0000000..eba22be --- /dev/null +++ b/packages/client-core/tests/history-fast-path.test.ts @@ -0,0 +1,21 @@ +import {describe,it,expect,vi} from 'vitest' +import {CodexRemoteClient} from '../src/codex-client.js' +import {runScenarios} from '../../../scripts/test-scenarios.mjs' +describe('history fast-path recovery',()=>{ + it('returns small history in one round trip and falls back only on explicit read-only compatibility/size errors',async()=>{ + await runScenarios([undefined,'INVALID_MESSAGE','RESPONSE_TOO_LARGE','RPC_TIMEOUT','RPC_ABORTED','PERMISSION_DENIED'].map(code => ({name:code ?? 'small history',run:async()=>{ + const rpc=vi.fn(async(method:string)=>{if(method==='codex.app.call'){if(code)throw Object.assign(Error(code),{code});return {records:[]}} + if(method==='codex.app.transfer.commit')return {kind:'inline',response:{records:[]}};return {}}) + const client=new CodexRemoteClient({rpc} as never,true) + if(code && !['INVALID_MESSAGE','RESPONSE_TOO_LARGE'].includes(code)) {await expect(client.request('dsh/sessionHistory',{threadId:'t'})).rejects.toMatchObject({code});expect(rpc).toHaveBeenCalledTimes(1)} + else {expect(await client.request('dsh/sessionHistory',{threadId:'t'})).toEqual({records:[]});expect(rpc).toHaveBeenCalledTimes(code?5:1)} + }}))) + }) +}) + +it('keeps legacy desktop/web history complete unless preview was explicitly enabled',async()=>{ + const rpc=vi.fn(async(method:string)=>method==='codex.app.transfer.commit'?{kind:'inline',response:{records:[]}}:{}) + await new CodexRemoteClient({rpc} as never).request('dsh/sessionHistory',{threadId:'t'}) + expect(rpc.mock.calls.some(call=>call[0]==='codex.app.call')).toBe(false) + expect(rpc).toHaveBeenCalledTimes(4) +})