diff --git a/apps/android/tests/remote-runtime.test.ts b/apps/android/tests/remote-runtime.test.ts index 6c95791..90c675e 100644 --- a/apps/android/tests/remote-runtime.test.ts +++ b/apps/android/tests/remote-runtime.test.ts @@ -4,12 +4,14 @@ import type { AndroidConnectionOptions } from '../src/services/connection' import type { DeviceIdentity, RemoteDevice } from '../src/types' const { client, service } = vi.hoisted(() => ({ - client: { connect: vi.fn(), close: vi.fn() }, + client: { connect: vi.fn(), close: vi.fn(), rpc: vi.fn(), supportsBinaryUpload: vi.fn() }, service: { start: vi.fn(), stop: vi.fn(), setStatus: vi.fn() }, })) vi.mock('../src/services/connection', () => ({ AndroidRemoteConnection: class { connect = client.connect close = client.close + rpc = client.rpc + supportsBinaryUpload = client.supportsBinaryUpload } })) vi.mock('../src/services/foreground-service', () => ({ foregroundService: service })) import { AndroidRemoteRuntime } from '../src/services/remote-runtime' @@ -190,3 +192,24 @@ describe('Android carrier foreground service ownership', () => { ], prepare) }) }) + +it('binds upload RPC callers to one connection generation, including reconnect to the same Host', async () => { + const runtime = new AndroidRemoteRuntime() + client.supportsBinaryUpload.mockReturnValue(true) + client.rpc.mockResolvedValue({ok:true}) + await connect(runtime) + const first = runtime.createRpcCaller() + expect(first.supportsBinaryUpload).toBe(true) + await first('workspace.upload.open',{}) + await runtime.close() + await connect(runtime) + await expect(first('workspace.upload.chunk.binary',{})).rejects.toThrow('replaced') + expect(client.rpc).toHaveBeenCalledTimes(1) + const second = runtime.createRpcCaller() + await second('workspace.upload.open',{}) + const options = client.connect.mock.calls.at(-1)![5] as AndroidConnectionOptions + options.onClose?.({retryable:true}) + await expect(second('workspace.upload.commit',{})).rejects.toThrow('closed') + expect(client.rpc).toHaveBeenCalledTimes(2) + await runtime.close() +})