mirror of
https://github.com/stablyai/orca.git
synced 2026-10-09 08:02:35 +00:00
* feat(serve): run orca serve on the local orcad slot behind ORCA_SERVE_RUNTIME=orcad (T6-11) * fix(serve): keep orcad selection app-side and wait out Windows temp cleanup * refactor(orcad): move the data-root privacy check out of the instance lock --------- Co-authored-by: m4air <m4air@Mac.localdomain>
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { OrcadInstanceLockError, type OrcadInstanceLock } from '../orcad/orcad-instance-lock'
|
|
import { acquireDesktopProfileInstanceLock } from './desktop-profile-instance-lock'
|
|
|
|
describe('the desktop share of the profile instance lock', () => {
|
|
it('takes the lock as the desktop', () => {
|
|
const lock: OrcadInstanceLock = Object.assign(Object.create(null), { release: vi.fn() })
|
|
const acquire = vi.fn(() => lock)
|
|
expect(acquireDesktopProfileInstanceLock('/profile', acquire)).toEqual({
|
|
state: 'acquired',
|
|
lock
|
|
})
|
|
expect(acquire).toHaveBeenCalledWith('/profile', { role: 'desktop' })
|
|
})
|
|
|
|
it('refuses while a live orcad serves the profile, and says so', () => {
|
|
const write = vi.fn()
|
|
const result = acquireDesktopProfileInstanceLock(
|
|
'/profile',
|
|
() => {
|
|
throw new OrcadInstanceLockError('orcad_instance_lock_held', 'Another orcad (pid 7) ...')
|
|
},
|
|
write
|
|
)
|
|
expect(result).toEqual({
|
|
state: 'held',
|
|
message: '[single-instance] Another orcad (pid 7) ...'
|
|
})
|
|
expect(write).toHaveBeenCalledWith(2, '[single-instance] Another orcad (pid 7) ...\n')
|
|
})
|
|
|
|
it('still starts when the lock cannot be taken for any other reason', () => {
|
|
vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
expect(
|
|
acquireDesktopProfileInstanceLock('/profile', () => {
|
|
throw new OrcadInstanceLockError('orcad_instance_lock_unreadable', 'unreadable')
|
|
})
|
|
).toEqual({ state: 'unavailable' })
|
|
})
|
|
})
|