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.

2.0 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import {
  agentSessionPromptQuestions,
  isValidAgentSessionQuestionAnswers,
  legacyAgentSessionQuestionAnswers,
  legacyAgentSessionSelectedOptionId
} from './agent-session-question-answer'

describe('provider free-text question metadata', () => {
  const body = {
    question: 'Edit the text',
    options: [],
    freeTextQuestionId: 'editor:1',
    freeTextInput: { allowEmpty: true, multiline: true, initialValue: 'first\nsecond' }
  }

  it.each([
    ['', 'editor%3A1:'],
    ['  ', 'editor%3A1:%20%20'],
    [
      ' first\nsecond\u2028third\u2029fourth ',
      'editor%3A1:%20first%0Asecond%E2%80%A8third%E2%80%A9fourth%20'
    ]
  ])('preserves the exact answer %j across the older wire form', (other, expectedEncoded) => {
    const answers = [{ questionId: 'editor:1', optionIds: [], other }]
    const encoded = legacyAgentSessionSelectedOptionId(body, answers)
    expect(encoded).toBe(expectedEncoded)
    expect(legacyAgentSessionQuestionAnswers(body, encoded!)).toEqual(answers)
    expect(isValidAgentSessionQuestionAnswers(agentSessionPromptQuestions(body), answers)).toBe(
      true
    )
  })

  it('requires an explicitly supplied answer even when empty is allowed', () => {
    expect(
      isValidAgentSessionQuestionAnswers(agentSessionPromptQuestions(body), [
        { questionId: 'editor:1', optionIds: [] }
      ])
    ).toBe(false)
    expect(legacyAgentSessionQuestionAnswers(body, 'another:')).toBeNull()
  })

  it('keeps the previous empty-answer rejection when metadata is absent', () => {
    const legacy = {
      question: 'Provide text',
      options: [],
      freeTextQuestionId: 'q1',
      freeTextInput: undefined
    }
    const answers = [{ questionId: 'q1', optionIds: [], other: '  ' }]
    expect(isValidAgentSessionQuestionAnswers(agentSessionPromptQuestions(legacy), answers)).toBe(
      false
    )
    expect(legacyAgentSessionSelectedOptionId(legacy, answers)).toBeNull()
    expect(legacyAgentSessionQuestionAnswers(legacy, 'q1:')).toBeNull()
  })
})