49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { expect, it, vi } from 'vitest'
|
|
|
|
import { createMobileBackendResolver } from './mobile-backend'
|
|
|
|
const local = { mode: 'local', baseUrl: 'http://127.0.0.1:12345', token: 'test-session' }
|
|
|
|
it('uses the phone profile even while another desktop profile is awaiting setup', async () => {
|
|
const ensureBackend = vi.fn(async (profile: string) => {
|
|
if (profile === 'fusion-frontier') return new Promise<typeof local>(() => {})
|
|
return local
|
|
})
|
|
const resolve = createMobileBackendResolver({
|
|
isRemote: () => false,
|
|
runtimeNeedsInstall: () => false,
|
|
ensureBackend
|
|
})
|
|
expect(await resolve('default')).toEqual({ baseUrl: local.baseUrl, token: local.token })
|
|
expect(ensureBackend).toHaveBeenCalledExactlyOnceWith('default')
|
|
})
|
|
|
|
it('never bootstraps an absent runtime or silently replaces a remote profile with default', async () => {
|
|
const ensureBackend = vi.fn(async () => local)
|
|
const resolve = createMobileBackendResolver({
|
|
isRemote: profile => profile === 'remote',
|
|
runtimeNeedsInstall: () => true,
|
|
ensureBackend
|
|
})
|
|
await expect(resolve('default')).rejects.toThrow('runtime_not_ready')
|
|
await expect(resolve('remote')).rejects.toThrow('remote_mode')
|
|
expect(ensureBackend).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('preserves an explicitly selected local profile and rejects remote-mode changes during resolution', async () => {
|
|
let remote = false
|
|
const ensureBackend = vi.fn(async () => local)
|
|
const resolve = createMobileBackendResolver({
|
|
isRemote: () => remote,
|
|
runtimeNeedsInstall: () => false,
|
|
ensureBackend
|
|
})
|
|
await resolve('kodlama')
|
|
expect(ensureBackend).toHaveBeenCalledExactlyOnceWith('kodlama')
|
|
ensureBackend.mockImplementationOnce(async () => {
|
|
remote = true
|
|
return local
|
|
})
|
|
await expect(resolve('kodlama')).rejects.toThrow('remote_mode')
|
|
})
|