mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 16:02:32 +00:00
* oom(01): A1-shared-readers — reintroduce #10179 subset Files: 18 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(02): A2-shared-image-media — reintroduce #10179 subset Files: 7 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(03): A3-shared-fs-listing — reintroduce #10179 subset Files: 21 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(04): A4-shared-remote-relay — reintroduce #10179 subset Files: 8 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(05): A5-shared-misc — reintroduce #10179 subset Files: 28 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(06): B-shared-wiring — reintroduce #10179 subset Files: 81 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { closeSync, ftruncateSync, mkdtempSync, openSync, rmSync, writeFileSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { NodeFileReadTooLargeError, readNodeFileSyncWithinLimit } from './node-bounded-file-reader'
|
|
|
|
const tempDirectories: string[] = []
|
|
|
|
function createTempFile(content: string): string {
|
|
const directory = mkdtempSync(join(tmpdir(), 'orca-bounded-sync-read-'))
|
|
tempDirectories.push(directory)
|
|
const path = join(directory, 'input')
|
|
writeFileSync(path, content)
|
|
return path
|
|
}
|
|
|
|
afterEach(() => {
|
|
for (const directory of tempDirectories.splice(0)) {
|
|
rmSync(directory, { recursive: true })
|
|
}
|
|
})
|
|
|
|
describe('readNodeFileSyncWithinLimit', () => {
|
|
it('returns stable bytes without changing them', () => {
|
|
const path = createTempFile('stable 🐋 bytes')
|
|
|
|
expect(readNodeFileSyncWithinLimit(path, 1024).buffer.toString('utf8')).toBe('stable 🐋 bytes')
|
|
})
|
|
|
|
it('rejects an oversized sparse file before allocating its declared size', () => {
|
|
const path = createTempFile('')
|
|
const descriptor = openSync(path, 'r+')
|
|
ftruncateSync(descriptor, 1025)
|
|
closeSync(descriptor)
|
|
|
|
expect(() => readNodeFileSyncWithinLimit(path, 1024)).toThrow(NodeFileReadTooLargeError)
|
|
})
|
|
})
|