Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

5.1 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { CODEX_SESSION_OPTION_CATALOG } from './agent-session-option-catalog-claude-codex'
import {
  applyNativeChatSessionOptionPicks,
  resolveStructuredLaunchSeedOptions,
  updateNativeChatSessionOptionDefaults
} from './native-chat/input/native-chat-session-option-defaults'
import type {
  PersistedNativeChatSessionOptions,
  SessionOptionValue
} from './native-chat/input/native-chat-session-options'
import {
  applyStructuredAgentSessionOptions,
  createStructuredAgentSessionOptionState,
  structuredAgentSessionOptionPicks
} from './structured-agent-session-options'

function liveState(current: { model: string; effort?: string; fastMode?: boolean }) {
  return applyStructuredAgentSessionOptions(
    createStructuredAgentSessionOptionState('codex'),
    CODEX_SESSION_OPTION_CATALOG,
    {
      models: [
        {
          id: 'account-model',
          label: 'Account Model',
          isDefault: true,
          defaultEffort: 'medium',
          efforts: [
            { value: 'medium', label: 'Medium' },
            { value: 'high', label: 'High' }
          ],
          supportsFastMode: true
        },
        {
          id: 'other-model',
          label: 'Other Model',
          isDefault: false,
          defaultEffort: 'low',
          efforts: [
            { value: 'low', label: 'Low' },
            { value: 'medium', label: 'Medium' }
          ],
          supportsFastMode: true
        }
      ],
      fastModeSupport: { supported: true },
      current
    }
  )
}

function persist(
  picks: readonly { modelId: string; optionId: string; value: SessionOptionValue }[]
): PersistedNativeChatSessionOptions {
  return applyNativeChatSessionOptionPicks({ persisted: undefined, agent: 'codex', picks })
}

describe('structuredAgentSessionOptionPicks', () => {
  it('pins the model an effort-only pick was chosen against', () => {
    const picks = structuredAgentSessionOptionPicks(liveState({ model: 'account-model' }), {
      effort: 'high'
    })
    expect(picks).toEqual([{ modelId: 'account-model', optionId: 'effort', value: 'high' }])
    // Without the model the launch resolves nothing at all, so the effort would be dead.
    expect(resolveStructuredLaunchSeedOptions(persist(picks), 'codex')).toEqual({
      model: 'account-model',
      effort: 'high'
    })
  })

  it('remembers the effort the provider reconciled, not the one in force before', () => {
    const state = liveState({ model: 'account-model', effort: 'high' })
    const picks = structuredAgentSessionOptionPicks(state, {
      model: 'other-model',
      effort: 'low'
    })
    expect(picks).toEqual([
      { modelId: 'other-model', optionId: 'model', value: 'other-model' },
      { modelId: 'other-model', optionId: 'effort', value: 'low' }
    ])
    expect(resolveStructuredLaunchSeedOptions(persist(picks), 'codex')).toEqual({
      model: 'other-model',
      effort: 'low'
    })
  })

  it('keeps a per-model effort so reselecting the old model restores its level', () => {
    const persisted = persist([
      ...structuredAgentSessionOptionPicks(liveState({ model: 'account-model' }), {
        effort: 'high'
      }),
      ...structuredAgentSessionOptionPicks(liveState({ model: 'account-model', effort: 'high' }), {
        model: 'other-model',
        effort: 'low'
      })
    ])
    const reselected = updateNativeChatSessionOptionDefaults({
      persisted,
      agent: 'codex',
      modelId: 'account-model',
      optionId: 'model',
      value: 'account-model'
    })
    expect(resolveStructuredLaunchSeedOptions(reselected, 'codex')).toEqual({
      model: 'account-model',
      effort: 'high'
    })
  })

  it('writes nothing before the provider catalog lands', () => {
    expect(
      structuredAgentSessionOptionPicks(createStructuredAgentSessionOptionState('codex'), {
        effort: 'high'
      })
    ).toEqual([])
  })

  it('drops ids a launch cannot seed back', () => {
    expect(
      structuredAgentSessionOptionPicks(liveState({ model: 'account-model' }), {
        permissionMode: 'plan'
      })
    ).toEqual([])
  })

  it('remembers explicit Fast on and off as booleans and re-encodes the launch seed', () => {
    const state = liveState({ model: 'account-model', fastMode: true })
    const picks = structuredAgentSessionOptionPicks(state, { fastMode: 'false' })
    expect(picks).toEqual([{ modelId: 'account-model', optionId: 'fastMode', value: false }])
    expect(resolveStructuredLaunchSeedOptions(persist(picks), 'codex')).toEqual({
      model: 'account-model',
      fastMode: 'false'
    })
  })
})

describe('applyNativeChatSessionOptionPicks', () => {
  it('leaves every other agent untouched', () => {
    const persisted = applyNativeChatSessionOptionPicks({
      persisted: { claude: { model: 'opus', valuesByModel: { opus: { effort: 'high' } } } },
      agent: 'codex',
      picks: [{ modelId: 'gpt-fast', optionId: 'effort', value: 'low' }]
    })
    expect(resolveStructuredLaunchSeedOptions(persisted, 'claude')).toEqual({
      model: 'opus',
      effort: 'high'
    })
    expect(resolveStructuredLaunchSeedOptions(persisted, 'codex')).toEqual({
      model: 'gpt-fast',
      effort: 'low'
    })
  })
})