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.

1.2 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import {
  limitQuickOpenFilesBySerializedBytes,
  limitQuickOpenSearchReplyBySerializedBytes
} from './quick-open-transport-budget'

describe('Quick Open transport byte budget', () => {
  it('returns the largest prefix that fits as a JSON array', () => {
    const files = ['src/a.ts', 'data/ignored\nfile.bin', 'src/b.ts']
    const budget = Buffer.byteLength(JSON.stringify(files.slice(0, 2)), 'utf8')
    expect(limitQuickOpenFilesBySerializedBytes(files, budget)).toEqual(files.slice(0, 2))
  })

  it('drops the lowest-ranked reply entries until the complete result fits', () => {
    const result = {
      worktree: 'wt-1',
      rootPath: '/repo',
      files: [
        { relativePath: 'src/b.ts', basename: 'b.ts', kind: 'text' as const },
        { relativePath: 'src/a.ts', basename: 'a.ts', kind: 'text' as const }
      ],
      totalCount: 2,
      truncated: false
    }
    const budget = Buffer.byteLength(
      JSON.stringify({ ...result, files: result.files.slice(0, 1) }),
      'utf8'
    )
    expect(limitQuickOpenSearchReplyBySerializedBytes(result, budget).files).toHaveLength(1)
    expect(limitQuickOpenSearchReplyBySerializedBytes(result, budget).truncated).toBe(true)
  })
})