mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
157 lines
5.1 KiB
TypeScript
157 lines
5.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
||
import {
|
||
describeRuntimeCompatBlock,
|
||
evaluateCompat,
|
||
evaluateRuntimeCompat
|
||
} from './protocol-compat'
|
||
import {
|
||
DESKTOP_PROTOCOL_VERSION,
|
||
MIN_COMPATIBLE_MOBILE_VERSION,
|
||
MIN_COMPATIBLE_RUNTIME_SERVER_VERSION,
|
||
RUNTIME_PROTOCOL_VERSION
|
||
} from './protocol-version'
|
||
|
||
const MOBILE_V = 1
|
||
|
||
describe('evaluateCompat', () => {
|
||
it('allows desktop protocol 3 to roll out before mobile protocol 2 updates', () => {
|
||
const verdict = evaluateCompat({
|
||
mobileProtocolVersion: 2,
|
||
minCompatibleDesktopVersion: 2,
|
||
desktopProtocolVersion: 3,
|
||
desktopMinCompatibleMobileVersion: 2
|
||
})
|
||
|
||
expect(verdict).toEqual({ kind: 'ok' })
|
||
})
|
||
|
||
it('allows mobile protocol 3 to roll out before desktop protocol 2 updates', () => {
|
||
const verdict = evaluateCompat({
|
||
mobileProtocolVersion: 3,
|
||
minCompatibleDesktopVersion: 2,
|
||
desktopProtocolVersion: 2,
|
||
desktopMinCompatibleMobileVersion: 2
|
||
})
|
||
|
||
expect(verdict).toEqual({ kind: 'ok' })
|
||
})
|
||
|
||
it('blocks with mobile-too-old when desktop requires a newer mobile', () => {
|
||
const verdict = evaluateCompat({
|
||
mobileProtocolVersion: MOBILE_V,
|
||
minCompatibleDesktopVersion: 0,
|
||
desktopProtocolVersion: 5,
|
||
desktopMinCompatibleMobileVersion: MOBILE_V + 1
|
||
})
|
||
expect(verdict).toEqual({
|
||
kind: 'blocked',
|
||
reason: 'mobile-too-old',
|
||
desktopVersion: 5,
|
||
requiredMobileVersion: MOBILE_V + 1
|
||
})
|
||
})
|
||
|
||
it('blocks with desktop-too-old when desktop reports below the local minimum', () => {
|
||
const verdict = evaluateCompat({
|
||
mobileProtocolVersion: MOBILE_V,
|
||
minCompatibleDesktopVersion: 5,
|
||
desktopProtocolVersion: 3,
|
||
desktopMinCompatibleMobileVersion: 0
|
||
})
|
||
expect(verdict).toEqual({
|
||
kind: 'blocked',
|
||
reason: 'desktop-too-old',
|
||
desktopVersion: 3,
|
||
requiredDesktopVersion: 5
|
||
})
|
||
})
|
||
|
||
it('mobile-too-old wins precedence when both constraints would fire', () => {
|
||
// Desktop’s too-old-mobile kill switch outranks mobile’s local judgment of desktop age.
|
||
const verdict = evaluateCompat({
|
||
mobileProtocolVersion: MOBILE_V,
|
||
minCompatibleDesktopVersion: 99,
|
||
desktopProtocolVersion: -1,
|
||
desktopMinCompatibleMobileVersion: MOBILE_V + 1
|
||
})
|
||
expect(verdict.kind).toBe('blocked')
|
||
expect((verdict as { reason: string }).reason).toBe('mobile-too-old')
|
||
})
|
||
|
||
it('hard-blocks protocol-1 mobile for the binary terminal stream cutover', () => {
|
||
const verdict = evaluateCompat({
|
||
mobileProtocolVersion: 1,
|
||
minCompatibleDesktopVersion: DESKTOP_PROTOCOL_VERSION,
|
||
desktopProtocolVersion: DESKTOP_PROTOCOL_VERSION,
|
||
desktopMinCompatibleMobileVersion: MIN_COMPATIBLE_MOBILE_VERSION
|
||
})
|
||
|
||
expect(verdict).toEqual({
|
||
kind: 'blocked',
|
||
reason: 'mobile-too-old',
|
||
desktopVersion: DESKTOP_PROTOCOL_VERSION,
|
||
requiredMobileVersion: MIN_COMPATIBLE_MOBILE_VERSION
|
||
})
|
||
})
|
||
})
|
||
|
||
describe('evaluateRuntimeCompat', () => {
|
||
it('allows client and server app versions to skew when protocol ranges overlap', () => {
|
||
const verdict = evaluateRuntimeCompat({
|
||
clientProtocolVersion: RUNTIME_PROTOCOL_VERSION,
|
||
minCompatibleServerProtocolVersion: MIN_COMPATIBLE_RUNTIME_SERVER_VERSION,
|
||
serverProtocolVersion: RUNTIME_PROTOCOL_VERSION + 3,
|
||
serverMinCompatibleClientProtocolVersion: RUNTIME_PROTOCOL_VERSION - 1
|
||
})
|
||
|
||
expect(verdict).toMatchObject({ kind: 'ok' })
|
||
})
|
||
|
||
it('blocks when the server requires a newer client protocol', () => {
|
||
const verdict = evaluateRuntimeCompat({
|
||
clientProtocolVersion: RUNTIME_PROTOCOL_VERSION,
|
||
minCompatibleServerProtocolVersion: MIN_COMPATIBLE_RUNTIME_SERVER_VERSION,
|
||
serverProtocolVersion: RUNTIME_PROTOCOL_VERSION + 1,
|
||
serverMinCompatibleClientProtocolVersion: RUNTIME_PROTOCOL_VERSION + 1
|
||
})
|
||
|
||
expect(verdict).toMatchObject({
|
||
kind: 'blocked',
|
||
reason: 'client-too-old',
|
||
requiredClientProtocolVersion: RUNTIME_PROTOCOL_VERSION + 1
|
||
})
|
||
expect(describeRuntimeCompatBlock(verdict)).toContain('client is too old')
|
||
})
|
||
|
||
it('blocks when the server protocol is below the client minimum', () => {
|
||
const verdict = evaluateRuntimeCompat({
|
||
clientProtocolVersion: RUNTIME_PROTOCOL_VERSION,
|
||
minCompatibleServerProtocolVersion: RUNTIME_PROTOCOL_VERSION,
|
||
serverProtocolVersion: RUNTIME_PROTOCOL_VERSION - 1,
|
||
serverMinCompatibleClientProtocolVersion: 0
|
||
})
|
||
|
||
expect(verdict).toMatchObject({
|
||
kind: 'blocked',
|
||
reason: 'server-too-old',
|
||
requiredServerProtocolVersion: RUNTIME_PROTOCOL_VERSION
|
||
})
|
||
expect(describeRuntimeCompatBlock(verdict)).toContain('server is too old')
|
||
})
|
||
|
||
it('treats missing server fields as protocol 0', () => {
|
||
const verdict = evaluateRuntimeCompat({
|
||
clientProtocolVersion: RUNTIME_PROTOCOL_VERSION,
|
||
minCompatibleServerProtocolVersion: 1,
|
||
serverProtocolVersion: undefined,
|
||
serverMinCompatibleClientProtocolVersion: undefined
|
||
})
|
||
|
||
expect(verdict).toMatchObject({
|
||
kind: 'blocked',
|
||
reason: 'server-too-old',
|
||
serverProtocolVersion: 0
|
||
})
|
||
})
|
||
})
|