Import apps/android/tests/remote-runtime.test.ts

This commit is contained in:
QQ 2026-11-17 08:36:07 +08:00
parent 2609d6c418
commit 3c7679409f
1 changed files with 24 additions and 1 deletions

View File

@ -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()
})