Files
orca/src/shared/quick-open-readdir-memory.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

93 lines
3.0 KiB
TypeScript

import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import {
createQuickOpenReaddirBudget,
listQuickOpenFilesWithReaddir
} from './quick-open-readdir-walk'
const tempRoots: string[] = []
async function makeRoot(): Promise<string> {
const root = await mkdtemp(join(tmpdir(), 'orca-quick-open-budget-'))
tempRoots.push(root)
return root
}
afterEach(async () => {
await Promise.all(tempRoots.splice(0).map((root) => rm(root, { recursive: true, force: true })))
})
describe('quick-open readdir memory limits', () => {
it('accepts the exact entry limit and rejects the next zero-file entry', async () => {
const root = await makeRoot()
await mkdir(join(root, 'a'))
await mkdir(join(root, 'b'))
await expect(
listQuickOpenFilesWithReaddir(root, {
budget: createQuickOpenReaddirBudget({ maxEntries: 2 })
})
).resolves.toEqual([])
await mkdir(join(root, 'c'))
await expect(
listQuickOpenFilesWithReaddir(root, {
budget: createQuickOpenReaddirBudget({ maxEntries: 2 })
})
).rejects.toThrow('File listing exceeded 2 entries')
})
it('caps retained directory paths even when the tree contains no files', async () => {
const root = await makeRoot()
await mkdir(join(root, 'a'))
await mkdir(join(root, 'b'))
await expect(
listQuickOpenFilesWithReaddir(root, {
budget: createQuickOpenReaddirBudget({ maxDirectories: 3 })
})
).resolves.toEqual([])
await expect(
listQuickOpenFilesWithReaddir(root, {
budget: createQuickOpenReaddirBudget({ maxDirectories: 2 })
})
).rejects.toThrow('File listing exceeded 2 directories')
})
it('accepts the exact depth limit and rejects a deeper directory', async () => {
const root = await makeRoot()
await mkdir(join(root, 'a', 'b'), { recursive: true })
await expect(
listQuickOpenFilesWithReaddir(root, {
budget: createQuickOpenReaddirBudget({ maxDepth: 2 })
})
).resolves.toEqual([])
await expect(
listQuickOpenFilesWithReaddir(root, {
budget: createQuickOpenReaddirBudget({ maxDepth: 1 })
})
).rejects.toThrow('File listing exceeded depth 1')
})
it('bounds aggregate path storage without changing exact-boundary output', async () => {
const root = await makeRoot()
const fileName = 'a.ts'
await writeFile(join(root, fileName), 'x')
const exactPathCodeUnits = root.length + fileName.length * 2
await expect(
listQuickOpenFilesWithReaddir(root, {
budget: createQuickOpenReaddirBudget({ maxPathCodeUnits: exactPathCodeUnits })
})
).resolves.toEqual([fileName])
await expect(
listQuickOpenFilesWithReaddir(root, {
budget: createQuickOpenReaddirBudget({ maxPathCodeUnits: exactPathCodeUnits - 1 })
})
).rejects.toThrow(`File listing exceeded ${exactPathCodeUnits - 1} path code units`)
})
})