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.6 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { rm, stat } from 'node:fs/promises'
import { basename } from 'node:path'
import {
  buildJcodeRuntimeDir,
  buildJcodeRuntimeDirEnv,
  ensureJcodeRuntimeDir,
  JCODE_RUNTIME_DIR_ENV_KEY,
  shouldInjectJcodeRuntimeDir
} from './jcode-runtime-dir'

describe('shared jcode-runtime-dir', () => {
  it('derives a short deterministic hash per pane', () => {
    const paneKey = 'tab-abc:leaf-123'
    const dir = buildJcodeRuntimeDir(paneKey)
    expect(basename(dir)).toMatch(/^[0-9a-f]{16}$/)
    expect(buildJcodeRuntimeDir(paneKey)).toBe(dir)
  })

  it('keeps runtime dirs distinct across panes', () => {
    expect(buildJcodeRuntimeDir('tab-a:leaf-1')).not.toBe(buildJcodeRuntimeDir('tab-a:leaf-2'))
  })

  it('builds the env only on unix platforms', () => {
    expect(buildJcodeRuntimeDirEnv('tab-a:leaf-b', 'darwin')).toEqual({
      [JCODE_RUNTIME_DIR_ENV_KEY]: buildJcodeRuntimeDir('tab-a:leaf-b')
    })
    expect(buildJcodeRuntimeDirEnv('tab-a:leaf-b', 'linux')).toBeDefined()
    expect(buildJcodeRuntimeDirEnv('tab-a:leaf-b', 'win32')).toBeUndefined()
    expect(shouldInjectJcodeRuntimeDir('win32')).toBe(false)
  })

  it('ensures the runtime dir exists and returns the env on unix', async () => {
    const paneKey = 'tab-a:leaf-c'
    const dir = buildJcodeRuntimeDir(paneKey)
    const env = await ensureJcodeRuntimeDir(paneKey, 'darwin')
    expect(env).toEqual({ [JCODE_RUNTIME_DIR_ENV_KEY]: dir })
    expect((await stat(dir)).isDirectory()).toBe(true)
    expect(await ensureJcodeRuntimeDir(paneKey, 'win32')).toBeUndefined()
    await rm(dir, { recursive: true, force: true })
  })
})