Files
orca/src/shared/ephemeral-vm-recipe-process.test.ts
T
NeilandOrca 879aad7dd6 oom(foundation): bound shared readers/limits + add BoundedMap primitive (#10299)
* oom(01): A1-shared-readers — reintroduce #10179 subset

Files: 18 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(02): A2-shared-image-media — reintroduce #10179 subset

Files: 7 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(03): A3-shared-fs-listing — reintroduce #10179 subset

Files: 21 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(04): A4-shared-remote-relay — reintroduce #10179 subset

Files: 8 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(05): A5-shared-misc — reintroduce #10179 subset

Files: 28 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(06): B-shared-wiring — reintroduce #10179 subset

Files: 81 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-07-24 21:36:57 -07:00

94 lines
2.7 KiB
TypeScript

import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { runRecipeCommand } from './ephemeral-vm-recipe-process'
const tmpRoots: string[] = []
afterEach(() => {
for (const root of tmpRoots.splice(0)) {
rmSync(root, { recursive: true, force: true })
}
})
function makeRepo(): string {
const root = mkdtempSync(join(tmpdir(), 'orca-vm-recipe-process-'))
tmpRoots.push(root)
return root
}
function nodeCommand(scriptPath: string): string {
return `"${process.execPath}" "${scriptPath}"`
}
describe('runRecipeCommand', () => {
it.each([
{ output: 'abcdef', maxCaptureBytes: 4, expected: 'cdef' },
{ output: 'A😀B', maxCaptureBytes: 5, expected: '😀B' },
{ output: '😀😀😀', maxCaptureBytes: 5, expected: '😀' }
])(
'retains a complete UTF-8 tail within $maxCaptureBytes bytes',
async ({ output, maxCaptureBytes, expected }) => {
const repoPath = makeRepo()
const scriptPath = join(repoPath, 'output.js')
writeFileSync(scriptPath, `process.stdout.write(${JSON.stringify(output)})`)
const result = await runRecipeCommand({
command: nodeCommand(scriptPath),
repoPath,
mode: 'create',
context: {
recipeId: 'cloud-sandbox',
repoPath
},
maxCaptureBytes
})
expect(result.stdout).toBe(expected)
expect(Buffer.byteLength(result.stdout, 'utf8')).toBeLessThanOrEqual(maxCaptureBytes)
}
)
it.skipIf(process.platform === 'win32')(
'cancels shell child processes without waiting for long-running descendants',
async () => {
const repoPath = makeRepo()
const scriptPath = join(repoPath, 'slow.js')
writeFileSync(
scriptPath,
[
"process.stderr.write('ready\\n')",
'setTimeout(() => {',
" console.log('done')",
'}, 5000)'
].join('\n')
)
const controller = new AbortController()
const result = await Promise.race([
runRecipeCommand({
command: nodeCommand(scriptPath),
repoPath,
mode: 'create',
context: {
recipeId: 'cloud-sandbox',
repoPath
},
signal: controller.signal,
onStderr: (chunk) => {
if (chunk.includes('ready')) {
controller.abort()
}
}
}),
new Promise<never>((_, reject) => {
setTimeout(() => reject(new Error('recipe cancellation timed out')), 1500)
})
])
expect(result.signal).toBe('SIGTERM')
}
)
})