mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
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 })
|
|
})
|
|
})
|