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.8 KB
Raw Blame
// @vitest-environment happy-dom
import { Terminal } from '@xterm/xterm'
import { afterEach, describe, expect, it } from 'vitest'
import { createTerminalDocumentScope, type TerminalDocumentScope } from './document-scope'
import { attachOsc52ClipboardBridge } from './osc52-clipboard-bridge'
import { resetTerminalDataReplyAuthority, resumeTerminalDataReplyAuthority } from './query-reply'

const terminals: Terminal[] = []

afterEach(() => {
  terminals.splice(0).forEach((term) => term.dispose())
})

function fixture() {
  const posted: unknown[] = []
  const scope = createTerminalDocumentScope({ postToHost: (message) => posted.push(message) })
  const term = new Terminal({ cols: 80, rows: 4, allowProposedApi: true })
  terminals.push(term)
  // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the real xterm exposes the narrower document terminal API.
  attachOsc52ClipboardBridge(scope, term as unknown as NonNullable<TerminalDocumentScope['term']>)
  const write = async (data: string) => {
    await new Promise<void>((resolve) => term.write(data, resolve))
    await Promise.resolve()
  }
  return { scope, posted, write }
}

// Match Claude Code’s /btw copy control sequence.
const BTW_COPY = `\x1b]52;c;${Buffer.from('hello from btw').toString('base64')}\x07`

describe('OSC 52 in the mobile terminal document', () => {
  it('posts a live copy to native as clipboard text', async () => {
    const { scope, posted, write } = fixture()
    resumeTerminalDataReplyAuthority(scope)
    await write(BTW_COPY)
    expect(posted).toEqual([{ type: 'clipboard-write', text: 'hello from btw' }])
  })

  it('drops a copy parsed before the replay boundary', async () => {
    const { scope, posted, write } = fixture()
    resetTerminalDataReplyAuthority(scope)
    await write(BTW_COPY)
    expect(posted).toEqual([])
  })
})